X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/30bf49d5d1539e9d02944230cf4489ebbccf5a45..8bc93b564c283a677e02dc2ac71b40b63a990e38:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index bdc9452ee..076869c1a 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -21,6 +21,7 @@ #include "dolphinmainwindow.h" +#include "config-terminal.h" #include "global.h" #include "dolphindockwidget.h" #include "dolphincontextmenu.h" @@ -47,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -78,7 +80,6 @@ #include #include #include -#include namespace { // Used for GeneralSettings::version() to determine whether @@ -142,7 +143,7 @@ DolphinMainWindow::DolphinMainWindow() : m_actionHandler = new DolphinViewActionHandler(actionCollection(), this); connect(m_actionHandler, &DolphinViewActionHandler::actionBeingHandled, this, &DolphinMainWindow::clearStatusBar); - connect(m_actionHandler, &DolphinViewActionHandler::createDirectory, this, &DolphinMainWindow::createDirectory); + connect(m_actionHandler, &DolphinViewActionHandler::createDirectoryTriggered, this, &DolphinMainWindow::createDirectory); m_remoteEncoding = new DolphinRemoteEncoding(this, m_actionHandler); connect(this, &DolphinMainWindow::urlChanged, @@ -407,7 +408,7 @@ void DolphinMainWindow::closeEvent(QCloseEvent* event) bool doNotAskAgainCheckboxResult = false; - const int result = KMessageBox::createKMessageBox(dialog, + const auto result = KMessageBox::createKMessageBox(dialog, buttons, QMessageBox::Warning, i18n("You have multiple tabs open in this window, are you sure you want to quit?"), @@ -434,6 +435,58 @@ void DolphinMainWindow::closeEvent(QCloseEvent* event) } } + if (m_terminalPanel->hasProgramRunning() && GeneralSettings::confirmClosingTerminalRunningProgram() && closedByUser) { + // Ask if the user really wants to quit Dolphin with a program that is still running in the Terminal panel + // Open a confirmation dialog with 3 buttons: + // QDialogButtonBox::Yes -> Quit + // QDialogButtonBox::No -> Show Terminal Panel + // QDialogButtonBox::Cancel -> do nothing + QDialog *dialog = new QDialog(this, Qt::Dialog); + dialog->setWindowTitle(i18nc("@title:window", "Confirmation")); + dialog->setModal(true); + auto standardButtons = QDialogButtonBox::Yes | QDialogButtonBox::Cancel; + if (!m_terminalPanel->isVisible()) { + standardButtons |= QDialogButtonBox::No; + } + QDialogButtonBox *buttons = new QDialogButtonBox(standardButtons); + KGuiItem::assign(buttons->button(QDialogButtonBox::Yes), KStandardGuiItem::quit()); + if (!m_terminalPanel->isVisible()) { + KGuiItem::assign( + buttons->button(QDialogButtonBox::No), + KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("utilities-terminal")))); + } + KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel()); + + bool doNotAskAgainCheckboxResult = false; + + const auto result = KMessageBox::createKMessageBox( + dialog, + buttons, + QMessageBox::Warning, + i18n("The program '%1' is still running in the Terminal panel. Are you sure you want to quit?", m_terminalPanel->runningProgramName()), + QStringList(), + i18n("Do not ask again"), + &doNotAskAgainCheckboxResult, + KMessageBox::Dangerous); + + if (doNotAskAgainCheckboxResult) { + GeneralSettings::setConfirmClosingTerminalRunningProgram(false); + } + + switch (result) { + case QDialogButtonBox::Yes: + // Quit + break; + case QDialogButtonBox::No: + actionCollection()->action("show_terminal_panel")->trigger(); + // Do not quit, ignore quit event + Q_FALLTHROUGH(); + default: + event->ignore(); + return; + } + } + GeneralSettings::setVersion(CurrentDolphinVersion); GeneralSettings::self()->save(); @@ -455,10 +508,6 @@ void DolphinMainWindow::updateNewMenu() m_newFileMenu->setViewShowsHiddenFiles(activeViewContainer()->view()->hiddenFilesShown()); m_newFileMenu->checkUpToDate(); m_newFileMenu->setPopupFiles(activeViewContainer()->url()); - - // If we're in the trash, also disable all the 'create new' items - // TODO: remove this once https://phabricator.kde.org/T8234 is implemented - slotWriteStateChanged(m_activeViewContainer->view()->url().scheme() != QLatin1String("trash")); } void DolphinMainWindow::createDirectory() @@ -555,7 +604,7 @@ void DolphinMainWindow::selectAll() // URL instead of all items of the view KUrlNavigator* urlNavigator = m_activeViewContainer->urlNavigator(); - QLineEdit* lineEdit = urlNavigator->editor()->lineEdit(); // krazy:exclude=qclasses + QLineEdit* lineEdit = urlNavigator->editor()->lineEdit(); const bool selectUrl = urlNavigator->isUrlEditable() && lineEdit->hasFocus(); if (selectUrl) { @@ -625,12 +674,19 @@ void DolphinMainWindow::toggleEditLocation() void DolphinMainWindow::replaceLocation() { KUrlNavigator* navigator = m_activeViewContainer->urlNavigator(); - navigator->setUrlEditable(true); - navigator->setFocus(); - - // select the whole text of the combo box editor - QLineEdit* lineEdit = navigator->editor()->lineEdit(); // krazy:exclude=qclasses - lineEdit->selectAll(); + QLineEdit* lineEdit = navigator->editor()->lineEdit(); + + // If the text field currently has focus and everything is selected, + // pressing the keyboard shortcut returns the whole thing to breadcrumb mode + if (navigator->isUrlEditable() + && lineEdit->hasFocus() + && lineEdit->selectedText() == lineEdit->text() ) { + navigator->setUrlEditable(false); + } else { + navigator->setUrlEditable(true); + navigator->setFocus(); + lineEdit->selectAll(); + } } void DolphinMainWindow::togglePanelLockState() @@ -807,10 +863,9 @@ void DolphinMainWindow::slotHandleUrlStatFinished(KJob* job) void DolphinMainWindow::slotWriteStateChanged(bool isFolderWritable) { - const auto actions = m_newFileMenu->menu()->actions(); - for (auto menuItem : actions) { - menuItem->setEnabled(isFolderWritable); - } + // trash:/ is writable but we don't want to create new items in it. + // TODO: remove the trash check once https://phabricator.kde.org/T8234 is implemented + newFileMenu()->setEnabled(isFolderWritable && m_activeViewContainer->url().scheme() != QLatin1String("trash")); } void DolphinMainWindow::openContextMenu(const QPoint& pos, @@ -859,6 +914,11 @@ void DolphinMainWindow::updateControlMenu() KActionCollection* ac = actionCollection(); + // Add "Create New" menu + menu->addMenu(m_newFileMenu->menu()); + + menu->addSeparator(); + // Add "Edit" actions bool added = addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Undo)), menu) | addActionToMenu(ac->action(KStandardAction::name(KStandardAction::Find)), menu) | @@ -995,14 +1055,16 @@ void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer) void DolphinMainWindow::tabCountChanged(int count) { const bool enableTabActions = (count > 1); - actionCollection()->action(KStandardAction::name(KStandardAction::Close))->setEnabled(enableTabActions); actionCollection()->action(QStringLiteral("activate_next_tab"))->setEnabled(enableTabActions); actionCollection()->action(QStringLiteral("activate_prev_tab"))->setEnabled(enableTabActions); } void DolphinMainWindow::updateWindowTitle() { - setWindowTitle(m_activeViewContainer->caption()); + const QString newTitle = m_activeViewContainer->caption(); + if (windowTitle() != newTitle) { + setWindowTitle(newTitle); + } } void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath) @@ -1028,6 +1090,7 @@ void DolphinMainWindow::setupActions() { // setup 'File' menu m_newFileMenu = new DolphinNewFileMenu(actionCollection(), this); + m_newFileMenu->setObjectName("newFileMenu"); QMenu* menu = m_newFileMenu->menu(); menu->setTitle(i18nc("@title:menu Create new folder, file, link, etc.", "Create New")); menu->setIcon(QIcon::fromTheme(QStringLiteral("document-new"))); @@ -1037,17 +1100,17 @@ void DolphinMainWindow::setupActions() QAction* newWindow = KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow, actionCollection()); newWindow->setText(i18nc("@action:inmenu File", "New &Window")); + newWindow->setIcon(QIcon::fromTheme(QStringLiteral("window-new"))); QAction* newTab = actionCollection()->addAction(QStringLiteral("new_tab")); newTab->setIcon(QIcon::fromTheme(QStringLiteral("tab-new"))); newTab->setText(i18nc("@action:inmenu File", "New Tab")); - actionCollection()->setDefaultShortcuts(newTab, {QKeySequence::AddTab}); + actionCollection()->setDefaultShortcuts(newTab, {Qt::CTRL + Qt::Key_T, Qt::CTRL + Qt::SHIFT + Qt::Key_N}); connect(newTab, &QAction::triggered, this, static_cast(&DolphinMainWindow::openNewActivatedTab)); QAction* closeTab = KStandardAction::close( m_tabWidget, static_cast(&DolphinTabWidget::closeTab), actionCollection()); closeTab->setText(i18nc("@action:inmenu File", "Close Tab")); - closeTab->setEnabled(false); KStandardAction::quit(this, &DolphinMainWindow::quit, actionCollection()); @@ -1151,7 +1214,7 @@ void DolphinMainWindow::setupActions() compareFiles->setEnabled(false); connect(compareFiles, &QAction::triggered, this, &DolphinMainWindow::compareFiles); -#ifndef Q_OS_WIN +#ifdef HAVE_TERMINAL if (KAuthorized::authorize(QStringLiteral("shell_access"))) { QAction* openTerminal = actionCollection()->addAction(QStringLiteral("open_terminal")); openTerminal->setText(i18nc("@action:inmenu Tools", "Open Terminal")); @@ -1270,7 +1333,7 @@ void DolphinMainWindow::setupDockWidgets() this, &DolphinMainWindow::showErrorMessage); // Setup "Terminal" -#ifndef Q_OS_WIN +#ifdef HAVE_TERMINAL if (KAuthorized::authorize(QStringLiteral("shell_access"))) { DolphinDockWidget* terminalDock = new DolphinDockWidget(i18nc("@title:window Shell terminal", "Terminal")); terminalDock->setLocked(lock); @@ -1336,6 +1399,20 @@ void DolphinMainWindow::setupDockWidgets() this, &DolphinMainWindow::slotStorageTearDownExternallyRequested); m_tabWidget->slotPlacesPanelVisibilityChanged(m_placesPanel->isVisible()); + auto actionShowAllPlaces = new QAction(QIcon::fromTheme(QStringLiteral("hint")), i18nc("@item:inmenu", "Show Hidden Places"), this); + actionShowAllPlaces->setCheckable(true); + actionShowAllPlaces->setDisabled(true); + + connect(actionShowAllPlaces, &QAction::triggered, this, [actionShowAllPlaces, this](bool checked){ + actionShowAllPlaces->setIcon(QIcon::fromTheme(checked ? QStringLiteral("visibility") : QStringLiteral("hint"))); + m_placesPanel->showHiddenEntries(checked); + }); + + connect(m_placesPanel, &PlacesPanel::showHiddenEntriesChanged, this, [actionShowAllPlaces] (bool checked){ + actionShowAllPlaces->setChecked(checked); + actionShowAllPlaces->setIcon(QIcon::fromTheme(checked ? QStringLiteral("visibility") : QStringLiteral("hint"))); + }); + // Add actions into the "Panels" menu KActionMenu* panelsMenu = new KActionMenu(i18nc("@action:inmenu View", "Panels"), this); actionCollection()->addAction(QStringLiteral("panels"), panelsMenu); @@ -1348,7 +1425,12 @@ void DolphinMainWindow::setupDockWidgets() panelsMenu->addAction(ac->action(QStringLiteral("show_folders_panel"))); panelsMenu->addAction(ac->action(QStringLiteral("show_terminal_panel"))); panelsMenu->addSeparator(); + panelsMenu->addAction(actionShowAllPlaces); panelsMenu->addAction(lockLayoutAction); + + connect(panelsMenu->menu(), &QMenu::aboutToShow, this, [actionShowAllPlaces, this]{ + actionShowAllPlaces->setEnabled(m_placesPanel->hiddenListCount()); + }); } void DolphinMainWindow::updateEditActions()