FileList/DirectoryTree: lazy initialization for QAction

This commit is contained in:
Le Tan 2018-05-23 20:07:41 +08:00
parent e048734414
commit d92453ef82
7 changed files with 199 additions and 240 deletions

View File

@ -46,7 +46,7 @@ sudo zypper in vnote
由于 Leap 42 及以下版本的 Qt 版本过低,我们无法在 OBS 上进行打包。请使用 AppImage 或自行构建。 由于 Leap 42 及以下版本的 Qt 版本过低,我们无法在 OBS 上进行打包。请使用 AppImage 或自行构建。
### Arch Linux ### Arch Linux
Arch Linux可以通过AUR中的 [vnote-git](https://aur.archlinux.org/packages/vnote/) 进行安装: Arch Linux可以通过AUR中的 [vnote](https://aur.archlinux.org/packages/vnote/) 进行安装:
```shell ```shell
git clone https://aur.archlinux.org/vnote.git git clone https://aur.archlinux.org/vnote.git

View File

@ -3,13 +3,8 @@
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="512px" height="512px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve"> width="512px" height="512px" viewBox="0 0 512 512" style="enable-background:new 0 0 512 512;" xml:space="preserve">
<g> <path style="fill:#000000" d="M399.3,168.9c-0.7-2.9-2-5-3.5-6.8l-83.7-91.7c-1.9-2.1-4.1-3.1-6.6-4.4c-2.9-1.5-6.1-1.6-9.4-1.6H136.2
<path style="fill:#000000" d="M398.6,169.2c-0.9-2.2-2-4.3-3.5-6.1l-83.8-91.7c-1.9-2.1-4.2-3.6-6.7-4.9c-2.9-1.5-6.1-2.1-9.5-2.1H135.2 c-12.4,0-23.7,9.6-23.7,22.9v335.2c0,13.4,11.3,25.9,23.7,25.9h243.1c12.4,0,21.2-12.5,21.2-25.9V178.4
c-12.4,0-22.7,10.6-22.7,23.9v335.2c0,13.4,10.3,24.9,22.7,24.9h243.1c12.4,0,22.2-11.5,22.2-24.9V179.4 C400.5,174.8,400.1,172.2,399.3,168.9z M305.5,111l58,63.5h-58V111z M144.5,416.5v-320h129v81.7c0,14.8,13.4,28.3,28.1,28.3h66.9
C400.5,175.8,400,172.3,398.6,169.2z M160.5,178.6c0-1.5,1.8-2.1,3.4-2.1h70.8c1.6,0,2.8,0.6,2.8,2.1v10.8c0,1.4-1.1,3.1-2.8,3.1 v210H144.5z"/>
h-70.8c-1.6,0-3.4-1.7-3.4-3.1V178.6z M160.5,306.6c0-1.5,1.8-2.1,3.4-2.1h122.2c1.6,0,2.4,0.6,2.4,2.1v10.8c0,1.4-0.7,3.1-2.4,3.1
H163.9c-1.6,0-3.4-1.7-3.4-3.1V306.6z M320.5,381.4c0,1.4-0.7,3.1-2.4,3.1H163.9c-1.6,0-3.4-1.7-3.4-3.1v-10.8
c0-1.5,1.8-2.1,3.4-2.1h154.2c1.6,0,2.4,0.6,2.4,2.1V381.4z M352.5,253.4c0,1.4-0.7,3.1-2.4,3.1H163.9c-1.6,0-3.4-1.7-3.4-3.1
v-10.8c0-1.5,1.8-2.1,3.4-2.1h186.2c1.6,0,2.4,0.6,2.4,2.1V253.4z M305.6,177.5c-5.6,0-11.1-5.2-11.1-11.3v-66l71.2,77.3H305.6z"/>
</g>
</svg> </svg>

Before

Width:  |  Height:  |  Size: 1.3 KiB

After

Width:  |  Height:  |  Size: 868 B

View File

@ -35,7 +35,6 @@ VDirectoryTree::VDirectoryTree(QWidget *parent)
setContextMenuPolicy(Qt::CustomContextMenu); setContextMenuPolicy(Qt::CustomContextMenu);
initShortcuts(); initShortcuts();
initActions();
connect(this, SIGNAL(itemExpanded(QTreeWidgetItem*)), connect(this, SIGNAL(itemExpanded(QTreeWidgetItem*)),
this, SLOT(handleItemExpanded(QTreeWidgetItem*))); this, SLOT(handleItemExpanded(QTreeWidgetItem*)));
@ -88,85 +87,6 @@ void VDirectoryTree::initShortcuts()
} }
} }
void VDirectoryTree::initActions()
{
m_newNoteAct = new QAction(VIconUtils::menuIcon(":/resources/icons/create_note_tb.svg"),
tr("New &Note"), this);
VUtils::fixTextWithShortcut(m_newNoteAct, "NewNote");
m_newNoteAct->setToolTip(tr("Create a note in selected folder"));
connect(m_newNoteAct, &QAction::triggered,
this, [this]() {
g_mainWin->getFileList()->newFile();
});
newRootDirAct = new QAction(VIconUtils::menuIcon(":/resources/icons/create_rootdir.svg"),
tr("New &Root Folder"), this);
newRootDirAct->setToolTip(tr("Create a root folder in current notebook"));
connect(newRootDirAct, &QAction::triggered,
this, &VDirectoryTree::newRootDirectory);
newSubDirAct = new QAction(VIconUtils::menuIcon(":/resources/icons/create_subdir.svg"),
tr("New &Subfolder"), this);
newSubDirAct->setToolTip(tr("Create a subfolder"));
VUtils::fixTextWithShortcut(newSubDirAct, "NewSubfolder");
connect(newSubDirAct, &QAction::triggered,
this, &VDirectoryTree::newSubDirectory);
deleteDirAct = new QAction(VIconUtils::menuDangerIcon(":/resources/icons/delete_dir.svg"),
tr("&Delete"), this);
deleteDirAct->setToolTip(tr("Delete selected folder"));
connect(deleteDirAct, &QAction::triggered,
this, &VDirectoryTree::deleteSelectedDirectory);
dirInfoAct = new QAction(VIconUtils::menuIcon(":/resources/icons/dir_info.svg"),
tr("&Info\t%1").arg(VUtils::getShortcutText(c_infoShortcutSequence)), this);
dirInfoAct->setToolTip(tr("View and edit current folder's information"));
connect(dirInfoAct, &QAction::triggered,
this, &VDirectoryTree::editDirectoryInfo);
copyAct = new QAction(VIconUtils::menuIcon(":/resources/icons/copy.svg"),
tr("&Copy\t%1").arg(VUtils::getShortcutText(c_copyShortcutSequence)), this);
copyAct->setToolTip(tr("Copy selected folders"));
connect(copyAct, &QAction::triggered,
this, &VDirectoryTree::copySelectedDirectories);
cutAct = new QAction(VIconUtils::menuIcon(":/resources/icons/cut.svg"),
tr("C&ut\t%1").arg(VUtils::getShortcutText(c_cutShortcutSequence)), this);
cutAct->setToolTip(tr("Cut selected folders"));
connect(cutAct, &QAction::triggered,
this, &VDirectoryTree::cutSelectedDirectories);
pasteAct = new QAction(VIconUtils::menuIcon(":/resources/icons/paste.svg"),
tr("&Paste\t%1").arg(VUtils::getShortcutText(c_pasteShortcutSequence)), this);
pasteAct->setToolTip(tr("Paste folders in this folder"));
connect(pasteAct, &QAction::triggered,
this, &VDirectoryTree::pasteDirectoriesFromClipboard);
m_openLocationAct = new QAction(tr("&Open Folder Location"), this);
m_openLocationAct->setToolTip(tr("Open the folder containing this folder in operating system"));
connect(m_openLocationAct, &QAction::triggered,
this, &VDirectoryTree::openDirectoryLocation);
m_pinToHistoryAct = new QAction(VIconUtils::menuIcon(":/resources/icons/pin.svg"),
tr("Pin To History"),
this);
m_pinToHistoryAct->setToolTip(tr("Pin selected folder to History"));
connect(m_pinToHistoryAct, &QAction::triggered,
this, &VDirectoryTree::pinDirectoryToHistory);
m_reloadAct = new QAction(tr("&Reload From Disk"), this);
m_reloadAct->setToolTip(tr("Reload the content of this folder (or notebook) from disk"));
connect(m_reloadAct, &QAction::triggered,
this, &VDirectoryTree::reloadFromDisk);
m_sortAct = new QAction(VIconUtils::menuIcon(":/resources/icons/sort.svg"),
tr("&Sort"),
this);
m_sortAct->setToolTip(tr("Sort folders in this folder/notebook manually"));
connect(m_sortAct, SIGNAL(triggered(bool)),
this, SLOT(sortItems()));
}
void VDirectoryTree::setNotebook(VNotebook *p_notebook) void VDirectoryTree::setNotebook(VNotebook *p_notebook)
{ {
if (m_notebook == p_notebook) { if (m_notebook == p_notebook) {
@ -396,23 +316,54 @@ void VDirectoryTree::contextMenuRequested(QPoint pos)
QMenu menu(this); QMenu menu(this);
menu.setToolTipsVisible(true); menu.setToolTipsVisible(true);
QAction *newRootDirAct = new QAction(VIconUtils::menuIcon(":/resources/icons/create_rootdir.svg"),
tr("New &Root Folder"),
&menu);
newRootDirAct->setToolTip(tr("Create a root folder in current notebook"));
connect(newRootDirAct, &QAction::triggered,
this, &VDirectoryTree::newRootDirectory);
QAction *sortAct = new QAction(VIconUtils::menuIcon(":/resources/icons/sort.svg"),
tr("&Sort"),
&menu);
sortAct->setToolTip(tr("Sort folders in this folder/notebook manually"));
connect(sortAct, SIGNAL(triggered(bool)),
this, SLOT(sortItems()));
if (!item) { if (!item) {
// Context menu on the free space of the QTreeWidget // Context menu on the free space of the QTreeWidget
menu.addAction(newRootDirAct); menu.addAction(newRootDirAct);
if (topLevelItemCount() > 1) { if (topLevelItemCount() > 1) {
menu.addAction(m_sortAct); menu.addAction(sortAct);
} }
} else { } else {
// Context menu on a QTreeWidgetItem // Context menu on a QTreeWidgetItem
menu.addAction(m_newNoteAct); QAction *newNoteAct = new QAction(VIconUtils::menuIcon(":/resources/icons/create_note_tb.svg"),
tr("New &Note"),
&menu);
VUtils::fixTextWithShortcut(newNoteAct, "NewNote");
newNoteAct->setToolTip(tr("Create a note in selected folder"));
connect(newNoteAct, &QAction::triggered,
this, [this]() {
g_mainWin->getFileList()->newFile();
});
menu.addAction(newNoteAct);
QAction *newSubDirAct = new QAction(VIconUtils::menuIcon(":/resources/icons/create_subdir.svg"),
tr("New &Subfolder"),
&menu);
newSubDirAct->setToolTip(tr("Create a subfolder"));
VUtils::fixTextWithShortcut(newSubDirAct, "NewSubfolder");
connect(newSubDirAct, &QAction::triggered,
this, &VDirectoryTree::newSubDirectory);
if (item->parent()) { if (item->parent()) {
// Low-level item // Low-level item
menu.addAction(newSubDirAct); menu.addAction(newSubDirAct);
if (item->parent()->childCount() > 1) { if (item->parent()->childCount() > 1) {
menu.addAction(m_sortAct); menu.addAction(sortAct);
} }
} else { } else {
// Top-level item // Top-level item
@ -420,13 +371,34 @@ void VDirectoryTree::contextMenuRequested(QPoint pos)
menu.addAction(newSubDirAct); menu.addAction(newSubDirAct);
if (topLevelItemCount() > 1) { if (topLevelItemCount() > 1) {
menu.addAction(m_sortAct); menu.addAction(sortAct);
} }
} }
menu.addSeparator(); menu.addSeparator();
QAction *deleteDirAct = new QAction(VIconUtils::menuDangerIcon(":/resources/icons/delete_dir.svg"),
tr("&Delete"),
&menu);
deleteDirAct->setToolTip(tr("Delete selected folder"));
connect(deleteDirAct, &QAction::triggered,
this, &VDirectoryTree::deleteSelectedDirectory);
menu.addAction(deleteDirAct); menu.addAction(deleteDirAct);
QAction *copyAct = new QAction(VIconUtils::menuIcon(":/resources/icons/copy.svg"),
tr("&Copy\t%1").arg(VUtils::getShortcutText(c_copyShortcutSequence)),
&menu);
copyAct->setToolTip(tr("Copy selected folders"));
connect(copyAct, &QAction::triggered,
this, &VDirectoryTree::copySelectedDirectories);
menu.addAction(copyAct); menu.addAction(copyAct);
QAction *cutAct = new QAction(VIconUtils::menuIcon(":/resources/icons/cut.svg"),
tr("C&ut\t%1").arg(VUtils::getShortcutText(c_cutShortcutSequence)),
&menu);
cutAct->setToolTip(tr("Cut selected folders"));
connect(cutAct, &QAction::triggered,
this, &VDirectoryTree::cutSelectedDirectories);
menu.addAction(cutAct); menu.addAction(cutAct);
} }
@ -435,15 +407,44 @@ void VDirectoryTree::contextMenuRequested(QPoint pos)
menu.addSeparator(); menu.addSeparator();
} }
QAction *pasteAct = new QAction(VIconUtils::menuIcon(":/resources/icons/paste.svg"),
tr("&Paste\t%1").arg(VUtils::getShortcutText(c_pasteShortcutSequence)),
&menu);
pasteAct->setToolTip(tr("Paste folders in this folder"));
connect(pasteAct, &QAction::triggered,
this, &VDirectoryTree::pasteDirectoriesFromClipboard);
menu.addAction(pasteAct); menu.addAction(pasteAct);
} }
menu.addSeparator(); menu.addSeparator();
menu.addAction(m_reloadAct);
QAction *reloadAct = new QAction(tr("&Reload From Disk"), &menu);
reloadAct->setToolTip(tr("Reload the content of this folder (or notebook) from disk"));
connect(reloadAct, &QAction::triggered,
this, &VDirectoryTree::reloadFromDisk);
menu.addAction(reloadAct);
if (item) { if (item) {
menu.addAction(m_openLocationAct); QAction *openLocationAct = new QAction(tr("&Open Folder Location"), &menu);
menu.addAction(m_pinToHistoryAct); openLocationAct->setToolTip(tr("Open the folder containing this folder in operating system"));
connect(openLocationAct, &QAction::triggered,
this, &VDirectoryTree::openDirectoryLocation);
menu.addAction(openLocationAct);
QAction *pinToHistoryAct = new QAction(VIconUtils::menuIcon(":/resources/icons/pin.svg"),
tr("Pin To History"),
&menu);
pinToHistoryAct->setToolTip(tr("Pin selected folder to History"));
connect(pinToHistoryAct, &QAction::triggered,
this, &VDirectoryTree::pinDirectoryToHistory);
menu.addAction(pinToHistoryAct);
QAction *dirInfoAct = new QAction(VIconUtils::menuIcon(":/resources/icons/dir_info.svg"),
tr("&Info\t%1").arg(VUtils::getShortcutText(c_infoShortcutSequence)),
&menu);
dirInfoAct->setToolTip(tr("View and edit current folder's information"));
connect(dirInfoAct, &QAction::triggered,
this, &VDirectoryTree::editDirectoryInfo);
menu.addAction(dirInfoAct); menu.addAction(dirInfoAct);
} }

