# HG changeset patch # User Torsten # Date 1392666128 -3600 # Node ID 3a509de8e7911c19ce47250741841b489e5b6953 # Parent 00d684465379f622e4421300df430a078e1be35d 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 diff -r 00d684465379 -r 3a509de8e791 libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Sun Feb 16 18:42:30 2014 -0800 +++ b/libgui/src/m-editor/file-editor-tab.cc Mon Feb 17 20:42:08 2014 +0100 @@ -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); diff -r 00d684465379 -r 3a509de8e791 libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h Sun Feb 16 18:42:30 2014 -0800 +++ b/libgui/src/m-editor/file-editor-tab.h Mon Feb 17 20:42:08 2014 +0100 @@ -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); diff -r 00d684465379 -r 3a509de8e791 libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Sun Feb 16 18:42:30 2014 -0800 +++ b/libgui/src/m-editor/file-editor.cc Mon Feb 17 20:42:08 2014 +0100 @@ -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); diff -r 00d684465379 -r 3a509de8e791 libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h Sun Feb 16 18:42:30 2014 -0800 +++ b/libgui/src/m-editor/file-editor.h Mon Feb 17 20:42:08 2014 +0100 @@ -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; diff -r 00d684465379 -r 3a509de8e791 libgui/src/settings-dialog.ui --- a/libgui/src/settings-dialog.ui Sun Feb 16 18:42:30 2014 -0800 +++ b/libgui/src/settings-dialog.ui Mon Feb 17 20:42:08 2014 +0100 @@ -32,7 +32,7 @@ - 5 + 1 @@ -389,7 +389,7 @@ 0 0 662 - 399 + 419 @@ -781,35 +781,131 @@ 0 - - - - true - - - Code completion - - - false - - - - + 6 + + 4 + + + + Auto completion + + + + + + + + + 0 + + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 10 + 0 + + + + + + + + true + + + Match keywords + + + true + + + + + + + true + + + Case sensitive + + + true + + + + + + + true + + + Replace word by suggested one + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + true + + + Match words in document + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + false - # of characters typed before completion list displayed + after number of characters typed: - + false @@ -834,7 +930,20 @@ - + + + + true + + + Show completion list automatically ... + + + false + + + + Qt::Horizontal @@ -849,117 +958,6 @@ - - - - 0 - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 10 - 0 - - - - - - - - false - - - Match keywords - - - true - - - - - - - false - - - Case sensitive - - - true - - - - - - - false - - - Replace word by suggested one - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - false - - - Match words in document - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 10 - 0 - - - - @@ -2006,54 +2004,6 @@ - editor_codeCompletion - toggled(bool) - editor_checkbox_ac_keywords - setEnabled(bool) - - - 83 - 170 - - - 238 - 201 - - - - - editor_codeCompletion - toggled(bool) - editor_checkbox_ac_document - setEnabled(bool) - - - 83 - 170 - - - 390 - 201 - - - - - editor_codeCompletion - toggled(bool) - editor_checkbox_ac_replace - setEnabled(bool) - - - 83 - 170 - - - 427 - 229 - - - - editor_highlightCurrentLine toggled(bool) editor_label_cl_color @@ -2070,22 +2020,6 @@ - editor_codeCompletion - toggled(bool) - editor_checkbox_ac_case - setEnabled(bool) - - - 83 - 172 - - - 525 - 203 - - - - editor_ws_checkbox toggled(bool) editor_ws_indent_checkbox