mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-06 06:19:52 +08:00
feature/add_viewarea_shortcut_close_other_right (#2173)
* feature/add_viewarea_shortcut_close_other_right * delete default * adj multi * del blank line * add close all and close left * adj * adj * del unless
This commit is contained in:
parent
17af3b8dc0
commit
8c0c056c47
@ -24,7 +24,9 @@ namespace vnotex
|
|||||||
NewNote,
|
NewNote,
|
||||||
NewFolder,
|
NewFolder,
|
||||||
CloseTab,
|
CloseTab,
|
||||||
|
CloseAllTabs,
|
||||||
CloseOtherTabs,
|
CloseOtherTabs,
|
||||||
|
CloseTabsToTheLeft,
|
||||||
CloseTabsToTheRight,
|
CloseTabsToTheRight,
|
||||||
NavigationDock,
|
NavigationDock,
|
||||||
OutlineDock,
|
OutlineDock,
|
||||||
|
@ -16,7 +16,9 @@
|
|||||||
"NewNote" : "Ctrl+Alt+N",
|
"NewNote" : "Ctrl+Alt+N",
|
||||||
"NewFolder" : "Ctrl+Alt+S",
|
"NewFolder" : "Ctrl+Alt+S",
|
||||||
"CloseTab" : "Ctrl+G, X",
|
"CloseTab" : "Ctrl+G, X",
|
||||||
|
"CloseAllTabs": "",
|
||||||
"CloseOtherTabs" : "",
|
"CloseOtherTabs" : "",
|
||||||
|
"CloseTabsToTheLeft" : "",
|
||||||
"CloseTabsToTheRight" : "",
|
"CloseTabsToTheRight" : "",
|
||||||
"NavigationDock" : "Ctrl+G, A",
|
"NavigationDock" : "Ctrl+G, A",
|
||||||
"OutlineDock" : "Ctrl+G, U",
|
"OutlineDock" : "Ctrl+G, U",
|
||||||
|
@ -819,6 +819,50 @@ void ViewArea::setupShortcuts()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CloseAllTabs
|
||||||
|
{
|
||||||
|
auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::CloseAllTabs), this);
|
||||||
|
if (shortcut) {
|
||||||
|
connect(shortcut, &QShortcut::activated,
|
||||||
|
this, [this]() {
|
||||||
|
getCurrentViewSplit()->closeMultipleTabs(ViewSplit::CloseTabMode::CloseAllTabs);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CloseOtherTabs
|
||||||
|
{
|
||||||
|
auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::CloseOtherTabs), this);
|
||||||
|
if (shortcut) {
|
||||||
|
connect(shortcut, &QShortcut::activated,
|
||||||
|
this, [this]() {
|
||||||
|
getCurrentViewSplit()->closeMultipleTabs(ViewSplit::CloseTabMode::CloseOtherTabs);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CloseTabsToTheLeft
|
||||||
|
{
|
||||||
|
auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::CloseTabsToTheLeft), this);
|
||||||
|
if (shortcut) {
|
||||||
|
connect(shortcut, &QShortcut::activated,
|
||||||
|
this, [this]() {
|
||||||
|
getCurrentViewSplit()->closeMultipleTabs(ViewSplit::CloseTabMode::CloseTabsToTheLeft);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// CloseTabsToTheRight
|
||||||
|
{
|
||||||
|
auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::CloseTabsToTheRight), this);
|
||||||
|
if (shortcut) {
|
||||||
|
connect(shortcut, &QShortcut::activated,
|
||||||
|
this, [this]() {
|
||||||
|
getCurrentViewSplit()->closeMultipleTabs(ViewSplit::CloseTabMode::CloseTabsToTheRight);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// LocateNode.
|
// LocateNode.
|
||||||
{
|
{
|
||||||
auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::LocateNode), this);
|
auto shortcut = WidgetUtils::createShortcut(coreConfig.getShortcut(CoreConfig::LocateNode), this);
|
||||||
|
@ -541,34 +541,41 @@ void ViewSplit::createContextMenuOnTabBar(QMenu *p_menu, int p_tabIdx)
|
|||||||
coreConfig.getShortcut(CoreConfig::Shortcut::CloseTab));
|
coreConfig.getShortcut(CoreConfig::Shortcut::CloseTab));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close All Tabs.
|
||||||
|
{
|
||||||
|
auto closeTabAct = p_menu->addAction(tr("Close All Tabs"),
|
||||||
|
[this, p_tabIdx]() {
|
||||||
|
closeMultipleTabs(p_tabIdx, CloseTabMode::CloseAllTabs);
|
||||||
|
});
|
||||||
|
WidgetUtils::addActionShortcutText(closeTabAct,
|
||||||
|
coreConfig.getShortcut(CoreConfig::Shortcut::CloseAllTabs));
|
||||||
|
}
|
||||||
|
|
||||||
// Close Other Tabs.
|
// Close Other Tabs.
|
||||||
{
|
{
|
||||||
auto closeTabAct = p_menu->addAction(tr("Close Other Tabs"),
|
auto closeTabAct = p_menu->addAction(tr("Close Other Tabs"),
|
||||||
[this, p_tabIdx]() {
|
[this, p_tabIdx]() {
|
||||||
QVector<ViewWindow *> windowsNeedToClose;
|
closeMultipleTabs(p_tabIdx, CloseTabMode::CloseOtherTabs);
|
||||||
int cnt = getViewWindowCount();
|
|
||||||
for (int i = 0; i < cnt; ++i) {
|
|
||||||
if (i != p_tabIdx) {
|
|
||||||
windowsNeedToClose.push_back(getViewWindow(i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto win : windowsNeedToClose) {
|
|
||||||
emit viewWindowCloseRequested(win);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
WidgetUtils::addActionShortcutText(closeTabAct,
|
WidgetUtils::addActionShortcutText(closeTabAct,
|
||||||
coreConfig.getShortcut(CoreConfig::Shortcut::CloseOtherTabs));
|
coreConfig.getShortcut(CoreConfig::Shortcut::CloseOtherTabs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close Tabs To The Left
|
||||||
|
{
|
||||||
|
auto closeTabAct = p_menu->addAction(tr("Close Tabs To The Left"),
|
||||||
|
[this, p_tabIdx]() {
|
||||||
|
closeMultipleTabs(p_tabIdx, CloseTabMode::CloseTabsToTheLeft);
|
||||||
|
});
|
||||||
|
WidgetUtils::addActionShortcutText(closeTabAct,
|
||||||
|
coreConfig.getShortcut(CoreConfig::Shortcut::CloseTabsToTheLeft));
|
||||||
|
}
|
||||||
|
|
||||||
// Close Tabs To The Right.
|
// Close Tabs To The Right.
|
||||||
{
|
{
|
||||||
auto closeTabAct = p_menu->addAction(tr("Close Tabs To The Right"),
|
auto closeTabAct = p_menu->addAction(tr("Close Tabs To The Right"),
|
||||||
[this, p_tabIdx]() {
|
[this, p_tabIdx]() {
|
||||||
int cnt = getViewWindowCount();
|
closeMultipleTabs(p_tabIdx, CloseTabMode::CloseTabsToTheRight);
|
||||||
for (int i = cnt - 1; i > p_tabIdx; --i) {
|
|
||||||
closeTab(i);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
WidgetUtils::addActionShortcutText(closeTabAct,
|
WidgetUtils::addActionShortcutText(closeTabAct,
|
||||||
coreConfig.getShortcut(CoreConfig::Shortcut::CloseTabsToTheRight));
|
coreConfig.getShortcut(CoreConfig::Shortcut::CloseTabsToTheRight));
|
||||||
@ -700,6 +707,46 @@ void ViewSplit::closeTab(int p_idx)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ViewSplit::closeMultipleTabs(CloseTabMode p_ctm)
|
||||||
|
{
|
||||||
|
closeMultipleTabs(currentIndex(), p_ctm);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ViewSplit::closeMultipleTabs(int p_idx, CloseTabMode p_ctm)
|
||||||
|
{
|
||||||
|
QVector<ViewWindow *> windowsNeedToClose;
|
||||||
|
int cnt = getViewWindowCount();
|
||||||
|
|
||||||
|
switch (p_ctm) {
|
||||||
|
case CloseTabMode::CloseAllTabs:
|
||||||
|
for (int i = 0; i < cnt; i++) {
|
||||||
|
windowsNeedToClose.push_back(getViewWindow(i));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CloseTabMode::CloseOtherTabs:
|
||||||
|
for (int i = 0; i < cnt; i++) {
|
||||||
|
if (i != p_idx) {
|
||||||
|
windowsNeedToClose.push_back(getViewWindow(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CloseTabMode::CloseTabsToTheLeft:
|
||||||
|
for (int i = 0; i < p_idx; i++) {
|
||||||
|
windowsNeedToClose.push_back(getViewWindow(i));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case CloseTabMode::CloseTabsToTheRight:
|
||||||
|
for (int i = cnt - 1; i > p_idx; i--) {
|
||||||
|
windowsNeedToClose.push_back(getViewWindow(i));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto win : windowsNeedToClose) {
|
||||||
|
emit viewWindowCloseRequested(win);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ViewSplit::mousePressEvent(QMouseEvent *p_event)
|
void ViewSplit::mousePressEvent(QMouseEvent *p_event)
|
||||||
{
|
{
|
||||||
QTabWidget::mousePressEvent(p_event);
|
QTabWidget::mousePressEvent(p_event);
|
||||||
|
@ -70,6 +70,15 @@ namespace vnotex
|
|||||||
|
|
||||||
void updateStateToWorkspace() const;
|
void updateStateToWorkspace() const;
|
||||||
|
|
||||||
|
enum class CloseTabMode {
|
||||||
|
CloseAllTabs,
|
||||||
|
CloseOtherTabs,
|
||||||
|
CloseTabsToTheLeft,
|
||||||
|
CloseTabsToTheRight
|
||||||
|
};
|
||||||
|
|
||||||
|
void closeMultipleTabs(CloseTabMode p_ctm);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void viewWindowCloseRequested(ViewWindow *p_win);
|
void viewWindowCloseRequested(ViewWindow *p_win);
|
||||||
|
|
||||||
@ -136,6 +145,8 @@ namespace vnotex
|
|||||||
|
|
||||||
void activateNextTab(bool p_backward);
|
void activateNextTab(bool p_backward);
|
||||||
|
|
||||||
|
void closeMultipleTabs(int p_idx, CloseTabMode ctm);
|
||||||
|
|
||||||
ID m_id = 0;
|
ID m_id = 0;
|
||||||
|
|
||||||
const QVector<QSharedPointer<ViewWorkspace>> &m_allWorkspaces;
|
const QVector<QSharedPointer<ViewWorkspace>> &m_allWorkspaces;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user