[utilities/krusader] krusader: New tabs start in current folder and can be inserted next to the current tab or at the end
Toni Asensi Esteve
null at kde.org
Tue Jul 6 21:16:25 BST 2021
Git commit cf2296b94a091581df8729b73cbe0dba4641d554 by Toni Asensi Esteve.
Committed on 06/07/2021 at 20:15.
Pushed by asensi into branch 'master'.
New tabs start in current folder and can be inserted next to the current tab or at the end
ADDED: New tabs start in current folder.
ADDED: New tabs can be inserted next to the current tab or at the end of the tab list.
GUI: An "Insert Tabs After Current" / "Insert new tabs to the right of the current one" option can be chosen.
Revision: https://invent.kde.org/utilities/krusader/-/merge_requests/50
M +3 -2 krusader/Konfigurator/kgpanel.cpp
M +20 -13 krusader/panelmanager.cpp
M +3 -2 krusader/panelmanager.h
M +16 -7 krusader/paneltabbar.cpp
M +6 -1 krusader/tabactions.cpp
M +3 -1 krusader/tabactions.h
https://invent.kde.org/utilities/krusader/commit/cf2296b94a091581df8729b73cbe0dba4641d554
diff --git a/krusader/Konfigurator/kgpanel.cpp b/krusader/Konfigurator/kgpanel.cpp
index fbc195ab..d0f7abcd 100644
--- a/krusader/Konfigurator/kgpanel.cpp
+++ b/krusader/Konfigurator/kgpanel.cpp
@@ -120,9 +120,10 @@ void KgPanel::setupGeneralTab()
{"Look&Feel", "Expanding Tabs", true, i18n("Expanding tabs"), true, i18n("Expanding tabs.") },
{"Look&Feel", "Show New Tab Button", true, i18n("Show new tab button"), true, i18n("Show new tab button.") },
{"Look&Feel", "Close Tab By Double Click", false, i18n("Close tab by double click"), true, i18n("Close tab by double click.") },
- {"Look&Feel", "Show Tab Bar On Single Tab", true, i18n("Show Tab Bar on single tab"), true, i18n("Show the tab bar with only one tab.") }
+ {"Look&Feel", "Show Tab Bar On Single Tab", true, i18n("Show Tab Bar on single tab"), true, i18n("Show the tab bar with only one tab.") },
+ {"Look&Feel", "Insert Tabs After Current", false, i18n("Insert tabs after current"), false, i18n("Insert new tabs to the right of the current one.") }
};
- cbs = createCheckBoxGroup(2, 0, tabbar_settings, 6 /*count*/, groupBox, PAGE_GENERAL);
+ cbs = createCheckBoxGroup(2, 0, tabbar_settings, 7 /*count*/, groupBox, PAGE_GENERAL);
gridLayout->addWidget(cbs, 0, 0, 1, 2);
// ----------------- Tab Bar position ----------------------------------
diff --git a/krusader/panelmanager.cpp b/krusader/panelmanager.cpp
index 84eb9ba0..98b54a90 100644
--- a/krusader/panelmanager.cpp
+++ b/krusader/panelmanager.cpp
@@ -49,11 +49,11 @@ PanelManager::PanelManager(QWidget *parent, KrMainWindow* mainWindow, bool left)
// new tab button
_newTab = new QToolButton(this);
_newTab->setAutoRaise(true);
- _newTab->setText(i18n("Open a new tab in home"));
- _newTab->setToolTip(i18n("Open a new tab in home"));
+ _newTab->setText(i18n("Open a new tab"));
+ _newTab->setToolTip(i18n("Open a new tab"));
_newTab->setIcon(Icon("tab-new"));
_newTab->adjustSize();
- connect(_newTab, &QToolButton::clicked, this, QOverload<>::of(&PanelManager::slotNewTab));
+ connect(_newTab, &QToolButton::clicked, this, &PanelManager::slotNewTabFromUI);
// tab-bar
_tabbar = new PanelTabBar(this, _actions);
@@ -171,15 +171,16 @@ ListPanel *PanelManager::addPanel(bool setCurrent, const KConfigGroup &cfg, int
return p;
}
-ListPanel *PanelManager::duplicatePanel(const KConfigGroup &cfg, KrPanel *nextTo)
+ListPanel *PanelManager::duplicatePanel(const KConfigGroup &cfg, KrPanel *nextTo, int insertIndex)
{
// Search for the position where the passed panel is
- int insertIndex = -1;
- int quantOfPanels = _tabbar->count();
- for (int i = 0; i < quantOfPanels; i++) {
- if (_tabbar->getPanel(i) == nextTo) {
- insertIndex = i + 1;
- break;
+ if (insertIndex == -1) {
+ int quantOfPanels = _tabbar->count();
+ for (int i = 0; i < quantOfPanels; i++) {
+ if (_tabbar->getPanel(i) == nextTo) {
+ insertIndex = i + 1;
+ break;
+ }
}
}
@@ -213,7 +214,7 @@ void PanelManager::loadSettings(KConfigGroup config)
if (grpTab.keyList().isEmpty())
continue;
- ListPanel *panel = i < numTabsOld ? _tabbar->getPanel(i) : addPanel(false, grpTab);
+ ListPanel *panel = i < numTabsOld ? _tabbar->getPanel(i) : addPanel(false, grpTab, i);
panel->restoreSettings(grpTab);
_tabbar->updateTab(panel);
}
@@ -283,15 +284,21 @@ void PanelManager::slotNewTab(const QUrl &url, bool setCurrent, int insertIndex)
p->start(url);
}
+void PanelManager::slotNewTabFromUI()
+{
+ int insertIndex = KConfigGroup(krConfig, "Look&Feel").readEntry("Insert Tabs After Current", false) ? _tabbar->currentIndex() + 1 : _tabbar->count();
+ slotDuplicateTab(currentPanel()->virtualPath(), currentPanel(), insertIndex);
+}
+
void PanelManager::slotNewTab()
{
slotNewTab(QUrl::fromLocalFile(QDir::home().absolutePath()));
_currentPanel->slotFocusOnMe();
}
-void PanelManager::slotDuplicateTab(const QUrl &url, KrPanel *nextTo)
+void PanelManager::slotDuplicateTab(const QUrl &url, KrPanel *nextTo, int insertIndex)
{
- ListPanel *p = duplicatePanel(KConfigGroup(), nextTo);
+ ListPanel *p = duplicatePanel(KConfigGroup(), nextTo, insertIndex);
if(nextTo && nextTo->gui) {
// We duplicate tab settings by writing original settings to a temporary
// group and making the new tab read settings from it. Duplicating
diff --git a/krusader/panelmanager.h b/krusader/panelmanager.h
index 4578f537..6aada37b 100644
--- a/krusader/panelmanager.h
+++ b/krusader/panelmanager.h
@@ -98,8 +98,9 @@ public slots:
Q_SCRIPTABLE void newTabs(const QStringList& urls);
void slotNewTab(const QUrl &url, bool setCurrent = true, int insertIndex = -1);
+ void slotNewTabFromUI();
void slotNewTab();
- void slotDuplicateTab(const QUrl &url, KrPanel *nextTo);
+ void slotDuplicateTab(const QUrl &url, KrPanel *nextTo, int insertIndex = -1);
void slotLockTab();
void slotPinTab();
void slotNextTab();
@@ -126,7 +127,7 @@ private:
void updateTabbarPos();
void tabsCountChanged();
ListPanel *addPanel(bool setCurrent = true, const KConfigGroup &cfg = KConfigGroup(), int insertIndex = -1);
- ListPanel *duplicatePanel(const KConfigGroup &cfg, KrPanel *nextTo);
+ ListPanel *duplicatePanel(const KConfigGroup &cfg, KrPanel *nextTo, int insertIndex = -1);
ListPanel* createPanel(const KConfigGroup& cfg);
void connectPanel(ListPanel *p);
void disconnectPanel(ListPanel *p);
diff --git a/krusader/paneltabbar.cpp b/krusader/paneltabbar.cpp
index 28d637d0..4f2d7be2 100644
--- a/krusader/paneltabbar.cpp
+++ b/krusader/paneltabbar.cpp
@@ -32,7 +32,6 @@
#include <KI18n/KLocalizedString>
#include <KWidgetsAddons/KActionMenu>
-
static const int sDragEnterDelay = 500; // msec
PanelTabBar::PanelTabBar(QWidget *parent, TabActions *actions): QTabBar(parent),
@@ -49,7 +48,7 @@ PanelTabBar::PanelTabBar(QWidget *parent, TabActions *actions): QTabBar(parent),
setExpanding(expandingTabs);
setTabsClosable(showCloseButtons);
- insertAction(actions->actNewTab);
+ insertAction(actions->actNewTabFromUI);
insertAction(actions->actLockTab);
insertAction(actions->actPinTab);
insertAction(actions->actDupTab);
@@ -82,22 +81,32 @@ void PanelTabBar::insertAction(QAction* action)
int PanelTabBar::addPanel(ListPanel *panel, bool setCurrent, int insertIndex)
{
+ // If the position where to place the new tab is not specified,
+ // take the settings into account
+ if (insertIndex == -1) {
+ insertIndex = KConfigGroup(krConfig, "Look&Feel").readEntry("Insert Tabs After Current", false) ?
+ currentIndex() + 1 : count();
+ }
+
QUrl virtualPath = panel->virtualPath();
panel->setPinnedUrl(virtualPath);
const QString text = squeeze(virtualPath);
- const int index = insertIndex != -1 ? insertTab(insertIndex, text) : addTab(text);
+ // In the help about `insertTab()` it's written that it inserts a new tab at
+ // position `index`. If `index` is out of range, the new tab is appened. Returns
+ // the new tab's index
+ insertIndex = insertTab(insertIndex, text);
- setTabData(index, QVariant((long long) panel));
+ setTabData(insertIndex, QVariant(reinterpret_cast<long long>(panel)));
- setIcon(index, panel);
+ setIcon(insertIndex, panel);
// make sure all tabs lengths are correct
layoutTabs();
if (setCurrent)
- setCurrentIndex(index);
+ setCurrentIndex(insertIndex);
- return index;
+ return insertIndex;
}
ListPanel* PanelTabBar::getPanel(int tabIdx)
diff --git a/krusader/tabactions.cpp b/krusader/tabactions.cpp
index eadff031..d6457617 100644
--- a/krusader/tabactions.cpp
+++ b/krusader/tabactions.cpp
@@ -20,7 +20,7 @@
TabActions::TabActions(QObject *parent, KrMainWindow *mainWindow) : ActionsBase(parent, mainWindow)
{
- actNewTab = action(i18n("New Tab"), "tab-new", QKeySequence::keyBindings(QKeySequence::AddTab), this, SLOT(newTab()), "new tab");
+ actNewTabFromUI = action(i18n("New Tab"), "tab-new", QKeySequence::keyBindings(QKeySequence::AddTab), this, SLOT(newTabFromUI()), "new_tab_from_UI");
actDupTab = action(i18n("Duplicate Current Tab"), "tab-duplicate", Qt::ALT + Qt::CTRL + Qt::SHIFT + Qt::Key_N, SLOT(duplicateTab()), "duplicate tab");
actMoveTabToOtherSide = action(i18n("Move Current Tab to Other Side"), nullptr, Qt::CTRL + Qt::SHIFT + Qt::Key_O, SLOT(moveTabToOtherSide()), "move_tab_to_other_side");
actMoveTabToLeft = action(i18n("Move Current Tab to the Left"), nullptr, Qt::CTRL + Qt::SHIFT + Qt::Key_PageUp, SLOT(moveTabToLeft()), "move_tab_to_left");
@@ -66,6 +66,11 @@ void TabActions::newTab()
activeManager()->slotNewTab();
}
+void TabActions::newTabFromUI()
+{
+ activeManager()->slotNewTabFromUI();
+}
+
void TabActions::duplicateTab()
{
KrPanel *activePanel = static_cast<KrMainWindow*>(_mainWindow)->activePanel();
diff --git a/krusader/tabactions.h b/krusader/tabactions.h
index 20741fd3..c5383f8c 100644
--- a/krusader/tabactions.h
+++ b/krusader/tabactions.h
@@ -30,6 +30,7 @@ public slots:
protected slots:
void newTab();
+ void newTabFromUI();
void duplicateTab();
void lockTab();
void pinTab();
@@ -46,7 +47,8 @@ protected slots:
protected:
inline PanelManager *activeManager();
- QAction *actNewTab, *actDupTab, *actCloseTab, *actUndoCloseTab;
+ QAction *actNewTabFromUI; //! When using the User Interface to open a new tab (with its peculiarities)
+ QAction *actDupTab, *actCloseTab, *actUndoCloseTab;
QAction *actPreviousTab, *actNextTab, *actMoveTabToOtherSide;
QAction *actCloseInactiveTabs, *actCloseDuplicatedTabs, *actLockTab, *actPinTab;
QAction *actMoveTabToLeft, *actMoveTabToRight;
More information about the kde-doc-english
mailing list