mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
EditWindow: lazy initialization of actions
This commit is contained in:
parent
f130c3dd98
commit
b076e87509
@ -19,14 +19,16 @@
|
||||
extern VConfigManager *g_config;
|
||||
extern VMainWindow *g_mainWin;
|
||||
|
||||
#define GET_TAB_FROM_SENDER() static_cast<QAction *>(sender())->data().toInt()
|
||||
|
||||
VEditWindow::VEditWindow(VEditArea *editArea, QWidget *parent)
|
||||
: QTabWidget(parent),
|
||||
m_editArea(editArea),
|
||||
m_curTabWidget(NULL),
|
||||
m_lastTabWidget(NULL)
|
||||
m_lastTabWidget(NULL),
|
||||
m_removeSplitAct(NULL)
|
||||
{
|
||||
setAcceptDrops(true);
|
||||
initTabActions();
|
||||
setupCornerWidget();
|
||||
|
||||
// Explicit speficy in macOS.
|
||||
@ -59,202 +61,6 @@ VEditWindow::VEditWindow(VEditArea *editArea, QWidget *parent)
|
||||
this, &VEditWindow::contextMenuRequested);
|
||||
}
|
||||
|
||||
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();
|
||||
Q_ASSERT(tab != -1);
|
||||
closeTab(tab);
|
||||
});
|
||||
|
||||
m_closeOthersAct = new QAction(tr("Close Other Tabs"), this);
|
||||
m_closeOthersAct->setToolTip(tr("Close all other note tabs"));
|
||||
connect(m_closeOthersAct, &QAction::triggered,
|
||||
this, [this](){
|
||||
int tab = this->m_closeOthersAct->data().toInt();
|
||||
Q_ASSERT(tab != -1);
|
||||
|
||||
for (int i = tab - 1; i >= 0; --i) {
|
||||
this->setCurrentIndex(i);
|
||||
this->updateTabStatus(i);
|
||||
if (this->closeTab(i)) {
|
||||
--tab;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = tab + 1; i < this->count();) {
|
||||
this->setCurrentIndex(i);
|
||||
this->updateTabStatus(i);
|
||||
if (!this->closeTab(i)) {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
m_closeAllAct = new QAction(tr("Close All Tabs"), this);
|
||||
m_closeAllAct->setToolTip(tr("Close all the note tabs"));
|
||||
connect(m_closeAllAct, &QAction::triggered,
|
||||
this, [this](){
|
||||
for (int i = 0; i < this->count();) {
|
||||
this->setCurrentIndex(i);
|
||||
this->updateTabStatus(i);
|
||||
if (!this->closeTab(i)) {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
m_closeRightAct = new QAction(tr("Close Tabs To The Right"), this);
|
||||
m_closeRightAct->setToolTip(tr("Close all the note tabs to the right of current tab"));
|
||||
connect(m_closeRightAct, &QAction::triggered,
|
||||
this, [this](){
|
||||
int tab = this->m_closeRightAct->data().toInt();
|
||||
Q_ASSERT(tab != -1);
|
||||
|
||||
for (int i = tab + 1; i < this->count();) {
|
||||
this->setCurrentIndex(i);
|
||||
this->updateTabStatus(i);
|
||||
if (!this->closeTab(i)) {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
m_noteInfoAct = new QAction(VIconUtils::menuIcon(":/resources/icons/note_info.svg"),
|
||||
tr("Note Info"), this);
|
||||
m_noteInfoAct->setToolTip(tr("View and edit information of the note"));
|
||||
connect(m_noteInfoAct, &QAction::triggered,
|
||||
this, [this](){
|
||||
int tab = this->m_noteInfoAct->data().toInt();
|
||||
Q_ASSERT(tab != -1);
|
||||
|
||||
VEditTab *editor = getTab(tab);
|
||||
QPointer<VFile> file = editor->getFile();
|
||||
Q_ASSERT(file);
|
||||
if (file->getType() == FileType::Note) {
|
||||
VNoteFile *tmpFile = dynamic_cast<VNoteFile *>((VFile *)file);
|
||||
g_mainWin->getFileList()->fileInfo(tmpFile);
|
||||
} else if (file->getType() == FileType::Orphan) {
|
||||
g_mainWin->editOrphanFileInfo(file);
|
||||
}
|
||||
});
|
||||
|
||||
m_addToCartAct = new QAction(VIconUtils::menuIcon(":/resources/icons/cart.svg"),
|
||||
tr("Add To Cart"),
|
||||
this);
|
||||
m_addToCartAct->setToolTip(tr("Add this note to Cart for further processing"));
|
||||
connect(m_addToCartAct, &QAction::triggered,
|
||||
this, [this](){
|
||||
int tab = this->m_addToCartAct->data().toInt();
|
||||
Q_ASSERT(tab != -1);
|
||||
|
||||
VEditTab *editor = getTab(tab);
|
||||
QPointer<VFile> file = editor->getFile();
|
||||
Q_ASSERT(file);
|
||||
g_mainWin->getCart()->addFile(file->fetchPath());
|
||||
g_mainWin->showStatusMessage(tr("1 note added to Cart"));
|
||||
});
|
||||
|
||||
m_pinToHistoryAct = new QAction(VIconUtils::menuIcon(":/resources/icons/pin.svg"),
|
||||
tr("Pin To History"),
|
||||
this);
|
||||
m_pinToHistoryAct->setToolTip(tr("Pin this note to History"));
|
||||
connect(m_pinToHistoryAct, &QAction::triggered,
|
||||
this, [this](){
|
||||
int tab = this->m_pinToHistoryAct->data().toInt();
|
||||
Q_ASSERT(tab != -1);
|
||||
|
||||
VEditTab *editor = getTab(tab);
|
||||
QPointer<VFile> file = editor->getFile();
|
||||
Q_ASSERT(file);
|
||||
QStringList files;
|
||||
files << file->fetchPath();
|
||||
g_mainWin->getHistoryList()->pinFiles(files);
|
||||
g_mainWin->showStatusMessage(tr("1 note pinned to History"));
|
||||
});
|
||||
|
||||
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, [this](){
|
||||
int tab = this->m_openLocationAct->data().toInt();
|
||||
Q_ASSERT(tab != -1);
|
||||
|
||||
VEditTab *editor = getTab(tab);
|
||||
QPointer<VFile> file = editor->getFile();
|
||||
Q_ASSERT(file);
|
||||
QUrl url = QUrl::fromLocalFile(file->fetchBasePath());
|
||||
QDesktopServices::openUrl(url);
|
||||
});
|
||||
|
||||
m_reloadAct = new QAction(tr("Reload From Disk"), this);
|
||||
m_reloadAct->setToolTip(tr("Reload the content of this note from disk"));
|
||||
connect(m_reloadAct, &QAction::triggered,
|
||||
this, [this](){
|
||||
int tab = this->m_reloadAct->data().toInt();
|
||||
Q_ASSERT(tab != -1);
|
||||
|
||||
VEditTab *editor = getTab(tab);
|
||||
editor->reloadFromDisk();
|
||||
});
|
||||
|
||||
m_recycleBinAct = new QAction(VIconUtils::menuIcon(":/resources/icons/recycle_bin.svg"),
|
||||
tr("&Recycle Bin"), this);
|
||||
m_recycleBinAct->setToolTip(tr("Open the recycle bin of this note"));
|
||||
connect(m_recycleBinAct, &QAction::triggered,
|
||||
this, [this]() {
|
||||
int tab = this->m_recycleBinAct->data().toInt();
|
||||
Q_ASSERT(tab != -1);
|
||||
|
||||
VEditTab *editor = getTab(tab);
|
||||
VFile *file = editor->getFile();
|
||||
Q_ASSERT(file);
|
||||
|
||||
QString folderPath;
|
||||
if (file->getType() == FileType::Note) {
|
||||
const VNoteFile *tmpFile = dynamic_cast<const VNoteFile *>((VFile *)file);
|
||||
folderPath = tmpFile->getNotebook()->getRecycleBinFolderPath();
|
||||
} else if (file->getType() == FileType::Orphan) {
|
||||
const VOrphanFile *tmpFile = dynamic_cast<const VOrphanFile *>((VFile *)file);
|
||||
folderPath = tmpFile->fetchRecycleBinFolderPath();
|
||||
} else {
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
|
||||
QUrl url = QUrl::fromLocalFile(folderPath);
|
||||
QDesktopServices::openUrl(url);
|
||||
});
|
||||
}
|
||||
|
||||
void VEditWindow::setupCornerWidget()
|
||||
{
|
||||
// Left button
|
||||
@ -274,34 +80,17 @@ void VEditWindow::setupCornerWidget()
|
||||
leftBtn->setMenu(leftMenu);
|
||||
|
||||
// Right button
|
||||
// Actions
|
||||
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);
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
rightBtn = new QPushButton(VIconUtils::editWindowCornerIcon(":/resources/icons/corner_menu.svg"),
|
||||
"", this);
|
||||
rightBtn->setProperty("CornerBtn", true);
|
||||
rightBtn->setToolTip(tr("Menu"));
|
||||
QMenu *rightMenu = new QMenu(this);
|
||||
rightMenu->setToolTipsVisible(true);
|
||||
rightMenu->addAction(splitAct);
|
||||
rightMenu->addAction(removeSplitAct);
|
||||
rightBtn->setMenu(rightMenu);
|
||||
connect(rightMenu, &QMenu::aboutToShow,
|
||||
this, &VEditWindow::updateSplitMenu);
|
||||
this, [this, rightMenu]() {
|
||||
updateSplitMenu(rightMenu);
|
||||
});
|
||||
|
||||
// Move all buttons to the right corner.
|
||||
QWidget *widget = new QWidget(this);
|
||||
@ -670,105 +459,310 @@ void VEditWindow::mousePressEvent(QMouseEvent *event)
|
||||
QTabWidget::mousePressEvent(event);
|
||||
}
|
||||
|
||||
QAction *VEditWindow::getRemoveSplitAction()
|
||||
{
|
||||
if (!m_removeSplitAct) {
|
||||
m_removeSplitAct = new QAction(VIconUtils::menuIcon(":/resources/icons/remove_split.svg"),
|
||||
tr("Remove split"),
|
||||
this);
|
||||
m_removeSplitAct->setToolTip(tr("Remove current split window"));
|
||||
VUtils::fixTextWithCaptainShortcut(m_removeSplitAct, "RemoveSplit");
|
||||
connect(m_removeSplitAct, &QAction::triggered,
|
||||
this, &VEditWindow::removeSplit);
|
||||
}
|
||||
|
||||
return m_removeSplitAct;
|
||||
}
|
||||
|
||||
void VEditWindow::contextMenuRequested(QPoint pos)
|
||||
{
|
||||
QMenu menu(this);
|
||||
menu.setToolTipsVisible(true);
|
||||
|
||||
if (canRemoveSplit()) {
|
||||
menu.addAction(removeSplitAct);
|
||||
menu.addAction(getRemoveSplitAction());
|
||||
menu.exec(this->mapToGlobal(pos));
|
||||
}
|
||||
}
|
||||
|
||||
void VEditWindow::tabbarContextMenuRequested(QPoint p_pos)
|
||||
{
|
||||
QMenu menu(this);
|
||||
menu.setToolTipsVisible(true);
|
||||
|
||||
QTabBar *bar = tabBar();
|
||||
int tab = bar->tabAt(p_pos);
|
||||
if (tab == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
QMenu menu(this);
|
||||
menu.setToolTipsVisible(true);
|
||||
|
||||
QAction *recycleBinAct = new QAction(VIconUtils::menuIcon(":/resources/icons/recycle_bin.svg"),
|
||||
tr("&Recycle Bin"),
|
||||
&menu);
|
||||
recycleBinAct->setToolTip(tr("Open the recycle bin of this note"));
|
||||
connect(recycleBinAct, &QAction::triggered,
|
||||
this, [this]() {
|
||||
int tab = GET_TAB_FROM_SENDER();
|
||||
Q_ASSERT(tab != -1);
|
||||
|
||||
VEditTab *editor = getTab(tab);
|
||||
VFile *file = editor->getFile();
|
||||
Q_ASSERT(file);
|
||||
|
||||
QString folderPath;
|
||||
if (file->getType() == FileType::Note) {
|
||||
const VNoteFile *tmpFile = dynamic_cast<const VNoteFile *>((VFile *)file);
|
||||
folderPath = tmpFile->getNotebook()->getRecycleBinFolderPath();
|
||||
} else if (file->getType() == FileType::Orphan) {
|
||||
const VOrphanFile *tmpFile = dynamic_cast<const VOrphanFile *>((VFile *)file);
|
||||
folderPath = tmpFile->fetchRecycleBinFolderPath();
|
||||
} else {
|
||||
Q_ASSERT(false);
|
||||
}
|
||||
|
||||
QUrl url = QUrl::fromLocalFile(folderPath);
|
||||
QDesktopServices::openUrl(url);
|
||||
});
|
||||
|
||||
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, [this](){
|
||||
int tab = GET_TAB_FROM_SENDER();
|
||||
Q_ASSERT(tab != -1);
|
||||
|
||||
VEditTab *editor = getTab(tab);
|
||||
QPointer<VFile> file = editor->getFile();
|
||||
Q_ASSERT(file);
|
||||
QUrl url = QUrl::fromLocalFile(file->fetchBasePath());
|
||||
QDesktopServices::openUrl(url);
|
||||
});
|
||||
|
||||
QAction *reloadAct = new QAction(tr("Reload From Disk"), &menu);
|
||||
reloadAct->setToolTip(tr("Reload the content of this note from disk"));
|
||||
connect(reloadAct, &QAction::triggered,
|
||||
this, [this](){
|
||||
int tab = GET_TAB_FROM_SENDER();
|
||||
Q_ASSERT(tab != -1);
|
||||
|
||||
VEditTab *editor = getTab(tab);
|
||||
editor->reloadFromDisk();
|
||||
});
|
||||
|
||||
QAction *addToCartAct = new QAction(VIconUtils::menuIcon(":/resources/icons/cart.svg"),
|
||||
tr("Add To Cart"),
|
||||
&menu);
|
||||
addToCartAct->setToolTip(tr("Add this note to Cart for further processing"));
|
||||
connect(addToCartAct, &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);
|
||||
g_mainWin->getCart()->addFile(file->fetchPath());
|
||||
g_mainWin->showStatusMessage(tr("1 note added to Cart"));
|
||||
});
|
||||
|
||||
QAction *pinToHistoryAct = new QAction(VIconUtils::menuIcon(":/resources/icons/pin.svg"),
|
||||
tr("Pin To History"),
|
||||
&menu);
|
||||
pinToHistoryAct->setToolTip(tr("Pin this note to History"));
|
||||
connect(pinToHistoryAct, &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);
|
||||
QStringList files;
|
||||
files << file->fetchPath();
|
||||
g_mainWin->getHistoryList()->pinFiles(files);
|
||||
g_mainWin->showStatusMessage(tr("1 note pinned to History"));
|
||||
});
|
||||
|
||||
QAction *noteInfoAct = new QAction(VIconUtils::menuIcon(":/resources/icons/note_info.svg"),
|
||||
tr("Note Info"),
|
||||
&menu);
|
||||
noteInfoAct->setToolTip(tr("View and edit information of the note"));
|
||||
connect(noteInfoAct, &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);
|
||||
if (file->getType() == FileType::Note) {
|
||||
VNoteFile *tmpFile = dynamic_cast<VNoteFile *>((VFile *)file);
|
||||
g_mainWin->getFileList()->fileInfo(tmpFile);
|
||||
} else if (file->getType() == FileType::Orphan) {
|
||||
g_mainWin->editOrphanFileInfo(file);
|
||||
}
|
||||
});
|
||||
|
||||
VEditTab *editor = getTab(tab);
|
||||
VFile *file = editor->getFile();
|
||||
if (file->getType() == FileType::Note) {
|
||||
// Locate to folder.
|
||||
m_locateAct->setData(tab);
|
||||
menu.addAction(m_locateAct);
|
||||
QAction *locateAct = new QAction(VIconUtils::menuIcon(":/resources/icons/locate_note.svg"),
|
||||
tr("Locate To Folder"),
|
||||
&menu);
|
||||
locateAct->setToolTip(tr("Locate the folder of current note"));
|
||||
VUtils::fixTextWithCaptainShortcut(locateAct, "LocateCurrentFile");
|
||||
connect(locateAct, &QAction::triggered,
|
||||
this, &VEditWindow::handleLocateAct);
|
||||
locateAct->setData(tab);
|
||||
menu.addAction(locateAct);
|
||||
|
||||
menu.addSeparator();
|
||||
|
||||
m_recycleBinAct->setData(tab);
|
||||
menu.addAction(m_recycleBinAct);
|
||||
recycleBinAct->setData(tab);
|
||||
menu.addAction(recycleBinAct);
|
||||
|
||||
m_openLocationAct->setData(tab);
|
||||
menu.addAction(m_openLocationAct);
|
||||
openLocationAct->setData(tab);
|
||||
menu.addAction(openLocationAct);
|
||||
|
||||
m_reloadAct->setData(tab);
|
||||
menu.addAction(m_reloadAct);
|
||||
reloadAct->setData(tab);
|
||||
menu.addAction(reloadAct);
|
||||
|
||||
m_addToCartAct->setData(tab);
|
||||
menu.addAction(m_addToCartAct);
|
||||
addToCartAct->setData(tab);
|
||||
menu.addAction(addToCartAct);
|
||||
|
||||
m_pinToHistoryAct->setData(tab);
|
||||
menu.addAction(m_pinToHistoryAct);
|
||||
pinToHistoryAct->setData(tab);
|
||||
menu.addAction(pinToHistoryAct);
|
||||
|
||||
m_noteInfoAct->setData(tab);
|
||||
menu.addAction(m_noteInfoAct);
|
||||
noteInfoAct->setData(tab);
|
||||
menu.addAction(noteInfoAct);
|
||||
} else if (file->getType() == FileType::Orphan
|
||||
&& !(dynamic_cast<VOrphanFile *>(file)->isSystemFile())) {
|
||||
m_recycleBinAct->setData(tab);
|
||||
menu.addAction(m_recycleBinAct);
|
||||
recycleBinAct->setData(tab);
|
||||
menu.addAction(recycleBinAct);
|
||||
|
||||
m_openLocationAct->setData(tab);
|
||||
menu.addAction(m_openLocationAct);
|
||||
openLocationAct->setData(tab);
|
||||
menu.addAction(openLocationAct);
|
||||
|
||||
m_reloadAct->setData(tab);
|
||||
menu.addAction(m_reloadAct);
|
||||
reloadAct->setData(tab);
|
||||
menu.addAction(reloadAct);
|
||||
|
||||
m_addToCartAct->setData(tab);
|
||||
menu.addAction(m_addToCartAct);
|
||||
addToCartAct->setData(tab);
|
||||
menu.addAction(addToCartAct);
|
||||
|
||||
m_pinToHistoryAct->setData(tab);
|
||||
menu.addAction(m_pinToHistoryAct);
|
||||
pinToHistoryAct->setData(tab);
|
||||
menu.addAction(pinToHistoryAct);
|
||||
|
||||
m_noteInfoAct->setData(tab);
|
||||
menu.addAction(m_noteInfoAct);
|
||||
noteInfoAct->setData(tab);
|
||||
menu.addAction(noteInfoAct);
|
||||
}
|
||||
|
||||
|
||||
int totalWin = m_editArea->windowCount();
|
||||
// When there is only one tab and one split window, there is no need to
|
||||
// display these two actions.
|
||||
if (totalWin > 1 || count() > 1) {
|
||||
menu.addSeparator();
|
||||
m_moveLeftAct->setData(tab);
|
||||
// Move one split left.
|
||||
menu.addAction(m_moveLeftAct);
|
||||
|
||||
m_moveRightAct->setData(tab);
|
||||
// Move one split right.
|
||||
menu.addAction(m_moveRightAct);
|
||||
QAction *moveLeftAct = new QAction(VIconUtils::menuIcon(":/resources/icons/move_tab_left.svg"),
|
||||
tr("Move One Split Left"),
|
||||
&menu);
|
||||
moveLeftAct->setToolTip(tr("Move current tab to the split on the left"));
|
||||
VUtils::fixTextWithCaptainShortcut(moveLeftAct, "MoveTabSplitLeft");
|
||||
connect(moveLeftAct, &QAction::triggered,
|
||||
this, &VEditWindow::handleMoveLeftAct);
|
||||
moveLeftAct->setData(tab);
|
||||
menu.addAction(moveLeftAct);
|
||||
|
||||
QAction *moveRightAct = new QAction(VIconUtils::menuIcon(":/resources/icons/move_tab_right.svg"),
|
||||
tr("Move One Split Right"),
|
||||
&menu);
|
||||
moveRightAct->setToolTip(tr("Move current tab to the split on the right"));
|
||||
VUtils::fixTextWithCaptainShortcut(moveRightAct, "MoveTabSplitRight");
|
||||
connect(moveRightAct, &QAction::triggered,
|
||||
this, &VEditWindow::handleMoveRightAct);
|
||||
moveRightAct->setData(tab);
|
||||
menu.addAction(moveRightAct);
|
||||
}
|
||||
|
||||
menu.addSeparator();
|
||||
|
||||
// Close tab, or other tabs, or tabs to the right.
|
||||
menu.addSeparator();
|
||||
m_closeTabAct->setData(tab);
|
||||
menu.addAction(m_closeTabAct);
|
||||
QAction *closeTabAct = new QAction(VIconUtils::menuIcon(":/resources/icons/close.svg"),
|
||||
tr("Close Tab"),
|
||||
&menu);
|
||||
closeTabAct->setToolTip(tr("Close current note tab"));
|
||||
if (!VUtils::fixTextWithShortcut(closeTabAct, "CloseNote")) {
|
||||
VUtils::fixTextWithCaptainShortcut(closeTabAct, "CloseNote");
|
||||
}
|
||||
|
||||
connect(closeTabAct, &QAction::triggered,
|
||||
this, [this](){
|
||||
int tab = GET_TAB_FROM_SENDER();
|
||||
Q_ASSERT(tab != -1);
|
||||
closeTab(tab);
|
||||
});
|
||||
closeTabAct->setData(tab);
|
||||
menu.addAction(closeTabAct);
|
||||
|
||||
if (count() > 1) {
|
||||
m_closeOthersAct->setData(tab);
|
||||
menu.addAction(m_closeOthersAct);
|
||||
QAction *closeOthersAct = new QAction(tr("Close Other Tabs"), &menu);
|
||||
closeOthersAct->setToolTip(tr("Close all other note tabs"));
|
||||
connect(closeOthersAct, &QAction::triggered,
|
||||
this, [this](){
|
||||
int tab = GET_TAB_FROM_SENDER();
|
||||
Q_ASSERT(tab != -1);
|
||||
for (int i = tab - 1; i >= 0; --i) {
|
||||
this->setCurrentIndex(i);
|
||||
this->updateTabStatus(i);
|
||||
if (this->closeTab(i)) {
|
||||
--tab;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = tab + 1; i < this->count();) {
|
||||
this->setCurrentIndex(i);
|
||||
this->updateTabStatus(i);
|
||||
if (!this->closeTab(i)) {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
});
|
||||
closeOthersAct->setData(tab);
|
||||
menu.addAction(closeOthersAct);
|
||||
|
||||
if (tab < count() - 1) {
|
||||
m_closeRightAct->setData(tab);
|
||||
menu.addAction(m_closeRightAct);
|
||||
QAction *closeRightAct = new QAction(tr("Close Tabs To The Right"), &menu);
|
||||
closeRightAct->setToolTip(tr("Close all the note tabs to the right of current tab"));
|
||||
connect(closeRightAct, &QAction::triggered,
|
||||
this, [this](){
|
||||
int tab = GET_TAB_FROM_SENDER();
|
||||
Q_ASSERT(tab != -1);
|
||||
for (int i = tab + 1; i < this->count();) {
|
||||
this->setCurrentIndex(i);
|
||||
this->updateTabStatus(i);
|
||||
if (!this->closeTab(i)) {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
});
|
||||
closeRightAct->setData(tab);
|
||||
menu.addAction(closeRightAct);
|
||||
}
|
||||
}
|
||||
|
||||
menu.addAction(m_closeAllAct);
|
||||
QAction *closeAllAct = new QAction(tr("Close All Tabs"), &menu);
|
||||
closeAllAct->setToolTip(tr("Close all the note tabs"));
|
||||
connect(closeAllAct, &QAction::triggered,
|
||||
this, [this](){
|
||||
for (int i = 0; i < this->count();) {
|
||||
this->setCurrentIndex(i);
|
||||
this->updateTabStatus(i);
|
||||
if (!this->closeTab(i)) {
|
||||
++i;
|
||||
}
|
||||
}
|
||||
});
|
||||
menu.addAction(closeAllAct);
|
||||
|
||||
if (!menu.actions().isEmpty()) {
|
||||
menu.exec(bar->mapToGlobal(p_pos));
|
||||
@ -788,13 +782,25 @@ void VEditWindow::tabListJump(VFile *p_file)
|
||||
updateTabStatus(idx);
|
||||
}
|
||||
|
||||
void VEditWindow::updateSplitMenu()
|
||||
void VEditWindow::updateSplitMenu(QMenu *p_menu)
|
||||
{
|
||||
if (canRemoveSplit()) {
|
||||
removeSplitAct->setVisible(true);
|
||||
} else {
|
||||
removeSplitAct->setVisible(false);
|
||||
if (p_menu->isEmpty()) {
|
||||
QAction *splitAct = new QAction(VIconUtils::menuIcon(":/resources/icons/split_window.svg"),
|
||||
tr("Split"),
|
||||
p_menu);
|
||||
splitAct->setToolTip(tr("Split current window vertically"));
|
||||
VUtils::fixTextWithCaptainShortcut(splitAct, "VerticalSplit");
|
||||
connect(splitAct, &QAction::triggered,
|
||||
this, [this](){
|
||||
splitWindow(true);
|
||||
});
|
||||
|
||||
p_menu->addAction(splitAct);
|
||||
|
||||
p_menu->addAction(getRemoveSplitAction());
|
||||
}
|
||||
|
||||
getRemoveSplitAction()->setVisible(canRemoveSplit());
|
||||
}
|
||||
|
||||
bool VEditWindow::canRemoveSplit()
|
||||
@ -943,7 +949,7 @@ QVector<VEditTabInfo> VEditWindow::getAllTabsInfo() const
|
||||
|
||||
void VEditWindow::handleLocateAct()
|
||||
{
|
||||
int tab = m_locateAct->data().toInt();
|
||||
int tab = GET_TAB_FROM_SENDER();
|
||||
VEditTab *editor = getTab(tab);
|
||||
QPointer<VFile> file = editor->getFile();
|
||||
if (file->getType() == FileType::Note) {
|
||||
@ -953,14 +959,14 @@ void VEditWindow::handleLocateAct()
|
||||
|
||||
void VEditWindow::handleMoveLeftAct()
|
||||
{
|
||||
int tab = m_moveLeftAct->data().toInt();
|
||||
int tab = GET_TAB_FROM_SENDER();
|
||||
Q_ASSERT(tab != -1);
|
||||
moveTabOneSplit(tab, false);
|
||||
}
|
||||
|
||||
void VEditWindow::handleMoveRightAct()
|
||||
{
|
||||
int tab = m_moveRightAct->data().toInt();
|
||||
int tab = GET_TAB_FROM_SENDER();
|
||||
Q_ASSERT(tab != -1);
|
||||
moveTabOneSplit(tab, true);
|
||||
}
|
||||
|
@ -14,6 +14,7 @@
|
||||
class QPushButton;
|
||||
class QActionGroup;
|
||||
class VEditArea;
|
||||
class QMenu;
|
||||
|
||||
// Tab info for navigation mode.
|
||||
struct TabNavigationInfo
|
||||
@ -146,7 +147,8 @@ private slots:
|
||||
|
||||
void handleTabCurrentHeaderChanged(const VHeaderPointer &p_header);
|
||||
|
||||
void updateSplitMenu();
|
||||
void updateSplitMenu(QMenu *p_menu);
|
||||
|
||||
void tabbarContextMenuRequested(QPoint p_pos);
|
||||
void handleLocateAct();
|
||||
void handleMoveLeftAct();
|
||||
@ -165,8 +167,8 @@ private slots:
|
||||
void tabRequestToClose(VEditTab *p_tab);
|
||||
|
||||
private:
|
||||
void initTabActions();
|
||||
void setupCornerWidget();
|
||||
|
||||
void removeEditTab(int p_index);
|
||||
|
||||
int insertEditTab(int p_index, VFile *p_file, QWidget *p_page);
|
||||
@ -194,6 +196,8 @@ private:
|
||||
// Connect the signals of VEditTab to this VEditWindow.
|
||||
void connectEditTab(const VEditTab *p_tab);
|
||||
|
||||
QAction *getRemoveSplitAction();
|
||||
|
||||
VEditArea *m_editArea;
|
||||
|
||||
// These two members are only used for alternateTab().
|
||||
@ -206,42 +210,7 @@ private:
|
||||
QPushButton *leftBtn;
|
||||
|
||||
// Actions
|
||||
QAction *splitAct;
|
||||
QAction *removeSplitAct;
|
||||
// Locate current note in the directory and file list
|
||||
QAction *m_locateAct;
|
||||
QAction *m_moveLeftAct;
|
||||
QAction *m_moveRightAct;
|
||||
|
||||
// Close current tab action in tab menu.
|
||||
QAction *m_closeTabAct;
|
||||
|
||||
// Close other tabs action in tab menu.
|
||||
QAction *m_closeOthersAct;
|
||||
|
||||
// Close tabs to the right in tab menu.
|
||||
QAction *m_closeRightAct;
|
||||
|
||||
// Close all tabs.
|
||||
QAction *m_closeAllAct;
|
||||
|
||||
// View and edit info about this note.
|
||||
QAction *m_noteInfoAct;
|
||||
|
||||
// Add this note to Cart.
|
||||
QAction *m_addToCartAct;
|
||||
|
||||
// Pin this note to History.
|
||||
QAction *m_pinToHistoryAct;
|
||||
|
||||
// Open the location (the folder containing this file) of this note.
|
||||
QAction *m_openLocationAct;
|
||||
|
||||
// Reload the note from disk.
|
||||
QAction *m_reloadAct;
|
||||
|
||||
// Open the recycle bin folder of this note.
|
||||
QAction *m_recycleBinAct;
|
||||
QAction *m_removeSplitAct;
|
||||
};
|
||||
|
||||
inline QString VEditWindow::generateTooltip(const VFile *p_file) const
|
||||
|
Loading…
x
Reference in New Issue
Block a user