Mercurial > octave-libtiff
changeset 24484:abb075ada761
Allow commenting with manually selected comment strings (bug #52695):
* file-editor-tab.cc (comment_selected_text, do_comment_selected_text):
new boolean parameter for comment string from settings or from input dialog
* file-editor-tab.h (comment_selected_text, do_comment_selected_text):
new boolean parameter for comment string from settings or from input dialog
* file-editor.cc (check_actions): enable new action depending on tabs;
(request_comment_selected_text): emit signal for commenting with string
from preferences;
(request_comment_var_selected_text): new slot emitting the signal for
commenting with manually selected string;
(set_shortcuts): set the shortcut for the new action;
(construct): add new action to the edit menu of the editor;
(add_file_editor_tab): signal for commenting and related slot in editor tab
now have an additional boolean parameter
* file-editor.h: new action with new slot, signal for commenting now have
an additional boolean parameter
* shortcut-manager.cc (do_init_data): initialize the shortcut for the new
action
author | Torsten <mttl@mailbox.org> |
---|---|
date | Thu, 28 Dec 2017 21:13:49 +0100 |
parents | dac2ad033c43 |
children | ad04b8055d91 |
files | libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/shortcut-manager.cc |
diffstat | 5 files changed, 38 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc Thu Dec 28 10:17:01 2017 -0500 +++ b/libgui/src/m-editor/file-editor-tab.cc Thu Dec 28 21:13:49 2017 +0100 @@ -1172,12 +1172,12 @@ } void -file_editor_tab::comment_selected_text (const QWidget *ID) +file_editor_tab::comment_selected_text (const QWidget *ID, bool input_str) { if (ID != this) return; - do_comment_selected_text (true); + do_comment_selected_text (true, input_str); } void @@ -1460,16 +1460,26 @@ } void -file_editor_tab::do_comment_selected_text (bool comment) +file_editor_tab::do_comment_selected_text (bool comment, bool input_str) { - QStringList comment_str = _edit_area->comment_string (comment); QRegExp rxc; QString ws = "^([ \\t]*)"; + QStringList comment_str = _edit_area->comment_string (comment); + QString used_comment_str = comment_str.at (0); if (comment) { - // Commenting (only one string possible) - rxc = QRegExp (ws + comment_str.at (0)); + if (input_str) + { + bool ok; + + used_comment_str = QInputDialog::getText ( + this, tr ("Comment selected text"), tr ("Comment string to use:\n"), + QLineEdit::Normal, comment_str.at (0), &ok); + + if ((! ok) || used_comment_str.isEmpty ()) + used_comment_str = comment_str.at (0); // No input, use preference + } } else { @@ -1526,7 +1536,7 @@ { if (comment) { - _edit_area->insertAt (comment_str.at (0), i, 0); + _edit_area->insertAt (used_comment_str, i, 0); } else { @@ -1573,7 +1583,7 @@ int cpline, col; _edit_area->getCursorPosition (&cpline, &col); if (comment) - _edit_area->insertAt (comment_str.at (0), cpline, 0); + _edit_area->insertAt (used_comment_str, cpline, 0); else { QString line (_edit_area->text (cpline));
--- a/libgui/src/m-editor/file-editor-tab.h Thu Dec 28 10:17:01 2017 -0500 +++ b/libgui/src/m-editor/file-editor-tab.h Thu Dec 28 21:13:49 2017 +0100 @@ -103,7 +103,7 @@ void scintilla_command (const QWidget *, unsigned int); - void comment_selected_text (const QWidget *ID); + void comment_selected_text (const QWidget *ID, bool input_str); void uncomment_selected_text (const QWidget *ID); void indent_selected_text (const QWidget *ID); @@ -249,7 +249,7 @@ void show_dialog (QDialog *dlg, bool modal); int check_file_modified (); - void do_comment_selected_text (bool comment); + void do_comment_selected_text (bool comment, bool input_str = false); void do_indent_selected_text (bool indent); void do_smart_indent_line_or_selected_text (void);
--- a/libgui/src/m-editor/file-editor.cc Thu Dec 28 10:17:01 2017 -0500 +++ b/libgui/src/m-editor/file-editor.cc Thu Dec 28 21:13:49 2017 +0100 @@ -261,6 +261,7 @@ m_comment_selection_action->setEnabled (have_tabs); m_uncomment_selection_action->setEnabled (have_tabs); + m_comment_var_selection_action->setEnabled (have_tabs); m_indent_selection_action->setEnabled (have_tabs); m_unindent_selection_action->setEnabled (have_tabs); m_smart_indent_line_or_selection_action->setEnabled (have_tabs); @@ -763,7 +764,7 @@ void file_editor::request_comment_selected_text (bool) { - emit fetab_comment_selected_text (m_tab_widget->currentWidget ()); + emit fetab_comment_selected_text (m_tab_widget->currentWidget (), false); } void @@ -772,6 +773,12 @@ emit fetab_uncomment_selected_text (m_tab_widget->currentWidget ()); } +void +file_editor::request_comment_var_selected_text (bool) +{ + emit fetab_comment_selected_text (m_tab_widget->currentWidget (), true); +} + // slots for Edit->Format actions void file_editor::request_upper_case (bool) @@ -1211,6 +1218,7 @@ shortcut_manager::set_shortcut (m_transpose_line_action, "editor_edit:transpose_line"); shortcut_manager::set_shortcut (m_comment_selection_action, "editor_edit:comment_selection"); shortcut_manager::set_shortcut (m_uncomment_selection_action, "editor_edit:uncomment_selection"); + shortcut_manager::set_shortcut (m_comment_var_selection_action, "editor_edit:comment_var_selection"); shortcut_manager::set_shortcut (m_upper_case_action, "editor_edit:upper_case"); shortcut_manager::set_shortcut (m_lower_case_action, "editor_edit:lower_case"); @@ -1848,6 +1856,8 @@ tr ("&Comment"), SLOT (request_comment_selected_text (bool))); m_uncomment_selection_action = add_action (m_edit_fmt_menu, QIcon (), tr ("&Uncomment"), SLOT (request_uncomment_selected_text (bool))); + m_comment_var_selection_action = add_action (m_edit_fmt_menu, QIcon (), + tr ("Comment (Choosing String)"), SLOT (request_comment_var_selected_text (bool))); m_edit_fmt_menu->addSeparator (); @@ -2219,8 +2229,8 @@ unsigned int)), f, SLOT (scintilla_command (const QWidget *, unsigned int))); - connect (this, SIGNAL (fetab_comment_selected_text (const QWidget*)), - f, SLOT (comment_selected_text (const QWidget*))); + connect (this, SIGNAL (fetab_comment_selected_text (const QWidget*, bool)), + f, SLOT (comment_selected_text (const QWidget*, bool))); connect (this, SIGNAL (fetab_uncomment_selected_text (const QWidget*)), f, SLOT (uncomment_selected_text (const QWidget*)));
--- a/libgui/src/m-editor/file-editor.h Thu Dec 28 10:17:01 2017 -0500 +++ b/libgui/src/m-editor/file-editor.h Thu Dec 28 21:13:49 2017 +0100 @@ -169,7 +169,7 @@ void fetab_next_breakpoint (const QWidget *ID); void fetab_previous_breakpoint (const QWidget *ID); void fetab_remove_all_breakpoints (const QWidget *ID); - void fetab_comment_selected_text (const QWidget *ID); + void fetab_comment_selected_text (const QWidget *ID, bool); void fetab_uncomment_selected_text (const QWidget *ID); void fetab_indent_selected_text (const QWidget *ID); void fetab_unindent_selected_text (const QWidget *ID); @@ -247,6 +247,7 @@ void request_comment_selected_text (bool); void request_uncomment_selected_text (bool); + void request_comment_var_selected_text (bool); void request_upper_case (bool); void request_lower_case (bool); @@ -376,6 +377,7 @@ QAction *m_upper_case_action; QAction *m_lower_case_action; QAction *m_comment_selection_action; + QAction *m_comment_var_selection_action; QAction *m_uncomment_selection_action; QAction *m_indent_selection_action; QAction *m_unindent_selection_action;
--- a/libgui/src/shortcut-manager.cc Thu Dec 28 10:17:01 2017 -0500 +++ b/libgui/src/shortcut-manager.cc Thu Dec 28 21:13:49 2017 +0100 @@ -366,6 +366,8 @@ QKeySequence (ctrl + Qt::Key_R)); init (tr ("Uncomment Selection"), "editor_edit:uncomment_selection", QKeySequence (ctrl_shift + Qt::Key_R)); + init (tr ("Comment Selection (Choosing String)"), "editor_edit:comment_var_selection", + QKeySequence (ctrl_alt + Qt::Key_R)); init (tr ("Uppercase Selection"), "editor_edit:upper_case", QKeySequence (ctrl + Qt::Key_U)); init (tr ("Lowercase Selection"), "editor_edit:lower_case",