View File

@ -113,8 +113,6 @@ private:
void initShortcuts(); void initShortcuts();
void initActions();
// Update @p_item's direct children only: deleted, added, renamed. // Update @p_item's direct children only: deleted, added, renamed.
void updateItemDirectChildren(QTreeWidgetItem *p_item); void updateItemDirectChildren(QTreeWidgetItem *p_item);
@ -166,25 +164,6 @@ private:
// Magic number for clipboard operations. // Magic number for clipboard operations.
int m_magicForClipboard; int m_magicForClipboard;
// Actions
QAction *m_newNoteAct;
QAction *newRootDirAct;
QAction *newSubDirAct;
QAction *deleteDirAct;
QAction *dirInfoAct;
QAction *copyAct;
QAction *cutAct;
QAction *pasteAct;
QAction *m_openLocationAct;
QAction *m_pinToHistoryAct;
QAction *m_sortAct;
// Reload content from disk.
QAction *m_reloadAct;
static const QString c_infoShortcutSequence; static const QString c_infoShortcutSequence;
static const QString c_copyShortcutSequence; static const QString c_copyShortcutSequence;
static const QString c_cutShortcutSequence; static const QString c_cutShortcutSequence;

View File

@ -34,12 +34,12 @@ const QString VFileList::c_pasteShortcutSequence = "Ctrl+V";
VFileList::VFileList(QWidget *parent) VFileList::VFileList(QWidget *parent)
: QWidget(parent), : QWidget(parent),
VNavigationMode(), VNavigationMode(),
m_openWithMenu(NULL),
m_itemClicked(NULL), m_itemClicked(NULL),
m_fileToCloseInSingleClick(NULL) m_fileToCloseInSingleClick(NULL)
{ {
setupUI(); setupUI();
initShortcuts(); initShortcuts();
initActions();
m_clickTimer = new QTimer(this); m_clickTimer = new QTimer(this);
m_clickTimer->setSingleShot(true); m_clickTimer->setSingleShot(true);
@ -125,96 +125,6 @@ void VFileList::initShortcuts()
}); });
} }
void VFileList::initActions()
{
newFileAct = new QAction(VIconUtils::menuIcon(":/resources/icons/create_note.svg"),
tr("&New Note"), this);
VUtils::fixTextWithShortcut(newFileAct, "NewNote");
newFileAct->setToolTip(tr("Create a note in current folder"));
connect(newFileAct, SIGNAL(triggered(bool)),
this, SLOT(newFile()));
m_openInReadAct = new QAction(VIconUtils::menuIcon(":/resources/icons/reading.svg"),
tr("&Open In Read Mode"), this);
m_openInReadAct->setToolTip(tr("Open current note in read mode"));
connect(m_openInReadAct, &QAction::triggered,
this, [this]() {
QListWidgetItem *item = fileList->currentItem();
if (item) {
emit fileClicked(getVFile(item), OpenFileMode::Read, true);
}
});
m_openInEditAct = new QAction(VIconUtils::menuIcon(":/resources/icons/editing.svg"),
tr("Open In &Edit Mode"), this);
m_openInEditAct->setToolTip(tr("Open current note in edit mode"));
connect(m_openInEditAct, &QAction::triggered,
this, [this]() {
QListWidgetItem *item = fileList->currentItem();
if (item) {
emit fileClicked(getVFile(item), OpenFileMode::Edit, true);
}
});
deleteFileAct = new QAction(VIconUtils::menuDangerIcon(":/resources/icons/delete_note.svg"),
tr("&Delete"), this);
deleteFileAct->setToolTip(tr("Delete selected note"));
connect(deleteFileAct, SIGNAL(triggered(bool)),
this, SLOT(deleteSelectedFiles()));
fileInfoAct = new QAction(VIconUtils::menuIcon(":/resources/icons/note_info.svg"),
tr("&Info\t%1").arg(VUtils::getShortcutText(c_infoShortcutSequence)), this);
fileInfoAct->setToolTip(tr("View and edit current note's information"));
connect(fileInfoAct, SIGNAL(triggered(bool)),
this, SLOT(fileInfo()));
copyAct = new QAction(VIconUtils::menuIcon(":/resources/icons/copy.svg"),
tr("&Copy\t%1").arg(VUtils::getShortcutText(c_copyShortcutSequence)), this);
copyAct->setToolTip(tr("Copy selected notes"));
connect(copyAct, &QAction::triggered,
this, &VFileList::copySelectedFiles);
cutAct = new QAction(VIconUtils::menuIcon(":/resources/icons/cut.svg"),
tr("C&ut\t%1").arg(VUtils::getShortcutText(c_cutShortcutSequence)), this);
cutAct->setToolTip(tr("Cut selected notes"));
connect(cutAct, &QAction::triggered,
this, &VFileList::cutSelectedFiles);
pasteAct = new QAction(VIconUtils::menuIcon(":/resources/icons/paste.svg"),
tr("&Paste\t%1").arg(VUtils::getShortcutText(c_pasteShortcutSequence)), this);
pasteAct->setToolTip(tr("Paste notes in current folder"));
connect(pasteAct, &QAction::triggered,
this, &VFileList::pasteFilesFromClipboard);
m_openLocationAct = new QAction(tr("&Open Note Location"), this);
m_openLocationAct->setToolTip(tr("Open the folder containing this note in operating system"));
connect(m_openLocationAct, &QAction::triggered,
this, &VFileList::openFileLocation);
m_addToCartAct = new QAction(VIconUtils::menuIcon(":/resources/icons/cart.svg"),
tr("Add To Cart"),
this);
m_addToCartAct->setToolTip(tr("Add selected notes to Cart for further processing"));
connect(m_addToCartAct, &QAction::triggered,
this, &VFileList::addFileToCart);
m_pinToHistoryAct = new QAction(VIconUtils::menuIcon(":/resources/icons/pin.svg"),
tr("Pin To History"),
this);
m_pinToHistoryAct->setToolTip(tr("Pin selected notes to History"));
connect(m_pinToHistoryAct, &QAction::triggered,
this, &VFileList::pinFileToHistory);
m_sortAct = new QAction(VIconUtils::menuIcon(":/resources/icons/sort.svg"),
tr("&Sort"),
this);
m_sortAct->setToolTip(tr("Sort notes in this folder manually"));
connect(m_sortAct, &QAction::triggered,
this, &VFileList::sortItems);
initOpenWithMenu();
}
void VFileList::setDirectory(VDirectory *p_directory) void VFileList::setDirectory(VDirectory *p_directory)
{ {
// QPointer will be set to NULL automatically once the directory was deleted. // QPointer will be set to NULL automatically once the directory was deleted.
@ -610,25 +520,83 @@ void VFileList::contextMenuRequested(QPoint pos)
VNoteFile *file = getVFile(item); VNoteFile *file = getVFile(item);
if (file) { if (file) {
if (file->getDocType() == DocType::Markdown) { if (file->getDocType() == DocType::Markdown) {
menu.addAction(m_openInReadAct); QAction *openInReadAct = new QAction(VIconUtils::menuIcon(":/resources/icons/reading.svg"),
menu.addAction(m_openInEditAct); tr("&Open In Read Mode"),
&menu);
openInReadAct->setToolTip(tr("Open current note in read mode"));
connect(openInReadAct, &QAction::triggered,
this, [this]() {
QListWidgetItem *item = fileList->currentItem();
if (item) {
emit fileClicked(getVFile(item), OpenFileMode::Read, true);
}
});
menu.addAction(openInReadAct);
QAction *openInEditAct = new QAction(VIconUtils::menuIcon(":/resources/icons/editing.svg"),
tr("Open In &Edit Mode"),
&menu);
openInEditAct->setToolTip(tr("Open current note in edit mode"));
connect(openInEditAct, &QAction::triggered,
this, [this]() {
QListWidgetItem *item = fileList->currentItem();
if (item) {
emit fileClicked(getVFile(item), OpenFileMode::Edit, true);
}
});
menu.addAction(openInEditAct);
} }
menu.addMenu(m_openWithMenu); menu.addMenu(getOpenWithMenu());
menu.addSeparator(); menu.addSeparator();
} }
} }
QAction *newFileAct = new QAction(VIconUtils::menuIcon(":/resources/icons/create_note.svg"),
tr("&New Note"),
&menu);
VUtils::fixTextWithShortcut(newFileAct, "NewNote");
newFileAct->setToolTip(tr("Create a note in current folder"));
connect(newFileAct, SIGNAL(triggered(bool)),
this, SLOT(newFile()));
menu.addAction(newFileAct); menu.addAction(newFileAct);
if (fileList->count() > 1) { if (fileList->count() > 1) {
menu.addAction(m_sortAct); QAction *sortAct = new QAction(VIconUtils::menuIcon(":/resources/icons/sort.svg"),
tr("&Sort"),
&menu);
sortAct->setToolTip(tr("Sort notes in this folder manually"));
connect(sortAct, &QAction::triggered,
this, &VFileList::sortItems);
menu.addAction(sortAct);
} }
if (item) { if (item) {
menu.addSeparator(); menu.addSeparator();
QAction *deleteFileAct = new QAction(VIconUtils::menuDangerIcon(":/resources/icons/delete_note.svg"),
tr("&Delete"),
&menu);
deleteFileAct->setToolTip(tr("Delete selected note"));
connect(deleteFileAct, SIGNAL(triggered(bool)),
this, SLOT(deleteSelectedFiles()));
menu.addAction(deleteFileAct); menu.addAction(deleteFileAct);
QAction *copyAct = new QAction(VIconUtils::menuIcon(":/resources/icons/copy.svg"),
tr("&Copy\t%1").arg(VUtils::getShortcutText(c_copyShortcutSequence)),
&menu);
copyAct->setToolTip(tr("Copy selected notes"));
connect(copyAct, &QAction::triggered,
this, &VFileList::copySelectedFiles);
menu.addAction(copyAct); menu.addAction(copyAct);
QAction *cutAct = new QAction(VIconUtils::menuIcon(":/resources/icons/cut.svg"),
tr("C&ut\t%1").arg(VUtils::getShortcutText(c_cutShortcutSequence)),
&menu);
cutAct->setToolTip(tr("Cut selected notes"));
connect(cutAct, &QAction::triggered,
this, &VFileList::cutSelectedFiles);
menu.addAction(cutAct); menu.addAction(cutAct);
} }
@ -637,19 +605,48 @@ void VFileList::contextMenuRequested(QPoint pos)
menu.addSeparator(); menu.addSeparator();
} }
QAction *pasteAct = new QAction(VIconUtils::menuIcon(":/resources/icons/paste.svg"),
tr("&Paste\t%1").arg(VUtils::getShortcutText(c_pasteShortcutSequence)),
&menu);
pasteAct->setToolTip(tr("Paste notes in current folder"));
connect(pasteAct, &QAction::triggered,
this, &VFileList::pasteFilesFromClipboard);
menu.addAction(pasteAct); menu.addAction(pasteAct);
} }
if (item) { if (item) {
menu.addSeparator(); menu.addSeparator();
if (selectedSize == 1) { if (selectedSize == 1) {
menu.addAction(m_openLocationAct); QAction *openLocationAct = new QAction(tr("&Open Note Location"), &menu);
openLocationAct->setToolTip(tr("Open the folder containing this note in operating system"));
connect(openLocationAct, &QAction::triggered,
this, &VFileList::openFileLocation);
menu.addAction(openLocationAct);
} }
menu.addAction(m_addToCartAct); QAction *addToCartAct = new QAction(VIconUtils::menuIcon(":/resources/icons/cart.svg"),
menu.addAction(m_pinToHistoryAct); tr("Add To Cart"),
&menu);
addToCartAct->setToolTip(tr("Add selected notes to Cart for further processing"));
connect(addToCartAct, &QAction::triggered,
this, &VFileList::addFileToCart);
menu.addAction(addToCartAct);
QAction *pinToHistoryAct = new QAction(VIconUtils::menuIcon(":/resources/icons/pin.svg"),
tr("Pin To History"),
&menu);
pinToHistoryAct->setToolTip(tr("Pin selected notes to History"));
connect(pinToHistoryAct, &QAction::triggered,
this, &VFileList::pinFileToHistory);
menu.addAction(pinToHistoryAct);
if (selectedSize == 1) { if (selectedSize == 1) {
QAction *fileInfoAct = new QAction(VIconUtils::menuIcon(":/resources/icons/note_info.svg"),
tr("&Info\t%1").arg(VUtils::getShortcutText(c_infoShortcutSequence)),
&menu);
fileInfoAct->setToolTip(tr("View and edit current note's information"));
connect(fileInfoAct, SIGNAL(triggered(bool)),
this, SLOT(fileInfo()));
menu.addAction(fileInfoAct); menu.addAction(fileInfoAct);
} }
} }
@ -1151,8 +1148,12 @@ void VFileList::sortItems()
} }
} }
void VFileList::initOpenWithMenu() QMenu *VFileList::getOpenWithMenu()
{ {
if (m_openWithMenu) {
return m_openWithMenu;
}
m_openWithMenu = new QMenu(tr("Open With"), this); m_openWithMenu = new QMenu(tr("Open With"), this);
m_openWithMenu->setToolTipsVisible(true); m_openWithMenu->setToolTipsVisible(true);
@ -1240,6 +1241,8 @@ void VFileList::initOpenWithMenu()
}); });
m_openWithMenu->addAction(addAct); m_openWithMenu->addAction(addAct);
return m_openWithMenu;
} }
void VFileList::handleOpenWithActionTriggered() void VFileList::handleOpenWithActionTriggered()

View File

@ -136,9 +136,6 @@ private:
// Remove and delete item related to @p_file from list widget. // Remove and delete item related to @p_file from list widget.
void removeFileListItem(VNoteFile *p_file); void removeFileListItem(VNoteFile *p_file);
// Init actions.
void initActions();
// Return the corresponding QListWidgetItem of @p_file. // Return the corresponding QListWidgetItem of @p_file.
QListWidgetItem *findItem(const VNoteFile *p_file); QListWidgetItem *findItem(const VNoteFile *p_file);
@ -164,8 +161,7 @@ private:
// Check if there are files in clipboard available to paste. // Check if there are files in clipboard available to paste.
bool pasteAvailable() const; bool pasteAvailable() const;
// Init Open With menu. QMenu *getOpenWithMenu();
void initOpenWithMenu();
void activateItem(QListWidgetItem *p_item, bool p_restoreFocus = false); void activateItem(QListWidgetItem *p_item, bool p_restoreFocus = false);
@ -182,24 +178,6 @@ private:
// Magic number for clipboard operations. // Magic number for clipboard operations.
int m_magicForClipboard; int m_magicForClipboard;
// Actions
QAction *m_openInReadAct;
QAction *m_openInEditAct;
QAction *newFileAct;
QAction *deleteFileAct;
QAction *fileInfoAct;
QAction *copyAct;
QAction *cutAct;
QAction *pasteAct;
QAction *m_openLocationAct;
QAction *m_sortAct;
QAction *m_addToCartAct;
QAction *m_pinToHistoryAct;
// Context sub-menu of Open With. // Context sub-menu of Open With.
QMenu *m_openWithMenu; QMenu *m_openWithMenu;

View File

@ -264,6 +264,7 @@ void VHistoryList::updateList()
m_itemList->addItem(seps[i].m_item); m_itemList->addItem(seps[i].m_item);
} }
QIcon noteIcon(VIconUtils::treeViewIcon(":/resources/icons/note_item.svg"));
QIcon folderIcon(VIconUtils::treeViewIcon(":/resources/icons/dir_item.svg")); QIcon folderIcon(VIconUtils::treeViewIcon(":/resources/icons/dir_item.svg"));
for (auto it = m_histories.cbegin(); it != m_histories.cend(); ++it) { for (auto it = m_histories.cbegin(); it != m_histories.cend(); ++it) {
QListWidgetItem *item = new QListWidgetItem(VUtils::fileNameFromPath(it->m_file)); QListWidgetItem *item = new QListWidgetItem(VUtils::fileNameFromPath(it->m_file));
@ -272,6 +273,8 @@ void VHistoryList::updateList()
if (it->m_isFolder) { if (it->m_isFolder) {
item->setIcon(folderIcon); item->setIcon(folderIcon);
} else {
item->setIcon(noteIcon);
} }
if (it->m_isPinned) { if (it->m_isPinned) {