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!ia0y~yU=RRd4mJh`2Kmqb6B!s7*pj^6T^PXNr}OT51_lPs z0*}aI1_nK45N51cYG1~{z`$PO>Fdh=n3<7RSFGM{(G>;;2FViFh!W@g+}zZ>5(ej@ z)Wnk16ovB4k_-iRPv3y>Mm}){1_pOe7sn8b)5!@EpBe-^|IU}$t8+qWZ`>^&85tR# zH*+}796NdNz`>IT51c#5CvNQbe(^-^fB)6b@wmCQ?Dd(#_GkrTNXM~628O8hoMJ1} R&SZid>gnp|vd$@?2>`1gMF0Q* 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 zcmZP=KHxtC0|O}--RJ+cy?Xx}2TlEN9X;p2bIRiX-npy(2bXR5A6>uWe^UGY|5+1` q{V$q%7G?*AeoF2CPb7fagJD0B+Htynr0a)4a->p3X^ literal 0 HcmV?d00001