Commit 4572021a authored by hjk's avatar hjk
Browse files

TextEditor: Consolidate various currentTextEditor() implementations



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