2014-08-10 16:52:06 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2014 by Emmanuel Pescosta <emmanuelpescosta099@gmail.com> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "dolphintabwidget.h"
|
|
|
|
|
Elide tab titles left so key information at the end of the string doesn't get cut off
Summary:
Tab Titles currently elide right. Generally the more useful information is at the right
side of the string--even more so when full paths are being used.
BUG: 406569
FIXED-IN: 19.04.2
Test Plan:
- No change when tab titles don't get elided
- When tabs show the full path and titles are elided, they're now useful: {F6782447}
- When tabs don't show the full path and are elided, they're elided on the other side which seems maybe a tiny bit better, but at least no worse: {F6782448}
Reviewers: #dolphin, #vdg, elvisangelaccio
Reviewed By: #dolphin, elvisangelaccio
Subscribers: ndavis, elvisangelaccio, kneckermcknacksack, filipf, kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D20689
2019-04-19 16:24:52 +00:00
|
|
|
#include "dolphin_generalsettings.h"
|
2014-08-10 16:52:06 +00:00
|
|
|
#include "dolphintabbar.h"
|
|
|
|
#include "dolphintabpage.h"
|
|
|
|
#include "dolphinviewcontainer.h"
|
|
|
|
|
|
|
|
#include <KConfigGroup>
|
2015-10-21 11:45:01 +00:00
|
|
|
#include <KShell>
|
2014-08-22 21:17:02 +00:00
|
|
|
#include <kio/global.h>
|
2020-04-05 11:44:12 +00:00
|
|
|
#include <KIO/CommandLauncherJob>
|
2019-10-21 19:39:30 +00:00
|
|
|
#include <KAcceleratorManager>
|
2018-03-04 13:38:16 +00:00
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QDropEvent>
|
2014-08-10 16:52:06 +00:00
|
|
|
|
|
|
|
DolphinTabWidget::DolphinTabWidget(QWidget* parent) :
|
|
|
|
QTabWidget(parent),
|
2016-12-17 13:23:20 +00:00
|
|
|
m_placesSelectorVisible(true),
|
2018-04-08 04:35:38 +00:00
|
|
|
m_lastViewedTab(0)
|
2014-08-10 16:52:06 +00:00
|
|
|
{
|
2019-10-21 19:39:30 +00:00
|
|
|
KAcceleratorManager::setNoAccel(this);
|
|
|
|
|
2016-03-16 21:17:37 +00:00
|
|
|
connect(this, &DolphinTabWidget::tabCloseRequested,
|
2019-05-05 15:20:44 +00:00
|
|
|
this, QOverload<int>::of(&DolphinTabWidget::closeTab));
|
2016-03-16 21:17:37 +00:00
|
|
|
connect(this, &DolphinTabWidget::currentChanged,
|
|
|
|
this, &DolphinTabWidget::currentTabChanged);
|
2014-08-10 16:52:06 +00:00
|
|
|
|
|
|
|
DolphinTabBar* tabBar = new DolphinTabBar(this);
|
2016-03-16 21:17:37 +00:00
|
|
|
connect(tabBar, &DolphinTabBar::openNewActivatedTab,
|
2019-05-05 15:20:44 +00:00
|
|
|
this, QOverload<int>::of(&DolphinTabWidget::openNewActivatedTab));
|
2016-03-16 21:17:37 +00:00
|
|
|
connect(tabBar, &DolphinTabBar::tabDropEvent,
|
|
|
|
this, &DolphinTabWidget::tabDropEvent);
|
|
|
|
connect(tabBar, &DolphinTabBar::tabDetachRequested,
|
|
|
|
this, &DolphinTabWidget::detachTab);
|
2014-08-10 16:52:06 +00:00
|
|
|
tabBar->hide();
|
|
|
|
|
|
|
|
setTabBar(tabBar);
|
|
|
|
setDocumentMode(true);
|
|
|
|
setElideMode(Qt::ElideRight);
|
|
|
|
setUsesScrollButtons(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
DolphinTabPage* DolphinTabWidget::currentTabPage() const
|
|
|
|
{
|
|
|
|
return tabPageAt(currentIndex());
|
|
|
|
}
|
|
|
|
|
2018-04-08 04:35:38 +00:00
|
|
|
DolphinTabPage* DolphinTabWidget::nextTabPage() const
|
|
|
|
{
|
|
|
|
const int index = currentIndex() + 1;
|
|
|
|
return tabPageAt(index < count() ? index : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
DolphinTabPage* DolphinTabWidget::prevTabPage() const
|
|
|
|
{
|
|
|
|
const int index = currentIndex() - 1;
|
|
|
|
return tabPageAt(index >= 0 ? index : (count() - 1));
|
|
|
|
}
|
|
|
|
|
2014-08-10 16:52:06 +00:00
|
|
|
DolphinTabPage* DolphinTabWidget::tabPageAt(const int index) const
|
|
|
|
{
|
|
|
|
return static_cast<DolphinTabPage*>(widget(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinTabWidget::saveProperties(KConfigGroup& group) const
|
|
|
|
{
|
|
|
|
const int tabCount = count();
|
|
|
|
group.writeEntry("Tab Count", tabCount);
|
|
|
|
group.writeEntry("Active Tab Index", currentIndex());
|
|
|
|
|
|
|
|
for (int i = 0; i < tabCount; ++i) {
|
|
|
|
const DolphinTabPage* tabPage = tabPageAt(i);
|
2014-08-20 21:06:39 +00:00
|
|
|
group.writeEntry("Tab Data " % QString::number(i), tabPage->saveState());
|
2014-08-10 16:52:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinTabWidget::readProperties(const KConfigGroup& group)
|
|
|
|
{
|
|
|
|
const int tabCount = group.readEntry("Tab Count", 0);
|
|
|
|
for (int i = 0; i < tabCount; ++i) {
|
|
|
|
if (i >= count()) {
|
|
|
|
openNewActivatedTab();
|
|
|
|
}
|
2014-08-20 21:06:39 +00:00
|
|
|
if (group.hasKey("Tab Data " % QString::number(i))) {
|
|
|
|
// Tab state created with Dolphin > 4.14.x
|
|
|
|
const QByteArray state = group.readEntry("Tab Data " % QString::number(i), QByteArray());
|
|
|
|
tabPageAt(i)->restoreState(state);
|
|
|
|
} else {
|
|
|
|
// Tab state created with Dolphin <= 4.14.x
|
|
|
|
const QByteArray state = group.readEntry("Tab " % QString::number(i), QByteArray());
|
|
|
|
tabPageAt(i)->restoreStateV1(state);
|
|
|
|
}
|
2014-08-10 16:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const int index = group.readEntry("Active Tab Index", 0);
|
|
|
|
setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinTabWidget::refreshViews()
|
|
|
|
{
|
Elide tab titles left so key information at the end of the string doesn't get cut off
Summary:
Tab Titles currently elide right. Generally the more useful information is at the right
side of the string--even more so when full paths are being used.
BUG: 406569
FIXED-IN: 19.04.2
Test Plan:
- No change when tab titles don't get elided
- When tabs show the full path and titles are elided, they're now useful: {F6782447}
- When tabs don't show the full path and are elided, they're elided on the other side which seems maybe a tiny bit better, but at least no worse: {F6782448}
Reviewers: #dolphin, #vdg, elvisangelaccio
Reviewed By: #dolphin, elvisangelaccio
Subscribers: ndavis, elvisangelaccio, kneckermcknacksack, filipf, kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D20689
2019-04-19 16:24:52 +00:00
|
|
|
// Left-elision is better when showing full paths, since you care most
|
|
|
|
// about the current directory which is on the right
|
|
|
|
if (GeneralSettings::showFullPathInTitlebar()) {
|
|
|
|
setElideMode(Qt::ElideLeft);
|
|
|
|
} else {
|
|
|
|
setElideMode(Qt::ElideRight);
|
|
|
|
}
|
|
|
|
|
2014-08-10 16:52:06 +00:00
|
|
|
const int tabCount = count();
|
|
|
|
for (int i = 0; i < tabCount; ++i) {
|
2018-08-28 07:00:13 +00:00
|
|
|
tabBar()->setTabText(i, tabName(tabPageAt(i)));
|
2014-08-10 16:52:06 +00:00
|
|
|
tabPageAt(i)->refreshViews();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-10 23:09:30 +00:00
|
|
|
bool DolphinTabWidget::isUrlOpen(const QUrl &url) const
|
|
|
|
{
|
|
|
|
return indexByUrl(url).first >= 0;
|
|
|
|
}
|
|
|
|
|
2014-08-10 16:52:06 +00:00
|
|
|
void DolphinTabWidget::openNewActivatedTab()
|
|
|
|
{
|
|
|
|
const DolphinViewContainer* oldActiveViewContainer = currentTabPage()->activeViewContainer();
|
|
|
|
Q_ASSERT(oldActiveViewContainer);
|
|
|
|
|
|
|
|
const bool isUrlEditable = oldActiveViewContainer->urlNavigator()->isUrlEditable();
|
|
|
|
|
|
|
|
openNewActivatedTab(oldActiveViewContainer->url());
|
|
|
|
|
|
|
|
DolphinViewContainer* newActiveViewContainer = currentTabPage()->activeViewContainer();
|
|
|
|
Q_ASSERT(newActiveViewContainer);
|
|
|
|
|
|
|
|
// The URL navigator of the new tab should have the same editable state
|
|
|
|
// as the current tab
|
2019-01-29 13:31:46 +00:00
|
|
|
newActiveViewContainer->urlNavigator()->setUrlEditable(isUrlEditable);
|
2014-08-10 16:52:06 +00:00
|
|
|
|
2019-01-29 13:31:46 +00:00
|
|
|
// Always focus the new tab's view
|
|
|
|
newActiveViewContainer->view()->setFocus();
|
2014-08-10 16:52:06 +00:00
|
|
|
}
|
|
|
|
|
2014-10-21 19:18:43 +00:00
|
|
|
void DolphinTabWidget::openNewActivatedTab(const QUrl& primaryUrl, const QUrl& secondaryUrl)
|
2014-08-10 16:52:06 +00:00
|
|
|
{
|
|
|
|
openNewTab(primaryUrl, secondaryUrl);
|
|
|
|
setCurrentIndex(count() - 1);
|
|
|
|
}
|
|
|
|
|
2019-02-12 10:07:43 +00:00
|
|
|
void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl, TabPlacement tabPlacement)
|
2014-08-10 16:52:06 +00:00
|
|
|
{
|
|
|
|
QWidget* focusWidget = QApplication::focusWidget();
|
|
|
|
|
|
|
|
DolphinTabPage* tabPage = new DolphinTabPage(primaryUrl, secondaryUrl, this);
|
2019-07-28 14:16:49 +00:00
|
|
|
tabPage->setActive(false);
|
2014-08-10 16:52:06 +00:00
|
|
|
tabPage->setPlacesSelectorVisible(m_placesSelectorVisible);
|
2016-03-16 21:17:37 +00:00
|
|
|
connect(tabPage, &DolphinTabPage::activeViewChanged,
|
|
|
|
this, &DolphinTabWidget::activeViewChanged);
|
|
|
|
connect(tabPage, &DolphinTabPage::activeViewUrlChanged,
|
|
|
|
this, &DolphinTabWidget::tabUrlChanged);
|
2019-02-12 10:07:43 +00:00
|
|
|
int newTabIndex = -1;
|
|
|
|
if (tabPlacement == AfterCurrentTab) {
|
|
|
|
newTabIndex = currentIndex() + 1;
|
|
|
|
}
|
2019-09-02 07:13:56 +00:00
|
|
|
insertTab(newTabIndex, tabPage, QIcon() /* loaded in tabInserted */, tabName(tabPage));
|
2014-08-10 16:52:06 +00:00
|
|
|
|
|
|
|
if (focusWidget) {
|
|
|
|
// The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
|
|
|
|
// in background, assure that the previous focused widget gets the focus back.
|
|
|
|
focusWidget->setFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-27 10:55:53 +00:00
|
|
|
void DolphinTabWidget::openDirectories(const QList<QUrl>& dirs, bool splitView)
|
2014-08-10 16:52:06 +00:00
|
|
|
{
|
2015-04-27 10:55:53 +00:00
|
|
|
Q_ASSERT(dirs.size() > 0);
|
2014-08-10 16:52:06 +00:00
|
|
|
|
2014-10-20 22:27:42 +00:00
|
|
|
QList<QUrl>::const_iterator it = dirs.constBegin();
|
2014-08-10 16:52:06 +00:00
|
|
|
while (it != dirs.constEnd()) {
|
2014-10-20 22:27:42 +00:00
|
|
|
const QUrl& primaryUrl = *(it++);
|
2019-09-10 23:09:30 +00:00
|
|
|
const QPair<int, bool> indexInfo = indexByUrl(primaryUrl);
|
|
|
|
const int index = indexInfo.first;
|
|
|
|
const bool isInPrimaryView = indexInfo.second;
|
|
|
|
if (index >= 0) {
|
|
|
|
setCurrentIndex(index);
|
|
|
|
const auto tabPage = tabPageAt(index);
|
|
|
|
if (isInPrimaryView) {
|
2019-09-02 21:15:08 +00:00
|
|
|
tabPage->primaryViewContainer()->setActive(true);
|
|
|
|
} else {
|
|
|
|
tabPage->secondaryViewContainer()->setActive(true);
|
|
|
|
}
|
2020-03-01 17:20:54 +00:00
|
|
|
// BUG: 417230
|
2020-03-01 16:31:02 +00:00
|
|
|
// Required for updateViewState() call in openFiles() to work as expected
|
|
|
|
// If there is a selection, updateViewState() calls are effectively a no-op
|
|
|
|
tabPage->activeViewContainer()->view()->clearSelection();
|
Open externally called files/directories in new tabs
Summary:
FEATURE: 183429
FIXED-IN: 19.08.0
GUI: new cli argument --new-window
Externally called files/directories are opened in a a new tab of an instance of Dolphin that already exists. If any of the given URIs are already open in a tab, then those tabs are activated instead of a new tab being opened. If there is no instance then the files/directories are opened in a new window. The newly opened file/directory has its tab activated, and consequently, the window is also activated.
When the user clicks "Open In New Window" or "Detach Tab", the files/directories are opened in a new window.
Test Plan:
[Manual]
Before testing, set the default file manager in system settings as the newly built Dolphin executable.
One must also include the new dolphin executable in the $PATH, otherwise some functions will attempt to open the system dolphin instead of the new one.
Furthermore, running two different versions of Dolphin (in particular, where one does not have this patch included) can result in bugs appearing, in particular, new tabs not opening as old instances will not recognise the DBus commands sent to it. However, I see no reason why a user will have two different versions of Dolphin (apart from people like us :D).
Open directories with the help of auxillary programs (i.e. a browser). The files/directories should appear in a new window if an instance does not exist. If an existence already exists, then a new tab should be opened and activated in that instance and the window activated.
Use QDBusViewer to open folders/items by calling the ShowFolders/ShowItems methods in org.freedesktop.FileManager1 of the Dolphin instance.
When a user chooses to "Open In New Window"/"Detach Tab" then the files/directories should be opened in a new window.
Reviewers: #dolphin, elvisangelaccio
Subscribers: zzag, dfaure, fvogt, fikrim, magar, fbg13, davidedmundson, kwin, ngraham, elvisangelaccio, anthonyfieroni, kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D16648
2019-05-30 20:22:43 +00:00
|
|
|
continue;
|
|
|
|
}
|
2015-04-27 10:55:53 +00:00
|
|
|
if (splitView && (it != dirs.constEnd())) {
|
2014-10-20 22:27:42 +00:00
|
|
|
const QUrl& secondaryUrl = *(it++);
|
Open externally called files/directories in new tabs
Summary:
FEATURE: 183429
FIXED-IN: 19.08.0
GUI: new cli argument --new-window
Externally called files/directories are opened in a a new tab of an instance of Dolphin that already exists. If any of the given URIs are already open in a tab, then those tabs are activated instead of a new tab being opened. If there is no instance then the files/directories are opened in a new window. The newly opened file/directory has its tab activated, and consequently, the window is also activated.
When the user clicks "Open In New Window" or "Detach Tab", the files/directories are opened in a new window.
Test Plan:
[Manual]
Before testing, set the default file manager in system settings as the newly built Dolphin executable.
One must also include the new dolphin executable in the $PATH, otherwise some functions will attempt to open the system dolphin instead of the new one.
Furthermore, running two different versions of Dolphin (in particular, where one does not have this patch included) can result in bugs appearing, in particular, new tabs not opening as old instances will not recognise the DBus commands sent to it. However, I see no reason why a user will have two different versions of Dolphin (apart from people like us :D).
Open directories with the help of auxillary programs (i.e. a browser). The files/directories should appear in a new window if an instance does not exist. If an existence already exists, then a new tab should be opened and activated in that instance and the window activated.
Use QDBusViewer to open folders/items by calling the ShowFolders/ShowItems methods in org.freedesktop.FileManager1 of the Dolphin instance.
When a user chooses to "Open In New Window"/"Detach Tab" then the files/directories should be opened in a new window.
Reviewers: #dolphin, elvisangelaccio
Subscribers: zzag, dfaure, fvogt, fikrim, magar, fbg13, davidedmundson, kwin, ngraham, elvisangelaccio, anthonyfieroni, kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D16648
2019-05-30 20:22:43 +00:00
|
|
|
openNewActivatedTab(primaryUrl, secondaryUrl);
|
2014-08-10 16:52:06 +00:00
|
|
|
} else {
|
Open externally called files/directories in new tabs
Summary:
FEATURE: 183429
FIXED-IN: 19.08.0
GUI: new cli argument --new-window
Externally called files/directories are opened in a a new tab of an instance of Dolphin that already exists. If any of the given URIs are already open in a tab, then those tabs are activated instead of a new tab being opened. If there is no instance then the files/directories are opened in a new window. The newly opened file/directory has its tab activated, and consequently, the window is also activated.
When the user clicks "Open In New Window" or "Detach Tab", the files/directories are opened in a new window.
Test Plan:
[Manual]
Before testing, set the default file manager in system settings as the newly built Dolphin executable.
One must also include the new dolphin executable in the $PATH, otherwise some functions will attempt to open the system dolphin instead of the new one.
Furthermore, running two different versions of Dolphin (in particular, where one does not have this patch included) can result in bugs appearing, in particular, new tabs not opening as old instances will not recognise the DBus commands sent to it. However, I see no reason why a user will have two different versions of Dolphin (apart from people like us :D).
Open directories with the help of auxillary programs (i.e. a browser). The files/directories should appear in a new window if an instance does not exist. If an existence already exists, then a new tab should be opened and activated in that instance and the window activated.
Use QDBusViewer to open folders/items by calling the ShowFolders/ShowItems methods in org.freedesktop.FileManager1 of the Dolphin instance.
When a user chooses to "Open In New Window"/"Detach Tab" then the files/directories should be opened in a new window.
Reviewers: #dolphin, elvisangelaccio
Subscribers: zzag, dfaure, fvogt, fikrim, magar, fbg13, davidedmundson, kwin, ngraham, elvisangelaccio, anthonyfieroni, kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D16648
2019-05-30 20:22:43 +00:00
|
|
|
openNewActivatedTab(primaryUrl);
|
2014-08-10 16:52:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-27 10:55:53 +00:00
|
|
|
void DolphinTabWidget::openFiles(const QList<QUrl>& files, bool splitView)
|
2014-08-10 16:52:06 +00:00
|
|
|
{
|
2015-04-27 10:55:53 +00:00
|
|
|
Q_ASSERT(files.size() > 0);
|
2014-08-10 16:52:06 +00:00
|
|
|
|
|
|
|
// Get all distinct directories from 'files' and open a tab
|
|
|
|
// for each directory. If the "split view" option is enabled, two
|
|
|
|
// directories are shown inside one tab (see openDirectories()).
|
2014-10-20 22:27:42 +00:00
|
|
|
QList<QUrl> dirs;
|
2014-10-21 19:18:43 +00:00
|
|
|
foreach (const QUrl& url, files) {
|
2014-10-21 20:01:34 +00:00
|
|
|
const QUrl dir(url.adjusted(QUrl::RemoveFilename));
|
2014-08-10 16:52:06 +00:00
|
|
|
if (!dirs.contains(dir)) {
|
|
|
|
dirs.append(dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const int oldTabCount = count();
|
2015-04-27 10:55:53 +00:00
|
|
|
openDirectories(dirs, splitView);
|
2014-08-10 16:52:06 +00:00
|
|
|
const int tabCount = count();
|
|
|
|
|
|
|
|
// Select the files. Although the files can be split between several
|
|
|
|
// tabs, there is no need to split 'files' accordingly, as
|
|
|
|
// the DolphinView will just ignore invalid selections.
|
2020-03-01 16:31:02 +00:00
|
|
|
for (int i = 0; i < tabCount; ++i) {
|
2014-08-10 16:52:06 +00:00
|
|
|
DolphinTabPage* tabPage = tabPageAt(i);
|
|
|
|
tabPage->markUrlsAsSelected(files);
|
|
|
|
tabPage->markUrlAsCurrent(files.first());
|
2020-03-01 16:31:02 +00:00
|
|
|
if (i < oldTabCount) {
|
|
|
|
// Force selection of file if directory was already open, BUG: 417230
|
|
|
|
tabPage->activeViewContainer()->view()->updateViewState();
|
|
|
|
}
|
2014-08-10 16:52:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinTabWidget::closeTab()
|
|
|
|
{
|
|
|
|
closeTab(currentIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinTabWidget::closeTab(const int index)
|
|
|
|
{
|
|
|
|
Q_ASSERT(index >= 0);
|
|
|
|
Q_ASSERT(index < count());
|
|
|
|
|
|
|
|
if (count() < 2) {
|
Close Dolphin if last tab closed
Summary:
Allows closing of last tab via shortcut or menubar (File->Close Tab), which then results in closing dolphin.
FEATURE: 397101
Test Plan: [Manual] Check closing tab closes dolphin via shortcut and menubar.
Reviewers: #dolphin, ngraham, #vdg, elvisangelaccio
Reviewed By: #dolphin, ngraham, #vdg, elvisangelaccio
Subscribers: thsurrel, svenmauch, abetts, elvisangelaccio, ngraham, #dolphin, kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D15278
2018-10-27 09:23:52 +00:00
|
|
|
// Close Dolphin when closing the last tab.
|
|
|
|
parentWidget()->close();
|
2014-08-10 16:52:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DolphinTabPage* tabPage = tabPageAt(index);
|
2014-08-10 18:36:44 +00:00
|
|
|
emit rememberClosedTab(tabPage->activeViewContainer()->url(), tabPage->saveState());
|
2014-08-10 16:52:06 +00:00
|
|
|
|
|
|
|
removeTab(index);
|
|
|
|
tabPage->deleteLater();
|
|
|
|
}
|
|
|
|
|
2019-10-13 14:37:00 +00:00
|
|
|
void DolphinTabWidget::activateTab(const int index)
|
|
|
|
{
|
|
|
|
if (index < count()) {
|
|
|
|
setCurrentIndex(index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinTabWidget::activateLastTab()
|
|
|
|
{
|
|
|
|
setCurrentIndex(count() - 1);
|
|
|
|
}
|
|
|
|
|
2014-08-10 16:52:06 +00:00
|
|
|
void DolphinTabWidget::activateNextTab()
|
|
|
|
{
|
|
|
|
const int index = currentIndex() + 1;
|
|
|
|
setCurrentIndex(index < count() ? index : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinTabWidget::activatePrevTab()
|
|
|
|
{
|
|
|
|
const int index = currentIndex() - 1;
|
|
|
|
setCurrentIndex(index >= 0 ? index : (count() - 1));
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinTabWidget::slotPlacesPanelVisibilityChanged(bool visible)
|
|
|
|
{
|
|
|
|
// The places-selector from the URL navigator should only be shown
|
|
|
|
// if the places dock is invisible
|
|
|
|
m_placesSelectorVisible = !visible;
|
|
|
|
|
|
|
|
const int tabCount = count();
|
|
|
|
for (int i = 0; i < tabCount; ++i) {
|
|
|
|
DolphinTabPage* tabPage = tabPageAt(i);
|
|
|
|
tabPage->setPlacesSelectorVisible(m_placesSelectorVisible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-10 18:36:44 +00:00
|
|
|
void DolphinTabWidget::restoreClosedTab(const QByteArray& state)
|
|
|
|
{
|
|
|
|
openNewActivatedTab();
|
|
|
|
currentTabPage()->restoreState(state);
|
|
|
|
}
|
|
|
|
|
2014-08-10 16:52:06 +00:00
|
|
|
void DolphinTabWidget::detachTab(int index)
|
|
|
|
{
|
|
|
|
Q_ASSERT(index >= 0);
|
|
|
|
|
2015-10-21 11:45:01 +00:00
|
|
|
QStringList args;
|
2014-08-10 16:52:06 +00:00
|
|
|
|
|
|
|
const DolphinTabPage* tabPage = tabPageAt(index);
|
2015-10-21 11:45:01 +00:00
|
|
|
args << tabPage->primaryViewContainer()->url().url();
|
2014-08-10 16:52:06 +00:00
|
|
|
if (tabPage->splitViewEnabled()) {
|
2015-10-21 11:45:01 +00:00
|
|
|
args << tabPage->secondaryViewContainer()->url().url();
|
|
|
|
args << QStringLiteral("--split");
|
2014-08-10 16:52:06 +00:00
|
|
|
}
|
Open externally called files/directories in new tabs
Summary:
FEATURE: 183429
FIXED-IN: 19.08.0
GUI: new cli argument --new-window
Externally called files/directories are opened in a a new tab of an instance of Dolphin that already exists. If any of the given URIs are already open in a tab, then those tabs are activated instead of a new tab being opened. If there is no instance then the files/directories are opened in a new window. The newly opened file/directory has its tab activated, and consequently, the window is also activated.
When the user clicks "Open In New Window" or "Detach Tab", the files/directories are opened in a new window.
Test Plan:
[Manual]
Before testing, set the default file manager in system settings as the newly built Dolphin executable.
One must also include the new dolphin executable in the $PATH, otherwise some functions will attempt to open the system dolphin instead of the new one.
Furthermore, running two different versions of Dolphin (in particular, where one does not have this patch included) can result in bugs appearing, in particular, new tabs not opening as old instances will not recognise the DBus commands sent to it. However, I see no reason why a user will have two different versions of Dolphin (apart from people like us :D).
Open directories with the help of auxillary programs (i.e. a browser). The files/directories should appear in a new window if an instance does not exist. If an existence already exists, then a new tab should be opened and activated in that instance and the window activated.
Use QDBusViewer to open folders/items by calling the ShowFolders/ShowItems methods in org.freedesktop.FileManager1 of the Dolphin instance.
When a user chooses to "Open In New Window"/"Detach Tab" then the files/directories should be opened in a new window.
Reviewers: #dolphin, elvisangelaccio
Subscribers: zzag, dfaure, fvogt, fikrim, magar, fbg13, davidedmundson, kwin, ngraham, elvisangelaccio, anthonyfieroni, kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D16648
2019-05-30 20:22:43 +00:00
|
|
|
args << QStringLiteral("--new-window");
|
2014-08-10 16:52:06 +00:00
|
|
|
|
2020-04-05 11:44:12 +00:00
|
|
|
KIO::CommandLauncherJob *job = new KIO::CommandLauncherJob("dolphin", args, this);
|
|
|
|
job->setDesktopName(QStringLiteral("org.kde.dolphin"));
|
|
|
|
job->start();
|
2014-08-10 16:52:06 +00:00
|
|
|
|
|
|
|
closeTab(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinTabWidget::openNewActivatedTab(int index)
|
|
|
|
{
|
|
|
|
Q_ASSERT(index >= 0);
|
|
|
|
const DolphinTabPage* tabPage = tabPageAt(index);
|
|
|
|
openNewActivatedTab(tabPage->activeViewContainer()->url());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinTabWidget::tabDropEvent(int index, QDropEvent* event)
|
|
|
|
{
|
|
|
|
if (index >= 0) {
|
2014-12-26 07:57:42 +00:00
|
|
|
DolphinView* view = tabPageAt(index)->activeViewContainer()->view();
|
2017-07-12 08:40:15 +00:00
|
|
|
view->dropUrls(view->url(), event, view);
|
2014-08-10 16:52:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-21 19:18:43 +00:00
|
|
|
void DolphinTabWidget::tabUrlChanged(const QUrl& url)
|
2014-08-10 16:52:06 +00:00
|
|
|
{
|
|
|
|
const int index = indexOf(qobject_cast<QWidget*>(sender()));
|
|
|
|
if (index >= 0) {
|
2018-08-28 07:00:13 +00:00
|
|
|
tabBar()->setTabText(index, tabName(tabPageAt(index)));
|
2019-09-02 07:13:56 +00:00
|
|
|
if (tabBar()->isVisible()) {
|
|
|
|
tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(url)));
|
|
|
|
} else {
|
|
|
|
// Mark as dirty, actually load once the tab bar actually gets shown
|
|
|
|
tabBar()->setTabIcon(index, QIcon());
|
|
|
|
}
|
2014-08-13 20:06:28 +00:00
|
|
|
|
|
|
|
// Emit the currentUrlChanged signal if the url of the current tab has been changed.
|
|
|
|
if (index == currentIndex()) {
|
|
|
|
emit currentUrlChanged(url);
|
|
|
|
}
|
2014-08-10 16:52:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinTabWidget::currentTabChanged(int index)
|
|
|
|
{
|
2018-04-08 04:35:38 +00:00
|
|
|
// last-viewed tab deactivation
|
|
|
|
if (DolphinTabPage* tabPage = tabPageAt(m_lastViewedTab)) {
|
2017-05-22 17:35:29 +00:00
|
|
|
tabPage->setActive(false);
|
|
|
|
}
|
|
|
|
DolphinTabPage* tabPage = tabPageAt(index);
|
|
|
|
DolphinViewContainer* viewContainer = tabPage->activeViewContainer();
|
2014-08-13 20:06:28 +00:00
|
|
|
emit activeViewChanged(viewContainer);
|
|
|
|
emit currentUrlChanged(viewContainer->url());
|
2017-05-22 17:35:29 +00:00
|
|
|
tabPage->setActive(true);
|
2018-04-08 04:35:38 +00:00
|
|
|
m_lastViewedTab = index;
|
2014-08-10 16:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinTabWidget::tabInserted(int index)
|
|
|
|
{
|
|
|
|
QTabWidget::tabInserted(index);
|
|
|
|
|
|
|
|
if (count() > 1) {
|
2019-09-02 07:13:56 +00:00
|
|
|
// Resolve all pending tab icons
|
|
|
|
for (int i = 0; i < count(); ++i) {
|
|
|
|
if (tabBar()->tabIcon(i).isNull()) {
|
|
|
|
tabBar()->setTabIcon(i, QIcon::fromTheme(KIO::iconNameForUrl(tabPageAt(i)->activeViewContainer()->url())));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-10 16:52:06 +00:00
|
|
|
tabBar()->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
emit tabCountChanged(count());
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinTabWidget::tabRemoved(int index)
|
|
|
|
{
|
|
|
|
QTabWidget::tabRemoved(index);
|
|
|
|
|
|
|
|
// If only one tab is left, then remove the tab entry so that
|
|
|
|
// closing the last tab is not possible.
|
|
|
|
if (count() < 2) {
|
|
|
|
tabBar()->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
emit tabCountChanged(count());
|
|
|
|
}
|
|
|
|
|
2018-08-28 07:00:13 +00:00
|
|
|
QString DolphinTabWidget::tabName(DolphinTabPage* tabPage) const
|
2014-08-10 16:52:06 +00:00
|
|
|
{
|
2018-08-28 07:00:13 +00:00
|
|
|
if (!tabPage) {
|
2018-07-28 15:29:00 +00:00
|
|
|
return QString();
|
2014-08-10 16:52:06 +00:00
|
|
|
}
|
2018-08-28 07:50:41 +00:00
|
|
|
QString name = tabPage->activeViewContainer()->caption();
|
2018-07-28 15:29:00 +00:00
|
|
|
// Make sure that a '&' inside the directory name is displayed correctly
|
|
|
|
// and not misinterpreted as a keyboard shortcut in QTabBar::setTabText()
|
|
|
|
return name.replace('&', QLatin1String("&&"));
|
2014-08-10 16:52:06 +00:00
|
|
|
}
|
Open externally called files/directories in new tabs
Summary:
FEATURE: 183429
FIXED-IN: 19.08.0
GUI: new cli argument --new-window
Externally called files/directories are opened in a a new tab of an instance of Dolphin that already exists. If any of the given URIs are already open in a tab, then those tabs are activated instead of a new tab being opened. If there is no instance then the files/directories are opened in a new window. The newly opened file/directory has its tab activated, and consequently, the window is also activated.
When the user clicks "Open In New Window" or "Detach Tab", the files/directories are opened in a new window.
Test Plan:
[Manual]
Before testing, set the default file manager in system settings as the newly built Dolphin executable.
One must also include the new dolphin executable in the $PATH, otherwise some functions will attempt to open the system dolphin instead of the new one.
Furthermore, running two different versions of Dolphin (in particular, where one does not have this patch included) can result in bugs appearing, in particular, new tabs not opening as old instances will not recognise the DBus commands sent to it. However, I see no reason why a user will have two different versions of Dolphin (apart from people like us :D).
Open directories with the help of auxillary programs (i.e. a browser). The files/directories should appear in a new window if an instance does not exist. If an existence already exists, then a new tab should be opened and activated in that instance and the window activated.
Use QDBusViewer to open folders/items by calling the ShowFolders/ShowItems methods in org.freedesktop.FileManager1 of the Dolphin instance.
When a user chooses to "Open In New Window"/"Detach Tab" then the files/directories should be opened in a new window.
Reviewers: #dolphin, elvisangelaccio
Subscribers: zzag, dfaure, fvogt, fikrim, magar, fbg13, davidedmundson, kwin, ngraham, elvisangelaccio, anthonyfieroni, kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D16648
2019-05-30 20:22:43 +00:00
|
|
|
|
2019-09-10 23:09:30 +00:00
|
|
|
QPair<int, bool> DolphinTabWidget::indexByUrl(const QUrl& url) const
|
Open externally called files/directories in new tabs
Summary:
FEATURE: 183429
FIXED-IN: 19.08.0
GUI: new cli argument --new-window
Externally called files/directories are opened in a a new tab of an instance of Dolphin that already exists. If any of the given URIs are already open in a tab, then those tabs are activated instead of a new tab being opened. If there is no instance then the files/directories are opened in a new window. The newly opened file/directory has its tab activated, and consequently, the window is also activated.
When the user clicks "Open In New Window" or "Detach Tab", the files/directories are opened in a new window.
Test Plan:
[Manual]
Before testing, set the default file manager in system settings as the newly built Dolphin executable.
One must also include the new dolphin executable in the $PATH, otherwise some functions will attempt to open the system dolphin instead of the new one.
Furthermore, running two different versions of Dolphin (in particular, where one does not have this patch included) can result in bugs appearing, in particular, new tabs not opening as old instances will not recognise the DBus commands sent to it. However, I see no reason why a user will have two different versions of Dolphin (apart from people like us :D).
Open directories with the help of auxillary programs (i.e. a browser). The files/directories should appear in a new window if an instance does not exist. If an existence already exists, then a new tab should be opened and activated in that instance and the window activated.
Use QDBusViewer to open folders/items by calling the ShowFolders/ShowItems methods in org.freedesktop.FileManager1 of the Dolphin instance.
When a user chooses to "Open In New Window"/"Detach Tab" then the files/directories should be opened in a new window.
Reviewers: #dolphin, elvisangelaccio
Subscribers: zzag, dfaure, fvogt, fikrim, magar, fbg13, davidedmundson, kwin, ngraham, elvisangelaccio, anthonyfieroni, kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D16648
2019-05-30 20:22:43 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < count(); i++) {
|
2019-09-02 21:15:08 +00:00
|
|
|
const auto tabPage = tabPageAt(i);
|
|
|
|
if (url == tabPage->primaryViewContainer()->url()) {
|
|
|
|
return qMakePair(i, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tabPage->splitViewEnabled() && url == tabPage->secondaryViewContainer()->url()) {
|
|
|
|
return qMakePair(i, false);
|
Open externally called files/directories in new tabs
Summary:
FEATURE: 183429
FIXED-IN: 19.08.0
GUI: new cli argument --new-window
Externally called files/directories are opened in a a new tab of an instance of Dolphin that already exists. If any of the given URIs are already open in a tab, then those tabs are activated instead of a new tab being opened. If there is no instance then the files/directories are opened in a new window. The newly opened file/directory has its tab activated, and consequently, the window is also activated.
When the user clicks "Open In New Window" or "Detach Tab", the files/directories are opened in a new window.
Test Plan:
[Manual]
Before testing, set the default file manager in system settings as the newly built Dolphin executable.
One must also include the new dolphin executable in the $PATH, otherwise some functions will attempt to open the system dolphin instead of the new one.
Furthermore, running two different versions of Dolphin (in particular, where one does not have this patch included) can result in bugs appearing, in particular, new tabs not opening as old instances will not recognise the DBus commands sent to it. However, I see no reason why a user will have two different versions of Dolphin (apart from people like us :D).
Open directories with the help of auxillary programs (i.e. a browser). The files/directories should appear in a new window if an instance does not exist. If an existence already exists, then a new tab should be opened and activated in that instance and the window activated.
Use QDBusViewer to open folders/items by calling the ShowFolders/ShowItems methods in org.freedesktop.FileManager1 of the Dolphin instance.
When a user chooses to "Open In New Window"/"Detach Tab" then the files/directories should be opened in a new window.
Reviewers: #dolphin, elvisangelaccio
Subscribers: zzag, dfaure, fvogt, fikrim, magar, fbg13, davidedmundson, kwin, ngraham, elvisangelaccio, anthonyfieroni, kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D16648
2019-05-30 20:22:43 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-02 21:15:08 +00:00
|
|
|
return qMakePair(-1, false);
|
Open externally called files/directories in new tabs
Summary:
FEATURE: 183429
FIXED-IN: 19.08.0
GUI: new cli argument --new-window
Externally called files/directories are opened in a a new tab of an instance of Dolphin that already exists. If any of the given URIs are already open in a tab, then those tabs are activated instead of a new tab being opened. If there is no instance then the files/directories are opened in a new window. The newly opened file/directory has its tab activated, and consequently, the window is also activated.
When the user clicks "Open In New Window" or "Detach Tab", the files/directories are opened in a new window.
Test Plan:
[Manual]
Before testing, set the default file manager in system settings as the newly built Dolphin executable.
One must also include the new dolphin executable in the $PATH, otherwise some functions will attempt to open the system dolphin instead of the new one.
Furthermore, running two different versions of Dolphin (in particular, where one does not have this patch included) can result in bugs appearing, in particular, new tabs not opening as old instances will not recognise the DBus commands sent to it. However, I see no reason why a user will have two different versions of Dolphin (apart from people like us :D).
Open directories with the help of auxillary programs (i.e. a browser). The files/directories should appear in a new window if an instance does not exist. If an existence already exists, then a new tab should be opened and activated in that instance and the window activated.
Use QDBusViewer to open folders/items by calling the ShowFolders/ShowItems methods in org.freedesktop.FileManager1 of the Dolphin instance.
When a user chooses to "Open In New Window"/"Detach Tab" then the files/directories should be opened in a new window.
Reviewers: #dolphin, elvisangelaccio
Subscribers: zzag, dfaure, fvogt, fikrim, magar, fbg13, davidedmundson, kwin, ngraham, elvisangelaccio, anthonyfieroni, kfm-devel
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D16648
2019-05-30 20:22:43 +00:00
|
|
|
}
|