Mercurial > octave
changeset 23237:904c8a356e76
provide the possibility for breaking lines only in comments (bug #41555)
* file-editor-tab.cc (notice_settings): get preference on breaking lines in
comments only;
(handle_char_added): check current style for comment and break lines if
desired, add comment string at the new line if comment is a line comment
* file-editor-tab.h: new class variable for line breaking in comments only
* settings-dialog.cc (settings_dialog): initialize new checkbox from settings;
(write_changed_settings): store state of the checkbox into settings file
* settings-dialog.ui: new checkbox for line breaking in comments only
author | Torsten <mttl@mailbox.org> |
---|---|
date | Sun, 26 Feb 2017 13:46:52 +0100 |
parents | 4cd5f975d26c |
children | 3de5efeffb86 |
files | libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/settings-dialog.cc libgui/src/settings-dialog.ui |
diffstat | 4 files changed, 70 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc Sat Feb 25 21:13:35 2017 +0100 +++ b/libgui/src/m-editor/file-editor-tab.cc Sun Feb 26 13:46:52 2017 +0100 @@ -2376,9 +2376,12 @@ else _line_break = 0; + _line_break_comments = + settings->value ("editor/break_lines_comments",false).toBool (); + // highlight all occurrences of a word selected by a double click - _highlight_all_occurrences = settings->value ( - "editor/highlight_all_occurrences", true).toBool (); + _highlight_all_occurrences = + settings->value ("editor/highlight_all_occurrences", true).toBool (); // reload changed files _always_reload_changed_files = @@ -2685,6 +2688,17 @@ if (col <= _line_break) return; + // If line breaking is only desired in comments, + // return if not in a comment + int style_comment = octave_qscintilla::ST_NONE; + if (_line_break_comments) + { + // line breaking only in comments, check for comment style + style_comment = _edit_area->is_style_comment (); + if (! style_comment) + return; // no comment, return + } + // Here we go for breaking the current line by inserting a newline. // For determining the position of a specific column, we have to get // the column from the QScintila function without taking tab lengths @@ -2712,8 +2726,8 @@ // Insert a newline char for breaking the line possibly followed // by a line comment string QString newline = QString ("\n"); - int style = _edit_area->is_style_comment (); - if (style == octave_qscintilla::ST_LINE_COMMENT) + style_comment = _edit_area->is_style_comment (); + if (style_comment == octave_qscintilla::ST_LINE_COMMENT) newline = newline + _edit_area->comment_string (); _edit_area->insertAt (newline, line, col_newline);
--- a/libgui/src/m-editor/file-editor-tab.h Sat Feb 25 21:13:35 2017 +0100 +++ b/libgui/src/m-editor/file-editor-tab.h Sun Feb 26 13:46:52 2017 +0100 @@ -301,6 +301,7 @@ static bool _cancelled; int _line_break; + bool _line_break_comments; int _line; int _col; bool _lines_changed;
--- a/libgui/src/settings-dialog.cc Sat Feb 25 21:13:35 2017 +0100 +++ b/libgui/src/settings-dialog.cc Sun Feb 26 13:46:52 2017 +0100 @@ -409,6 +409,8 @@ settings->value ("editor/long_line_column",80).toInt ()); ui->editor_break_checkbox->setChecked ( settings->value ("editor/break_lines",false).toBool ()); + ui->editor_break_checkbox->setChecked ( + settings->value ("editor/break_lines_comments",false).toBool ()); ui->editor_wrap_checkbox->setChecked ( settings->value ("editor/wrap_lines",false).toBool ()); ui->cb_edit_status_bar->setChecked ( @@ -804,6 +806,8 @@ ui->editor_long_line_column->value ()); settings->setValue ("editor/break_lines", ui->editor_break_checkbox->isChecked ()); + settings->setValue ("editor/break_lines_comments", + ui->editor_break_comments_checkbox->isChecked ()); settings->setValue ("editor/wrap_lines", ui->editor_wrap_checkbox->isChecked ()); settings->setValue ("editor/code_folding",
--- a/libgui/src/settings-dialog.ui Sat Feb 25 21:13:35 2017 +0100 +++ b/libgui/src/settings-dialog.ui Sun Feb 26 13:46:52 2017 +0100 @@ -498,9 +498,9 @@ <property name="geometry"> <rect> <x>0</x> - <y>-327</y> + <y>0</y> <width>642</width> - <height>927</height> + <height>956</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout_16"> @@ -969,21 +969,12 @@ </widget> </item> <item> - <widget class="QCheckBox" name="editor_wrap_checkbox"> + <widget class="QCheckBox" name="editor_break_comments_checkbox"> <property name="enabled"> - <bool>true</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="toolTip"> - <string>This works well for monospaced fonts. The line is drawn at a position based on the width of a space character in the default font. It may not work very well if styles use proportional fonts or if varied font sizes or bold, italic and normal texts are used.</string> + <bool>false</bool> </property> <property name="text"> - <string>Wrap lines at window border</string> + <string>Break lines only in comments</string> </property> <property name="checked"> <bool>false</bool> @@ -1097,6 +1088,32 @@ </item> </layout> </item> + <item> + <layout class="QHBoxLayout" name="horizontalLayout_19"> + <item> + <widget class="QCheckBox" name="editor_wrap_checkbox"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Minimum" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="toolTip"> + <string>This works well for monospaced fonts. The line is drawn at a position based on the width of a space character in the default font. It may not work very well if styles use proportional fonts or if varied font sizes or bold, italic and normal texts are used.</string> + </property> + <property name="text"> + <string>Wrap long lines at curent window border</string> + </property> + <property name="checked"> + <bool>false</bool> + </property> + </widget> + </item> + </layout> + </item> </layout> </widget> </item> @@ -3054,5 +3071,21 @@ </hint> </hints> </connection> + <connection> + <sender>editor_break_checkbox</sender> + <signal>toggled(bool)</signal> + <receiver>editor_break_comments_checkbox</receiver> + <slot>setEnabled(bool)</slot> + <hints> + <hint type="sourcelabel"> + <x>286</x> + <y>446</y> + </hint> + <hint type="destinationlabel"> + <x>483</x> + <y>446</y> + </hint> + </hints> + </connection> </connections> </ui>