Prechádzať zdrojové kódy

FileManager: Open PNG files with QuickShow when activated.

Andreas Kling 6 rokov pred
rodič
commit
5ca62f356b

+ 2 - 0
AK/AKString.h

@@ -74,6 +74,8 @@ public:
     const char* characters() const { return m_impl ? m_impl->characters() : nullptr; }
     const char* characters() const { return m_impl ? m_impl->characters() : nullptr; }
     char operator[](ssize_t i) const { ASSERT(m_impl); return (*m_impl)[i]; }
     char operator[](ssize_t i) const { ASSERT(m_impl); return (*m_impl)[i]; }
 
 
+    bool ends_with(const String&) const;
+
     bool operator==(const String&) const;
     bool operator==(const String&) const;
     bool operator!=(const String& other) const { return !(*this == other); }
     bool operator!=(const String& other) const { return !(*this == other); }
     bool operator<(const String&) const;
     bool operator<(const String&) const;

+ 11 - 0
AK/String.cpp

@@ -126,4 +126,15 @@ String String::format(const char* fmt, ...)
     return builder.to_string();
     return builder.to_string();
 }
 }
 
 
+bool String::ends_with(const String& str) const
+{
+    if (str.is_empty())
+        return true;
+    if (is_empty())
+        return false;
+    if (str.length() > length())
+        return false;
+    return !memcmp(characters() + (length() - str.length()), str.characters(), str.length());
+}
+
 }
 }

+ 10 - 0
Applications/FileManager/DirectoryTableModel.cpp

@@ -236,6 +236,16 @@ void DirectoryTableModel::activate(const GModelIndex& index)
         return;
         return;
     }
     }
 
 
+    if (path.string().ends_with(".png")) {
+        if (fork() == 0) {
+            int rc = execl("/bin/qs", "/bin/qs", path.string().characters(), nullptr);
+            if (rc < 0)
+                perror("exec");
+            ASSERT_NOT_REACHED();
+        }
+        return;
+    }
+
     if (fork() == 0) {
     if (fork() == 0) {
         int rc = execl("/bin/TextEditor", "/bin/TextEditor", path.string().characters(), nullptr);
         int rc = execl("/bin/TextEditor", "/bin/TextEditor", path.string().characters(), nullptr);
         if (rc < 0)
         if (rc < 0)