Commit 9e9523b8 authored by con's avatar con

Make sorting of method overview optional.

You can switch between sorted/unsorted via the method overview's context
menu.
parent ff2afcab
......@@ -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;
......
......@@ -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
......
......@@ -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();
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment