mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
GCommonActions: Add "Open..." action
Make use of this in PaintBrush and TextEditor. :^)
This commit is contained in:
parent
48b1b55629
commit
74c4e62659
4 changed files with 8 additions and 2 deletions
|
@ -44,7 +44,7 @@ int main(int argc, char** argv)
|
||||||
menubar->add_menu(move(app_menu));
|
menubar->add_menu(move(app_menu));
|
||||||
|
|
||||||
auto file_menu = make<GMenu>("File");
|
auto file_menu = make<GMenu>("File");
|
||||||
file_menu->add_action(GAction::create("Open...", { Mod_Ctrl, Key_O }, [&](auto&) {
|
file_menu->add_action(GCommonActions::make_open_action([&](auto&) {
|
||||||
GFilePicker picker;
|
GFilePicker picker;
|
||||||
if (picker.exec() == GFilePicker::ExecOK) {
|
if (picker.exec() == GFilePicker::ExecOK) {
|
||||||
auto filename = picker.selected_file().string();
|
auto filename = picker.selected_file().string();
|
||||||
|
|
|
@ -132,7 +132,7 @@ TextEditorWidget::TextEditorWidget()
|
||||||
update_title();
|
update_title();
|
||||||
});
|
});
|
||||||
|
|
||||||
m_open_action = GAction::create("Open...", { Mod_Ctrl, Key_O }, GraphicsBitmap::load_from_file("/res/icons/16x16/open.png"), [this](const GAction&) {
|
m_open_action = GCommonActions::make_open_action([this](auto&) {
|
||||||
Optional<String> open_path = GFilePicker::get_open_filepath();
|
Optional<String> open_path = GFilePicker::get_open_filepath();
|
||||||
|
|
||||||
if (!open_path.has_value())
|
if (!open_path.has_value())
|
||||||
|
|
|
@ -6,6 +6,11 @@
|
||||||
|
|
||||||
namespace GCommonActions {
|
namespace GCommonActions {
|
||||||
|
|
||||||
|
NonnullRefPtr<GAction> make_open_action(Function<void(GAction&)> callback, GWidget* widget)
|
||||||
|
{
|
||||||
|
return GAction::create("Open...", { Mod_Ctrl, Key_O }, GraphicsBitmap::load_from_file("/res/icons/16x16/open.png"), move(callback), widget);
|
||||||
|
}
|
||||||
|
|
||||||
NonnullRefPtr<GAction> make_move_to_front_action(Function<void(GAction&)> callback, GWidget* widget)
|
NonnullRefPtr<GAction> make_move_to_front_action(Function<void(GAction&)> callback, GWidget* widget)
|
||||||
{
|
{
|
||||||
return GAction::create("Move to front", { Mod_Ctrl | Mod_Shift, Key_Up }, GraphicsBitmap::load_from_file("/res/icons/16x16/move-to-front.png"), move(callback), widget);
|
return GAction::create("Move to front", { Mod_Ctrl | Mod_Shift, Key_Up }, GraphicsBitmap::load_from_file("/res/icons/16x16/move-to-front.png"), move(callback), widget);
|
||||||
|
|
|
@ -19,6 +19,7 @@ class GMenuItem;
|
||||||
class GWidget;
|
class GWidget;
|
||||||
|
|
||||||
namespace GCommonActions {
|
namespace GCommonActions {
|
||||||
|
NonnullRefPtr<GAction> make_open_action(Function<void(GAction&)>, GWidget* widget = nullptr);
|
||||||
NonnullRefPtr<GAction> make_undo_action(Function<void(GAction&)>, GWidget* widget = nullptr);
|
NonnullRefPtr<GAction> make_undo_action(Function<void(GAction&)>, GWidget* widget = nullptr);
|
||||||
NonnullRefPtr<GAction> make_redo_action(Function<void(GAction&)>, GWidget* widget = nullptr);
|
NonnullRefPtr<GAction> make_redo_action(Function<void(GAction&)>, GWidget* widget = nullptr);
|
||||||
NonnullRefPtr<GAction> make_cut_action(Function<void(GAction&)>, GWidget* widget = nullptr);
|
NonnullRefPtr<GAction> make_cut_action(Function<void(GAction&)>, GWidget* widget = nullptr);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue