2020-08-25 17:07:38 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2014 Emmanuel Pescosta <emmanuelpescosta099@gmail.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2014-08-10 16:52:06 +00:00
|
|
|
|
|
|
|
#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 "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
|
|
|
|
2020-09-20 16:53:59 +00:00
|
|
|
DolphinTabWidget::DolphinTabWidget(DolphinNavigatorsWidgetAction *navigatorsWidget, QWidget* parent) :
|
2014-08-10 16:52:06 +00:00
|
|
|
QTabWidget(parent),
|
2020-09-20 16:53:59 +00:00
|
|
|
m_lastViewedTab(nullptr),
|
|
|
|
m_navigatorsWidget{navigatorsWidget}
|
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();
|
|
|
|
}
|
2021-04-23 17:43:55 +00:00
|
|
|
const QByteArray state = group.readEntry("Tab Data " % QString::number(i), QByteArray());
|
|
|
|
tabPageAt(i)->restoreState(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()
|
|
|
|
{
|
2020-09-20 16:53:59 +00:00
|
|
|
std::unique_ptr<DolphinUrlNavigator::VisualState> oldNavigatorState;
|
2020-10-28 16:52:29 +00:00
|
|
|
if (currentTabPage()->primaryViewActive() || !m_navigatorsWidget->secondaryUrlNavigator()) {
|
2020-09-20 16:53:59 +00:00
|
|
|
oldNavigatorState = m_navigatorsWidget->primaryUrlNavigator()->visualState();
|
|
|
|
} else {
|
|
|
|
oldNavigatorState = m_navigatorsWidget->secondaryUrlNavigator()->visualState();
|
|
|
|
}
|
|
|
|
|
2014-08-10 16:52:06 +00:00
|
|
|
const DolphinViewContainer* oldActiveViewContainer = currentTabPage()->activeViewContainer();
|
|
|
|
Q_ASSERT(oldActiveViewContainer);
|
|
|
|
|
|
|
|
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
|
2020-09-20 16:53:59 +00:00
|
|
|
newActiveViewContainer->urlNavigator()->setVisualState(*oldNavigatorState.get());
|
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);
|
2020-12-12 13:17:23 +00:00
|
|
|
if (GeneralSettings::openNewTabAfterLastTab()) {
|
|
|
|
setCurrentIndex(count() - 1);
|
|
|
|
} else {
|
|
|
|
setCurrentIndex(currentIndex() + 1);
|
|
|
|
}
|
2014-08-10 16:52:06 +00:00
|
|
|
}
|
|
|
|
|
2020-12-12 13:17:23 +00:00
|
|
|
void DolphinTabWidget::openNewTab(const QUrl& primaryUrl, const QUrl& secondaryUrl)
|
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);
|
2016-03-16 21:17:37 +00:00
|
|
|
connect(tabPage, &DolphinTabPage::activeViewChanged,
|
|
|
|
this, &DolphinTabWidget::activeViewChanged);
|
|
|
|
connect(tabPage, &DolphinTabPage::activeViewUrlChanged,
|
|
|
|
this, &DolphinTabWidget::tabUrlChanged);
|
2021-09-13 15:34:40 +00:00
|
|
|
connect(tabPage->activeViewContainer(), &DolphinViewContainer::captionChanged, this, [this, tabPage]() {
|
|
|
|
const int tabIndex = indexOf(tabPage);
|
|
|
|
Q_ASSERT(tabIndex >= 0);
|
|
|
|
tabBar()->setTabText(tabIndex, tabName(tabPage));
|
|
|
|
});
|
|
|
|
|
2019-02-12 10:07:43 +00:00
|
|
|
int newTabIndex = -1;
|
2020-12-12 13:17:23 +00:00
|
|
|
if (!GeneralSettings::openNewTabAfterLastTab()) {
|
2019-02-12 10:07:43 +00:00
|
|
|
newTabIndex = currentIndex() + 1;
|
|
|
|
}
|
2021-09-13 15:34:40 +00:00
|
|
|
|
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
|
|
|
|
2021-03-18 19:42:59 +00:00
|
|
|
bool somethingWasAlreadyOpen = false;
|
|
|
|
|
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;
|
2021-03-18 19:42:59 +00:00
|
|
|
|
|
|
|
// When the user asks for a URL that's already open, activate it instead
|
|
|
|
// of opening a second copy
|
2019-09-10 23:09:30 +00:00
|
|
|
if (index >= 0) {
|
2021-03-18 19:42:59 +00:00
|
|
|
somethingWasAlreadyOpen = true;
|
|
|
|
activateTab(index);
|
2019-09-10 23:09:30 +00:00
|
|
|
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();
|
2021-03-30 19:30:27 +00:00
|
|
|
} else if (splitView && (it != dirs.constEnd())) {
|
2014-10-20 22:27:42 +00:00
|
|
|
const QUrl& secondaryUrl = *(it++);
|
2021-03-18 19:42:59 +00:00
|
|
|
if (somethingWasAlreadyOpen) {
|
|
|
|
openNewTab(primaryUrl, secondaryUrl);
|
|
|
|
} else {
|
|
|
|
openNewActivatedTab(primaryUrl, secondaryUrl);
|
|
|
|
}
|
2014-08-10 16:52:06 +00:00
|
|
|
} else {
|
2021-03-18 19:42:59 +00:00
|
|
|
if (somethingWasAlreadyOpen) {
|
|
|
|
openNewTab(primaryUrl);
|
|
|
|
} else {
|
|
|
|
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;
|
2020-10-23 17:48:22 +00:00
|
|
|
for (const QUrl& url : files) {
|
2022-05-18 12:52:26 +00:00
|
|
|
const QUrl dir(url.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash));
|
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);
|
2020-10-23 17:51:33 +00:00
|
|
|
Q_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));
|
|
|
|
}
|
|
|
|
|
2014-08-10 18:36:44 +00:00
|
|
|
void DolphinTabWidget::restoreClosedTab(const QByteArray& state)
|
|
|
|
{
|
|
|
|
openNewActivatedTab();
|
|
|
|
currentTabPage()->restoreState(state);
|
|
|
|
}
|
|
|
|
|
Allow to copy or move selection to the other split view
Summary:
FEATURE: 276167
Default keyboard shortcuts set to `SHIFT+F5` for `copy`, `SHIFT+F6` for `move`
Reviewers: #dolphin, elvisangelaccio, ngraham, meven, dfaure
Reviewed By: #dolphin, elvisangelaccio, ngraham, meven, dfaure
Subscribers: yurchor, kde-doc-english, dfaure, meven, kfm-devel
Tags: #dolphin, #documentation
Differential Revision: https://phabricator.kde.org/D29006
2020-05-14 22:17:31 +00:00
|
|
|
void DolphinTabWidget::copyToInactiveSplitView()
|
|
|
|
{
|
|
|
|
const DolphinTabPage* tabPage = tabPageAt(currentIndex());
|
|
|
|
DolphinViewContainer* activeViewContainer = currentTabPage()->activeViewContainer();
|
|
|
|
if (!tabPage->splitViewEnabled() || activeViewContainer->view()->selectedItems().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tabPage->primaryViewActive()) {
|
|
|
|
// copy from left panel to right
|
2020-05-18 22:22:26 +00:00
|
|
|
activeViewContainer->view()->copySelectedItems(activeViewContainer->view()->selectedItems(), tabPage->secondaryViewContainer()->url());
|
Allow to copy or move selection to the other split view
Summary:
FEATURE: 276167
Default keyboard shortcuts set to `SHIFT+F5` for `copy`, `SHIFT+F6` for `move`
Reviewers: #dolphin, elvisangelaccio, ngraham, meven, dfaure
Reviewed By: #dolphin, elvisangelaccio, ngraham, meven, dfaure
Subscribers: yurchor, kde-doc-english, dfaure, meven, kfm-devel
Tags: #dolphin, #documentation
Differential Revision: https://phabricator.kde.org/D29006
2020-05-14 22:17:31 +00:00
|
|
|
} else {
|
|
|
|
// copy from right panel to left
|
2020-05-18 22:22:26 +00:00
|
|
|
activeViewContainer->view()->copySelectedItems(activeViewContainer->view()->selectedItems(), tabPage->primaryViewContainer()->url());
|
Allow to copy or move selection to the other split view
Summary:
FEATURE: 276167
Default keyboard shortcuts set to `SHIFT+F5` for `copy`, `SHIFT+F6` for `move`
Reviewers: #dolphin, elvisangelaccio, ngraham, meven, dfaure
Reviewed By: #dolphin, elvisangelaccio, ngraham, meven, dfaure
Subscribers: yurchor, kde-doc-english, dfaure, meven, kfm-devel
Tags: #dolphin, #documentation
Differential Revision: https://phabricator.kde.org/D29006
2020-05-14 22:17:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinTabWidget::moveToInactiveSplitView()
|
|
|
|
{
|
|
|
|
const DolphinTabPage* tabPage = tabPageAt(currentIndex());
|
|
|
|
DolphinViewContainer* activeViewContainer = currentTabPage()->activeViewContainer();
|
|
|
|
if (!tabPage->splitViewEnabled() || activeViewContainer->view()->selectedItems().isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tabPage->primaryViewActive()) {
|
|
|
|
// move from left panel to right
|
2020-05-18 22:22:26 +00:00
|
|
|
activeViewContainer->view()->moveSelectedItems(activeViewContainer->view()->selectedItems(), tabPage->secondaryViewContainer()->url());
|
Allow to copy or move selection to the other split view
Summary:
FEATURE: 276167
Default keyboard shortcuts set to `SHIFT+F5` for `copy`, `SHIFT+F6` for `move`
Reviewers: #dolphin, elvisangelaccio, ngraham, meven, dfaure
Reviewed By: #dolphin, elvisangelaccio, ngraham, meven, dfaure
Subscribers: yurchor, kde-doc-english, dfaure, meven, kfm-devel
Tags: #dolphin, #documentation
Differential Revision: https://phabricator.kde.org/D29006
2020-05-14 22:17:31 +00:00
|
|
|
} else {
|
|
|
|
// move from right panel to left
|
2020-05-18 22:22:26 +00:00
|
|
|
activeViewContainer->view()->moveSelectedItems(activeViewContainer->view()->selectedItems(), tabPage->primaryViewContainer()->url());
|
Allow to copy or move selection to the other split view
Summary:
FEATURE: 276167
Default keyboard shortcuts set to `SHIFT+F5` for `copy`, `SHIFT+F6` for `move`
Reviewers: #dolphin, elvisangelaccio, ngraham, meven, dfaure
Reviewed By: #dolphin, elvisangelaccio, ngraham, meven, dfaure
Subscribers: yurchor, kde-doc-english, dfaure, meven, kfm-devel
Tags: #dolphin, #documentation
Differential Revision: https://phabricator.kde.org/D29006
2020-05-14 22:17:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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)));
|
2020-10-23 17:15:07 +00:00
|
|
|
tabBar()->setTabToolTip(index, url.toDisplayString(QUrl::PreferLocalFile));
|
2019-09-02 07:13:56 +00:00
|
|
|
if (tabBar()->isVisible()) {
|
2020-11-24 17:07:56 +00:00
|
|
|
// ensure the path url ends with a slash to have proper folder icon for remote folders
|
|
|
|
const QUrl pathUrl = QUrl(url.adjusted(QUrl::StripTrailingSlash).toString(QUrl::FullyEncoded).append("/"));
|
|
|
|
tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(pathUrl)));
|
2019-09-02 07:13:56 +00:00
|
|
|
} 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()) {
|
2020-10-23 17:51:33 +00:00
|
|
|
Q_EMIT currentUrlChanged(url);
|
2014-08-13 20:06:28 +00:00
|
|
|
}
|
2014-08-10 16:52:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DolphinTabWidget::currentTabChanged(int index)
|
|
|
|
{
|
2020-09-20 16:53:59 +00:00
|
|
|
DolphinTabPage *tabPage = tabPageAt(index);
|
|
|
|
if (tabPage == m_lastViewedTab) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (m_lastViewedTab) {
|
|
|
|
m_lastViewedTab->disconnectNavigators();
|
|
|
|
m_lastViewedTab->setActive(false);
|
2017-05-22 17:35:29 +00:00
|
|
|
}
|
2020-10-28 16:52:29 +00:00
|
|
|
if (tabPage->splitViewEnabled() && !m_navigatorsWidget->secondaryUrlNavigator()) {
|
|
|
|
m_navigatorsWidget->createSecondaryUrlNavigator();
|
|
|
|
}
|
2017-05-22 17:35:29 +00:00
|
|
|
DolphinViewContainer* viewContainer = tabPage->activeViewContainer();
|
2020-10-23 17:51:33 +00:00
|
|
|
Q_EMIT activeViewChanged(viewContainer);
|
|
|
|
Q_EMIT currentUrlChanged(viewContainer->url());
|
2017-05-22 17:35:29 +00:00
|
|
|
tabPage->setActive(true);
|
2020-09-20 16:53:59 +00:00
|
|
|
tabPage->connectNavigators(m_navigatorsWidget);
|
|
|
|
m_navigatorsWidget->setSecondaryNavigatorVisible(tabPage->splitViewEnabled());
|
2020-11-09 13:25:15 +00:00
|
|
|
m_lastViewedTab = tabPage;
|
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) {
|
2020-07-08 08:59:11 +00:00
|
|
|
const QUrl url = tabPageAt(i)->activeViewContainer()->url();
|
2019-09-02 07:13:56 +00:00
|
|
|
if (tabBar()->tabIcon(i).isNull()) {
|
2020-11-24 17:07:56 +00:00
|
|
|
// ensure the path url ends with a slash to have proper folder icon for remote folders
|
|
|
|
const QUrl pathUrl = QUrl(url.adjusted(QUrl::StripTrailingSlash).toString(QUrl::FullyEncoded).append("/"));
|
|
|
|
tabBar()->setTabIcon(i, QIcon::fromTheme(KIO::iconNameForUrl(pathUrl)));
|
2020-07-08 08:59:11 +00:00
|
|
|
}
|
|
|
|
if (tabBar()->tabToolTip(i).isEmpty()) {
|
2020-10-23 17:15:07 +00:00
|
|
|
tabBar()->setTabToolTip(index, url.toDisplayString(QUrl::PreferLocalFile));
|
2019-09-02 07:13:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-10 16:52:06 +00:00
|
|
|
tabBar()->show();
|
|
|
|
}
|
|
|
|
|
2020-10-23 17:51:33 +00:00
|
|
|
Q_EMIT tabCountChanged(count());
|
2014-08-10 16:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2020-10-23 17:51:33 +00:00
|
|
|
Q_EMIT tabCountChanged(count());
|
2014-08-10 16:52:06 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|