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
Notes: sideshowbarker 2024-07-18 20:46:57 +09:00
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());
};
auto properties_action
= GUI::Action::create(
"Properties", { Mod_Alt, Key_Return }, Gfx::Bitmap::load_from_file("/res/icons/16x16/properties.png"), [&](const GUI::Action&) {
String path = directory_view.path();
Vector<String> selected = directory_view.selected_file_paths();
auto properties_action = GUI::CommonActions::make_properties_action(
[&](auto&) {
String path = directory_view.path();
Vector<String> selected = directory_view.selected_file_paths();
show_properties(path, path, selected, directory_view.window());
},
window);
show_properties(path, path, selected, directory_view.window());
},
window);
auto paste_action = GUI::CommonActions::make_paste_action(
[&](const GUI::Action&) {
@ -658,25 +657,24 @@ int run_in_windowed_mode(RefPtr<Core::ConfigFile> config, String initial_locatio
},
window);
auto properties_action
= GUI::Action::create(
"Properties", { Mod_Alt, Key_Return }, Gfx::Bitmap::load_from_file("/res/icons/16x16/properties.png"), [&](const GUI::Action& action) {
String container_dir_path;
String path;
Vector<String> selected;
if (action.activator() == directory_context_menu || directory_view.active_widget()->is_focused()) {
path = directory_view.path();
container_dir_path = path;
selected = directory_view.selected_file_paths();
} else {
path = directories_model->full_path(tree_view.selection().first());
container_dir_path = LexicalPath(path).basename();
selected = tree_view_selected_file_paths();
}
auto properties_action = GUI::CommonActions::make_properties_action(
[&](auto& action) {
String container_dir_path;
String path;
Vector<String> selected;
if (action.activator() == directory_context_menu || directory_view.active_widget()->is_focused()) {
path = directory_view.path();
container_dir_path = path;
selected = directory_view.selected_file_paths();
} else {
path = directories_model->full_path(tree_view.selection().first());
container_dir_path = LexicalPath(path).basename();
selected = tree_view_selected_file_paths();
}
show_properties(container_dir_path, path, selected, directory_view.window());
},
window);
show_properties(container_dir_path, path, selected, directory_view.window());
},
window);
auto paste_action = GUI::CommonActions::make_paste_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;
auto process_properties_action = GUI::Action::create("Properties", { Mod_Alt, Key_Return }, [&](auto&) {
auto pid = selected_id(ProcessModel::Column::PID);
auto process_properties_action = GUI::CommonActions::make_properties_action(
[&](auto&) {
auto pid = selected_id(ProcessModel::Column::PID);
RefPtr<GUI::Window> process_window;
if (!process_windows.contains(pid)) {
process_window = build_process_window(pid);
process_window->on_close_request = [pid, &process_windows] {
process_windows.remove(pid);
return GUI::Window::CloseRequestDecision::Close;
};
process_windows.set(pid, *process_window);
}
process_window->show();
process_window->move_to_front();
});
RefPtr<GUI::Window> process_window;
if (!process_windows.contains(pid)) {
process_window = build_process_window(pid);
process_window->on_close_request = [pid, &process_windows] {
process_windows.remove(pid);
return GUI::Window::CloseRequestDecision::Close;
};
process_windows.set(pid, *process_window);
}
process_window->show();
process_window->move_to_front();
});
auto menubar = GUI::MenuBar::construct();
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);
}
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)

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_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_properties_action(Function<void(Action&)>, Core::Object* parent = nullptr);
};
class Action final : public Core::Object {