suport Quick Access by Ctrl+Alt+I

This commit is contained in:
Le Tan 2018-09-06 21:11:55 +08:00
parent 3d188fa648
commit c4c7f99ca7
13 changed files with 188 additions and 27 deletions

View File

@ -283,10 +283,33 @@ VGeneralTab::VGeneralTab(QWidget *p_parent)
// Startup pages.
QLayout *startupLayout = setupStartupPagesLayout();
// Quick access.
m_quickAccessEdit = new VLineEdit(this);
m_quickAccessEdit->setPlaceholderText(tr("Path of file to quick access"));
m_quickAccessEdit->setToolTip(tr("Set the path of a file to quick access "
"(absolute or relative to configuration folder)"));
QPushButton *browseBtn = new QPushButton(tr("Browse"), this);
connect(browseBtn, &QPushButton::clicked,
this, [this]() {
QString filePath = QFileDialog::getOpenFileName(this,
tr("Select File To Quick Access"),
g_config->getDocumentPathOrHomePath());
if (!filePath.isEmpty()) {
m_quickAccessEdit->setText(filePath);
}
});
QHBoxLayout *qaLayout = new QHBoxLayout();
qaLayout->addWidget(m_quickAccessEdit);
qaLayout->addWidget(browseBtn);
QFormLayout *optionLayout = new QFormLayout();
optionLayout->addRow(tr("Language:"), m_langCombo);
optionLayout->addRow(m_systemTray);
optionLayout->addRow(tr("Startup pages:"), startupLayout);
optionLayout->addRow(tr("Quick access:"), qaLayout);
QVBoxLayout *mainLayout = new QVBoxLayout();
mainLayout->addLayout(optionLayout);
@ -363,6 +386,10 @@ bool VGeneralTab::loadConfiguration()
return false;
}
if (!loadQuickAccess()) {
return false;
}
return true;
}
@ -380,6 +407,10 @@ bool VGeneralTab::saveConfiguration()
return false;
}
if (!saveQuickAccess()) {
return false;
}
return true;
}
@ -466,6 +497,18 @@ bool VGeneralTab::saveStartupPageType()
return true;
}
bool VGeneralTab::loadQuickAccess()
{
m_quickAccessEdit->setText(g_config->getQuickAccess());
return true;
}
bool VGeneralTab::saveQuickAccess()
{
g_config->setQuickAccess(m_quickAccessEdit->text());
return true;
}
VLookTab::VLookTab(QWidget *p_parent)
: QWidget(p_parent)
{

View File

@ -37,6 +37,9 @@ private:
bool loadStartupPageType();
bool saveStartupPageType();
bool loadQuickAccess();
bool saveQuickAccess();
// Language
QComboBox *m_langCombo;
@ -52,6 +55,9 @@ private:
// Startup pages add files button.
QPushButton *m_startupPagesAddBtn;
// Quick access note path.
VLineEdit *m_quickAccessEdit;
static const QVector<QString> c_availableLangs;
};

View File

@ -0,0 +1,4 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<path style="fill:#000000" d="M256 32C132.288 32 32 132.288 32 256s100.288 224 224 224 224-100.288 224-224S379.712 32 256 32zm135.765 359.765C355.5 428.028 307.285 448 256 448s-99.5-19.972-135.765-56.235C83.972 355.5 64 307.285 64 256s19.972-99.5 56.235-135.765C156.5 83.972 204.715 64 256 64s99.5 19.972 135.765 56.235C428.028 156.5 448 204.715 448 256s-19.972 99.5-56.235 135.765z"/>
<path style="fill:#000000" d="M200.043 106.067c-40.631 15.171-73.434 46.382-90.717 85.933H256l-55.957-85.933zM412.797 288A160.723 160.723 0 0 0 416 256c0-36.624-12.314-70.367-33.016-97.334L311 288h101.797zM359.973 134.395C332.007 110.461 295.694 96 256 96c-7.966 0-15.794.591-23.448 1.715L310.852 224l49.121-89.605zM99.204 224A160.65 160.65 0 0 0 96 256c0 36.639 12.324 70.394 33.041 97.366L201 224H99.204zM311.959 405.932c40.631-15.171 73.433-46.382 90.715-85.932H256l55.959 85.932zM152.046 377.621C180.009 401.545 216.314 416 256 416c7.969 0 15.799-.592 23.456-1.716L201.164 288l-49.118 89.621z"/>
</svg>

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -194,6 +194,10 @@ vim_exemption_keys=cvx
; Could be absolute path
flash_page=flash_page.md
; Path of the quick access note, related to the configuration folder
; Could be absolute path
quick_access=
; Whether close note before editting with external editor
close_before_external_editor=true
@ -214,7 +218,7 @@ search_options=4,2,7,0,0,""
; Number of items in history
; 0 to disable history
history_size=50
history_size=100
; View order of note list
; 0 - configuration file
@ -397,6 +401,8 @@ ActivateNextTab=Ctrl+Tab
ActivatePreviousTab=Ctrl+Shift+Tab
; Activate flash page
FlashPage=Ctrl+Alt+L
; Quick access note
QuickAccess=Ctrl+Alt+I
; Open via system's default program
OpenViaDefaultProgram=F12
; Full screen

