X-Git-Url: https://cloud.milkyroute.net/gitweb/dolphin.git/blobdiff_plain/3c6ecfa246c17077f2e84a45e56da8943d6db1c3..1af2241243f4aed24b68ffee048091a55f63a1f2:/src/dolphinmainwindow.cpp diff --git a/src/dolphinmainwindow.cpp b/src/dolphinmainwindow.cpp index f8b35d4a7..dcf22e455 100644 --- a/src/dolphinmainwindow.cpp +++ b/src/dolphinmainwindow.cpp @@ -25,7 +25,6 @@ #include "dolphindockwidget.h" #include "dolphincontextmenu.h" #include "dolphinnewfilemenu.h" -#include "dolphinplacesmodelsingleton.h" #include "dolphinrecenttabsmenu.h" #include "dolphintabwidget.h" #include "dolphinviewcontainer.h" @@ -49,7 +48,6 @@ #include #include #include -#include #include #include #include @@ -137,14 +135,14 @@ DolphinMainWindow::DolphinMainWindow() : connect(m_tabWidget, &DolphinTabWidget::tabCountChanged, this, &DolphinMainWindow::tabCountChanged); connect(m_tabWidget, &DolphinTabWidget::currentUrlChanged, - this, &DolphinMainWindow::setUrlAsCaption); + this, &DolphinMainWindow::updateWindowTitle); setCentralWidget(m_tabWidget); setupActions(); 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, @@ -457,10 +455,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() @@ -557,7 +551,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) { @@ -592,6 +586,7 @@ void DolphinMainWindow::reloadView() { clearStatusBar(); m_activeViewContainer->reload(); + m_activeViewContainer->statusBar()->updateSpaceInfo(); } void DolphinMainWindow::stopLoading() @@ -626,12 +621,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() @@ -808,10 +810,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, @@ -860,6 +861,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) | @@ -996,51 +1002,13 @@ 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::setUrlAsCaption(const QUrl& url) +void DolphinMainWindow::updateWindowTitle() { - QString schemePrefix; - if (!url.isLocalFile()) { - schemePrefix.append(url.scheme() + " - "); - if (!url.host().isEmpty()) { - schemePrefix.append(url.host() + " - "); - } - } - - if (GeneralSettings::showFullPathInTitlebar()) { - const QString path = url.adjusted(QUrl::StripTrailingSlash).path(); - setWindowTitle(schemePrefix + path); - return; - } - - KFilePlacesModel *placesModel = DolphinPlacesModelSingleton::instance().placesModel(); - const auto& matchedPlaces = placesModel->match(placesModel->index(0,0), KFilePlacesModel::UrlRole, url, 1, Qt::MatchExactly); - - if (!matchedPlaces.isEmpty()) { - setWindowTitle(placesModel->text(matchedPlaces.first())); - return; - } - - QString fileName = url.adjusted(QUrl::StripTrailingSlash).fileName(); - if (fileName.isEmpty()) { - fileName = '/'; - } - - if (m_activeViewContainer->isSearchModeEnabled()) { - if(m_activeViewContainer->currentSearchText().isEmpty()){ - setWindowTitle(i18n("Search")); - } else { - const auto searchText = i18n("Search for %1", m_activeViewContainer->currentSearchText()); - setWindowTitle(searchText); - } - return; - } - - setWindowTitle(schemePrefix + fileName); + setWindowTitle(m_activeViewContainer->caption()); } void DolphinMainWindow::slotStorageTearDownFromPlacesRequested(const QString& mountPath) @@ -1066,6 +1034,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"))); @@ -1075,17 +1044,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, {Qt::CTRL + Qt::Key_T, 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()); @@ -1266,6 +1235,8 @@ void DolphinMainWindow::setupDockWidgets() infoDock->setLocked(lock); infoDock->setObjectName(QStringLiteral("infoDock")); infoDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + +#ifdef HAVE_BALOO InformationPanel* infoPanel = new InformationPanel(infoDock); infoPanel->setCustomContextMenuActions({lockLayoutAction}); connect(infoPanel, &InformationPanel::urlActivated, this, &DolphinMainWindow::handleUrl); @@ -1281,6 +1252,7 @@ void DolphinMainWindow::setupDockWidgets() infoPanel, &InformationPanel::setSelection); connect(this, &DolphinMainWindow::requestItemInfo, infoPanel, &InformationPanel::requestDelayedItemInfo); +#endif // Setup "Folders" DolphinDockWidget* foldersDock = new DolphinDockWidget(i18nc("@title:window", "Folders")); @@ -1371,17 +1343,38 @@ 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); panelsMenu->setDelayed(false); const KActionCollection* ac = actionCollection(); panelsMenu->addAction(ac->action(QStringLiteral("show_places_panel"))); +#ifdef HAVE_BALOO panelsMenu->addAction(ac->action(QStringLiteral("show_information_panel"))); +#endif 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() @@ -1501,7 +1494,7 @@ void DolphinMainWindow::refreshViews() const bool splitView = GeneralSettings::splitView(); m_tabWidget->currentTabPage()->setSplitViewEnabled(splitView); updateSplitAction(); - setUrlAsCaption(activeViewContainer()->url()); + updateWindowTitle(); } emit settingsChanged();