]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/dolphinview.cpp
SVN_SILENT made messages (.desktop file)
[dolphin.git] / src / dolphinview.cpp
index 5cea1bde0fa859624c2642a897c46773651beb97..5899404793361b156efcdd43e8175cfc81c451fb 100644 (file)
 #include "draganddrophelper.h"
 #include "folderexpander.h"
 #include "renamedialog.h"
+#include "revisioncontrolobserver.h"
 #include "tooltips/tooltipmanager.h"
 #include "settings/dolphinsettings.h"
 #include "viewproperties.h"
 #include "zoomlevelinfo.h"
 
-#include <kdebug.h>
-
 /**
  * Helper function for sorting items with qSort() in
  * DolphinView::renameSelectedItems().
@@ -100,13 +99,15 @@ DolphinView::DolphinView(QWidget* parent,
     m_columnView(0),
     m_fileItemDelegate(0),
     m_selectionModel(0),
+    m_selectionChangedTimer(0),
     m_dolphinModel(dolphinModel),
     m_dirLister(dirLister),
     m_proxyModel(proxyModel),
     m_previewGenerator(0),
     m_toolTipManager(0),
+    m_revisionControlObserver(0),
     m_rootUrl(),
-    m_currentItemUrl(),
+    m_activeItemUrl(),
     m_createdItemUrl(),
     m_selectedItems(),
     m_newFileNames(),
@@ -190,7 +191,7 @@ void DolphinView::setActive(bool active)
 
     QColor color = KColorScheme(QPalette::Active, KColorScheme::View).background().color();
     if (active) {
-        emit selectionChanged(selectedItems());
+        emitSelectionChangedSignal();
     } else {
         color.setAlpha(150);
     }
@@ -331,6 +332,7 @@ void DolphinView::clearSelection()
     const QModelIndex currentIndex = selModel->currentIndex();
     selModel->setCurrentIndex(currentIndex, QItemSelectionModel::Current |
                                             QItemSelectionModel::Clear);
+    m_selectedItems.clear();
 }
 
 KFileItemList DolphinView::selectedItems() const
@@ -377,7 +379,7 @@ int DolphinView::selectedItemsCount() const
         return m_columnView->selectedItems().count();
     }
 
-    return itemView()->selectionModel()->selection().count();
+    return itemView()->selectionModel()->selectedIndexes().count();
 }
 
 void DolphinView::setContentsPosition(int x, int y)
@@ -520,6 +522,10 @@ void DolphinView::updateView(const KUrl& url, const KUrl& rootUrl)
         loadDirectory(url);
     }
 
+    // When changing the URL there is no need to keep the revision
+    // data of the previous URL.
+    m_dolphinModel->clearRevisionData();
+
     emit startedPathLoading(url);
 }
 
@@ -607,12 +613,16 @@ QString DolphinView::statusBarText() const
     return text;
 }
 
+QList<QAction*> DolphinView::revisionControlActions(const KFileItemList& items) const
+{
+    return items.isEmpty()
+           ? m_revisionControlObserver->contextMenuActions(url().path(KUrl::AddTrailingSlash))
+           : m_revisionControlObserver->contextMenuActions(items);
+}
+
 void DolphinView::setUrl(const KUrl& url)
 {
     m_newFileNames.clear();
-
-    // remember current item candidate (see slotDirListerCompleted())
-    m_currentItemUrl = url;
     updateView(url, KUrl());
 }
 
@@ -661,6 +671,10 @@ void DolphinView::renameSelectedItems()
             return;
         }
         delete dialog;
+        
+        // the selection would be invalid after renaming the items, so just clear
+        // it before
+        clearSelection();
 
         // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
         // as one operation instead of n rename operations like it is done now...
@@ -958,6 +972,14 @@ void DolphinView::triggerItem(const KFileItem& item)
     emit itemTriggered(item); // caught by DolphinViewContainer or DolphinPart
 }
 
+void DolphinView::emitDelayedSelectionChangedSignal()
+{
+    // Invoke emitSelectionChangedSignal() with a delay of 300 ms. This assures
+    // that fast selection changes don't result in expensive operations to
+    // collect all file items for the signal (see DolphinView::selectedItems()).
+    m_selectionChangedTimer->start();
+}
+
 void DolphinView::emitSelectionChangedSignal()
 {
     emit selectionChanged(DolphinView::selectedItems());
@@ -1102,6 +1124,11 @@ bool DolphinView::isTabsForFilesEnabled() const
     return m_tabsForFiles;
 }
 
+void DolphinView::activateItem(const KUrl& url)
+{
+    m_activeItemUrl = url;
+}
+
 bool DolphinView::itemsExpandable() const
 {
     return (m_detailsView != 0) && m_detailsView->itemsExpandable();
@@ -1193,9 +1220,9 @@ void DolphinView::slotRequestUrlChange(const KUrl& url)
 
 void DolphinView::slotDirListerCompleted()
 {
-    if (!m_currentItemUrl.isEmpty()) {
+    if (!m_activeItemUrl.isEmpty()) {
         // assure that the current item remains visible
-        const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_currentItemUrl);
+        const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_activeItemUrl);
         if (dirIndex.isValid()) {
             const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
             QAbstractItemView* view = itemView();
@@ -1204,23 +1231,24 @@ void DolphinView::slotDirListerCompleted()
             if (clearSelection) {
                 view->clearSelection();
             }
+            m_activeItemUrl.clear();
         }
-        m_currentItemUrl.clear();
     }
 
     if (!m_newFileNames.isEmpty()) {
         // select all newly added items created by a paste operation or
         // a drag & drop operation
-        QItemSelectionModel* selectionModel = itemView()->selectionModel();
         const int rowCount = m_proxyModel->rowCount();
+        QItemSelection selection;
         for (int row = 0; row < rowCount; ++row) {
             const QModelIndex proxyIndex = m_proxyModel->index(row, 0);
             const QModelIndex dirIndex = m_proxyModel->mapToSource(proxyIndex);
             const KUrl url = m_dolphinModel->itemForIndex(dirIndex).url();
             if (m_newFileNames.contains(url.fileName())) {
-                selectionModel->select(proxyIndex, QItemSelectionModel::Select);
+                selection.merge(QItemSelection(proxyIndex, proxyIndex), QItemSelectionModel::Select);
             }
         }
+        itemView()->selectionModel()->select(selection, QItemSelectionModel::Select);
 
         m_newFileNames.clear();
     }
@@ -1430,6 +1458,12 @@ void DolphinView::createView()
         m_selectionModel = view->selectionModel();
     }
 
+    m_selectionChangedTimer = new QTimer(this);
+    m_selectionChangedTimer->setSingleShot(true);
+    m_selectionChangedTimer->setInterval(300);
+    connect(m_selectionChangedTimer, SIGNAL(timeout()),
+            this, SLOT(emitSelectionChangedSignal()));
+
     // reparent the selection model, as it should not be deleted
     // when deleting the model
     m_selectionModel->setParent(this);
@@ -1439,6 +1473,14 @@ void DolphinView::createView()
     m_previewGenerator = new KFilePreviewGenerator(view);
     m_previewGenerator->setPreviewShown(m_showPreview);
 
+    m_revisionControlObserver = new RevisionControlObserver(view);
+    connect(m_revisionControlObserver, SIGNAL(infoMessage(const QString&)),
+            this, SIGNAL(infoMessage(const QString&)));
+    connect(m_revisionControlObserver, SIGNAL(errorMessage(const QString&)),
+            this, SIGNAL(errorMessage(const QString&)));
+    connect(m_revisionControlObserver, SIGNAL(operationCompletedMessage(const QString&)),
+            this, SIGNAL(operationCompletedMessage(const QString&)));
+
     if (DolphinSettings::instance().generalSettings()->showToolTips()) {
         m_toolTipManager = new ToolTipManager(view, m_proxyModel);
         connect(m_controller, SIGNAL(hideToolTip()),
@@ -1448,7 +1490,7 @@ void DolphinView::createView()
     m_topLayout->insertWidget(1, view);
 
     connect(view->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection&)),
-            this, SLOT(emitSelectionChangedSignal()));
+            this, SLOT(emitDelayedSelectionChangedSignal()));
     connect(view->verticalScrollBar(), SIGNAL(valueChanged(int)),
             this, SLOT(emitContentsMoved()));
     connect(view->horizontalScrollBar(), SIGNAL(valueChanged(int)),