View File

@ -1337,6 +1337,10 @@ bool VUtils::isControlModifierForVim(int p_modifiers)
void VUtils::touchFile(const QString &p_file)
{
if (p_file.isEmpty()) {
return;
}
QFile file(p_file);
if (!file.open(QIODevice::WriteOnly)) {
qWarning() << "fail to touch file" << p_file;

View File

@ -1404,6 +1404,25 @@ const QString &VConfigManager::getFlashPage() const
return m_flashPage;
}
const QString &VConfigManager::getQuickAccess() const
{
if (m_quickAccess.isEmpty()) {
VConfigManager *var = const_cast<VConfigManager *>(this);
var->m_quickAccess = var->getConfigFromSettings("global",
"quick_access").toString();
if (VUtils::checkFileNameLegal(m_quickAccess)) {
var->m_quickAccess = QDir(getConfigFolder()).filePath(m_quickAccess);
}
}
if (!m_quickAccess.isEmpty() && !QFileInfo::exists(m_quickAccess)) {
VUtils::touchFile(m_quickAccess);
}
return m_quickAccess;
}
void VConfigManager::initThemes()
{
m_themes.clear();

View File

@ -481,6 +481,9 @@ public:
const QString &getFlashPage() const;
const QString &getQuickAccess() const;
void setQuickAccess(const QString &p_path);
// All the themes.
QList<QString> getThemes() const;
@ -917,6 +920,9 @@ private:
// Absolute path of flash page.
QString m_flashPage;
// Absolute path of quick access note.
QString m_quickAccess;
// The theme name.
QString m_theme;
@ -2597,4 +2603,14 @@ inline void VConfigManager::setInsertNewNoteInFront(bool p_enabled)
m_insertNewNoteInFront = p_enabled;
setConfigToSettings("global", "insert_new_note_in_front", m_insertNewNoteInFront);
}
inline void VConfigManager::setQuickAccess(const QString &p_path)
{
if (m_quickAccess == p_path) {
return;
}
m_quickAccess = p_path;
setConfigToSettings("global", "quick_access", m_quickAccess);
}
#endif // VCONFIGMANAGER_H

View File

@ -524,10 +524,10 @@ void VEditWindow::tabbarContextMenuRequested(QPoint p_pos)
QString folderPath;
if (file->getType() == FileType::Note) {
const VNoteFile *tmpFile = dynamic_cast<const VNoteFile *>((VFile *)file);
const VNoteFile *tmpFile = static_cast<const VNoteFile *>((VFile *)file);
folderPath = tmpFile->getNotebook()->getRecycleBinFolderPath();
} else if (file->getType() == FileType::Orphan) {
const VOrphanFile *tmpFile = dynamic_cast<const VOrphanFile *>((VFile *)file);
const VOrphanFile *tmpFile = static_cast<const VOrphanFile *>((VFile *)file);
folderPath = tmpFile->fetchRecycleBinFolderPath();
} else {
Q_ASSERT(false);
@ -598,6 +598,23 @@ void VEditWindow::tabbarContextMenuRequested(QPoint p_pos)
g_mainWin->showStatusMessage(tr("1 note pinned to History"));
});
QAction *quickAccessAct = new QAction(VIconUtils::menuIcon(":/resources/icons/quick_access.svg"),
tr("Set As Quick Access"),
&menu);
quickAccessAct->setToolTip(tr("Set this note as quick access"));
connect(quickAccessAct, &QAction::triggered,
this, [this](){
int tab = GET_TAB_FROM_SENDER();
Q_ASSERT(tab != -1);
VEditTab *editor = getTab(tab);
QPointer<VFile> file = editor->getFile();
Q_ASSERT(file);
QString fp(file->fetchPath());
g_config->setQuickAccess(fp);
g_mainWin->showStatusMessage(tr("Quick access: %1").arg(fp));
});
QAction *noteInfoAct = new QAction(VIconUtils::menuIcon(":/resources/icons/note_info.svg"),
tr("Note Info"),
&menu);
@ -611,7 +628,7 @@ void VEditWindow::tabbarContextMenuRequested(QPoint p_pos)
QPointer<VFile> file = editor->getFile();
Q_ASSERT(file);
if (file->getType() == FileType::Note) {
VNoteFile *tmpFile = dynamic_cast<VNoteFile *>((VFile *)file);
VNoteFile *tmpFile = static_cast<VNoteFile *>((VFile *)file);
g_mainWin->getFileList()->fileInfo(tmpFile);
} else if (file->getType() == FileType::Orphan) {
g_mainWin->editOrphanFileInfo(file);
@ -620,7 +637,10 @@ void VEditWindow::tabbarContextMenuRequested(QPoint p_pos)
VEditTab *editor = getTab(tab);
VFile *file = editor->getFile();
if (file->getType() == FileType::Note) {
bool isNote = file->getType() == FileType::Note;
bool isNonSystemOrphan = file->getType() == FileType::Orphan
&& !(static_cast<VOrphanFile *>(file)->isSystemFile());
if (isNote) {
// Locate to folder.
QAction *locateAct = new QAction(VIconUtils::menuIcon(":/resources/icons/locate_note.svg"),
tr("Locate To Folder"),
@ -633,7 +653,9 @@ void VEditWindow::tabbarContextMenuRequested(QPoint p_pos)
menu.addAction(locateAct);
menu.addSeparator();
}
if (isNote || isNonSystemOrphan) {
recycleBinAct->setData(tab);
menu.addAction(recycleBinAct);
@ -649,24 +671,8 @@ void VEditWindow::tabbarContextMenuRequested(QPoint p_pos)
pinToHistoryAct->setData(tab);
menu.addAction(pinToHistoryAct);
noteInfoAct->setData(tab);
menu.addAction(noteInfoAct);
} else if (file->getType() == FileType::Orphan
&& !(dynamic_cast<VOrphanFile *>(file)->isSystemFile())) {
recycleBinAct->setData(tab);
menu.addAction(recycleBinAct);
openLocationAct->setData(tab);
menu.addAction(openLocationAct);
reloadAct->setData(tab);
menu.addAction(reloadAct);
addToCartAct->setData(tab);
menu.addAction(addToCartAct);
pinToHistoryAct->setData(tab);
menu.addAction(pinToHistoryAct);
quickAccessAct->setData(tab);
menu.addAction(quickAccessAct);
noteInfoAct->setData(tab);
menu.addAction(noteInfoAct);
@ -889,7 +895,7 @@ void VEditWindow::scrollToHeader(const VHeaderPointer &p_header)
void VEditWindow::handleTabStatusUpdated(const VEditTabInfo &p_info)
{
int idx = indexOf(dynamic_cast<QWidget *>(sender()));
int idx = indexOf(static_cast<QWidget *>(sender()));
if (p_info.m_type == VEditTabInfo::InfoType::All) {
updateTabInfo(idx);
@ -904,7 +910,7 @@ void VEditWindow::handleTabStatusUpdated(const VEditTabInfo &p_info)
void VEditWindow::handleTabStatusMessage(const QString &p_msg)
{
int idx = indexOf(dynamic_cast<QWidget *>(sender()));
int idx = indexOf(static_cast<QWidget *>(sender()));
if (idx == currentIndex()) {
emit statusMessage(p_msg);
}
@ -912,7 +918,7 @@ void VEditWindow::handleTabStatusMessage(const QString &p_msg)
void VEditWindow::handleTabVimStatusUpdated(const VVim *p_vim)
{
int idx = indexOf(dynamic_cast<QWidget *>(sender()));
int idx = indexOf(static_cast<QWidget *>(sender()));
if (idx == currentIndex()) {
emit vimStatusUpdated(p_vim);
}
@ -1149,7 +1155,7 @@ bool VEditWindow::showOpenedFileList()
}
leftBtn->showMenu();
VOpenedListMenu *menu = dynamic_cast<VOpenedListMenu *>(leftBtn->menu());
VOpenedListMenu *menu = static_cast<VOpenedListMenu *>(leftBtn->menu());
return menu->isAccepted();
}

View File

@ -237,6 +237,17 @@ void VFileList::pinFileToHistory() const
.arg(items.size() > 1 ? tr("notes") : tr("note")));
}
void VFileList::setFileQuickAccess() const
{
QList<QListWidgetItem *> items = fileList->selectedItems();
if (items.size() == 1) {
QString fp(getVFile(items[0])->fetchPath());
g_config->setQuickAccess(fp);
g_mainWin->showStatusMessage(tr("Quick access: %1").arg(fp));
}
}
void VFileList::fileInfo(VNoteFile *p_file)
{
if (!p_file) {
@ -665,6 +676,14 @@ void VFileList::contextMenuRequested(QPoint pos)
this, &VFileList::pinFileToHistory);
menu.addAction(pinToHistoryAct);
QAction *quickAccessAct = new QAction(VIconUtils::menuIcon(":/resources/icons/quick_access.svg"),
tr("Set As Quick Access"),
&menu);
quickAccessAct->setToolTip(tr("Set current note as quick access"));
connect(quickAccessAct, &QAction::triggered,
this, &VFileList::setFileQuickAccess);
menu.addAction(quickAccessAct);
if (selectedSize == 1) {
QAction *fileInfoAct = new QAction(VIconUtils::menuIcon(":/resources/icons/note_info.svg"),
tr("&Info (Rename)\t%1").arg(VUtils::getShortcutText(c_infoShortcutSequence)),

View File

@ -93,6 +93,8 @@ private slots:
// Add selected files to History and pin them.
void pinFileToHistory() const;
void setFileQuickAccess() const;
// Copy selected files to clipboard.
// Will put a Json string into the clipboard which contains the information
// about copied files.

View File

@ -640,6 +640,20 @@ QToolBar *VMainWindow::initNoteToolBar(QSize p_iconSize)
connect(flashPageAct, &QAction::triggered,
this, &VMainWindow::openFlashPage);
QAction *quickAccessAct = new QAction(VIconUtils::toolButtonIcon(":/resources/icons/quick_access.svg"),
tr("Quick Access"),
this);
quickAccessAct->setStatusTip(tr("Open quick access note"));
keySeq = g_config->getShortcutKeySequence("QuickAccess");
seq = QKeySequence(keySeq);
if (!seq.isEmpty()) {
quickAccessAct->setText(tr("Quick Access\t%1").arg(VUtils::getShortcutText(keySeq)));
quickAccessAct->setShortcut(seq);
}
connect(quickAccessAct, &QAction::triggered,
this, &VMainWindow::openQuickAccess);
QAction *universalEntryAct = new QAction(VIconUtils::toolButtonIcon(":/resources/icons/universal_entry_tb.svg"),
tr("Universal Entry"),
this);
@ -656,6 +670,7 @@ QToolBar *VMainWindow::initNoteToolBar(QSize p_iconSize)
m_noteToolBar->addWidget(m_attachmentBtn);
m_noteToolBar->addAction(flashPageAct);
m_noteToolBar->addAction(quickAccessAct);
m_noteToolBar->addAction(universalEntryAct);
return m_noteToolBar;
@ -2857,6 +2872,24 @@ void VMainWindow::openFlashPage()
true);
}
void VMainWindow::openQuickAccess()
{
const QString &qaPath = g_config->getQuickAccess();
if (qaPath.isEmpty()) {
VUtils::showMessage(QMessageBox::Information,
tr("Info"),
tr("Quick Access is not set."),
tr("Please specify the note for Quick Access in the settings dialog "
"or the context menu of a note."),
QMessageBox::Ok,
QMessageBox::Ok,
this);
return;
}
openFiles(QStringList(qaPath), false, g_config->getNoteOpenMode());
}
void VMainWindow::initHeadingButton(QToolBar *p_tb)
{
m_headingBtn = new QPushButton(VIconUtils::toolButtonIcon(":/resources/icons/heading.svg"),

View File

@ -194,6 +194,8 @@ private slots:
// Open flash page in edit mode.
void openFlashPage();
void openQuickAccess();
void customShortcut();
void toggleEditReadMode();

View File

@ -270,5 +270,6 @@
<file>utils/turndown/turndown.js</file>
<file>utils/turndown/turndown-plugin-gfm.js</file>
<file>resources/common.css</file>
<file>resources/icons/quick_access.svg</file>
</qresource>
</RCC>