Mercurial > hg > octave-nkf
diff libgui/src/m-editor/file-editor.cc @ 19438: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 | 63c5f95afeb3 |
children | 9582fad68730 |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -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);