]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Merge branch 'Applications/19.08'
authorElvis Angelaccio <elvis.angelaccio@kde.org>
Mon, 2 Sep 2019 21:18:33 +0000 (23:18 +0200)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Mon, 2 Sep 2019 21:18:33 +0000 (23:18 +0200)
1  2 
src/dolphinmainwindow.cpp
src/dolphintabwidget.cpp
src/dolphinviewcontainer.cpp

index 004e8e165e8fcfb2fe5812ed77ce6955bd4d3df1,c9ed9c5cd5045b2d4f58bd8f7e171159d62f03da..e851fa2b0934ba5e780fb9502e41dedd92c7d21c
@@@ -32,7 -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"
@@@ -273,7 -272,7 +273,7 @@@ void DolphinMainWindow::changeUrl(cons
      }
  
      m_activeViewContainer->setUrl(url);
 -    updateEditActions();
 +    updateFileAndEditActions();
      updatePasteAction();
      updateViewActions();
      updateGoActions();
@@@ -302,7 -301,7 +302,7 @@@ void DolphinMainWindow::slotEditableSta
  
  void DolphinMainWindow::slotSelectionChanged(const KFileItemList& selection)
  {
 -    updateEditActions();
 +    updateFileAndEditActions();
  
      const int selectedUrlsCount = m_tabWidget->currentTabPage()->selectedItemsCount();
  
@@@ -353,32 -352,6 +353,32 @@@ void DolphinMainWindow::openNewActivate
      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);
@@@ -644,12 -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));
@@@ -784,7 -751,7 +784,7 @@@ void DolphinMainWindow::togglePanelLock
  
  void DolphinMainWindow::slotTerminalPanelVisibilityChanged()
  {
 -    if (m_terminalPanel->isHiddenInVisibleWindow()) {
 +    if (m_terminalPanel->isHiddenInVisibleWindow() && m_activeViewContainer) {
          m_activeViewContainer->view()->setFocus();
      }
  }
@@@ -1117,9 -1084,6 +1117,9 @@@ void DolphinMainWindow::activeViewChang
      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);
      m_actionHandler->setCurrentView(viewContainer->view());
  
      updateHistory();
 -    updateEditActions();
 +    updateFileAndEditActions();
      updatePasteAction();
      updateViewActions();
      updateGoActions();
 +    updateSearchAction();
  
      const QUrl url = viewContainer->url();
      emit urlChanged(url);
@@@ -1193,7 -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."
          "<nl/>You can drag and drop items between windows."));
      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 "
          "the find bar so we can have a look at it while the settings are "
          "explained.</para>"));
  
 +    // 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."));
@@@ -1714,20 -1659,15 +1714,20 @@@ void DolphinMainWindow::setupDockWidget
      });
  }
  
 -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));
          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();
  
@@@ -1795,9 -1727,10 +1795,9 @@@ void DolphinMainWindow::createControlBu
  
      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);
      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
@@@ -1870,11 -1805,6 +1870,11 @@@ void DolphinMainWindow::connectViewSign
              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,
@@@ -2159,7 -2089,7 +2159,7 @@@ void DolphinMainWindow::UndoUiInterface
  
  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;
