Commit 092d8ca9 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer

Restored changes to the overview combo that accidentally got reverted

Accidentally reverted in commit 713105ad.
Thanks to Christian Hönig for notifying.
parent 4e1025fb
...@@ -75,6 +75,7 @@ ...@@ -75,6 +75,7 @@
#include <QtGui/QTextEdit> #include <QtGui/QTextEdit>
#include <QtGui/QComboBox> #include <QtGui/QComboBox>
#include <QtGui/QTreeView> #include <QtGui/QTreeView>
#include <QtGui/QSortFilterProxyModel>
using namespace CPlusPlus; using namespace CPlusPlus;
using namespace CppEditor::Internal; using namespace CppEditor::Internal;
...@@ -243,7 +244,22 @@ void CPPEditor::createToolBar(CPPEditorEditable *editable) ...@@ -243,7 +244,22 @@ void CPPEditor::createToolBar(CPPEditorEditable *editable)
m_methodCombo->setMaxVisibleItems(20); m_methodCombo->setMaxVisibleItems(20);
m_overviewModel = new OverviewModel(this); m_overviewModel = new OverviewModel(this);
m_methodCombo->setModel(m_overviewModel); 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(m_methodCombo, SIGNAL(activated(int)), this, SLOT(jumpToMethod(int)));
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(updateMethodBoxIndex())); connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(updateMethodBoxIndex()));
...@@ -366,7 +382,7 @@ void CPPEditor::updateFileName() ...@@ -366,7 +382,7 @@ void CPPEditor::updateFileName()
void CPPEditor::jumpToMethod(int) void CPPEditor::jumpToMethod(int)
{ {
QModelIndex index = m_methodCombo->view()->currentIndex(); QModelIndex index = m_proxyModel->mapToSource(m_methodCombo->view()->currentIndex());
Symbol *symbol = m_overviewModel->symbolFromIndex(index); Symbol *symbol = m_overviewModel->symbolFromIndex(index);
if (! symbol) if (! symbol)
return; return;
...@@ -374,6 +390,25 @@ void CPPEditor::jumpToMethod(int) ...@@ -374,6 +390,25 @@ void CPPEditor::jumpToMethod(int)
openCppEditorAt(linkToSymbol(symbol)); 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() void CPPEditor::updateMethodBoxIndex()
{ {
int line = 0, column = 0; int line = 0, column = 0;
...@@ -394,7 +429,7 @@ void CPPEditor::updateMethodBoxIndex() ...@@ -394,7 +429,7 @@ void CPPEditor::updateMethodBoxIndex()
if (lastIndex.isValid()) { if (lastIndex.isValid()) {
bool blocked = m_methodCombo->blockSignals(true); bool blocked = m_methodCombo->blockSignals(true);
m_methodCombo->setCurrentIndex(lastIndex.row()); m_methodCombo->setCurrentIndex(m_proxyModel->mapFromSource(lastIndex).row());
updateMethodBoxToolTip(); updateMethodBoxToolTip();
(void) m_methodCombo->blockSignals(blocked); (void) m_methodCombo->blockSignals(blocked);
} }
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
class QComboBox; class QComboBox;
class QSortFilterProxyModel;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace CPlusPlus { namespace CPlusPlus {
...@@ -86,6 +87,7 @@ public: ...@@ -86,6 +87,7 @@ public:
public slots: public slots:
virtual void setFontSettings(const TextEditor::FontSettings &); virtual void setFontSettings(const TextEditor::FontSettings &);
void setSortedMethodOverview(bool sort);
void switchDeclarationDefinition(); void switchDeclarationDefinition();
void jumpToDefinition(); void jumpToDefinition();
...@@ -94,7 +96,6 @@ public slots: ...@@ -94,7 +96,6 @@ public slots:
void deleteStartOfToken(); void deleteStartOfToken();
void deleteEndOfToken(); void deleteEndOfToken();
protected: protected:
void contextMenuEvent(QContextMenuEvent *); void contextMenuEvent(QContextMenuEvent *);
void mouseMoveEvent(QMouseEvent *); void mouseMoveEvent(QMouseEvent *);
...@@ -115,6 +116,7 @@ private slots: ...@@ -115,6 +116,7 @@ private slots:
void onDocumentUpdated(CPlusPlus::Document::Ptr doc); void onDocumentUpdated(CPlusPlus::Document::Ptr doc);
private: private:
bool sortedMethodOverview() const;
CPlusPlus::Symbol *findDefinition(CPlusPlus::Symbol *symbol); CPlusPlus::Symbol *findDefinition(CPlusPlus::Symbol *symbol);
virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar); virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar);
...@@ -161,6 +163,8 @@ private: ...@@ -161,6 +163,8 @@ private:
QList<int> m_contexts; QList<int> m_contexts;
QComboBox *m_methodCombo; QComboBox *m_methodCombo;
CPlusPlus::OverviewModel *m_overviewModel; CPlusPlus::OverviewModel *m_overviewModel;
QSortFilterProxyModel *m_proxyModel;
QAction *m_sortAction;
}; };
} // namespace Internal } // namespace Internal
......
...@@ -106,7 +106,8 @@ CppPlugin *CppPlugin::m_instance = 0; ...@@ -106,7 +106,8 @@ CppPlugin *CppPlugin::m_instance = 0;
CppPlugin::CppPlugin() : CppPlugin::CppPlugin() :
m_actionHandler(0), m_actionHandler(0),
m_factory(0) m_factory(0),
m_sortedMethodOverview(false)
{ {
m_instance = this; m_instance = this;
} }
...@@ -133,6 +134,20 @@ void CppPlugin::initializeEditor(CPPEditor *editor) ...@@ -133,6 +134,20 @@ void CppPlugin::initializeEditor(CPPEditor *editor)
// auto completion // auto completion
connect(editor, SIGNAL(requestAutoCompletion(ITextEditable*, bool)), connect(editor, SIGNAL(requestAutoCompletion(ITextEditable*, bool)),
TextEditor::Internal::CompletionSupport::instance(), SLOT(autoComplete(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) bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMessage)
...@@ -194,14 +209,30 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess ...@@ -194,14 +209,30 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
| TextEditor::TextEditorActionHandler::UnCommentSelection | TextEditor::TextEditorActionHandler::UnCommentSelection
| TextEditor::TextEditorActionHandler::UnCollapseAll); | TextEditor::TextEditorActionHandler::UnCollapseAll);
readSettings();
return true; 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() void CppPlugin::extensionsInitialized()
{ {
m_actionHandler->initializeActions(); m_actionHandler->initializeActions();
} }
void CppPlugin::shutdown()
{
writeSettings();
}
void CppPlugin::switchDeclarationDefinition() void CppPlugin::switchDeclarationDefinition()
{ {
Core::EditorManager *em = Core::EditorManager::instance(); Core::EditorManager *em = Core::EditorManager::instance();
......
...@@ -58,10 +58,19 @@ public: ...@@ -58,10 +58,19 @@ public:
bool initialize(const QStringList &arguments, QString *error_message = 0); bool initialize(const QStringList &arguments, QString *error_message = 0);
void extensionsInitialized(); void extensionsInitialized();
void shutdown();
// Connect editor to settings changed signals. // Connect editor to settings changed signals.
void initializeEditor(CPPEditor *editor); void initializeEditor(CPPEditor *editor);
bool sortedMethodOverview() const;
signals:
void methodOverviewSortingChanged(bool sort);
public slots:
void setSortedMethodOverview(bool sorted);
private slots: private slots:
void switchDeclarationDefinition(); void switchDeclarationDefinition();
void jumpToDefinition(); void jumpToDefinition();
...@@ -69,11 +78,14 @@ private slots: ...@@ -69,11 +78,14 @@ private slots:
private: private:
friend class CppEditorFactory; friend class CppEditorFactory;
Core::IEditor *createEditor(QWidget *parent); Core::IEditor *createEditor(QWidget *parent);
void writeSettings();
void readSettings();
static CppPlugin *m_instance; static CppPlugin *m_instance;
TextEditor::TextEditorActionHandler *m_actionHandler; TextEditor::TextEditorActionHandler *m_actionHandler;
CppEditorFactory *m_factory; CppEditorFactory *m_factory;
bool m_sortedMethodOverview;
}; };
class CppEditorFactory : public Core::IEditorFactory 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