Commit 7ae82b9f authored by Konstantin Tokarev's avatar Konstantin Tokarev Committed by hjk

Added TextEditor commands FollowSymbol and JumpToFile.

Most of editors have "jump to file" or "follow symbol" actions. This
patch reduces amount of related boilerplate code.

New actions are made optional to prevent shortcut clash (both use F2).

Change-Id: I2af580ed9d6789df25f4487ba001f3b83887c504
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent aa722e6a
......@@ -180,11 +180,6 @@ void CMakeEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
highlighter->rehighlight();
}
void CMakeEditorWidget::jumpToFile()
{
openLink(findLinkAt(textCursor()));
}
static bool isValidFileNameChar(const QChar &c)
{
if (c.isLetterOrNumber()
......
......@@ -83,8 +83,6 @@ public:
CMakeEditorFactory *factory() { return m_factory; }
TextEditor::TextEditorActionHandler *actionHandler() const { return m_ah; }
void jumpToFile();
Link findLinkAt(const QTextCursor &cursor,
bool resolveTarget = true);
......
......@@ -54,7 +54,8 @@ CMakeEditorFactory::CMakeEditorFactory(CMakeManager *manager)
m_actionHandler =
new TextEditorActionHandler(Constants::C_CMAKEEDITOR,
TextEditorActionHandler::UnCommentSelection);
TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::JumpToFileUnderCursor);
ICore *core = ICore::instance();
ActionManager *am = core->actionManager();
......@@ -62,11 +63,7 @@ CMakeEditorFactory::CMakeEditorFactory(CMakeManager *manager)
Command *cmd;
Context cmakeEditorContext = Context(Constants::C_CMAKEEDITOR);
QAction *jumpToFile = new QAction(tr("Jump to File Under Cursor"), this);
cmd = am->registerAction(jumpToFile,
Constants::JUMP_TO_FILE, cmakeEditorContext);
cmd->setDefaultKeySequence(QKeySequence(Qt::Key_F2));
connect(jumpToFile, SIGNAL(triggered()), this, SLOT(jumpToFile()));
cmd = am->command(TextEditor::Constants::JUMP_TO_FILE_UNDER_CURSOR);
contextMenu->addAction(cmd);
QAction *separator = new QAction(this);
......@@ -101,14 +98,6 @@ Core::IEditor *CMakeEditorFactory::createEditor(QWidget *parent)
return rc->editor();
}
void CMakeEditorFactory::jumpToFile()
{
Core::EditorManager *em = Core::EditorManager::instance();
CMakeEditorWidget *editor = qobject_cast<CMakeEditorWidget*>(em->currentEditor()->widget());
if (editor)
editor->jumpToFile();
}
QStringList CMakeEditorFactory::mimeTypes() const
{
return m_mimeTypes;
......
......@@ -60,9 +60,6 @@ public:
Core::IDocument *open(const QString &fileName);
Core::IEditor *createEditor(QWidget *parent);
public slots:
void jumpToFile();
private:
const QStringList m_mimeTypes;
CMakeManager *m_manager;
......
......@@ -52,7 +52,6 @@ const char M_CONTEXT[] = "CMakeEditor.ContextMenu";
// Actions
const char SEPARATOR[] = "CMakeEditor.Separator";
const char JUMP_TO_FILE[] = "CMakeEditor.JumpToFile";
} // namespace Constants
} // namespace CMakeProjectManager
......
......@@ -1485,11 +1485,6 @@ CPPEditorWidget::Link CPPEditorWidget::findLinkAt(const QTextCursor &cursor,
return Link();
}
void CPPEditorWidget::jumpToDefinition()
{
openLink(findLinkAt(textCursor()));
}
Symbol *CPPEditorWidget::findDefinition(Symbol *symbol, const Snapshot &snapshot) const
{
if (symbol->isFunction())
......
......@@ -208,7 +208,6 @@ public Q_SLOTS:
virtual void setTabSettings(const TextEditor::TabSettings &);
void setSortedOutline(bool sort);
void switchDeclarationDefinition();
void jumpToDefinition();
void renameSymbolUnderCursor();
void renameUsages();
void findUsages();
......
......@@ -48,7 +48,6 @@ const char SEPARATOR[] = "CppEditor.Separator";
const char SEPARATOR2[] = "CppEditor.Separator2";
const char SEPARATOR3[] = "CppEditor.Separator3";
const char SEPARATOR4[] = "CppEditor.Separator4";
const char JUMP_TO_DEFINITION[] = "CppEditor.JumpToDefinition";
const char UPDATE_CODEMODEL[] = "CppEditor.UpdateCodeModel";
const int TYPE_HIERARCHY_PRIORITY = 700;
......
......@@ -242,12 +242,7 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
cmd = am->command(Core::Id(CppTools::Constants::SWITCH_HEADER_SOURCE));
contextMenu->addAction(cmd);
QAction *jumpToDefinition = new QAction(tr("Follow Symbol Under Cursor"), this);
cmd = am->registerAction(jumpToDefinition,
Constants::JUMP_TO_DEFINITION, context, true);
cmd->setDefaultKeySequence(QKeySequence(Qt::Key_F2));
connect(jumpToDefinition, SIGNAL(triggered()),
this, SLOT(jumpToDefinition()));
cmd = am->command(TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR);
contextMenu->addAction(cmd);
cppToolsMenu->addAction(cmd);
......@@ -304,7 +299,8 @@ bool CppPlugin::initialize(const QStringList & /*arguments*/, QString *errorMess
m_actionHandler = new TextEditor::TextEditorActionHandler(CppEditor::Constants::C_CPPEDITOR,
TextEditor::TextEditorActionHandler::Format
| TextEditor::TextEditorActionHandler::UnCommentSelection
| TextEditor::TextEditorActionHandler::UnCollapseAll);
| TextEditor::TextEditorActionHandler::UnCollapseAll
| TextEditor::TextEditorActionHandler::FollowSymbolUnderCursor);
m_actionHandler->initializeActions();
......@@ -355,14 +351,6 @@ void CppPlugin::switchDeclarationDefinition()
editor->switchDeclarationDefinition();
}
void CppPlugin::jumpToDefinition()
{
Core::EditorManager *em = Core::EditorManager::instance();
CPPEditorWidget *editor = qobject_cast<CPPEditorWidget*>(em->currentEditor()->widget());
if (editor)
editor->jumpToDefinition();
}
void CppPlugin::renameSymbolUnderCursor()
{
Core::EditorManager *em = Core::EditorManager::instance();
......
......@@ -83,7 +83,6 @@ public slots:
private slots:
void switchDeclarationDefinition();
void jumpToDefinition();
void renameSymbolUnderCursor();
void onTaskStarted(const QString &type);
void onAllTasksFinished(const QString &type);
......
......@@ -78,8 +78,6 @@
#include <utils/treewidgetcolumnstretcher.h>
#include <utils/stylehelper.h>
#include <cppeditor/cppeditorconstants.h>
#include <cpptools/cpptoolsconstants.h>
#include <QAbstractTableModel>
......@@ -895,7 +893,7 @@ FakeVimPluginPrivate::FakeVimPluginPrivate(FakeVimPlugin *plugin)
QRegExp("^(cN(ext)?|cp(revious)?)!?( (.*))?$");
defaultExCommandMap()["Coreplugin.OutputPane.nextitem"] =
QRegExp("^cn(ext)?!?( (.*))?$");
defaultExCommandMap()[CppEditor::Constants::JUMP_TO_DEFINITION] =
defaultExCommandMap()[TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR] =
QRegExp("^tag?$");
defaultExCommandMap()[Core::Constants::GO_BACK] =
QRegExp("^pop?$");
......
......@@ -1387,11 +1387,6 @@ TextEditor::BaseTextEditorWidget::Link QmlJSTextEditorWidget::findLinkAt(const Q
return Link();
}
void QmlJSTextEditorWidget::followSymbolUnderCursor()
{
openLink(findLinkAt(textCursor()));
}
void QmlJSTextEditorWidget::findUsages()
{
m_findReferences->findUsages(editorDocument()->fileName(), textCursor().position());
......
......@@ -176,7 +176,6 @@ public slots:
void reparseDocumentNow();
void updateSemanticInfo();
void updateSemanticInfoNow();
void followSymbolUnderCursor();
void findUsages();
void renameUsages();
void showContextPane();
......
......@@ -51,7 +51,6 @@ const char TASK_SEARCH[] = "QmlJSEditor.TaskSearch";
const char SETTINGS_CATEGORY_QML[] = "J.QtQuick";
const char SETTINGS_TR_CATEGORY_QML[] = QT_TRANSLATE_NOOP("QmlJSEditor", "Qt Quick");
const char FOLLOW_SYMBOL_UNDER_CURSOR[] = "QmlJSEditor.FollowSymbolUnderCursor";
const char FIND_USAGES[] = "QmlJSEditor.FindUsages";
const char RENAME_USAGES[] = "QmlJSEditor.RenameUsages";
const char RUN_SEMANTIC_SCAN[] = "QmlJSEditor.RunSemanticScan";
......
......@@ -174,7 +174,8 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
m_actionHandler = new TextEditor::TextEditorActionHandler(QmlJSEditor::Constants::C_QMLJSEDITOR_ID,
TextEditor::TextEditorActionHandler::Format
| TextEditor::TextEditorActionHandler::UnCommentSelection
| TextEditor::TextEditorActionHandler::UnCollapseAll);
| TextEditor::TextEditorActionHandler::UnCollapseAll
| TextEditor::TextEditorActionHandler::FollowSymbolUnderCursor);
m_actionHandler->initializeActions();
Core::ActionManager *am = Core::ICore::actionManager();
......@@ -185,10 +186,7 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
qmlToolsMenu->addAction(createSeparator(am, this, globalContext, QmlJSEditor::Constants::SEPARATOR3));
Core::Command *cmd;
QAction *followSymbolUnderCursorAction = new QAction(tr("Follow Symbol Under Cursor"), this);
cmd = am->registerAction(followSymbolUnderCursorAction, Constants::FOLLOW_SYMBOL_UNDER_CURSOR, context);
cmd->setDefaultKeySequence(QKeySequence(Qt::Key_F2));
connect(followSymbolUnderCursorAction, SIGNAL(triggered()), this, SLOT(followSymbolUnderCursor()));
cmd = am->command(TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR);
contextMenu->addAction(cmd);
qmlToolsMenu->addAction(cmd);
......@@ -294,14 +292,6 @@ Utils::JsonSchemaManager *QmlJSEditorPlugin::jsonManager() const
return m_jsonManager.data();
}
void QmlJSEditorPlugin::followSymbolUnderCursor()
{
Core::EditorManager *em = Core::EditorManager::instance();
if (QmlJSTextEditorWidget *editor = qobject_cast<QmlJSTextEditorWidget*>(em->currentEditor()->widget()))
editor->followSymbolUnderCursor();
}
void QmlJSEditorPlugin::findUsages()
{
Core::EditorManager *em = Core::EditorManager::instance();
......
......@@ -100,7 +100,6 @@ public:
Utils::JsonSchemaManager *jsonManager() const;
public Q_SLOTS:
void followSymbolUnderCursor();
void findUsages();
void renameUsages();
void reformatFile();
......
......@@ -233,11 +233,6 @@ void ProFileEditorWidget::setFontSettings(const TextEditor::FontSettings &fs)
highlighter->rehighlight();
}
void ProFileEditorWidget::jumpToFile()
{
openLink(findLinkAt(textCursor()));
}
//
// ProFileDocument
//
......
......@@ -88,7 +88,6 @@ protected:
public slots:
virtual void setFontSettings(const TextEditor::FontSettings &);
void jumpToFile();
private:
ProFileEditorFactory *m_factory;
......
......@@ -63,7 +63,6 @@ const char BUILDSUBDIR[] = "Qt4Builder.BuildSubDir";
const char REBUILDSUBDIR[] = "Qt4Builder.RebuildSubDir";
const char CLEANSUBDIR[] = "Qt4Builder.CleanSubDir";
const char ADDLIBRARY[] = "Qt4.AddLibrary";
const char JUMP_TO_FILE[] = "Qt4.JumpToFile";
const char SEPARATOR[] = "Qt4.Separator";
// Tasks
......
......@@ -129,7 +129,8 @@ bool Qt4ProjectManagerPlugin::initialize(const QStringList &arguments, QString *
TextEditor::TextEditorActionHandler *editorHandler
= new TextEditor::TextEditorActionHandler(Constants::C_PROFILEEDITOR,
TextEditor::TextEditorActionHandler::UnCommentSelection);
TextEditor::TextEditorActionHandler::UnCommentSelection
| TextEditor::TextEditorActionHandler::JumpToFileUnderCursor);
m_proFileEditorFactory = new ProFileEditorFactory(m_qt4ProjectManager, editorHandler);
addObject(m_proFileEditorFactory);
......@@ -238,12 +239,7 @@ bool Qt4ProjectManagerPlugin::initialize(const QStringList &arguments, QString *
Core::Context proFileEditorContext = Core::Context(Qt4ProjectManager::Constants::C_PROFILEEDITOR);
QAction *jumpToFile = new QAction(tr("Jump to File Under Cursor"), this);
command = am->registerAction(jumpToFile,
Constants::JUMP_TO_FILE, proFileEditorContext);
command->setDefaultKeySequence(QKeySequence(Qt::Key_F2));
connect(jumpToFile, SIGNAL(triggered()),
this, SLOT(jumpToFile()));
command = am->command(TextEditor::Constants::JUMP_TO_FILE_UNDER_CURSOR);
contextMenu->addAction(command);
m_addLibraryAction = new QAction(tr("Add Library..."), this);
......@@ -369,12 +365,4 @@ void Qt4ProjectManagerPlugin::buildStateChanged(ProjectExplorer::Project *pro)
updateRunQMakeAction();
}
void Qt4ProjectManagerPlugin::jumpToFile()
{
Core::EditorManager *em = Core::EditorManager::instance();
ProFileEditorWidget *editor = qobject_cast<ProFileEditorWidget*>(em->currentEditor()->widget());
if (editor)
editor->jumpToFile();
}
Q_EXPORT_PLUGIN(Qt4ProjectManagerPlugin)
......@@ -75,7 +75,6 @@ private slots:
void updateRunQMakeAction();
void currentNodeChanged(ProjectExplorer::Node *node);
void buildStateChanged(ProjectExplorer::Project *pro);
void jumpToFile();
#ifdef WITH_TESTS
void testAbldOutputParsers_data();
......
......@@ -1074,6 +1074,11 @@ void BaseTextEditorWidget::unindent()
indentOrUnindent(false);
}
void BaseTextEditorWidget::openLinkUnderCursor()
{
openLink(findLinkAt(textCursor()));
}
void BaseTextEditorWidget::moveLineUpDown(bool up)
{
QTextCursor cursor = textCursor();
......
......@@ -326,6 +326,8 @@ public slots:
void indent();
void unindent();
void openLinkUnderCursor();
signals:
void changed();
......
......@@ -105,6 +105,8 @@ TextEditorActionHandler::TextEditorActionHandler(const char *context,
m_lowerCaseSelectionAction(0),
m_indentAction(0),
m_unindentAction(0),
m_followSymbolAction(0),
m_jumpToFileAction(0),
m_optionalActions(optionalActions),
m_currentEditor(0),
m_contextId(context),
......@@ -395,6 +397,16 @@ void TextEditorActionHandler::createActions()
command = am->registerAction(m_unindentAction, Constants::UNINDENT, m_contextId, true);
connect(m_unindentAction, SIGNAL(triggered()), this, SLOT(unindent()));
m_followSymbolAction = new QAction(tr("Follow Symbol Under Cursor"), this);
command = am->registerAction(m_followSymbolAction, Constants::FOLLOW_SYMBOL_UNDER_CURSOR, m_contextId, true);
command->setDefaultKeySequence(QKeySequence(Qt::Key_F2));
connect(m_followSymbolAction, SIGNAL(triggered()), this, SLOT(openLinkUnderCursor()));
m_jumpToFileAction = new QAction(tr("Jump To File Under Cursor"), this);
command = am->registerAction(m_jumpToFileAction, Constants::JUMP_TO_FILE_UNDER_CURSOR, m_contextId, true);
command->setDefaultKeySequence(QKeySequence(Qt::Key_F2));
connect(m_jumpToFileAction, SIGNAL(triggered()), this, SLOT(openLinkUnderCursor()));
QAction *a = 0;
a = new QAction(tr("Go to Line Start"), this);
command = am->registerAction(a, Constants::GOTO_LINE_START, m_contextId, true);
......@@ -508,6 +520,8 @@ void TextEditorActionHandler::updateActions(UpdateMode um)
a->setEnabled(um != ReadOnlyMode);
m_formatAction->setEnabled((m_optionalActions & Format) && um != ReadOnlyMode);
m_unCommentSelectionAction->setEnabled((m_optionalActions & UnCommentSelection) && um != ReadOnlyMode);
m_followSymbolAction->setEnabled(m_optionalActions & FollowSymbolUnderCursor);
m_jumpToFileAction->setEnabled(m_optionalActions & JumpToFileUnderCursor);
m_unfoldAllAction->setEnabled((m_optionalActions & UnCollapseAll));
m_visualizeWhitespaceAction->setChecked(m_currentEditor->displaySettings().m_visualizeWhitespace);
......@@ -632,6 +646,7 @@ FUNCTION(insertLineAbove)
FUNCTION(insertLineBelow)
FUNCTION(indent)
FUNCTION(unindent)
FUNCTION(openLinkUnderCursor)
FUNCTION(gotoLineStart)
FUNCTION(gotoLineStartWithSelection)
......
......@@ -63,7 +63,9 @@ public:
None = 0,
Format = 1,
UnCommentSelection = 2,
UnCollapseAll = 4
UnCollapseAll = 4,
FollowSymbolUnderCursor = 8,
JumpToFileUnderCursor = 16
};
explicit TextEditorActionHandler(const char *context, uint optionalActions = None);
......@@ -141,6 +143,7 @@ private slots:
void updateCurrentEditor(Core::IEditor *editor);
void indent();
void unindent();
void openLinkUnderCursor();
void gotoLineStart();
void gotoLineStartWithSelection();
......@@ -212,6 +215,8 @@ private:
QAction *m_lowerCaseSelectionAction;
QAction *m_indentAction;
QAction *m_unindentAction;
QAction *m_followSymbolAction;
QAction *m_jumpToFileAction;
QList<QAction *> m_modifyingActions;
uint m_optionalActions;
......
......@@ -105,6 +105,8 @@ const char CIRCULAR_PASTE[] = "TextEditor.CircularPaste";
const char SWITCH_UTF8BOM[] = "TextEditor.SwitchUtf8bom";
const char INDENT[] = "TextEditor.Indent";
const char UNINDENT[] = "TextEditor.Unindent";
const char FOLLOW_SYMBOL_UNDER_CURSOR[] = "TextEditor.FollowSymbolUnderCursor";
const char JUMP_TO_FILE_UNDER_CURSOR[] = "TextEditor.JumpToFileUnderCursor";
// Text color and style categories
const char C_TEXT[] = "Text";
......
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