]> cloud.milkyroute.net Git - dolphin.git/commitdiff
After creating an item with the "Create New..." menu, the new item should get selecte...
authorPeter Penz <peter.penz19@gmail.com>
Tue, 17 Mar 2009 20:47:03 +0000 (20:47 +0000)
committerPeter Penz <peter.penz19@gmail.com>
Tue, 17 Mar 2009 20:47:03 +0000 (20:47 +0000)
Open issues:
- F10 shortcut does not work yet (interface extension might be done in KNewMenu)
- Does not work in column view yet, but this is a colum view specific issue.

CCMAIL: rahman.duran@gmail.com
CCMAIL: faure@kde.org

svn path=/trunk/KDE/kdebase/apps/; revision=940624

src/CMakeLists.txt
src/dolphinnewmenu.cpp
src/dolphinnewmenuobserver.cpp [new file with mode: 0644]
src/dolphinnewmenuobserver.h [new file with mode: 0644]
src/dolphinview.cpp
src/dolphinview.h

index f2d9032fa416b2799b7366f04ef1c9a617785a39..ed8fbe562f3b8a1c1ceef9bff570caab78cfd498 100644 (file)
@@ -24,6 +24,7 @@ set(dolphinprivate_LIB_SRCS
     dolphindirlister.cpp
     dolphinfileitemdelegate.cpp
     dolphinmodel.cpp
+    dolphinnewmenuobserver.cpp
     dolphinsortfilterproxymodel.cpp
     dolphincategorydrawer.cpp
     dolphinview.cpp
index f4309ade37c91bc3918d7fd291886b4e261623c9..4b905734ec5f3dda3bb8903c646f6d74e0207b49 100644 (file)
@@ -19,7 +19,9 @@
  ***************************************************************************/
 
 #include "dolphinnewmenu.h"
+
 #include "dolphinmainwindow.h"
+#include "dolphinnewmenuobserver.h"
 #include "dolphinstatusbar.h"
 #include "dolphinview.h"
 #include "dolphinviewcontainer.h"
@@ -31,10 +33,12 @@ DolphinNewMenu::DolphinNewMenu(QWidget* parent, DolphinMainWindow* mainWin) :
     KNewMenu(mainWin->actionCollection(), parent, "create_new"),
     m_mainWin(mainWin)
 {
+    DolphinNewMenuObserver::instance().attach(this);
 }
 
 DolphinNewMenu::~DolphinNewMenu()
 {
+    DolphinNewMenuObserver::instance().detach(this);
 }
 
 void DolphinNewMenu::slotResult(KJob* job)
diff --git a/src/dolphinnewmenuobserver.cpp b/src/dolphinnewmenuobserver.cpp
new file mode 100644 (file)
index 0000000..80a6af3
--- /dev/null
@@ -0,0 +1,58 @@
+/***************************************************************************
+ *   Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at>                  *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+#include "dolphinnewmenuobserver.h"
+
+#include <kglobal.h>
+#include <knewmenu.h>
+
+class DolphinNewMenuObserverSingleton
+{
+public:
+    DolphinNewMenuObserver instance;
+};
+K_GLOBAL_STATIC(DolphinNewMenuObserverSingleton, s_dolphinNewMenuObserver)
+
+DolphinNewMenuObserver& DolphinNewMenuObserver::instance()
+{
+    return s_dolphinNewMenuObserver->instance;
+}
+
+void DolphinNewMenuObserver::attach(const KNewMenu* menu)
+{
+    connect(menu, SIGNAL(itemCreated(const KUrl&)),
+            this, SIGNAL(itemCreated(const KUrl&)));
+}
+
+void DolphinNewMenuObserver::detach(const KNewMenu* menu)
+{
+    disconnect(menu, SIGNAL(itemCreated(const KUrl&)),
+               this, SIGNAL(itemCreated(const KUrl&)));
+}
+
+DolphinNewMenuObserver::DolphinNewMenuObserver() :
+    QObject(0)
+{
+}
+
+DolphinNewMenuObserver::~DolphinNewMenuObserver()
+{
+}
+
+#include "dolphinnewmenuobserver.moc"
diff --git a/src/dolphinnewmenuobserver.h b/src/dolphinnewmenuobserver.h
new file mode 100644 (file)
index 0000000..3775efd
--- /dev/null
@@ -0,0 +1,56 @@
+/***************************************************************************
+ *   Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at>                  *
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This program is distributed in the hope that it will be useful,       *
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
+ *   GNU General Public License for more details.                          *
+ *                                                                         *
+ *   You should have received a copy of the GNU General Public License     *
+ *   along with this program; if not, write to the                         *
+ *   Free Software Foundation, Inc.,                                       *
+ *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
+ ***************************************************************************/
+
+#ifndef DOLPHINNEWMENUOBSERVER_H
+#define DOLPHINNEWMENUOBSERVER_H
+
+#include <QObject>
+
+#include "libdolphin_export.h"
+
+class KNewMenu;
+class KUrl;
+
+/**
+ * @brief Allows to observe new file items that have been created
+ *        by a DolphinNewMenu instance.
+ *
+ * As soon as a DolphinNewMenu instance created a new item,
+ * the observer will emit the signal itemCreated().
+ */
+class LIBDOLPHINPRIVATE_EXPORT DolphinNewMenuObserver : public QObject
+{
+    Q_OBJECT
+
+public:
+    static DolphinNewMenuObserver& instance();
+    void attach(const KNewMenu* menu);
+    void detach(const KNewMenu* menu);
+
+signals:
+    void itemCreated(const KUrl& url);
+
+private:
+    DolphinNewMenuObserver();
+    virtual ~DolphinNewMenuObserver();
+
+    friend class DolphinNewMenuObserverSingleton;
+};
+
+#endif
index 7d7b3503bb6e849eb9a52df4e895f69e733ed4f0..696caa04e2114d4ec30b944df62c34dec16d42e5 100644 (file)
 #include "dolphinmodel.h"
 #include "dolphincolumnview.h"
 #include "dolphincontroller.h"
+#include "dolphindetailsview.h"
 #include "dolphinfileitemdelegate.h"
+#include "dolphinnewmenuobserver.h"
 #include "dolphinsortfilterproxymodel.h"
-#include "dolphindetailsview.h"
 #include "dolphin_detailsmodesettings.h"
 #include "dolphiniconsview.h"
-#include "settings/dolphinsettings.h"
 #include "dolphin_generalsettings.h"
 #include "draganddrophelper.h"
 #include "folderexpander.h"
 #include "renamedialog.h"
 #include "tooltips/tooltipmanager.h"
+#include "settings/dolphinsettings.h"
 #include "viewproperties.h"
 #include "zoomlevelinfo.h"
 
@@ -104,6 +105,7 @@ DolphinView::DolphinView(QWidget* parent,
     m_toolTipManager(0),
     m_rootUrl(),
     m_currentItemUrl(),
+    m_createdItemUrl(),
     m_expandedDragSource(0)
 {
     m_topLayout = new QVBoxLayout(this);
@@ -146,6 +148,12 @@ DolphinView::DolphinView(QWidget* parent,
     connect(m_dirLister, SIGNAL(refreshItems(const QList<QPair<KFileItem,KFileItem>>&)),
             this, SLOT(slotRefreshItems()));
 
+    // When a new item has been created by the "Create New..." menu, the item should
+    // get selected and it must be assured that the item will get visible. As the
+    // creation is done asynchronously, several signals must be checked:
+    connect(&DolphinNewMenuObserver::instance(), SIGNAL(itemCreated(const KUrl&)),
+            this, SLOT(observeCreatedItem(const KUrl&)));
+
     applyViewProperties(url);
     m_topLayout->addWidget(itemView());
 }
@@ -1081,6 +1089,26 @@ void DolphinView::deleteWhenNotDragSource(QAbstractItemView *view)
     }
 }
 
+void DolphinView::observeCreatedItem(const KUrl& url)
+{
+    m_createdItemUrl = url;
+    connect(m_dolphinModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
+            this, SLOT(selectAndScrollToCreatedItem()));
+}
+
+void DolphinView::selectAndScrollToCreatedItem()
+{
+    const QModelIndex dirIndex = m_dolphinModel->indexForUrl(m_createdItemUrl);
+    if (dirIndex.isValid()) {
+        const QModelIndex proxyIndex = m_proxyModel->mapFromSource(dirIndex);
+        itemView()->setCurrentIndex(proxyIndex);
+    }
+
+    disconnect(m_dolphinModel, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
+               this, SLOT(selectAndScrollToCreatedItem()));
+    m_createdItemUrl = KUrl();
+}
+
 void DolphinView::emitContentsMoved()
 {
     // only emit the contents moved signal if:
index 1498de08aac98e0b57067935061fad4175a39c8f..c18785151cb7eda0c025d0d48f3ecfae850332f8 100644 (file)
@@ -642,6 +642,21 @@ private slots:
      */
     void deleteWhenNotDragSource(QAbstractItemView* view);
 
+    /**
+     * Observes the item with the URL \a url. As soon as the directory
+     * model indicates that the item is available, the item will
+     * get selected and it is assure that the item stays visible.
+     *
+     * @see selectAndScrollToCreatedItem()
+     */
+    void observeCreatedItem(const KUrl& url);
+
+    /**
+     * Selects and scrolls to the item that got observed
+     * by observeCreatedItem().
+     */
+    void selectAndScrollToCreatedItem();
+
 private:
     void loadDirectory(const KUrl& url, bool reload = false);
 
@@ -744,6 +759,7 @@ private:
 
     KUrl m_rootUrl;
     KUrl m_currentItemUrl;
+    KUrl m_createdItemUrl; // URL for a new item that got created by the "Create New..." menu
 
     QAbstractItemView* m_expandedDragSource;
 };