mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:47:34 +00:00
FileManager: Add Open in Terminal on folder context menu
This commit is contained in:
parent
47e1d5c05e
commit
86a4d0694f
3 changed files with 42 additions and 12 deletions
|
@ -26,6 +26,23 @@
|
|||
|
||||
namespace FileManager {
|
||||
|
||||
void spawn_terminal(String const& directory)
|
||||
{
|
||||
posix_spawn_file_actions_t spawn_actions;
|
||||
posix_spawn_file_actions_init(&spawn_actions);
|
||||
posix_spawn_file_actions_addchdir(&spawn_actions, directory.characters());
|
||||
|
||||
pid_t pid;
|
||||
const char* argv[] = { "Terminal", nullptr };
|
||||
if ((errno = posix_spawn(&pid, "/bin/Terminal", &spawn_actions, nullptr, const_cast<char**>(argv), environ))) {
|
||||
perror("posix_spawn");
|
||||
} else {
|
||||
if (disown(pid) < 0)
|
||||
perror("disown");
|
||||
}
|
||||
posix_spawn_file_actions_destroy(&spawn_actions);
|
||||
}
|
||||
|
||||
enum class FileOperation {
|
||||
Copy,
|
||||
};
|
||||
|
@ -570,18 +587,7 @@ void DirectoryView::setup_actions()
|
|||
});
|
||||
|
||||
m_open_terminal_action = GUI::Action::create("Open &Terminal Here", Gfx::Bitmap::load_from_file("/res/icons/16x16/app-terminal.png"), [&](auto&) {
|
||||
posix_spawn_file_actions_t spawn_actions;
|
||||
posix_spawn_file_actions_init(&spawn_actions);
|
||||
posix_spawn_file_actions_addchdir(&spawn_actions, path().characters());
|
||||
pid_t pid;
|
||||
const char* argv[] = { "Terminal", nullptr };
|
||||
if ((errno = posix_spawn(&pid, "/bin/Terminal", &spawn_actions, nullptr, const_cast<char**>(argv), environ))) {
|
||||
perror("posix_spawn");
|
||||
} else {
|
||||
if (disown(pid) < 0)
|
||||
perror("disown");
|
||||
}
|
||||
posix_spawn_file_actions_destroy(&spawn_actions);
|
||||
spawn_terminal(path());
|
||||
});
|
||||
|
||||
m_delete_action = GUI::CommonActions::make_delete_action([this](auto&) { do_delete(true); }, window());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue