forked from qt-creator/qt-creator
TextEditor: Consolidate various currentTextEditor() implementations
Change-Id: Ie61c985e31a76dfd34ec1db207753007cee9aff3 Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
@@ -57,12 +57,14 @@
|
|||||||
|
|
||||||
Q_DECLARE_METATYPE(Bookmarks::Internal::Bookmark*)
|
Q_DECLARE_METATYPE(Bookmarks::Internal::Bookmark*)
|
||||||
|
|
||||||
using namespace Bookmarks;
|
|
||||||
using namespace Bookmarks::Internal;
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
|
using namespace TextEditor;
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
|
namespace Bookmarks {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
BookmarkDelegate::BookmarkDelegate(QObject *parent)
|
BookmarkDelegate::BookmarkDelegate(QObject *parent)
|
||||||
: QStyledItemDelegate(parent), m_normalPixmap(0), m_selectedPixmap(0)
|
: QStyledItemDelegate(parent), m_normalPixmap(0), m_selectedPixmap(0)
|
||||||
{
|
{
|
||||||
@@ -428,7 +430,7 @@ QVariant BookmarkManager::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
void BookmarkManager::toggleBookmark()
|
void BookmarkManager::toggleBookmark()
|
||||||
{
|
{
|
||||||
TextEditor::ITextEditor *editor = currentTextEditor();
|
ITextEditor *editor = ITextEditor::currentTextEditor();
|
||||||
if (!editor)
|
if (!editor)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -529,7 +531,6 @@ Bookmark *BookmarkManager::bookmarkForIndex(const QModelIndex &index)
|
|||||||
|
|
||||||
bool BookmarkManager::gotoBookmark(Bookmark *bookmark)
|
bool BookmarkManager::gotoBookmark(Bookmark *bookmark)
|
||||||
{
|
{
|
||||||
using namespace TextEditor;
|
|
||||||
if (ITextEditor *editor = qobject_cast<ITextEditor *>(EditorManager::openEditorAt(bookmark->filePath(),
|
if (ITextEditor *editor = qobject_cast<ITextEditor *>(EditorManager::openEditorAt(bookmark->filePath(),
|
||||||
bookmark->lineNumber()))) {
|
bookmark->lineNumber()))) {
|
||||||
return (editor->currentLine() == bookmark->lineNumber());
|
return (editor->currentLine() == bookmark->lineNumber());
|
||||||
@@ -549,7 +550,7 @@ void BookmarkManager::prevInDocument()
|
|||||||
|
|
||||||
void BookmarkManager::documentPrevNext(bool next)
|
void BookmarkManager::documentPrevNext(bool next)
|
||||||
{
|
{
|
||||||
TextEditor::ITextEditor *editor = currentTextEditor();
|
ITextEditor *editor = ITextEditor::currentTextEditor();
|
||||||
int editorLine = editor->currentLine();
|
int editorLine = editor->currentLine();
|
||||||
QFileInfo fi(editor->document()->filePath());
|
QFileInfo fi(editor->document()->filePath());
|
||||||
if (!m_bookmarksMap.contains(fi.path()))
|
if (!m_bookmarksMap.contains(fi.path()))
|
||||||
@@ -633,18 +634,12 @@ void BookmarkManager::prev()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
TextEditor::ITextEditor *BookmarkManager::currentTextEditor() const
|
|
||||||
{
|
|
||||||
Core::IEditor *currEditor = EditorManager::currentEditor();
|
|
||||||
return qobject_cast<TextEditor::ITextEditor *>(currEditor);
|
|
||||||
}
|
|
||||||
|
|
||||||
BookmarkManager::State BookmarkManager::state() const
|
BookmarkManager::State BookmarkManager::state() const
|
||||||
{
|
{
|
||||||
if (m_bookmarksMap.empty())
|
if (m_bookmarksMap.empty())
|
||||||
return NoBookMarks;
|
return NoBookMarks;
|
||||||
|
|
||||||
TextEditor::ITextEditor *editor = currentTextEditor();
|
ITextEditor *editor = ITextEditor::currentTextEditor();
|
||||||
if (!editor)
|
if (!editor)
|
||||||
return HasBookMarks;
|
return HasBookMarks;
|
||||||
|
|
||||||
@@ -892,3 +887,6 @@ Core::NavigationView BookmarkViewFactory::createWidget()
|
|||||||
view.widget = bookmarkView;
|
view.widget = bookmarkView;
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace Bookmarks
|
||||||
|
@@ -116,8 +116,6 @@ private slots:
|
|||||||
int line);
|
int line);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TextEditor::ITextEditor *currentTextEditor() const;
|
|
||||||
|
|
||||||
void documentPrevNext(bool next);
|
void documentPrevNext(bool next);
|
||||||
|
|
||||||
Bookmark* findBookmark(const QString &path, const QString &fileName, int lineNumber);
|
Bookmark* findBookmark(const QString &path, const QString &fileName, int lineNumber);
|
||||||
|
@@ -695,14 +695,9 @@ bool fillParameters(DebuggerStartParameters *sp, const Kit *kit, QString *errorM
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static TextEditor::ITextEditor *currentTextEditor()
|
|
||||||
{
|
|
||||||
return qobject_cast<TextEditor::ITextEditor *>(EditorManager::currentEditor());
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool currentTextEditorPosition(ContextData *data)
|
static bool currentTextEditorPosition(ContextData *data)
|
||||||
{
|
{
|
||||||
TextEditor::ITextEditor *textEditor = currentTextEditor();
|
ITextEditor *textEditor = ITextEditor::currentTextEditor();
|
||||||
if (!textEditor)
|
if (!textEditor)
|
||||||
return false;
|
return false;
|
||||||
const IDocument *document = textEditor->document();
|
const IDocument *document = textEditor->document();
|
||||||
@@ -1069,7 +1064,7 @@ public slots:
|
|||||||
|
|
||||||
void handleExecRunToSelectedFunction()
|
void handleExecRunToSelectedFunction()
|
||||||
{
|
{
|
||||||
ITextEditor *textEditor = currentTextEditor();
|
ITextEditor *textEditor = ITextEditor::currentTextEditor();
|
||||||
QTC_ASSERT(textEditor, return);
|
QTC_ASSERT(textEditor, return);
|
||||||
QPlainTextEdit *ed = qobject_cast<QPlainTextEdit*>(textEditor->widget());
|
QPlainTextEdit *ed = qobject_cast<QPlainTextEdit*>(textEditor->widget());
|
||||||
if (!ed)
|
if (!ed)
|
||||||
@@ -2047,7 +2042,7 @@ void DebuggerPluginPrivate::requestContextMenu(ITextEditor *editor,
|
|||||||
|
|
||||||
void DebuggerPluginPrivate::toggleBreakpoint()
|
void DebuggerPluginPrivate::toggleBreakpoint()
|
||||||
{
|
{
|
||||||
ITextEditor *textEditor = currentTextEditor();
|
ITextEditor *textEditor = ITextEditor::currentTextEditor();
|
||||||
QTC_ASSERT(textEditor, return);
|
QTC_ASSERT(textEditor, return);
|
||||||
const int lineNumber = textEditor->currentLine();
|
const int lineNumber = textEditor->currentLine();
|
||||||
if (textEditor->property(Constants::OPENED_WITH_DISASSEMBLY).toBool()) {
|
if (textEditor->property(Constants::OPENED_WITH_DISASSEMBLY).toBool()) {
|
||||||
|
@@ -28,10 +28,11 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "itexteditor.h"
|
#include "itexteditor.h"
|
||||||
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
|
|
||||||
using namespace TextEditor;
|
namespace TextEditor {
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\class TextEditor::ITextEditorDocument
|
\class TextEditor::ITextEditorDocument
|
||||||
@@ -85,3 +86,11 @@ ITextEditorDocument *ITextEditor::textDocument()
|
|||||||
{
|
{
|
||||||
return qobject_cast<ITextEditorDocument *>(document());
|
return qobject_cast<ITextEditorDocument *>(document());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ITextEditor *ITextEditor::currentTextEditor()
|
||||||
|
{
|
||||||
|
return qobject_cast<ITextEditor *>(Core::EditorManager::currentEditor());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace TextEditor
|
||||||
|
@@ -140,6 +140,8 @@ public:
|
|||||||
TaskMarkRequest
|
TaskMarkRequest
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static ITextEditor *currentTextEditor();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void markRequested(TextEditor::ITextEditor *editor, int line, TextEditor::ITextEditor::MarkRequestKind kind);
|
void markRequested(TextEditor::ITextEditor *editor, int line, TextEditor::ITextEditor::MarkRequestKind kind);
|
||||||
void markContextMenuRequested(TextEditor::ITextEditor *editor, int line, QMenu *menu);
|
void markContextMenuRequested(TextEditor::ITextEditor *editor, int line, QMenu *menu);
|
||||||
|
@@ -200,11 +200,6 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static ITextEditor *currentTextEditor()
|
|
||||||
{
|
|
||||||
return qobject_cast<ITextEditor *>(Core::EditorManager::currentEditor());
|
|
||||||
}
|
|
||||||
|
|
||||||
void TextEditorPlugin::extensionsInitialized()
|
void TextEditorPlugin::extensionsInitialized()
|
||||||
{
|
{
|
||||||
m_searchResultWindow = Core::SearchResultWindow::instance();
|
m_searchResultWindow = Core::SearchResultWindow::instance();
|
||||||
@@ -224,7 +219,7 @@ void TextEditorPlugin::extensionsInitialized()
|
|||||||
tr("Selected text within the current document."),
|
tr("Selected text within the current document."),
|
||||||
[]() -> QString {
|
[]() -> QString {
|
||||||
QString value;
|
QString value;
|
||||||
if (ITextEditor *editor = currentTextEditor()) {
|
if (ITextEditor *editor = ITextEditor::currentTextEditor()) {
|
||||||
value = editor->selectedText();
|
value = editor->selectedText();
|
||||||
value.replace(QChar::ParagraphSeparator, QLatin1String("\n"));
|
value.replace(QChar::ParagraphSeparator, QLatin1String("\n"));
|
||||||
}
|
}
|
||||||
@@ -234,35 +229,35 @@ void TextEditorPlugin::extensionsInitialized()
|
|||||||
Core::VariableManager::registerIntVariable(kCurrentDocumentRow,
|
Core::VariableManager::registerIntVariable(kCurrentDocumentRow,
|
||||||
tr("Line number of the text cursor position in current document (starts with 1)."),
|
tr("Line number of the text cursor position in current document (starts with 1)."),
|
||||||
[]() -> int {
|
[]() -> int {
|
||||||
ITextEditor *editor = currentTextEditor();
|
ITextEditor *editor = ITextEditor::currentTextEditor();
|
||||||
return editor ? editor->currentLine() : 0;
|
return editor ? editor->currentLine() : 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
Core::VariableManager::registerIntVariable(kCurrentDocumentColumn,
|
Core::VariableManager::registerIntVariable(kCurrentDocumentColumn,
|
||||||
tr("Column number of the text cursor position in current document (starts with 0)."),
|
tr("Column number of the text cursor position in current document (starts with 0)."),
|
||||||
[]() -> int {
|
[]() -> int {
|
||||||
ITextEditor *editor = currentTextEditor();
|
ITextEditor *editor = ITextEditor::currentTextEditor();
|
||||||
return editor ? editor->currentColumn() : 0;
|
return editor ? editor->currentColumn() : 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
Core::VariableManager::registerIntVariable(kCurrentDocumentRowCount,
|
Core::VariableManager::registerIntVariable(kCurrentDocumentRowCount,
|
||||||
tr("Number of lines visible in current document."),
|
tr("Number of lines visible in current document."),
|
||||||
[]() -> int {
|
[]() -> int {
|
||||||
ITextEditor *editor = currentTextEditor();
|
ITextEditor *editor = ITextEditor::currentTextEditor();
|
||||||
return editor ? editor->rowCount() : 0;
|
return editor ? editor->rowCount() : 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
Core::VariableManager::registerIntVariable(kCurrentDocumentColumnCount,
|
Core::VariableManager::registerIntVariable(kCurrentDocumentColumnCount,
|
||||||
tr("Number of columns visible in current document."),
|
tr("Number of columns visible in current document."),
|
||||||
[]() -> int {
|
[]() -> int {
|
||||||
ITextEditor *editor = currentTextEditor();
|
ITextEditor *editor = ITextEditor::currentTextEditor();
|
||||||
return editor ? editor->columnCount() : 0;
|
return editor ? editor->columnCount() : 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
Core::VariableManager::registerIntVariable(kCurrentDocumentFontSize,
|
Core::VariableManager::registerIntVariable(kCurrentDocumentFontSize,
|
||||||
tr("Current document's font size in points."),
|
tr("Current document's font size in points."),
|
||||||
[]() -> int {
|
[]() -> int {
|
||||||
ITextEditor *editor = currentTextEditor();
|
ITextEditor *editor = ITextEditor::currentTextEditor();
|
||||||
return editor ? editor->widget()->font().pointSize() : 0;
|
return editor ? editor->widget()->font().pointSize() : 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user