changeset 19280:62756ba9e4e5 gui-release

add actions for showing text formatting chars and guides in the editor * file-editor.cc (toggle_preference): new function negating a settings entry; (show_line_numbers, show_white_space, show_eol_chars, show_indent_guides, show_ling_line): Slots of new actions calling toggel_prefernce in order to toggle the setting for showing the related chars or guides; (notice_settings): check or uncheck the actions depending on the settings; (construct): add new menu entries and actions into the view menu; (set_shortcuts): set the shortcuts for the new actions; (check_actions): only enable new menu entries when an editor tab exists * file-editor.h: new slots, new function, new actions, and new menu * shortcut_manager.cc (do_init_data): set the initial shortcuts for new actions
author Torsten <ttl@justmail.de>
date Sat, 11 Oct 2014 11:08:21 +0200
parents f3c4b48f3c53
children 9582fad68730
files libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/shortcut-manager.cc
diffstat 3 files changed, 95 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc	Sat Oct 11 11:05:53 2014 +0200
+++ b/libgui/src/m-editor/file-editor.cc	Sat Oct 11 11:08:21 2014 +0200
@@ -988,6 +988,41 @@
 }
 
 void
+file_editor::toggle_preference (const QString& preference, bool def)
+{
+  QSettings *settings = resource_manager::get_settings ();
+  bool old = settings->value (preference,def).toBool ();
+  settings->setValue (preference,!old);
+  notice_settings (settings);
+}
+
+void
+file_editor::show_line_numbers (bool)
+{
+  toggle_preference ("editor/showLineNumbers",true);
+}
+void
+file_editor::show_white_space (bool)
+{
+  toggle_preference ("editor/show_white_space",false);
+}
+void
+file_editor::show_eol_chars (bool)
+{
+  toggle_preference ("editor/show_eol_chars",false);
+}
+void
+file_editor::show_indent_guides (bool)
+{
+  toggle_preference ("editor/show_indent_guides",false);
+}
+void
+file_editor::show_long_line (bool)
+{
+  toggle_preference ("editor/long_line_marker",true);
+}
+
+void
 file_editor::zoom_in (bool)
 {
   emit fetab_zoom_in (_tab_widget->currentWidget ());
@@ -1065,6 +1100,18 @@
 
   _tab_widget->setUsesScrollButtons (true);
 
+  bool show_it;
+  show_it = settings->value ("editor/showLineNumbers",true).toBool ();
+  _show_linenum_action->setChecked (show_it);
+  show_it = settings->value ("editor/show_white_space",false).toBool ();
+  _show_whitespace_action->setChecked (show_it);
+  show_it = settings->value ("editor/show_eol_chars",false).toBool ();
+  _show_eol_action->setChecked (show_it);
+  show_it = settings->value ("editor/show_indent_guides",false).toBool ();
+  _show_indguide_action->setChecked (show_it);
+  show_it = settings->value ("editor/long_line_marker",true).toBool ();
+  _show_longline_action->setChecked (show_it);
+
   set_shortcuts ();
 
   // Relay signal to file editor tabs.
@@ -1316,6 +1363,30 @@
 
   QMenu *view_menu = m_add_menu (_menu_bar, tr ("&View"));
 
+  _view_editor_menu = view_menu->addMenu (tr ("&Editor"));
+
+  _show_linenum_action = add_action (_view_editor_menu, QIcon (),
+          tr ("Show &Line Numbers"), SLOT (show_line_numbers (bool)));
+  _show_linenum_action->setCheckable (true);
+
+  _show_whitespace_action = add_action (_view_editor_menu, QIcon (),
+          tr ("Show &White Spaces"), SLOT (show_white_space (bool)));
+  _show_whitespace_action->setCheckable (true);
+
+  _show_eol_action = add_action (_view_editor_menu, QIcon (),
+          tr ("Show Line &Endings"), SLOT (show_eol_chars (bool)));
+  _show_eol_action->setCheckable (true);
+
+  _show_indguide_action = add_action (_view_editor_menu, QIcon (),
+          tr ("Show &Indentation Guides"), SLOT (show_indent_guides (bool)));
+  _show_indguide_action->setCheckable (true);
+
+  _show_longline_action = add_action (_view_editor_menu, QIcon (),
+          tr ("Show Long Line &Marker"), SLOT (show_long_line (bool)));
+  _show_longline_action->setCheckable (true);
+
+  view_menu->addSeparator ();
+
   _zoom_in_action = add_action (view_menu, QIcon (),
           tr ("Zoom &In"), SLOT (zoom_in (bool)));
   _zoom_out_action = add_action (view_menu, QIcon (),
@@ -1670,6 +1741,11 @@
   shortcut_manager::set_shortcut (_styles_preferences_action, "editor_edit:styles_preferences");
 
   // View menu
+  shortcut_manager::set_shortcut (_show_linenum_action, "editor_view:show_line_numbers");
+  shortcut_manager::set_shortcut (_show_whitespace_action, "editor_view:show_white_spaces");
+  shortcut_manager::set_shortcut (_show_eol_action, "editor_view:show_eol_chars");
+  shortcut_manager::set_shortcut (_show_indguide_action, "editor_view:show_ind_guides");
+  shortcut_manager::set_shortcut (_show_longline_action, "editor_view:show_long_line");
   shortcut_manager::set_shortcut (_zoom_in_action, "editor_view:zoom_in");
   shortcut_manager::set_shortcut (_zoom_out_action, "editor_view:zoom_out");
   shortcut_manager::set_shortcut (_zoom_normal_action, "editor_view:zoom_normal");
@@ -1708,6 +1784,7 @@
   _context_help_action->setEnabled (have_tabs);
   _context_doc_action->setEnabled (have_tabs);
 
+  _view_editor_menu->setEnabled (have_tabs);
   _zoom_in_action->setEnabled (have_tabs);
   _zoom_out_action->setEnabled (have_tabs);
   _zoom_normal_action->setEnabled (have_tabs);
--- a/libgui/src/m-editor/file-editor.h	Sat Oct 11 11:05:53 2014 +0200
+++ b/libgui/src/m-editor/file-editor.h	Sat Oct 11 11:08:21 2014 +0200
@@ -214,6 +214,11 @@
   void request_styles_preferences (bool);
   void restore_create_file_setting ();
 
+  void show_line_numbers (bool);
+  void show_white_space (bool);
+  void show_eol_chars (bool);
+  void show_indent_guides (bool);
+  void show_long_line (bool);
   void zoom_in (bool);
   void zoom_out (bool);
   void zoom_normal (bool);
@@ -235,6 +240,8 @@
   void mru_menu_update (void);
   bool call_custom_editor (const QString& file_name = QString (), int line = -1);
 
+  void toggle_preference (const QString& preference, bool def);
+
   QWidget *find_tab_widget (const QString& openFileName) const;
   QAction *add_action (QMenu *menu, const QIcon &icon, const QString &text,
                        const char *member);
@@ -268,6 +275,11 @@
   QAction *_context_help_action;
   QAction *_context_doc_action;
 
+  QAction *_show_linenum_action;
+  QAction *_show_whitespace_action;
+  QAction *_show_eol_action;
+  QAction *_show_indguide_action;
+  QAction *_show_longline_action;
   QAction *_zoom_in_action;
   QAction *_zoom_out_action;
   QAction *_zoom_normal_action;
@@ -317,6 +329,7 @@
   QMenu *_edit_fmt_menu;
   QMenu *_edit_nav_menu;
   QMenu *_fileMenu;
+  QMenu *_view_editor_menu;
 
   QTabWidget *_tab_widget;
 
--- a/libgui/src/shortcut-manager.cc	Sat Oct 11 11:05:53 2014 +0200
+++ b/libgui/src/shortcut-manager.cc	Sat Oct 11 11:08:21 2014 +0200
@@ -262,6 +262,11 @@
         QKeySequence ());
 
   // view
+  init (tr ("Show Line Numbers"), "editor_view:show_line_numbers", QKeySequence ());
+  init (tr ("Show White Spaces"), "editor_view:show_white_spaces", QKeySequence ());
+  init (tr ("Show Line Endings"), "editor_view:show_eol_chars", QKeySequence ());
+  init (tr ("Show Indentation Guides"), "editor_view:show_ind_guides", QKeySequence ());
+  init (tr ("Show Long Line Marker"), "editor_view:show_long_line", QKeySequence ());
   init (tr ("Zoom In"), "editor_view:zoom_in", QKeySequence::ZoomIn);
   init (tr ("Zoom Out"), "editor_view:zoom_out", QKeySequence::ZoomOut);
 #if defined (Q_OS_MAC)