TextEditor: Add Alt shortcuts to menu actions

This commit is contained in:
Andreas Kling 2021-04-09 16:34:51 +02:00
parent 2bac9eb79d
commit f718f04b14
Notes: sideshowbarker 2024-07-18 20:37:24 +09:00

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -137,7 +137,7 @@ TextEditorWidget::TextEditorWidget()
};
m_wrap_around_checkbox->set_checked(true);
m_find_next_action = GUI::Action::create("Find next", { Mod_Ctrl, Key_G }, Gfx::Bitmap::load_from_file("/res/icons/16x16/find-next.png"), [&](auto&) {
m_find_next_action = GUI::Action::create("Find &Next", { Mod_Ctrl, Key_G }, Gfx::Bitmap::load_from_file("/res/icons/16x16/find-next.png"), [&](auto&) {
auto needle = m_find_textbox->text();
if (needle.is_empty())
return;
@ -156,7 +156,7 @@ TextEditorWidget::TextEditorWidget()
}
});
m_find_previous_action = GUI::Action::create("Find previous", { Mod_Ctrl | Mod_Shift, Key_G }, Gfx::Bitmap::load_from_file("/res/icons/16x16/find-previous.png"), [&](auto&) {
m_find_previous_action = GUI::Action::create("Find &Previous", { Mod_Ctrl | Mod_Shift, Key_G }, Gfx::Bitmap::load_from_file("/res/icons/16x16/find-previous.png"), [&](auto&) {
auto needle = m_find_textbox->text();
if (needle.is_empty())
return;
@ -179,7 +179,7 @@ TextEditorWidget::TextEditorWidget()
}
});
m_replace_action = GUI::Action::create("Replace", { Mod_Ctrl, Key_F1 }, [&](auto&) {
m_replace_action = GUI::Action::create("&Replace", { Mod_Ctrl, Key_F1 }, [&](auto&) {
auto needle = m_find_textbox->text();
auto substitute = m_replace_textbox->text();
if (needle.is_empty())
@ -199,7 +199,7 @@ TextEditorWidget::TextEditorWidget()
}
});
m_replace_all_action = GUI::Action::create("Replace all", { Mod_Ctrl, Key_F2 }, [&](auto&) {
m_replace_all_action = GUI::Action::create("Replace &All", { Mod_Ctrl, Key_F2 }, [&](auto&) {
auto needle = m_find_textbox->text();
auto substitute = m_replace_textbox->text();
if (needle.is_empty())
@ -247,7 +247,7 @@ TextEditorWidget::TextEditorWidget()
m_editor->set_focus(true);
};
m_vim_emulation_setting_action = GUI::Action::create_checkable("Vim emulation", { Mod_Ctrl | Mod_Shift | Mod_Alt, Key_V }, [&](auto& action) {
m_vim_emulation_setting_action = GUI::Action::create_checkable("&Vim Emulation", { Mod_Ctrl | Mod_Shift | Mod_Alt, Key_V }, [&](auto& action) {
if (action.is_checked())
m_editor->set_editing_engine(make<GUI::VimEditingEngine>());
else
@ -255,7 +255,7 @@ TextEditorWidget::TextEditorWidget()
});
m_vim_emulation_setting_action->set_checked(false);
m_find_replace_action = GUI::Action::create("Find/Replace...", { Mod_Ctrl, Key_F }, Gfx::Bitmap::load_from_file("/res/icons/16x16/find.png"), [this](auto&) {
m_find_replace_action = GUI::Action::create("&Find/Replace...", { Mod_Ctrl, Key_F }, Gfx::Bitmap::load_from_file("/res/icons/16x16/find.png"), [this](auto&) {
m_find_replace_widget->set_visible(true);
m_find_widget->set_visible(true);
m_replace_widget->set_visible(true);
@ -277,7 +277,7 @@ TextEditorWidget::TextEditorWidget()
m_editor->on_cursor_change = [this] { update_statusbar(); };
m_editor->on_selection_change = [this] { update_statusbar(); };
m_new_action = GUI::Action::create("New", { Mod_Ctrl, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [this](const GUI::Action&) {
m_new_action = GUI::Action::create("&New", { Mod_Ctrl, Key_N }, Gfx::Bitmap::load_from_file("/res/icons/16x16/new.png"), [this](const GUI::Action&) {
if (m_document_dirty) {
auto save_document_first_result = GUI::MessageBox::show(window(), "Save changes to current document first?", "Warning", GUI::MessageBox::Type::Warning, GUI::MessageBox::InputType::YesNoCancel);
if (save_document_first_result == GUI::Dialog::ExecResult::ExecYes)
@ -361,7 +361,7 @@ TextEditorWidget::~TextEditorWidget()
void TextEditorWidget::initialize_menubar(GUI::MenuBar& menubar)
{
auto& app_menu = menubar.add_menu("File");
auto& app_menu = menubar.add_menu("&File");
app_menu.add_action(*m_new_action);
app_menu.add_action(*m_open_action);
app_menu.add_action(*m_save_action);
@ -373,7 +373,7 @@ void TextEditorWidget::initialize_menubar(GUI::MenuBar& menubar)
GUI::Application::the()->quit();
}));
auto& edit_menu = menubar.add_menu("Edit");
auto& edit_menu = menubar.add_menu("&Edit");
edit_menu.add_action(m_editor->undo_action());
edit_menu.add_action(m_editor->redo_action());
edit_menu.add_separator();
@ -391,18 +391,18 @@ void TextEditorWidget::initialize_menubar(GUI::MenuBar& menubar)
edit_menu.add_action(*m_replace_all_action);
m_no_preview_action = GUI::Action::create_checkable(
"No preview", [this](auto&) {
"&No Preview", [this](auto&) {
set_preview_mode(PreviewMode::None);
});
m_markdown_preview_action = GUI::Action::create_checkable(
"Markdown preview", [this](auto&) {
"&Markdown Preview", [this](auto&) {
set_preview_mode(PreviewMode::Markdown);
},
this);
m_html_preview_action = GUI::Action::create_checkable(
"HTML preview", [this](auto&) {
"&HTML Preview", [this](auto&) {
set_preview_mode(PreviewMode::HTML);
},
this);
@ -412,7 +412,7 @@ void TextEditorWidget::initialize_menubar(GUI::MenuBar& menubar)
m_preview_actions.add_action(*m_html_preview_action);
m_preview_actions.set_exclusive(true);
m_layout_toolbar_action = GUI::Action::create_checkable("Toolbar", [&](auto& action) {
m_layout_toolbar_action = GUI::Action::create_checkable("&Toolbar", [&](auto& action) {
action.is_checked() ? m_toolbar_container->set_visible(true) : m_toolbar_container->set_visible(false);
m_config->write_bool_entry("Layout", "ShowToolbar", action.is_checked());
m_config->sync();
@ -421,7 +421,7 @@ void TextEditorWidget::initialize_menubar(GUI::MenuBar& menubar)
m_layout_toolbar_action->set_checked(show_toolbar);
m_toolbar_container->set_visible(show_toolbar);
m_layout_statusbar_action = GUI::Action::create_checkable("Status bar", [&](auto& action) {
m_layout_statusbar_action = GUI::Action::create_checkable("&Status Bar", [&](auto& action) {
action.is_checked() ? m_statusbar->set_visible(true) : m_statusbar->set_visible(false);
m_config->write_bool_entry("Layout", "ShowStatusBar", action.is_checked());
m_config->sync();
@ -439,15 +439,15 @@ void TextEditorWidget::initialize_menubar(GUI::MenuBar& menubar)
m_layout_ruler_action->set_checked(show_ruler);
m_editor->set_ruler_visible(show_ruler);
auto& view_menu = menubar.add_menu("View");
auto& layout_menu = view_menu.add_submenu("Layout");
auto& view_menu = menubar.add_menu("&View");
auto& layout_menu = view_menu.add_submenu("&Layout");
layout_menu.add_action(*m_layout_toolbar_action);
layout_menu.add_action(*m_layout_statusbar_action);
layout_menu.add_action(*m_layout_ruler_action);
view_menu.add_separator();
view_menu.add_action(GUI::Action::create("Editor font...", Gfx::Bitmap::load_from_file("/res/icons/16x16/app-font-editor.png"),
view_menu.add_action(GUI::Action::create("Editor &Font...", Gfx::Bitmap::load_from_file("/res/icons/16x16/app-font-editor.png"),
[&](auto&) {
auto picker = GUI::FontPicker::construct(window(), &m_editor->font(), false);
if (picker->exec() == GUI::Dialog::ExecOK) {
@ -459,14 +459,14 @@ void TextEditorWidget::initialize_menubar(GUI::MenuBar& menubar)
view_menu.add_separator();
m_wrapping_mode_actions.set_exclusive(true);
auto& wrapping_mode_menu = view_menu.add_submenu("Wrapping mode");
m_no_wrapping_action = GUI::Action::create_checkable("No wrapping", [&](auto&) {
auto& wrapping_mode_menu = view_menu.add_submenu("&Wrapping Mode");
m_no_wrapping_action = GUI::Action::create_checkable("&No Wrapping", [&](auto&) {
m_editor->set_wrapping_mode(GUI::TextEditor::WrappingMode::NoWrap);
});
m_wrap_anywhere_action = GUI::Action::create_checkable("Wrap anywhere", [&](auto&) {
m_wrap_anywhere_action = GUI::Action::create_checkable("Wrap &Anywhere", [&](auto&) {
m_editor->set_wrapping_mode(GUI::TextEditor::WrappingMode::WrapAnywhere);
});
m_wrap_at_words_action = GUI::Action::create_checkable("Wrap at words", [&](auto&) {
m_wrap_at_words_action = GUI::Action::create_checkable("Wrap at &Words", [&](auto&) {
m_editor->set_wrapping_mode(GUI::TextEditor::WrappingMode::WrapAtWords);
});
@ -483,7 +483,7 @@ void TextEditorWidget::initialize_menubar(GUI::MenuBar& menubar)
view_menu.add_separator();
m_soft_tab_width_actions.set_exclusive(true);
auto& soft_tab_width_menu = view_menu.add_submenu("Tab width");
auto& soft_tab_width_menu = view_menu.add_submenu("&Tab Width");
m_soft_tab_1_width_action = GUI::Action::create_checkable("1", [&](auto&) {
m_editor->set_soft_tab_width(1);
});
@ -516,10 +516,10 @@ void TextEditorWidget::initialize_menubar(GUI::MenuBar& menubar)
view_menu.add_separator();
m_visualize_trailing_whitespace_action = GUI::Action::create_checkable("Visualize trailing whitespace", [&](auto&) {
m_visualize_trailing_whitespace_action = GUI::Action::create_checkable("Visualize &Trailing Whitespace", [&](auto&) {
m_editor->set_visualize_trailing_whitespace(m_visualize_trailing_whitespace_action->is_checked());
});
m_visualize_leading_whitespace_action = GUI::Action::create_checkable("Visualize leading whitespace", [&](auto&) {
m_visualize_leading_whitespace_action = GUI::Action::create_checkable("Visualize &Leading Whitespace", [&](auto&) {
m_editor->set_visualize_leading_whitespace(m_visualize_leading_whitespace_action->is_checked());
});
@ -537,8 +537,8 @@ void TextEditorWidget::initialize_menubar(GUI::MenuBar& menubar)
syntax_actions.set_exclusive(true);
auto& syntax_menu = view_menu.add_submenu("Syntax");
m_plain_text_highlight = GUI::Action::create_checkable("Plain text", [&](auto&) {
auto& syntax_menu = view_menu.add_submenu("&Syntax");
m_plain_text_highlight = GUI::Action::create_checkable("&Plain Text", [&](auto&) {
m_editor->set_syntax_highlighter({});
m_editor->update();
});
@ -546,42 +546,42 @@ void TextEditorWidget::initialize_menubar(GUI::MenuBar& menubar)
syntax_actions.add_action(*m_plain_text_highlight);
syntax_menu.add_action(*m_plain_text_highlight);
m_cpp_highlight = GUI::Action::create_checkable("C++", [&](auto&) {
m_cpp_highlight = GUI::Action::create_checkable("&C++", [&](auto&) {
m_editor->set_syntax_highlighter(make<Cpp::SyntaxHighlighter>());
m_editor->update();
});
syntax_actions.add_action(*m_cpp_highlight);
syntax_menu.add_action(*m_cpp_highlight);
m_js_highlight = GUI::Action::create_checkable("JavaScript", [&](auto&) {
m_js_highlight = GUI::Action::create_checkable("&JavaScript", [&](auto&) {
m_editor->set_syntax_highlighter(make<JS::SyntaxHighlighter>());
m_editor->update();
});
syntax_actions.add_action(*m_js_highlight);
syntax_menu.add_action(*m_js_highlight);
m_gml_highlight = GUI::Action::create_checkable("GML", [&](auto&) {
m_gml_highlight = GUI::Action::create_checkable("&GML", [&](auto&) {
m_editor->set_syntax_highlighter(make<GUI::GMLSyntaxHighlighter>());
m_editor->update();
});
syntax_actions.add_action(*m_gml_highlight);
syntax_menu.add_action(*m_gml_highlight);
m_ini_highlight = GUI::Action::create_checkable("INI File", [&](auto&) {
m_ini_highlight = GUI::Action::create_checkable("&INI File", [&](auto&) {
m_editor->set_syntax_highlighter(make<GUI::IniSyntaxHighlighter>());
m_editor->update();
});
syntax_actions.add_action(*m_ini_highlight);
syntax_menu.add_action(*m_ini_highlight);
m_shell_highlight = GUI::Action::create_checkable("Shell File", [&](auto&) {
m_shell_highlight = GUI::Action::create_checkable("&Shell File", [&](auto&) {
m_editor->set_syntax_highlighter(make<Shell::SyntaxHighlighter>());
m_editor->update();
});
syntax_actions.add_action(*m_shell_highlight);
syntax_menu.add_action(*m_shell_highlight);
auto& help_menu = menubar.add_menu("Help");
auto& help_menu = menubar.add_menu("&Help");
help_menu.add_action(GUI::CommonActions::make_help_action([](auto&) {
Desktop::Launcher::open(URL::create_with_file_protocol("/usr/share/man/man1/TextEditor.md"), "/bin/Help");
}));