X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/8a942bb3d32784f37eabb75aceb58c8b965c77b0..81065795b78e06ec679ec0589fba7082e777ef2a:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index 1eed8c826..87d041b87 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -32,6 +32,7 @@ #include "dolphintabpage.h" #include "middleclickactioneventfilter.h" #include "panels/folders/folderspanel.h" +#include "panels/places/placesitemmodel.h" #include "panels/places/placespanel.h" #include "panels/information/informationpanel.h" #include "panels/terminal/terminalpanel.h" @@ -272,7 +273,7 @@ void DolphinMainWindow::changeUrl(const QUrl &url) } m_activeViewContainer->setUrl(url); - updateEditActions(); + updateFileAndEditActions(); updatePasteAction(); updateViewActions(); updateGoActions(); @@ -301,7 +302,7 @@ void DolphinMainWindow::slotEditableStateChanged(bool editable) void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection) { - updateEditActions(); + updateFileAndEditActions(); const int selectedUrlsCount = m_tabWidget->currentTabPage()->selectedItemsCount(); @@ -352,6 +353,32 @@ void DolphinMainWindow::openNewActivatedTab() m_tabWidget->openNewActivatedTab(); } +void DolphinMainWindow::addToPlaces() +{ + QUrl url; + QString name; + + // If nothing is selected, act on the current dir + if (m_activeViewContainer->view()->selectedItems().count() == 0) { + url = m_activeViewContainer->url(); + name = m_activeViewContainer->placesText(); + } else { + const auto dirToAdd = m_activeViewContainer->view()->selectedItems().first(); + url = dirToAdd.url(); + name = dirToAdd.name(); + } + if (url.isValid()) { + PlacesItemModel model; + QString icon; + if (m_activeViewContainer->isSearchModeEnabled()) { + icon = QStringLiteral("folder-saved-search-symbolic"); + } else { + icon = KIO::iconNameForUrl(url); + } + model.createPlacesItem(name, url, icon); + } +} + void DolphinMainWindow::openNewTab(const QUrl& url, DolphinTabWidget::TabPlacement tabPlacement) { m_tabWidget->openNewTab(url, QUrl(), tabPlacement); @@ -500,7 +527,7 @@ void DolphinMainWindow::closeEvent(QCloseEvent* event) if (!m_terminalPanel->isVisible()) { KGuiItem::assign( buttons->button(QDialogButtonBox::No), - KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("utilities-terminal")))); + KGuiItem(i18n("Show &Terminal Panel"), QIcon::fromTheme(QStringLiteral("dialog-scripts")))); } KGuiItem::assign(buttons->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel()); @@ -617,6 +644,12 @@ void DolphinMainWindow::find() m_activeViewContainer->setSearchModeEnabled(true); } +void DolphinMainWindow::updateSearchAction() +{ + QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search")); + toggleSearchAction->setChecked(m_activeViewContainer->isSearchModeEnabled()); +} + void DolphinMainWindow::updatePasteAction() { QAction* pasteAction = actionCollection()->action(KStandardAction::name(KStandardAction::Paste)); @@ -751,7 +784,7 @@ void DolphinMainWindow::togglePanelLockState() void DolphinMainWindow::slotTerminalPanelVisibilityChanged() { - if (m_terminalPanel->isHiddenInVisibleWindow()) { + if (m_terminalPanel->isHiddenInVisibleWindow() && m_activeViewContainer) { m_activeViewContainer->view()->setFocus(); } } @@ -1084,6 +1117,9 @@ void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer) m_activeViewContainer = viewContainer; if (oldViewContainer) { + const QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search")); + toggleSearchAction->disconnect(oldViewContainer); + // Disconnect all signals between the old view container (container, // view and url navigator) and main window. oldViewContainer->disconnect(this); @@ -1100,10 +1136,11 @@ void DolphinMainWindow::activeViewChanged(DolphinViewContainer* viewContainer) m_actionHandler->setCurrentView(viewContainer->view()); updateHistory(); - updateEditActions(); + updateFileAndEditActions(); updatePasteAction(); updateViewActions(); updateGoActions(); + updateSearchAction(); const QUrl url = viewContainer->url(); emit urlChanged(url); @@ -1156,6 +1193,7 @@ void DolphinMainWindow::setupActions() QAction* newWindow = KStandardAction::openNew(this, &DolphinMainWindow::openNewMainWindow, actionCollection()); newWindow->setText(i18nc("@action:inmenu File", "New &Window")); + newWindow->setToolTip(i18nc("@info", "Open a new Dolphin window")); newWindow->setWhatsThis(xi18nc("@info:whatsthis", "This opens a new " "window just like this one with the current location and view." "You can drag and drop items between windows.")); @@ -1171,6 +1209,12 @@ void DolphinMainWindow::setupActions() actionCollection()->setDefaultShortcuts(newTab, {Qt::CTRL + Qt::Key_T, Qt::CTRL + Qt::SHIFT + Qt::Key_N}); connect(newTab, &QAction::triggered, this, &DolphinMainWindow::openNewActivatedTab); + QAction* addToPlaces = actionCollection()->addAction(QStringLiteral("add_to_places")); + addToPlaces->setIcon(QIcon::fromTheme(QStringLiteral("bookmark-new"))); + addToPlaces->setWhatsThis(xi18nc("@info:whatsthis", "This adds the selected folder " + "to the Places panel.")); + connect(addToPlaces, &QAction::triggered, this, &DolphinMainWindow::addToPlaces); + QAction* closeTab = KStandardAction::close(m_tabWidget, QOverload<>::of(&DolphinTabWidget::closeTab), actionCollection()); closeTab->setText(i18nc("@action:inmenu File", "Close Tab")); closeTab->setWhatsThis(i18nc("@info:whatsthis", "This closes the " @@ -1224,6 +1268,17 @@ void DolphinMainWindow::setupActions() "the find bar so we can have a look at it while the settings are " "explained.")); + // toggle_search acts as a copy of the main searchAction to be used mainly + // in the toolbar, with no default shortcut attached, to avoid messing with + // existing workflows (search bar always open and Ctrl-F to focus) + QAction *toggleSearchAction = actionCollection()->addAction(QStringLiteral("toggle_search")); + toggleSearchAction->setText(i18nc("@action:inmenu", "Toggle Search Bar")); + toggleSearchAction->setIconText(i18nc("@action:intoolbar", "Search")); + toggleSearchAction->setIcon(searchAction->icon()); + toggleSearchAction->setToolTip(searchAction->toolTip()); + toggleSearchAction->setWhatsThis(searchAction->whatsThis()); + toggleSearchAction->setCheckable(true); + QAction* selectAllAction = KStandardAction::selectAll(this, &DolphinMainWindow::selectAll, actionCollection()); selectAllAction->setWhatsThis(xi18nc("@info:whatsthis", "This selects all " "files and folders in the current location.")); @@ -1351,7 +1406,7 @@ void DolphinMainWindow::setupActions() openTerminal->setWhatsThis(xi18nc("@info:whatsthis", "This opens a terminal application for the viewed location." "To learn more about terminals use the help in the terminal application.")); - openTerminal->setIcon(QIcon::fromTheme(QStringLiteral("utilities-terminal"))); + openTerminal->setIcon(QIcon::fromTheme(QStringLiteral("dialog-scripts"))); actionCollection()->setDefaultShortcut(openTerminal, Qt::SHIFT + Qt::Key_F4); connect(openTerminal, &QAction::triggered, this, &DolphinMainWindow::openTerminal); } @@ -1471,6 +1526,7 @@ void DolphinMainWindow::setupDockWidgets() const QString panelWhatsThis = xi18nc("@info:whatsthis", "To show or " "hide panels like this go to Control|Panels " "or View|Panels."); +#ifdef HAVE_BALOO actionCollection()->action(QStringLiteral("show_information_panel")) ->setWhatsThis(xi18nc("@info:whatsthis", " This toggles the " "information panel at the right side of the " @@ -1478,6 +1534,7 @@ void DolphinMainWindow::setupDockWidgets() "about the items your mouse is hovering over or about the selected " "items. Otherwise it informs you about the currently viewed folder." "For single items a preview of their contents is provided.")); +#endif infoDock->setWhatsThis(xi18nc("@info:whatsthis", "This panel " "provides in-depth information about the items your mouse is " "hovering over or about the selected items. Otherwise it informs " @@ -1536,7 +1593,7 @@ void DolphinMainWindow::setupDockWidgets() this, &DolphinMainWindow::slotTerminalPanelVisibilityChanged); QAction* terminalAction = terminalDock->toggleViewAction(); - createPanelAction(QIcon::fromTheme(QStringLiteral("utilities-terminal")), Qt::Key_F4, terminalAction, QStringLiteral("show_terminal_panel")); + createPanelAction(QIcon::fromTheme(QStringLiteral("dialog-scripts")), Qt::Key_F4, terminalAction, QStringLiteral("show_terminal_panel")); addDockWidget(Qt::BottomDockWidgetArea, terminalDock); connect(this, &DolphinMainWindow::urlChanged, @@ -1601,7 +1658,7 @@ 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); + auto actionShowAllPlaces = new QAction(QIcon::fromTheme(QStringLiteral("view-hidden")), i18nc("@item:inmenu", "Show Hidden Places"), this); actionShowAllPlaces->setCheckable(true); actionShowAllPlaces->setDisabled(true); actionShowAllPlaces->setWhatsThis(i18nc("@info:whatsthis", "This displays " @@ -1609,13 +1666,13 @@ void DolphinMainWindow::setupDockWidgets() "appear semi-transparent unless you uncheck their hide property.")); connect(actionShowAllPlaces, &QAction::triggered, this, [actionShowAllPlaces, this](bool checked){ - actionShowAllPlaces->setIcon(QIcon::fromTheme(checked ? QStringLiteral("visibility") : QStringLiteral("hint"))); + actionShowAllPlaces->setIcon(QIcon::fromTheme(checked ? QStringLiteral("view-visible") : QStringLiteral("view-hidden"))); 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"))); + actionShowAllPlaces->setIcon(QIcon::fromTheme(checked ? QStringLiteral("view-visible") : QStringLiteral("view-hidden"))); }); actionCollection()->action(QStringLiteral("show_places_panel")) @@ -1657,15 +1714,20 @@ void DolphinMainWindow::setupDockWidgets() }); } -void DolphinMainWindow::updateEditActions() + +void DolphinMainWindow::updateFileAndEditActions() { const KFileItemList list = m_activeViewContainer->view()->selectedItems(); + const KActionCollection* col = actionCollection(); + QAction* addToPlacesAction = col->action(QStringLiteral("add_to_places")); + if (list.isEmpty()) { stateChanged(QStringLiteral("has_no_selection")); + + addToPlacesAction->setText(i18nc("@action:inmenu Add current folder to places", "Add '%1' to Places", m_activeViewContainer->placesText())); } else { stateChanged(QStringLiteral("has_selection")); - KActionCollection* col = actionCollection(); QAction* renameAction = col->action(KStandardAction::name(KStandardAction::RenameFile)); QAction* moveToTrashAction = col->action(KStandardAction::name(KStandardAction::MoveToTrash)); QAction* deleteAction = col->action(KStandardAction::name(KStandardAction::DeleteFile)); @@ -1673,6 +1735,14 @@ void DolphinMainWindow::updateEditActions() QAction* deleteWithTrashShortcut = col->action(QStringLiteral("delete_shortcut")); // see DolphinViewActionHandler QAction* showTarget = col->action(QStringLiteral("show_target")); + if (list.length() == 1 && list.first().isDir()) { + addToPlacesAction->setEnabled(true); + addToPlacesAction->setText(i18nc("@action:inmenu Add current folder to places", "Add '%1' to Places", list.first().name())); + } else { + addToPlacesAction->setEnabled(false); + addToPlacesAction->setText(i18nc("@action:inmenu Add current folder to places", "Add to Places")); + } + KFileItemListProperties capabilities(list); const bool enableMoveToTrash = capabilities.isLocal() && capabilities.supportsMoving(); @@ -1725,10 +1795,9 @@ void DolphinMainWindow::createControlButton() m_controlButton = new QToolButton(this); m_controlButton->setIcon(QIcon::fromTheme(QStringLiteral("application-menu"))); - m_controlButton->setText(i18nc("@action", "Control")); + m_controlButton->setToolTip(i18nc("@action", "Show menu")); m_controlButton->setAttribute(Qt::WidgetAttribute::WA_CustomWhatsThis); m_controlButton->setPopupMode(QToolButton::InstantPopup); - m_controlButton->setToolButtonStyle(toolBar()->toolButtonStyle()); QMenu* controlMenu = new QMenu(m_controlButton); connect(controlMenu, &QMenu::aboutToShow, this, &DolphinMainWindow::updateControlMenu); @@ -1739,8 +1808,6 @@ void DolphinMainWindow::createControlButton() toolBar()->addWidget(m_controlButton); connect(toolBar(), &KToolBar::iconSizeChanged, m_controlButton, &QToolButton::setIconSize); - connect(toolBar(), &KToolBar::toolButtonStyleChanged, - m_controlButton, &QToolButton::setToolButtonStyle); // The added widgets are owned by the toolbar and may get deleted when e.g. the toolbar // gets edited. In this case we must add them again. The adding is done asynchronously by @@ -1803,6 +1870,11 @@ void DolphinMainWindow::connectViewSignals(DolphinViewContainer* container) this, &DolphinMainWindow::updateFilterBarAction); connect(container, &DolphinViewContainer::writeStateChanged, this, &DolphinMainWindow::slotWriteStateChanged); + connect(container, &DolphinViewContainer::searchModeEnabledChanged, + this, &DolphinMainWindow::updateSearchAction); + + const QAction* toggleSearchAction = actionCollection()->action(QStringLiteral("toggle_search")); + connect(toggleSearchAction, &QAction::triggered, container, &DolphinViewContainer::setSearchModeEnabled); const DolphinView* view = container->view(); connect(view, &DolphinView::selectionChanged, @@ -2087,7 +2159,7 @@ void DolphinMainWindow::UndoUiInterface::jobError(KIO::Job* job) bool DolphinMainWindow::isUrlOpen(const QString& url) { - if (m_tabWidget->getIndexByUrl(QUrl::fromUserInput((url))) >= 0) { + if (m_tabWidget->getIndexByUrl(QUrl::fromUserInput((url))).first >= 0) { return true; } else { return false;