Mercurial > hg > octave-nkf
changeset 18550:3a509de8e791 gui-release
automatic completion list as user preference (bug #41469)
* file-editor-tab.cc (constructor): remove unnecessary call for completion list;
(show_auto_completion): new slot showing autocompletion list at cursor;
(notice_settings): auto completion properties are set even if automatic
showing of the list is disabled, only treshold is updated
* file-editor-tab.h: new public slot show_completion list
* file-editor.cc (request_completion): new slot for completion-list-action
triggering a signal to the actual editor tab;
(construct): new action in edit menu for showing completion list, the signal
is connected to request_completion;
(add_file_editor_tab): connect signal for showing the completion list to
the new editor tab's slot show_auto_completion;
(set_shortcuts): set shortcut for new action;
(check_actions): disable new action when no tab is present
* file-editor.h: new action, new slot, new signal for tab
* settings-dialog.ui: update the settings dialog accordingly
author | Torsten <ttl@justmail.de> |
---|---|
date | Mon, 17 Feb 2014 20:42:08 +0100 |
parents | 00d684465379 |
children | 0f3bc7ccb875 |
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/settings-dialog.ui |
diffstat | 5 files changed, 197 insertions(+), 217 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc +++ b/libgui/src/m-editor/file-editor-tab.cc @@ -139,7 +139,6 @@ _edit_area->setUtf8 (true); // auto completion - _edit_area->autoCompleteFromAll (); _edit_area->setAutoCompletionSource (QsciScintilla::AcsAll); QVBoxLayout *edit_area_layout = new QVBoxLayout (); @@ -835,6 +834,32 @@ } void +file_editor_tab::show_auto_completion (const QWidget *ID) +{ + if (ID != this) + return; + + QsciScintilla::AutoCompletionSource s = _edit_area->autoCompletionSource (); + switch (s) + { + case QsciScintilla::AcsAll: + _edit_area->autoCompleteFromAll (); + break; + + case QsciScintilla::AcsAPIs: + _edit_area->autoCompleteFromAPIs (); + break; + + case QsciScintilla::AcsDocument: + _edit_area->autoCompleteFromDocument (); + break; + + case QsciScintilla::AcsNone: + break; + } +} + +void file_editor_tab::do_indent_selected_text (bool indent) { // TODO @@ -1361,30 +1386,29 @@ _edit_area->setCaretLineVisible (settings->value ("editor/highlightCurrentLine", true).toBool ()); - if (settings->value ("editor/codeCompletion", true).toBool ()) // auto compl. - { - bool match_keywords = settings->value + bool match_keywords = settings->value ("editor/codeCompletion_keywords",true).toBool (); - bool match_document = settings->value + bool match_document = settings->value ("editor/codeCompletion_document",true).toBool (); - QsciScintilla::AutoCompletionSource source = QsciScintilla::AcsNone; - if (match_keywords) - if (match_document) - source = QsciScintilla::AcsAll; - else - source = QsciScintilla::AcsAPIs; - else if (match_document) - source = QsciScintilla::AcsDocument; - _edit_area->setAutoCompletionSource (source); + QsciScintilla::AutoCompletionSource source = QsciScintilla::AcsNone; + if (match_keywords) + if (match_document) + source = QsciScintilla::AcsAll; + else + source = QsciScintilla::AcsAPIs; + else if (match_document) + source = QsciScintilla::AcsDocument; + _edit_area->setAutoCompletionSource (source); - _edit_area->setAutoCompletionReplaceWord - (settings->value ("editor/codeCompletion_replace",false).toBool ()); - _edit_area->setAutoCompletionCaseSensitivity - (settings->value ("editor/codeCompletion_case",true).toBool ()); - _edit_area->setAutoCompletionThreshold - (settings->value ("editor/codeCompletion_threshold",2).toInt ()); - } + _edit_area->setAutoCompletionReplaceWord + (settings->value ("editor/codeCompletion_replace",false).toBool ()); + _edit_area->setAutoCompletionCaseSensitivity + (settings->value ("editor/codeCompletion_case",true).toBool ()); + + if (settings->value ("editor/codeCompletion", true).toBool ()) + _edit_area->setAutoCompletionThreshold + (settings->value ("editor/codeCompletion_threshold",2).toInt ()); else _edit_area->setAutoCompletionThreshold (-1);
--- a/libgui/src/m-editor/file-editor-tab.h +++ b/libgui/src/m-editor/file-editor-tab.h @@ -99,6 +99,7 @@ void find (const QWidget *ID); void goto_line (const QWidget *ID, int line = -1); + void show_auto_completion (const QWidget *ID); void insert_debugger_pointer (const QWidget *ID, int line = -1); void delete_debugger_pointer (const QWidget *ID, int line = -1);
--- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -697,6 +697,12 @@ void +file_editor::request_completion (void) +{ + emit fetab_completion (_tab_widget->currentWidget ()); +} + +void file_editor::handle_mru_add_file (const QString& file_name) { _mru_files.removeAll (file_name); @@ -986,9 +992,10 @@ _goto_line_action = new QAction (tr ("Go &to Line..."), _tool_bar); + _completion_action = new QAction (tr ("&Show Completion List"), _tool_bar); + // the mru-list and an empty array of actions QSettings *settings = resource_manager::get_settings (); - // FIXME: what should happen if settings is 0? _mru_files = settings->value ("editor/mru_file_list").toStringList (); for (int i = 0; i < MaxMRUFiles; ++i) { @@ -1015,6 +1022,7 @@ _unindent_selection_action->setShortcutContext (Qt::WindowShortcut); _find_action->setShortcutContext (Qt::WindowShortcut); _goto_line_action->setShortcutContext (Qt::WindowShortcut); + _completion_action->setShortcutContext (Qt::WindowShortcut); // toolbar _tool_bar->addAction (new_action); @@ -1092,10 +1100,11 @@ editMenu->addSeparator (); editMenu->addAction (_comment_selection_action); editMenu->addAction (_uncomment_selection_action); - editMenu->addSeparator (); editMenu->addAction (_indent_selection_action); editMenu->addAction (_unindent_selection_action); editMenu->addSeparator (); + editMenu->addAction (_completion_action); + editMenu->addSeparator (); editMenu->addAction (_toggle_bookmark_action); editMenu->addAction (_next_bookmark_action); editMenu->addAction (_previous_bookmark_action); @@ -1237,6 +1246,9 @@ connect (_goto_line_action, SIGNAL (triggered ()), this, SLOT (request_goto_line ())); + connect (_completion_action, SIGNAL (triggered ()), + this, SLOT (request_completion ())); + connect (_mru_file_menu, SIGNAL (triggered (QAction *)), this, SLOT (request_mru_open_file (QAction *))); @@ -1396,6 +1408,9 @@ connect (this, SIGNAL (fetab_goto_line (const QWidget*, int)), f, SLOT (goto_line (const QWidget*, int))); + connect (this, SIGNAL (fetab_completion (const QWidget*)), + f, SLOT (show_auto_completion (const QWidget*))); + connect (this, SIGNAL (fetab_set_focus (const QWidget*)), f, SLOT (set_focus (const QWidget*))); @@ -1458,6 +1473,7 @@ _find_action->setShortcut (QKeySequence::Find); _goto_line_action->setShortcut (Qt::ControlModifier+ Qt::Key_G); + _completion_action->setShortcut (Qt::ControlModifier + Qt::Key_Space); _next_bookmark_action->setShortcut (Qt::Key_F2); _previous_bookmark_action->setShortcut (Qt::SHIFT + Qt::Key_F2); @@ -1492,6 +1508,7 @@ _find_action->setShortcut (no_key); _goto_line_action->setShortcut (no_key); + _completion_action->setShortcut (no_key); _next_bookmark_action->setShortcut (no_key); _previous_bookmark_action->setShortcut (no_key); @@ -1528,6 +1545,7 @@ _find_action->setEnabled (have_tabs); _goto_line_action->setEnabled (have_tabs); + _completion_action->setEnabled (have_tabs); _next_bookmark_action->setEnabled (have_tabs); _previous_bookmark_action->setEnabled (have_tabs);
--- a/libgui/src/m-editor/file-editor.h +++ b/libgui/src/m-editor/file-editor.h @@ -97,6 +97,7 @@ void fetab_unindent_selected_text (const QWidget* ID); void fetab_find (const QWidget* ID); void fetab_goto_line (const QWidget* ID, int line = -1); + void fetab_completion (const QWidget*); void fetab_insert_debugger_pointer (const QWidget* ID, int line = -1); void fetab_delete_debugger_pointer (const QWidget* ID, int line = -1); void fetab_do_breakpoint_marker (bool insert, const QWidget* ID, @@ -150,6 +151,7 @@ void request_find (void); void request_goto_line (void); + void request_completion (void); void handle_file_name_changed (const QString& fileName, const QString& toolTip); @@ -222,6 +224,7 @@ QAction *_find_action; QAction *_goto_line_action; + QAction *_completion_action; QAction *_next_bookmark_action; QAction *_previous_bookmark_action;
--- a/libgui/src/settings-dialog.ui +++ b/libgui/src/settings-dialog.ui @@ -32,7 +32,7 @@ </size> </property> <property name="currentIndex"> - <number>5</number> + <number>1</number> </property> <widget class="QWidget" name="tab_general"> <property name="enabled"> @@ -389,7 +389,7 @@ <x>0</x> <y>0</y> <width>662</width> - <height>399</height> + <height>419</height> </rect> </property> <layout class="QVBoxLayout" name="verticalLayout_16"> @@ -781,35 +781,131 @@ <property name="verticalSpacing"> <number>0</number> </property> - <item row="0" column="0"> - <widget class="QCheckBox" name="editor_codeCompletion"> - <property name="enabled"> - <bool>true</bool> - </property> - <property name="text"> - <string>Code completion</string> - </property> - <property name="checked"> - <bool>false</bool> - </property> - </widget> - </item> - <item row="0" column="2"> + <item row="1" column="1"> <layout class="QHBoxLayout" name="horizontalLayout_2"> <property name="spacing"> <number>6</number> </property> + <property name="bottomMargin"> + <number>4</number> + </property> <item> + <widget class="QLabel" name="label_16"> + <property name="text"> + <string>Auto completion</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="2" column="1"> + <layout class="QGridLayout" name="gridLayout_3"> + <property name="verticalSpacing"> + <number>0</number> + </property> + <item row="0" column="1"> + <spacer name="horizontalSpacer_15"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeType"> + <enum>QSizePolicy::Fixed</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>10</width> + <height>0</height> + </size> + </property> + </spacer> + </item> + <item row="0" column="0"> + <widget class="QCheckBox" name="editor_checkbox_ac_keywords"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>Match keywords</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QCheckBox" name="editor_checkbox_ac_case"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>Case sensitive</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="2"> + <widget class="QCheckBox" name="editor_checkbox_ac_replace"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>Replace word by suggested one</string> + </property> + </widget> + </item> + <item row="0" column="3"> + <spacer name="horizontalSpacer_8"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="0" column="2"> + <widget class="QCheckBox" name="editor_checkbox_ac_document"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>Match words in document</string> + </property> + </widget> + </item> + <item row="1" column="3"> + <spacer name="horizontalSpacer_19"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + </layout> + </item> + <item row="3" column="1"> + <layout class="QGridLayout" name="gridLayout_10"> + <item row="0" column="1"> <widget class="QLabel" name="editor_label_ac_threshold"> <property name="enabled"> <bool>false</bool> </property> <property name="text"> - <string># of characters typed before completion list displayed</string> + <string>after number of characters typed: </string> </property> </widget> </item> - <item> + <item row="0" column="2"> <widget class="QSpinBox" name="editor_spinbox_ac_threshold"> <property name="enabled"> <bool>false</bool> @@ -834,7 +930,20 @@ </property> </widget> </item> - <item> + <item row="0" column="0"> + <widget class="QCheckBox" name="editor_codeCompletion"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>Show completion list automatically ...</string> + </property> + <property name="checked"> + <bool>false</bool> + </property> + </widget> + </item> + <item row="0" column="3"> <spacer name="horizontalSpacer_2"> <property name="orientation"> <enum>Qt::Horizontal</enum> @@ -849,117 +958,6 @@ </item> </layout> </item> - <item row="1" column="2"> - <layout class="QGridLayout" name="gridLayout_3"> - <property name="verticalSpacing"> - <number>0</number> - </property> - <item row="0" column="1"> - <spacer name="horizontalSpacer_15"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Fixed</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>10</width> - <height>0</height> - </size> - </property> - </spacer> - </item> - <item row="0" column="0"> - <widget class="QCheckBox" name="editor_checkbox_ac_keywords"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Match keywords</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="1" column="0"> - <widget class="QCheckBox" name="editor_checkbox_ac_case"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Case sensitive</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="1" column="2"> - <widget class="QCheckBox" name="editor_checkbox_ac_replace"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Replace word by suggested one</string> - </property> - </widget> - </item> - <item row="0" column="3"> - <spacer name="horizontalSpacer_8"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - <item row="0" column="2"> - <widget class="QCheckBox" name="editor_checkbox_ac_document"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="text"> - <string>Match words in document</string> - </property> - </widget> - </item> - <item row="1" column="3"> - <spacer name="horizontalSpacer_19"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>40</width> - <height>20</height> - </size> - </property> - </spacer> - </item> - </layout> - </item> - <item row="0" column="1"> - <spacer name="horizontalSpacer_7"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="sizeType"> - <enum>QSizePolicy::Fixed</enum> - </property> - <property name="sizeHint" stdset="0"> - <size> - <width>10</width> - <height>0</height> - </size> - </property> - </spacer> - </item> </layout> </item> <item> @@ -2006,54 +2004,6 @@ </hints> </connection> <connection> - <sender>editor_codeCompletion</sender> - <signal>toggled(bool)</signal> - <receiver>editor_checkbox_ac_keywords</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>83</x> - <y>170</y> - </hint> - <hint type="destinationlabel"> - <x>238</x> - <y>201</y> - </hint> - </hints> - </connection> - <connection> - <sender>editor_codeCompletion</sender> - <signal>toggled(bool)</signal> - <receiver>editor_checkbox_ac_document</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>83</x> - <y>170</y> - </hint> - <hint type="destinationlabel"> - <x>390</x> - <y>201</y> - </hint> - </hints> - </connection> - <connection> - <sender>editor_codeCompletion</sender> - <signal>toggled(bool)</signal> - <receiver>editor_checkbox_ac_replace</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>83</x> - <y>170</y> - </hint> - <hint type="destinationlabel"> - <x>427</x> - <y>229</y> - </hint> - </hints> - </connection> - <connection> <sender>editor_highlightCurrentLine</sender> <signal>toggled(bool)</signal> <receiver>editor_label_cl_color</receiver> @@ -2070,22 +2020,6 @@ </hints> </connection> <connection> - <sender>editor_codeCompletion</sender> - <signal>toggled(bool)</signal> - <receiver>editor_checkbox_ac_case</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>83</x> - <y>172</y> - </hint> - <hint type="destinationlabel"> - <x>525</x> - <y>203</y> - </hint> - </hints> - </connection> - <connection> <sender>editor_ws_checkbox</sender> <signal>toggled(bool)</signal> <receiver>editor_ws_indent_checkbox</receiver>