Sfoglia il codice sorgente

FileManager: Open non-executable files in TextEditor by default.

Andreas Kling 6 anni fa
parent
commit
3ee0e82206

+ 8 - 0
Applications/FileManager/DirectoryTableModel.cpp

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

+ 1 - 1
Applications/TextEditor/main.cpp

@@ -29,7 +29,7 @@ int main(int argc, char** argv)
         statusbar->set_text(String::format("Line: %d, Column: %d", editor.cursor().line(), editor.cursor().column()));
     };
 
-    String path = "/home/anon/ReadMe.md";
+    String path = argc < 2 ? "/home/anon/ReadMe.md" : argv[1];
     {
         StringBuilder builder;
         int fd = open(path.characters(), O_RDONLY);