1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:27:35 +00:00

LibGUI: Add GUI::CommonActions::make_properties_action()

Many apps want a "Properties" action with the same icon and shortcut.
This commit is contained in:
Andreas Kling 2021-04-04 22:39:41 +02:00
parent 578f749791
commit eff7ea5b84
4 changed files with 45 additions and 40 deletions

View file

@ -310,15 +310,14 @@ int run_in_desktop_mode([[maybe_unused]] RefPtr<Core::ConfigFile> config)
cut_action->set_enabled(!view.selection().is_empty()); cut_action->set_enabled(!view.selection().is_empty());
}; };
auto properties_action auto properties_action = GUI::CommonActions::make_properties_action(
= GUI::Action::create( [&](auto&) {
"Properties", { Mod_Alt, Key_Return }, Gfx::Bitmap::load_from_file("/res/icons/16x16/properties.png"), [&](const GUI::Action&) { String path = directory_view.path();
String path = directory_view.path(); Vector<String> selected = directory_view.selected_file_paths();
Vector<String> selected = directory_view.selected_file_paths();
show_properties(path, path, selected, directory_view.window()); show_properties(path, path, selected, directory_view.window());
}, },
window); window);
auto paste_action = GUI::CommonActions::make_paste_action( auto paste_action = GUI::CommonActions::make_paste_action(
[&](const GUI::Action&) { [&](const GUI::Action&) {
@ -658,25 +657,24 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
}, },
window); window);
auto properties_action auto properties_action = GUI::CommonActions::make_properties_action(
= GUI::Action::create( [&](auto& action) {
"Properties", { Mod_Alt, Key_Return }, Gfx::Bitmap::load_from_file("/res/icons/16x16/properties.png"), [&](const GUI::Action& action) { String container_dir_path;
String container_dir_path; String path;
String path; Vector<String> selected;
Vector<String> selected; if (action.activator() == directory_context_menu || directory_view.active_widget()->is_focused()) {
if (action.activator() == directory_context_menu || directory_view.active_widget()->is_focused()) { path = directory_view.path();
path = directory_view.path(); container_dir_path = path;
container_dir_path = path; selected = directory_view.selected_file_paths();
selected = directory_view.selected_file_paths(); } else {
} else { path = directories_model->full_path(tree_view.selection().first());
path = directories_model->full_path(tree_view.selection().first()); container_dir_path = LexicalPath(path).basename();
container_dir_path = LexicalPath(path).basename(); selected = tree_view_selected_file_paths();
selected = tree_view_selected_file_paths(); }
}
show_properties(container_dir_path, path, selected, directory_view.window()); show_properties(container_dir_path, path, selected, directory_view.window());
}, },
window); window);
auto paste_action = GUI::CommonActions::make_paste_action( auto paste_action = GUI::CommonActions::make_paste_action(
[&](const GUI::Action& action) { [&](const GUI::Action& action) {

View file

@ -296,21 +296,22 @@ int main(int argc, char** argv)
HashMap<pid_t, NonnullRefPtr<GUI::Window>> process_windows; HashMap<pid_t, NonnullRefPtr<GUI::Window>> process_windows;
auto process_properties_action = GUI::Action::create("Properties", { Mod_Alt, Key_Return }, [&](auto&) { auto process_properties_action = GUI::CommonActions::make_properties_action(
auto pid = selected_id(ProcessModel::Column::PID); [&](auto&) {
auto pid = selected_id(ProcessModel::Column::PID);
RefPtr<GUI::Window> process_window; RefPtr<GUI::Window> process_window;
if (!process_windows.contains(pid)) { if (!process_windows.contains(pid)) {
process_window = build_process_window(pid); process_window = build_process_window(pid);
process_window->on_close_request = [pid, &process_windows] { process_window->on_close_request = [pid, &process_windows] {
process_windows.remove(pid); process_windows.remove(pid);
return GUI::Window::CloseRequestDecision::Close; return GUI::Window::CloseRequestDecision::Close;
}; };
process_windows.set(pid, *process_window); process_windows.set(pid, *process_window);
} }
process_window->show(); process_window->show();
process_window->move_to_front(); process_window->move_to_front();
}); });
auto menubar = GUI::MenuBar::construct(); auto menubar = GUI::MenuBar::construct();
auto& app_menu = menubar->add_menu("File"); auto& app_menu = menubar->add_menu("File");

View file

@ -141,6 +141,11 @@ NonnullRefPtr<Action> make_select_all_action(Function<void(Action&)> callback, C
return Action::create("Select all", { Mod_Ctrl, Key_A }, Gfx::Bitmap::load_from_file("/res/icons/16x16/select-all.png"), move(callback), parent); return Action::create("Select all", { Mod_Ctrl, Key_A }, Gfx::Bitmap::load_from_file("/res/icons/16x16/select-all.png"), move(callback), parent);
} }
NonnullRefPtr<Action> make_properties_action(Function<void(Action&)> callback, Core::Object* parent)
{
return Action::create("Properties", { Mod_Alt, Key_Return }, Gfx::Bitmap::load_from_file("/res/icons/16x16/properties.png"), move(callback), parent);
}
} }
NonnullRefPtr<Action> Action::create(String text, Function<void(Action&)> callback, Core::Object* parent) NonnullRefPtr<Action> Action::create(String text, Function<void(Action&)> callback, Core::Object* parent)

View file

@ -62,6 +62,7 @@ NonnullRefPtr<Action> make_go_forward_action(Function<void(Action&)>, Core::Obje
NonnullRefPtr<Action> make_go_home_action(Function<void(Action&)> callback, Core::Object* parent = nullptr); NonnullRefPtr<Action> make_go_home_action(Function<void(Action&)> callback, Core::Object* parent = nullptr);
NonnullRefPtr<Action> make_reload_action(Function<void(Action&)>, Core::Object* parent = nullptr); NonnullRefPtr<Action> make_reload_action(Function<void(Action&)>, Core::Object* parent = nullptr);
NonnullRefPtr<Action> make_select_all_action(Function<void(Action&)>, Core::Object* parent = nullptr); NonnullRefPtr<Action> make_select_all_action(Function<void(Action&)>, Core::Object* parent = nullptr);
NonnullRefPtr<Action> make_properties_action(Function<void(Action&)>, Core::Object* parent = nullptr);
}; };
class Action final : public Core::Object { class Action final : public Core::Object {