[kde-doc-english] KDE/kdebase/apps/lib/konq

David Faure faure at kde.org
Tue Feb 10 22:57:41 CET 2009


SVN commit 924484 by dfaure:

GUI: "Show Original File" (or "Show Original Directory") in the RMB popup for a symlink that points to
an item in another directory.
FEATURE: 65151


 M  +32 -1     konq_popupmenu.cpp  
 M  +1 -0      konq_popupmenu.h  


--- trunk/KDE/kdebase/apps/lib/konq/konq_popupmenu.cpp #924483:924484
@@ -94,6 +94,7 @@
     void slotPopupMimeType();
     void slotPopupProperties();
     void slotOpenShareFileDialog();
+    void slotShowOriginalFile();
 
     KonqPopupMenu* q;
     QString m_urlTitle;
@@ -177,11 +178,17 @@
     bool isTrashLink     = false;
     bool isCurrentTrash = false;
     bool currentDir     = false;
+    bool isSymLink = false;
+    bool isSymLinkInSameDir = false; // true for "ln -s foo bar", false for links to foo/sub or /foo
 
     //check if url is current directory
     if ( lstItems.count() == 1 )
     {
         KFileItem firstPopupItem( lstItems.first() );
+        if (firstPopupItem.isLink()) {
+            isSymLink = true;
+            isSymLinkInSameDir = !firstPopupItem.linkDest().contains('/');
+        }
         KUrl firstPopupURL( firstPopupItem.url() );
         firstPopupURL.cleanPath();
         //kDebug(1203) << "View path is " << url.url();
@@ -212,7 +219,7 @@
 
     addGroup( "topactions" ); // used e.g. for ShowMenuBar. includes a separator at the end
 
-    QAction * act;
+    KAction * act;
 
     QAction *actNewWindow = 0;
 
@@ -276,6 +283,15 @@
         q->addSeparator();
     }
 
+    if (!currentDir && isSymLink && !isSymLinkInSameDir) {
+        // #65151: offer to open the target's parent dir
+        act = m_ownActions.addAction("show_original");
+        act->setText(isDirectory ? i18n("Show Original Directory") : i18n("Show Original File"));
+        act->setHelpText(i18n("Opens a new file manager window showing the target of this link, in its parent directory."));
+        QObject::connect(act, SIGNAL(triggered()), q, SLOT(slotShowOriginalFile()));
+        q->addAction(act);
+    }
+
     // "open in new window" is either provided by us, or by the tabhandling group
     if (actNewWindow) {
         q->addAction(actNewWindow);
@@ -506,4 +522,19 @@
     }
 }
 
+void KonqPopupMenuPrivate::slotShowOriginalFile()
+{
+    const KFileItem item = m_popupMenuInfo.items().first();
+    const QString dest = item.linkDest();
+    KUrl destUrl = m_sViewURL;
+    if (dest.startsWith('/')) {
+        destUrl.setPath(dest);
+    } else {
+        destUrl.addPath(dest);
+    }
+    // Now destUrl points to the target file, let's go up to parent dir
+    destUrl.setPath(destUrl.directory());
+    KRun::runUrl(destUrl, "inode/directory", m_popupMenuInfo.parentWidget());
+}
+
 #include "konq_popupmenu.moc"
--- trunk/KDE/kdebase/apps/lib/konq/konq_popupmenu.h #924483:924484
@@ -110,6 +110,7 @@
   Q_PRIVATE_SLOT(d, void slotPopupMimeType())
   Q_PRIVATE_SLOT(d, void slotPopupProperties())
   Q_PRIVATE_SLOT(d, void slotOpenShareFileDialog())
+  Q_PRIVATE_SLOT(d, void slotShowOriginalFile())
 
 private:
   KonqPopupMenuPrivate *d;



More information about the kde-doc-english mailing list