FileManager: Use GUI::Process::spawn_or_show_error() to open terminals

This commit is contained in:
MacDue 2023-03-13 20:29:33 +00:00 committed by Linus Groh
parent d27a513dc5
commit 2aa8c9950e
3 changed files with 8 additions and 19 deletions

View file

@ -19,6 +19,7 @@
#include <LibGUI/Label.h>
#include <LibGUI/MessageBox.h>
#include <LibGUI/ModelEditingDelegate.h>
#include <LibGUI/Process.h>
#include <LibGUI/SortingProxyModel.h>
#include <serenity.h>
#include <spawn.h>
@ -27,21 +28,9 @@
namespace FileManager {
void spawn_terminal(DeprecatedString const& directory)
void spawn_terminal(GUI::Window* window, StringView 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;
char const* 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);
GUI::Process::spawn_or_show_error(window, "/bin/Terminal"sv, ReadonlySpan<StringView> {}, directory);
}
NonnullRefPtr<GUI::Action> LauncherHandler::create_launch_action(Function<void(LauncherHandler const&)> launch_handler)
@ -617,7 +606,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"sv).release_value_but_fixme_should_propagate_errors(), [&](auto&) {
spawn_terminal(path());
spawn_terminal(window(), path());
});
m_delete_action = GUI::CommonActions::make_delete_action([this](auto&) { do_delete(true); }, window());

View file

@ -21,7 +21,7 @@
namespace FileManager {
void spawn_terminal(DeprecatedString const& directory);
void spawn_terminal(GUI::Window* window, StringView directory);
class LauncherHandler : public RefCounted<LauncherHandler> {
public:

View file

@ -491,13 +491,13 @@ ErrorOr<int> run_in_desktop_mode()
auto open_terminal_action = GUI::Action::create("Open in &Terminal", {}, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-terminal.png"sv)), [&](auto&) {
auto paths = directory_view->selected_file_paths();
if (paths.is_empty()) {
spawn_terminal(directory_view->path());
spawn_terminal(window, directory_view->path());
return;
}
for (auto& path : paths) {
if (FileSystem::is_directory(path)) {
spawn_terminal(path);
spawn_terminal(window, path);
}
}
});
@ -841,7 +841,7 @@ ErrorOr<int> run_in_windowed_mode(DeprecatedString const& initial_location, Depr
for (auto& path : paths) {
if (FileSystem::is_directory(path)) {
spawn_terminal(path);
spawn_terminal(window, path);
}
}
},