瀏覽代碼

FileManager: Add a button to open links in their real directory

Alex McGrath 4 年之前
父節點
當前提交
a5f4cb78cf
共有 2 個文件被更改,包括 18 次插入3 次删除
  1. 17 3
      Applications/FileManager/PropertiesDialog.cpp
  2. 1 0
      Applications/FileManager/PropertiesDialog.h

+ 17 - 3
Applications/FileManager/PropertiesDialog.cpp

@@ -27,10 +27,12 @@
 #include "PropertiesDialog.h"
 #include <AK/LexicalPath.h>
 #include <AK/StringBuilder.h>
+#include <LibDesktop/Launcher.h>
 #include <LibGUI/BoxLayout.h>
 #include <LibGUI/CheckBox.h>
 #include <LibGUI/FileIconProvider.h>
 #include <LibGUI/FilePicker.h>
+#include <LibGUI/Link.h>
 #include <LibGUI/MessageBox.h>
 #include <LibGUI/TabWidget.h>
 #include <grp.h>
@@ -116,14 +118,18 @@ PropertiesDialog::PropertiesDialog(const String& path, bool disable_rename, Wind
 
     auto properties = Vector<PropertyValuePair>();
     properties.append({ "Type:", get_description(m_mode) });
-    properties.append({ "Location:", path });
+    auto parent_link = URL::create_with_file_protocol(m_parent_path);
+    properties.append(PropertyValuePair { "Location:", path, Optional(parent_link) });
 
     if (S_ISLNK(m_mode)) {
         auto link_destination = Core::File::read_link(path);
         if (link_destination.is_null()) {
             perror("readlink");
         } else {
-            properties.append({ "Link target:", link_destination });
+            auto link_directory = LexicalPath(link_destination);
+            ASSERT(link_directory.is_valid());
+            auto link_parent = URL::create_with_file_protocol(link_directory.dirname());
+            properties.append({ "Link target:", link_destination, Optional(link_parent) });
         }
     }
 
@@ -279,7 +285,15 @@ void PropertiesDialog::make_property_value_pairs(const Vector<PropertyValuePair>
         label_property.set_text_alignment(Gfx::TextAlignment::CenterLeft);
         label_property.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fill);
 
-        label_container.add<GUI::Label>(pair.value).set_text_alignment(Gfx::TextAlignment::CenterLeft);
+        if (!pair.link.has_value()) {
+            label_container.add<GUI::Label>(pair.value).set_text_alignment(Gfx::TextAlignment::CenterLeft);
+        } else {
+            auto& link = label_container.add<GUI::Link>(pair.value);
+            link.set_text_alignment(Gfx::TextAlignment::CenterLeft);
+            link.on_click = [pair]() {
+                Desktop::Launcher::open(pair.link.value());
+            };
+        }
 
         max_width = max(max_width, label_property.font().width(pair.property));
         property_labels.append(label_property);

+ 1 - 0
Applications/FileManager/PropertiesDialog.h

@@ -45,6 +45,7 @@ private:
     struct PropertyValuePair {
         String property;
         String value;
+        Optional<URL> link = {};
     };
 
     struct PermissionMasks {