From 97a695403b0d9f0fc321ae6fb8ff8be0422b1394 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 25 Aug 2019 12:23:34 +0200 Subject: [PATCH] TextEditor: Add a menu action for turning line-wrapping on/off --- Applications/TextEditor/TextEditorWidget.cpp | 10 +++++++++- Applications/TextEditor/TextEditorWidget.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Applications/TextEditor/TextEditorWidget.cpp b/Applications/TextEditor/TextEditorWidget.cpp index e3ee83daf0..4d27d34e85 100644 --- a/Applications/TextEditor/TextEditorWidget.cpp +++ b/Applications/TextEditor/TextEditorWidget.cpp @@ -65,7 +65,7 @@ TextEditorWidget::TextEditorWidget() selection_start = m_editor->normalized_selection().end(); auto found_range = m_editor->find_prev(needle, selection_start); - + dbg() << "find_prev(\"" << needle << "\") returned " << found_range; if (found_range.is_valid()) { m_editor->set_selection(found_range); @@ -137,8 +137,16 @@ TextEditorWidget::TextEditorWidget() m_save_as_action->activate(); }); + m_line_wrapping_setting_action = GAction::create("Line wrapping", [&](GAction& action) { + action.set_checked(!action.is_checked()); + m_editor->set_line_wrapping_enabled(action.is_checked()); + }); + m_line_wrapping_setting_action->set_checkable(true); + m_line_wrapping_setting_action->set_checked(m_editor->is_line_wrapping_enabled()); + auto menubar = make(); auto app_menu = make("Text Editor"); + app_menu->add_action(*m_line_wrapping_setting_action); app_menu->add_action(GAction::create("Quit", { Mod_Alt, Key_F4 }, [](const GAction&) { GApplication::the().quit(0); return; diff --git a/Applications/TextEditor/TextEditorWidget.h b/Applications/TextEditor/TextEditorWidget.h index 714b054619..45b1bb7506 100644 --- a/Applications/TextEditor/TextEditorWidget.h +++ b/Applications/TextEditor/TextEditorWidget.h @@ -29,6 +29,7 @@ private: RefPtr m_save_action; RefPtr m_save_as_action; RefPtr m_find_action; + RefPtr m_line_wrapping_setting_action; GTextBox* m_find_textbox { nullptr }; GButton* m_find_prev_button { nullptr };