diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index d6c253095137a4438541f54168d1ddb4c8e5347b..cc28c720e91478e3b0ce644e3620970717400e4d 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -240,18 +240,27 @@ void CPPEditor::createToolBar(CPPEditorEditable *editable) QTreeView *methodView = new OverviewTreeView; methodView->header()->hide(); methodView->setItemsExpandable(false); - methodView->setSortingEnabled(true); - methodView->sortByColumn(0, Qt::AscendingOrder); m_methodCombo->setView(methodView); m_methodCombo->setMaxVisibleItems(20); m_overviewModel = new OverviewModel(this); m_proxyModel = new QSortFilterProxyModel(this); m_proxyModel->setSourceModel(m_overviewModel); + if (CppPlugin::instance()->sortedMethodOverview()) + m_proxyModel->sort(0, Qt::AscendingOrder); + else + m_proxyModel->sort(-1, Qt::AscendingOrder); // don't sort yet, but set column for sortedMethodOverview() m_proxyModel->setDynamicSortFilter(true); m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); m_methodCombo->setModel(m_proxyModel); + m_methodCombo->setContextMenuPolicy(Qt::ActionsContextMenu); + m_sortAction = new QAction(tr("Sort alphabetically"), m_methodCombo); + m_sortAction->setCheckable(true); + m_sortAction->setChecked(sortedMethodOverview()); + connect(m_sortAction, SIGNAL(toggled(bool)), CppPlugin::instance(), SLOT(setSortedMethodOverview(bool))); + m_methodCombo->addAction(m_sortAction); + connect(m_methodCombo, SIGNAL(activated(int)), this, SLOT(jumpToMethod(int))); connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(updateMethodBoxIndex())); connect(m_methodCombo, SIGNAL(currentIndexChanged(int)), this, SLOT(updateMethodBoxToolTip())); @@ -381,6 +390,25 @@ void CPPEditor::jumpToMethod(int) openCppEditorAt(linkToSymbol(symbol)); } +void CPPEditor::setSortedMethodOverview(bool sort) +{ + if (sort != sortedMethodOverview()) { + if (sort) + m_proxyModel->sort(0, Qt::AscendingOrder); + else + m_proxyModel->sort(-1, Qt::AscendingOrder); + bool block = m_sortAction->blockSignals(true); + m_sortAction->setChecked(m_proxyModel->sortColumn() == 0); + m_sortAction->blockSignals(block); + updateMethodBoxIndex(); + } +} + +bool CPPEditor::sortedMethodOverview() const +{ + return (m_proxyModel->sortColumn() == 0); +} + void CPPEditor::updateMethodBoxIndex() { int line = 0, column = 0; diff --git a/src/plugins/cppeditor/cppeditor.h b/src/plugins/cppeditor/cppeditor.h index 7ef5e720a44fb785bdae54a8d7227aa20d349457..efae361e0e62b79070839d2c59e34f42a7516c51 100644 --- a/src/plugins/cppeditor/cppeditor.h +++ b/src/plugins/cppeditor/cppeditor.h @@ -87,6 +87,7 @@ public: public slots: virtual void setFontSettings(const TextEditor::FontSettings &); + void setSortedMethodOverview(bool sort); void switchDeclarationDefinition(); void jumpToDefinition(); @@ -95,7 +96,6 @@ public slots: void deleteStartOfToken(); void deleteEndOfToken(); - protected: void contextMenuEvent(QContextMenuEvent *); void mouseMoveEvent(QMouseEvent *); @@ -116,6 +116,7 @@ private slots: void onDocumentUpdated(CPlusPlus::Document::Ptr doc); private: + bool sortedMethodOverview() const; CPlusPlus::Symbol *findDefinition(CPlusPlus::Symbol *symbol); virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar); @@ -163,6 +164,7 @@ private: QComboBox *m_methodCombo; CPlusPlus::OverviewModel *m_overviewModel; QSortFilterProxyModel *m_proxyModel; + QAction *m_sortAction; }; } // namespace Internal diff --git a/src/plugins/cppeditor/cppplugin.cpp b/src/plugins/cppeditor/cppplugin.cpp index 29ad67314517bb22d5a10d5fdd09d2b2c6c03a7f..9e17083c2190fba27b2e796a25074c5a35f48034 100644 --- a/src/plugins/cppeditor/cppplugin.cpp +++ b/src/plugins/cppeditor/cppplugin.cpp @@ -106,7 +106,8 @@ CppPlugin *CppPlugin::m_instance = 0; CppPlugin::CppPlugin() : m_actionHandler(0), - m_factory(0) + m_factory(0), + m_sortedMethodOverview(false) { m_instance = this; } @@ -133,6 +134,20 @@ void CppPlugin::initializeEditor(CPPEditor *editor) // auto completion connect(editor, SIGNAL(requestAutoCompletion(ITextEditable*, bool)), TextEditor::Internal::CompletionSupport::instance(), SLOT(autoComplete(ITextEditable*, bool))); + // method combo box sorting + connect(this, SIGNAL(methodOverviewSortingChanged(bool)), + editor, SLOT(setSortedMethodOverview(bool))); +} + +void CppPlugin::setSortedMethodOverview(bool sorted) +{ + m_sortedMethodOverview = sorted; + emit methodOverviewSortingChanged(sorted); +} + +bool CppPlugin::sortedMethodOverview() const +{ + return m_sortedMethodOverview; } bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage) @@ -194,14 +209,30 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess | TextEditor::TextEditorActionHandler::UnCommentSelection | TextEditor::TextEditorActionHandler::UnCollapseAll); + readSettings(); return true; } +void CppPlugin::readSettings() +{ + m_sortedMethodOverview = Core::ICore::instance()->settings()->value("CppTools/SortedMethodOverview", false).toBool(); +} + +void CppPlugin::writeSettings() +{ + Core::ICore::instance()->settings()->setValue("CppTools/SortedMethodOverview", m_sortedMethodOverview); +} + void CppPlugin::extensionsInitialized() { m_actionHandler->initializeActions(); } +void CppPlugin::shutdown() +{ + writeSettings(); +} + void CppPlugin::switchDeclarationDefinition() { Core::EditorManager *em = Core::EditorManager::instance(); diff --git a/src/plugins/cppeditor/cppplugin.h b/src/plugins/cppeditor/cppplugin.h index 151eda3888532ce4d181b550a53f8d4dce94f2ba..4ad8400342b713de24c5ddebf7f7bf9d58217eb3 100644 --- a/src/plugins/cppeditor/cppplugin.h +++ b/src/plugins/cppeditor/cppplugin.h @@ -58,10 +58,19 @@ public: bool initialize(const QStringList &arguments, QString *error_message = 0); void extensionsInitialized(); + void shutdown(); // Connect editor to settings changed signals. void initializeEditor(CPPEditor *editor); + bool sortedMethodOverview() const; + +signals: + void methodOverviewSortingChanged(bool sort); + +public slots: + void setSortedMethodOverview(bool sorted); + private slots: void switchDeclarationDefinition(); void jumpToDefinition(); @@ -69,11 +78,14 @@ private slots: private: friend class CppEditorFactory; Core::IEditor *createEditor(QWidget *parent); + void writeSettings(); + void readSettings(); static CppPlugin *m_instance; TextEditor::TextEditorActionHandler *m_actionHandler; CppEditorFactory *m_factory; + bool m_sortedMethodOverview; }; class CppEditorFactory : public Core::IEditorFactory