diff --git a/src/resources/docs/shortcuts_en.md b/src/resources/docs/shortcuts_en.md index 9f8cbdd0..67323d2c 100644 --- a/src/resources/docs/shortcuts_en.md +++ b/src/resources/docs/shortcuts_en.md @@ -277,3 +277,7 @@ VNote supports following features of Vim: For now, VNote does **NOT** support the macro and repeat(`.`) features of Vim. Enjoy Vim in VNote! + +# Others +- `Ctrl+J` and `Ctrl+K` to navigate through items; +- `Ctrl+N` and `Ctrl+P` to navigate through search results in list; diff --git a/src/resources/docs/shortcuts_zh.md b/src/resources/docs/shortcuts_zh.md index c942fe6b..01ddcbf7 100644 --- a/src/resources/docs/shortcuts_zh.md +++ b/src/resources/docs/shortcuts_zh.md @@ -279,3 +279,7 @@ VNote支持以下几个Vim的特性: VNote目前暂时不支持Vim的宏和重复(`.`)特性。 在VNote上享受Vim的美好时光吧! + +# 其他 +- `Ctrl+J` 和 `Ctrl+K` 浏览导航; +- 在列表中,`Ctrl+N` 和 `Ctrl+P` 在搜索结果中导航; diff --git a/src/utils/vutils.cpp b/src/utils/vutils.cpp index 7efa0806..7451b3d8 100644 --- a/src/utils/vutils.cpp +++ b/src/utils/vutils.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "vorphanfile.h" #include "vnote.h" @@ -1236,3 +1237,25 @@ QString VUtils::getAvailableFontFamily(const QStringList &p_families) return QString(); } + +bool VUtils::fixTextWithShortcut(QAction *p_act, const QString &p_shortcut) +{ + QString keySeq = g_config->getShortcutKeySequence(p_shortcut); + if (!keySeq.isEmpty()) { + p_act->setText(QString("%1\t%2").arg(p_act->text()).arg(VUtils::getShortcutText(keySeq))); + return true; + } + + return false; +} + +bool VUtils::fixTextWithCaptainShortcut(QAction *p_act, const QString &p_shortcut) +{ + QString keyText = VUtils::getCaptainShortcutSequenceText(p_shortcut); + if (!keyText.isEmpty()) { + p_act->setText(QString("%1\t%2").arg(p_act->text()).arg(keyText)); + return true; + } + + return false; +} diff --git a/src/utils/vutils.h b/src/utils/vutils.h index 6e95f5dc..b7d828b4 100644 --- a/src/utils/vutils.h +++ b/src/utils/vutils.h @@ -18,6 +18,7 @@ class VNotebook; class QWidget; class QComboBox; class QWebEngineView; +class QAction; #if !defined(V_ASSERT) #define V_ASSERT(cond) ((!(cond)) ? qt_assert(#cond, __FILE__, __LINE__) : qt_noop()) @@ -301,6 +302,10 @@ public: static QString getAvailableFontFamily(const QStringList &p_families); + static bool fixTextWithShortcut(QAction *p_act, const QString &p_shortcut); + + static bool fixTextWithCaptainShortcut(QAction *p_act, const QString &p_shortcut); + // Regular expression for image link. // ![image title]( http://github.com/tamlok/vnote.jpg "alt \" text" ) // Captured texts (need to be trimmed): diff --git a/src/vdirectorytree.cpp b/src/vdirectorytree.cpp index e0a2320a..7c8c61d3 100644 --- a/src/vdirectorytree.cpp +++ b/src/vdirectorytree.cpp @@ -91,11 +91,7 @@ void VDirectoryTree::initActions() { m_newNoteAct = new QAction(VIconUtils::menuIcon(":/resources/icons/create_note_tb.svg"), tr("New &Note"), this); - QString shortcutStr = VUtils::getShortcutText(g_config->getShortcutKeySequence("NewNote")); - if (!shortcutStr.isEmpty()) { - m_newNoteAct->setText(tr("New &Note\t%1").arg(shortcutStr)); - } - + VUtils::fixTextWithShortcut(m_newNoteAct, "NewNote"); m_newNoteAct->setToolTip(tr("Create a note in selected folder")); connect(m_newNoteAct, &QAction::triggered, this, [this]() { @@ -111,11 +107,7 @@ void VDirectoryTree::initActions() newSubDirAct = new QAction(VIconUtils::menuIcon(":/resources/icons/create_subdir.svg"), tr("New &Subfolder"), this); newSubDirAct->setToolTip(tr("Create a subfolder")); - shortcutStr = VUtils::getShortcutText(g_config->getShortcutKeySequence("NewSubfolder")); - if (!shortcutStr.isEmpty()) { - newSubDirAct->setText(tr("&New Subfolder\t%1").arg(shortcutStr)); - } - + VUtils::fixTextWithShortcut(newSubDirAct, "NewSubfolder"); connect(newSubDirAct, &QAction::triggered, this, &VDirectoryTree::newSubDirectory); diff --git a/src/veditwindow.cpp b/src/veditwindow.cpp index e9ed0b32..ecac0f27 100644 --- a/src/veditwindow.cpp +++ b/src/veditwindow.cpp @@ -63,24 +63,31 @@ void VEditWindow::initTabActions() m_locateAct = new QAction(VIconUtils::menuIcon(":/resources/icons/locate_note.svg"), tr("Locate To Folder"), this); m_locateAct->setToolTip(tr("Locate the folder of current note")); + VUtils::fixTextWithCaptainShortcut(m_locateAct, "LocateCurrentFile"); connect(m_locateAct, &QAction::triggered, this, &VEditWindow::handleLocateAct); m_moveLeftAct = new QAction(VIconUtils::menuIcon(":/resources/icons/move_tab_left.svg"), tr("Move One Split Left"), this); m_moveLeftAct->setToolTip(tr("Move current tab to the split on the left")); + VUtils::fixTextWithCaptainShortcut(m_moveLeftAct, "MoveTabSplitLeft"); connect(m_moveLeftAct, &QAction::triggered, this, &VEditWindow::handleMoveLeftAct); m_moveRightAct = new QAction(VIconUtils::menuIcon(":/resources/icons/move_tab_right.svg"), tr("Move One Split Right"), this); m_moveRightAct->setToolTip(tr("Move current tab to the split on the right")); + VUtils::fixTextWithCaptainShortcut(m_moveRightAct, "MoveTabSplitRight"); connect(m_moveRightAct, &QAction::triggered, this, &VEditWindow::handleMoveRightAct); m_closeTabAct = new QAction(VIconUtils::menuIcon(":/resources/icons/close.svg"), tr("Close Tab"), this); m_closeTabAct->setToolTip(tr("Close current note tab")); + if (!VUtils::fixTextWithShortcut(m_closeTabAct, "CloseNote")) { + VUtils::fixTextWithCaptainShortcut(m_closeTabAct, "CloseNote"); + } + connect(m_closeTabAct, &QAction::triggered, this, [this](){ int tab = this->m_closeTabAct->data().toInt(); @@ -234,6 +241,11 @@ void VEditWindow::setupCornerWidget() "", this); leftBtn->setProperty("CornerBtn", true); leftBtn->setToolTip(tr("Opened Notes List")); + QString keyText = VUtils::getCaptainShortcutSequenceText("OpenedFileList"); + if (!keyText.isEmpty()) { + leftBtn->setToolTip(QString("%1\t%2").arg(leftBtn->toolTip()).arg(keyText)); + } + VOpenedListMenu *leftMenu = new VOpenedListMenu(this); leftMenu->setToolTipsVisible(true); connect(leftMenu, &VOpenedListMenu::fileTriggered, @@ -245,6 +257,7 @@ void VEditWindow::setupCornerWidget() splitAct = new QAction(VIconUtils::menuIcon(":/resources/icons/split_window.svg"), tr("Split"), this); splitAct->setToolTip(tr("Split current window vertically")); + VUtils::fixTextWithCaptainShortcut(splitAct, "VerticalSplit"); connect(splitAct, &QAction::triggered, this, [this](){ splitWindow(true); @@ -253,6 +266,7 @@ void VEditWindow::setupCornerWidget() removeSplitAct = new QAction(VIconUtils::menuIcon(":/resources/icons/remove_split.svg"), tr("Remove split"), this); removeSplitAct->setToolTip(tr("Remove current split window")); + VUtils::fixTextWithCaptainShortcut(removeSplitAct, "RemoveSplit"); connect(removeSplitAct, &QAction::triggered, this, &VEditWindow::removeSplit); diff --git a/src/vfilelist.cpp b/src/vfilelist.cpp index 7e8502bc..fc78229a 100644 --- a/src/vfilelist.cpp +++ b/src/vfilelist.cpp @@ -113,11 +113,7 @@ void VFileList::initActions() { newFileAct = new QAction(VIconUtils::menuIcon(":/resources/icons/create_note.svg"), tr("&New Note"), this); - QString shortcutStr = VUtils::getShortcutText(g_config->getShortcutKeySequence("NewNote")); - if (!shortcutStr.isEmpty()) { - newFileAct->setText(tr("&New Note\t%1").arg(shortcutStr)); - } - + VUtils::fixTextWithShortcut(newFileAct, "NewNote"); newFileAct->setToolTip(tr("Create a note in current folder")); connect(newFileAct, SIGNAL(triggered(bool)), this, SLOT(newFile())); diff --git a/src/vmainwindow.cpp b/src/vmainwindow.cpp index 7b5dc9f3..980e8b9a 100644 --- a/src/vmainwindow.cpp +++ b/src/vmainwindow.cpp @@ -356,11 +356,7 @@ void VMainWindow::initViewToolBar(QSize p_iconSize) QAction *onePanelViewAct = new QAction(VIconUtils::menuIcon(":/resources/icons/one_panel.svg"), tr("Single Panel"), m_viewActGroup); - QString keyText = VUtils::getCaptainShortcutSequenceText("OnePanelView"); - if (!keyText.isEmpty()) { - onePanelViewAct->setText(tr("Single Panel\t%1").arg(keyText)); - } - + VUtils::fixTextWithCaptainShortcut(onePanelViewAct, "OnePanelView"); onePanelViewAct->setStatusTip(tr("Display only the notes list panel")); onePanelViewAct->setCheckable(true); onePanelViewAct->setData((int)PanelViewState::SinglePanel); @@ -368,11 +364,7 @@ void VMainWindow::initViewToolBar(QSize p_iconSize) QAction *twoPanelViewAct = new QAction(VIconUtils::menuIcon(":/resources/icons/two_panels.svg"), tr("Two Panels"), m_viewActGroup); - keyText = VUtils::getCaptainShortcutSequenceText("OnePanelView"); - if (!keyText.isEmpty()) { - twoPanelViewAct->setText(tr("Two Panels\t%1").arg(keyText)); - } - + VUtils::fixTextWithCaptainShortcut(twoPanelViewAct, "OnePanelView"); twoPanelViewAct->setStatusTip(tr("Display both the folders and notes list panel")); twoPanelViewAct->setCheckable(true); twoPanelViewAct->setData((int)PanelViewState::TwoPanels); @@ -417,11 +409,7 @@ void VMainWindow::initViewToolBar(QSize p_iconSize) expandViewAct = new QAction(VIconUtils::toolButtonIcon(":/resources/icons/expand.svg"), tr("Expand"), this); - keyText = VUtils::getCaptainShortcutSequenceText("ExpandMode"); - if (!keyText.isEmpty()) { - expandViewAct->setText(tr("Expand\t%1").arg(keyText)); - } - + VUtils::fixTextWithCaptainShortcut(expandViewAct, "ExpandMode"); expandViewAct->setStatusTip(tr("Expand the edit area")); expandViewAct->setCheckable(true); expandViewAct->setMenu(panelMenu); @@ -708,11 +696,7 @@ void VMainWindow::initFileToolBar(QSize p_iconSize) m_discardExitAct = new QAction(VIconUtils::menuIcon(":/resources/icons/discard_exit.svg"), tr("Discard Changes And Read"), this); - keySeq = VUtils::getCaptainShortcutSequenceText("DiscardAndRead"); - if (!keySeq.isEmpty()) { - m_discardExitAct->setText(tr("Discard Changes And Read\t%1").arg(keySeq)); - } - + VUtils::fixTextWithCaptainShortcut(m_discardExitAct, "DiscardAndRead"); m_discardExitAct->setStatusTip(tr("Discard changes and exit edit mode")); connect(m_discardExitAct, &QAction::triggered, editArea, &VEditArea::readFile); @@ -778,11 +762,7 @@ void VMainWindow::initHelpMenu() QAction *shortcutAct = new QAction(tr("&Shortcuts Help"), this); shortcutAct->setToolTip(tr("View information about shortcut keys")); - QString keyText = VUtils::getCaptainShortcutSequenceText("ShortcutsHelp"); - if (!keyText.isEmpty()) { - shortcutAct->setText(tr("&Shortcuts Help\t%1").arg(keyText)); - } - + VUtils::fixTextWithCaptainShortcut(shortcutAct, "ShortcutsHelp"); connect(shortcutAct, &QAction::triggered, this, &VMainWindow::shortcutsHelp); @@ -1011,10 +991,7 @@ void VMainWindow::initFileMenu() // Export as PDF. m_exportAct = new QAction(tr("E&xport"), this); m_exportAct->setToolTip(tr("Export notes")); - QString keyText = VUtils::getCaptainShortcutSequenceText("Export"); - if (!keyText.isEmpty()) { - m_exportAct->setText(tr("E&xport\t%1").arg(keyText)); - } + VUtils::fixTextWithCaptainShortcut(m_exportAct, "Export"); connect(m_exportAct, &QAction::triggered, this, &VMainWindow::handleExportAct); @@ -1326,10 +1303,7 @@ void VMainWindow::initDockWindows() QAction *toggleAct = toolDock->toggleViewAction(); toggleAct->setToolTip(tr("Toggle the tools dock widget")); - QString keyText = VUtils::getCaptainShortcutSequenceText("ToolsDock"); - if (!keyText.isEmpty()) { - toggleAct->setText(tr("%1\t%2").arg(toggleAct->text()).arg(keyText)); - } + VUtils::fixTextWithCaptainShortcut(toggleAct, "ToolsDock"); m_viewMenu->addAction(toggleAct); }