diff options
author | Zac <zacary.gillerat@connect.qut.edu.au> | 2021-01-27 15:49:29 +1000 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-02 16:08:20 +0100 |
commit | bd6d0d229581e830c7a69cdb29252b9f63e0434a (patch) | |
tree | 84a2d3e93e80de3de0dda826632301664e3d9995 /Userland/Applications/TextEditor | |
parent | e11ec20650e5182f47675210dcd71e7301c34905 (diff) | |
download | serenity-bd6d0d229581e830c7a69cdb29252b9f63e0434a.zip |
TextEditor: Add vim status indicators to the statusbar
When using the VimEditingEngine in the TextEditor, vim's mode and the
previous key are shown in the editor's statusbar.
Diffstat (limited to 'Userland/Applications/TextEditor')
-rw-r--r-- | Userland/Applications/TextEditor/TextEditorWidget.cpp | 20 | ||||
-rw-r--r-- | Userland/Applications/TextEditor/TextEditorWidget.h | 3 | ||||
-rw-r--r-- | Userland/Applications/TextEditor/TextEditorWindow.gml | 1 |
3 files changed, 23 insertions, 1 deletions
diff --git a/Userland/Applications/TextEditor/TextEditorWidget.cpp b/Userland/Applications/TextEditor/TextEditorWidget.cpp index 9d31b106f8..1bd7ac19aa 100644 --- a/Userland/Applications/TextEditor/TextEditorWidget.cpp +++ b/Userland/Applications/TextEditor/TextEditorWidget.cpp @@ -39,11 +39,13 @@ #include <LibGUI/BoxLayout.h> #include <LibGUI/Button.h> #include <LibGUI/CppSyntaxHighlighter.h> +#include <LibGUI/EditingEngine.h> #include <LibGUI/FilePicker.h> #include <LibGUI/FontPicker.h> #include <LibGUI/GMLSyntaxHighlighter.h> #include <LibGUI/INISyntaxHighlighter.h> #include <LibGUI/JSSyntaxHighlighter.h> +#include <LibGUI/Label.h> #include <LibGUI/Menu.h> #include <LibGUI/MenuBar.h> #include <LibGUI/MessageBox.h> @@ -57,6 +59,7 @@ #include <LibGUI/ToolBarContainer.h> #include <LibGUI/VimEditingEngine.h> #include <LibGfx/Font.h> +#include <LibGfx/FontDatabase.h> #include <LibMarkdown/Document.h> #include <LibWeb/OutOfProcessWebView.h> #include <string.h> @@ -301,6 +304,21 @@ TextEditorWidget::TextEditorWidget() m_statusbar = *find_descendant_of_type_named<GUI::StatusBar>("statusbar"); + m_statusbar->label(m_vim_mode_statusbar_index)->set_visible(m_editor->editing_engine()->type() == GUI::EditingEngineType::Vim); + m_statusbar->label(m_vim_mode_statusbar_index)->set_font(Gfx::FontDatabase::default_bold_font()); + + m_statusbar->label(m_vim_previous_keys_statusbar_index)->set_visible(m_editor->editing_engine()->type() == GUI::EditingEngineType::Vim); + + m_editor->on_vim_statusbar_messages_changed = [this] { + m_statusbar->set_text(m_vim_mode_statusbar_index, m_editor->vim_mode_statusbar_message()); + m_statusbar->set_text(m_vim_previous_keys_statusbar_index, m_editor->vim_previous_keys_statusbar_message()); + }; + + m_editor->on_editing_engine_changed = [this]() { + m_statusbar->label(m_vim_mode_statusbar_index)->set_visible(m_editor->editing_engine()->type() == GUI::EditingEngineType::Vim); + m_statusbar->label(m_vim_previous_keys_statusbar_index)->set_visible(m_editor->editing_engine()->type() == GUI::EditingEngineType::Vim); + }; + m_editor->on_cursor_change = [this] { update_statusbar_cursor_position(); }; 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&) { @@ -666,5 +684,5 @@ void TextEditorWidget::update_statusbar_cursor_position() { StringBuilder builder; builder.appendff("Line: {}, Column: {}", m_editor->cursor().line() + 1, m_editor->cursor().column()); - m_statusbar->set_text(builder.to_string()); + m_statusbar->set_text(m_cursor_position_statusbar_index, builder.to_string()); } diff --git a/Userland/Applications/TextEditor/TextEditorWidget.h b/Userland/Applications/TextEditor/TextEditorWidget.h index 763087b9e4..28c4a9c3fd 100644 --- a/Userland/Applications/TextEditor/TextEditorWidget.h +++ b/Userland/Applications/TextEditor/TextEditorWidget.h @@ -91,6 +91,9 @@ private: RefPtr<GUI::Action> m_html_preview_action; RefPtr<GUI::StatusBar> m_statusbar; + const int m_cursor_position_statusbar_index = 0; + const int m_vim_mode_statusbar_index = 1; + const int m_vim_previous_keys_statusbar_index = 2; RefPtr<GUI::TextBox> m_find_textbox; RefPtr<GUI::TextBox> m_replace_textbox; diff --git a/Userland/Applications/TextEditor/TextEditorWindow.gml b/Userland/Applications/TextEditor/TextEditorWindow.gml index 433d01abff..b13865f697 100644 --- a/Userland/Applications/TextEditor/TextEditorWindow.gml +++ b/Userland/Applications/TextEditor/TextEditorWindow.gml @@ -84,5 +84,6 @@ @GUI::StatusBar { name: "statusbar" + label_count: 3 } } |