diff --combined src/dolphintabwidget.cpp
index bd0ee301f63426f31f57a3b80f86478f553a1796,7928c510e2aaa4df15ab281eaf863966baa80422..0546316f7763edc628b1425115b11deefbb1796c
@@@ -161,7 -161,6 +161,7 @@@ void DolphinTabWidget::openNewTab(cons
      QWidget* focusWidget = QApplication::focusWidget();
  
      DolphinTabPage* tabPage = new DolphinTabPage(primaryUrl, secondaryUrl, this);
 +    tabPage->setActive(false);
      tabPage->setPlacesSelectorVisible(m_placesSelectorVisible);
      connect(tabPage, &DolphinTabPage::activeViewChanged,
              this, &DolphinTabWidget::activeViewChanged);
      if (tabPlacement == AfterCurrentTab) {
          newTabIndex = currentIndex() + 1;
      }
 -    insertTab(newTabIndex, tabPage, QIcon::fromTheme(KIO::iconNameForUrl(primaryUrl)), tabName(tabPage));
 +    insertTab(newTabIndex, tabPage, QIcon() /* loaded in tabInserted */, tabName(tabPage));
  
      if (focusWidget) {
          // The DolphinViewContainer grabbed the keyboard focus. As the tab is opened
@@@ -187,9 -186,15 +187,15 @@@ void DolphinTabWidget::openDirectories(
      QList<QUrl>::const_iterator it = dirs.constBegin();
      while (it != dirs.constEnd()) {
          const QUrl& primaryUrl = *(it++);
-         const int index = getIndexByUrl(primaryUrl);
-         if (index >= 0) {
-             setCurrentIndex(index);
+         const QPair<int, bool> viewLocation = getIndexByUrl(primaryUrl);
+         if (viewLocation.first >= 0) {
+             setCurrentIndex(viewLocation.first);
+             const auto tabPage = tabPageAt(viewLocation.first);
+             if (viewLocation.second) {
+                 tabPage->primaryViewContainer()->setActive(true);
+             } else {
+                 tabPage->secondaryViewContainer()->setActive(true);
+             }
              continue;
          }
          if (splitView && (it != dirs.constEnd())) {
@@@ -324,12 -329,7 +330,12 @@@ void DolphinTabWidget::tabUrlChanged(co
      const int index = indexOf(qobject_cast<QWidget*>(sender()));
      if (index >= 0) {
          tabBar()->setTabText(index, tabName(tabPageAt(index)));
 -        tabBar()->setTabIcon(index, QIcon::fromTheme(KIO::iconNameForUrl(url)));
 +        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());
 +        }
  
          // Emit the currentUrlChanged signal if the url of the current tab has been changed.
          if (index == currentIndex()) {
@@@ -357,13 -357,6 +363,13 @@@ void DolphinTabWidget::tabInserted(int 
      QTabWidget::tabInserted(index);
  
      if (count() > 1) {
 +        // 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())));
 +            }
 +        }
 +
          tabBar()->show();
      }
  
@@@ -394,16 -387,17 +400,17 @@@ QString DolphinTabWidget::tabName(Dolph
      return name.replace('&', QLatin1String("&&"));
  }
  
int DolphinTabWidget::getIndexByUrl(const QUrl& url) const
QPair<int, bool> DolphinTabWidget::getIndexByUrl(const QUrl& url) const
  {
      for (int i = 0; i < count(); i++) {
-         // Conversion to display string is necessary to deal with the '~' alias.
-         // i.e. to acknowledge that ~/ is equivalent to /home/user/
-         const QUrl tabUrl = tabPageAt(i)->activeViewContainer()->url();
-         if (url == tabUrl ||
-             url.toDisplayString(QUrl::StripTrailingSlash) == tabUrl.toDisplayString(QUrl::StripTrailingSlash)) {
-             return i;
+         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);
          }
      }
-     return -1;
+     return qMakePair(-1, false);
  }
index 93e785f0d594f3e2234f98079c5148b00e27b1c3,6a8ff914b506d154452aded40568a193e65fb982..416a63e67c3bf6afdecb95cc390d247eefce210a
@@@ -412,8 -412,6 +412,8 @@@ void DolphinViewContainer::setSearchMod
      }
  
      m_searchModeEnabled = enabled;
 +
 +    emit searchModeEnabledChanged(enabled);
  }
  
  bool DolphinViewContainer::isSearchModeEnabled() const
@@@ -428,7 -426,7 +428,7 @@@ QString DolphinViewContainer::placesTex
      if (isSearchModeEnabled()) {
          text = i18n("Search for %1 in %2", m_searchBox->text(), m_searchBox->searchPath().fileName());
      } else {
-         text = url().fileName();
+         text = url().adjusted(QUrl::StripTrailingSlash).fileName();
          if (text.isEmpty()) {
              text = url().host();
          }