From 5f4245789dfdcf63c03b7354d8320d65c4560cf9 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 1 Mar 2019 14:57:42 +0100 Subject: [PATCH] FileManager: Allow launching processes by activating an executable file. --- .../FileManager/DirectoryTableModel.cpp | 17 +++++++++++++++-- Applications/FileManager/DirectoryTableModel.h | 2 ++ Base/res/icons/executable16.png | Bin 0 -> 223 bytes Base/res/icons/executable16.rgb | Bin 0 -> 1024 bytes 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 Base/res/icons/executable16.png create mode 100644 Base/res/icons/executable16.rgb diff --git a/Applications/FileManager/DirectoryTableModel.cpp b/Applications/FileManager/DirectoryTableModel.cpp index 757a00a62d..f610bcbecc 100644 --- a/Applications/FileManager/DirectoryTableModel.cpp +++ b/Applications/FileManager/DirectoryTableModel.cpp @@ -11,6 +11,7 @@ DirectoryTableModel::DirectoryTableModel() m_file_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/file16.rgb", { 16, 16 }); m_symlink_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/link16.rgb", { 16, 16 }); m_socket_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/socket16.rgb", { 16, 16 }); + m_executable_icon = GraphicsBitmap::load_from_file(GraphicsBitmap::Format::RGBA32, "/res/icons/executable16.rgb", { 16, 16 }); } DirectoryTableModel::~DirectoryTableModel() @@ -63,6 +64,8 @@ const GraphicsBitmap& DirectoryTableModel::icon_for(const Entry& entry) const return *m_symlink_icon; if (S_ISSOCK(entry.mode)) return *m_socket_icon; + if (entry.mode & S_IXUSR) + return *m_executable_icon; return *m_file_icon; } @@ -173,8 +176,18 @@ void DirectoryTableModel::open(const String& path) void DirectoryTableModel::activate(const GModelIndex& index) { auto& entry = this->entry(index.row()); + FileSystemPath path(String::format("%s/%s", m_path.characters(), entry.name.characters())); if (entry.is_directory()) { - FileSystemPath new_path(String::format("%s/%s", m_path.characters(), entry.name.characters())); - open(new_path.string()); + open(path.string()); + return; + } + if (entry.is_executable()) { + if (fork() == 0) { + int rc = execl(path.string().characters(), path.string().characters(), nullptr); + if (rc < 0) + perror("exec"); + ASSERT_NOT_REACHED(); + } + return; } } diff --git a/Applications/FileManager/DirectoryTableModel.h b/Applications/FileManager/DirectoryTableModel.h index 661517d953..f5d8e65ae7 100644 --- a/Applications/FileManager/DirectoryTableModel.h +++ b/Applications/FileManager/DirectoryTableModel.h @@ -40,6 +40,7 @@ private: uid_t gid { 0 }; ino_t inode { 0 }; bool is_directory() const { return S_ISDIR(mode); } + bool is_executable() const { return mode & S_IXUSR; } }; const Entry& entry(int index) const @@ -59,4 +60,5 @@ private: RetainPtr m_file_icon; RetainPtr m_symlink_icon; RetainPtr m_socket_icon; + RetainPtr m_executable_icon; }; diff --git a/Base/res/icons/executable16.png b/Base/res/icons/executable16.png new file mode 100644 index 0000000000000000000000000000000000000000..8de7113e144aa70f1bae064056a7b6b4c50e28bd GIT binary patch literal 223 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkEbHUgGKN%Kn&{kylr&-fqzqppayVYeb22er|4RUI~M9QEFmIYKlU6 zW=V#EyQgnJcq5-UP?5W*i(`nz>Er~7PYr^df9K2W)j6TGH|`dXjEoG=n>ie3j-5Ps z;2;p6JIE()?Du~0MDBn8)z9&`xwY)|nZovH1!G9ZF`zr6)^m!jOgobaG?Ky7)z4*} HQ$iB}s~|-H literal 0 HcmV?d00001 diff --git a/Base/res/icons/executable16.rgb b/Base/res/icons/executable16.rgb new file mode 100644 index 0000000000000000000000000000000000000000..d6232a6530172bb12f8618dcfb7adcdb833446a7 GIT binary patch literal 1024 zcmZQz7&hQP&?lr|bdUen_Uip_95nU6b@ZJ7&MAxkd*`nDA6&NKe{}th|4Hrp|7T4& n_P=Q6S(qId`YE;lKal`x4~G3jYRBpRk*=S@_(PA6A;AX#DeE~Y literal 0 HcmV?d00001