diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2018-02-16 12:53:35 +0100 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2018-03-15 11:21:01 +0000 |
commit | da2c66b1d0f0bf868f4ec88c7e61a57fd1095366 (patch) | |
tree | 5ef826190e393c70b9e92e3c13ace0c18d402ead /src/plugins/diffeditor | |
parent | 24db24734d92f2f3edc9bc1a17851e6ac0df643e (diff) |
Move git specific stuff out of diff editor plugin
Move it to the git plugin.
Change-Id: I8151573ed50df70776f7ebf0475dd41fb84fae83
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
Diffstat (limited to 'src/plugins/diffeditor')
-rw-r--r-- | src/plugins/diffeditor/descriptionwidgetwatcher.cpp | 78 | ||||
-rw-r--r-- | src/plugins/diffeditor/descriptionwidgetwatcher.h | 60 | ||||
-rw-r--r-- | src/plugins/diffeditor/diffeditor.cpp | 75 | ||||
-rw-r--r-- | src/plugins/diffeditor/diffeditor.pro | 8 | ||||
-rw-r--r-- | src/plugins/diffeditor/diffeditor.qbs | 2 | ||||
-rw-r--r-- | src/plugins/diffeditor/diffeditorconstants.h | 2 | ||||
-rw-r--r-- | src/plugins/diffeditor/diffeditorcontroller.cpp | 19 | ||||
-rw-r--r-- | src/plugins/diffeditor/diffeditorcontroller.h | 10 | ||||
-rw-r--r-- | src/plugins/diffeditor/diffeditordocument.cpp | 5 | ||||
-rw-r--r-- | src/plugins/diffeditor/diffeditordocument.h | 1 |
10 files changed, 150 insertions, 110 deletions
diff --git a/src/plugins/diffeditor/descriptionwidgetwatcher.cpp b/src/plugins/diffeditor/descriptionwidgetwatcher.cpp new file mode 100644 index 0000000000..0e310cfbcd --- /dev/null +++ b/src/plugins/diffeditor/descriptionwidgetwatcher.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#include "descriptionwidgetwatcher.h" +#include "diffeditor.h" +#include "diffeditorcontroller.h" + +#include <coreplugin/editormanager/documentmodel.h> +#include <coreplugin/editormanager/editormanager.h> +#include <texteditor/texteditor.h> + +using namespace Core; + +namespace DiffEditor { + +DescriptionWidgetWatcher::DescriptionWidgetWatcher(DiffEditorController *controller) + : QObject(controller), m_document(controller->document()) +{ + const QList<IEditor *> editors = DocumentModel::editorsForDocument(controller->document()); + for (auto *editor : editors) { + if (TextEditor::TextEditorWidget *widget = descriptionWidget(editor)) + m_widgets.append(widget); + } + + connect(EditorManager::instance(), &EditorManager::editorOpened, + [this](IEditor *editor) { + if (TextEditor::TextEditorWidget *widget = descriptionWidget(editor)) { + m_widgets.append(widget); + emit descriptionWidgetAdded(widget); + } + }); + + connect(EditorManager::instance(), &EditorManager::editorAboutToClose, + [this](IEditor *editor) { + if (TextEditor::TextEditorWidget *widget = descriptionWidget(editor)) { + emit descriptionWidgetRemoved(widget); + m_widgets.removeAll(widget); + } + }); +} + +QList<TextEditor::TextEditorWidget *> DescriptionWidgetWatcher::descriptionWidgets() const +{ + return m_widgets; +} + +TextEditor::TextEditorWidget *DescriptionWidgetWatcher::descriptionWidget(Core::IEditor *editor) const +{ + if (Internal::DiffEditor *diffEditor = qobject_cast<Internal::DiffEditor *>(editor)) { + if (diffEditor->document() == m_document) + return diffEditor->descriptionWidget(); + } + return nullptr; +} + +} // namespace DiffEditor diff --git a/src/plugins/diffeditor/descriptionwidgetwatcher.h b/src/plugins/diffeditor/descriptionwidgetwatcher.h new file mode 100644 index 0000000000..46988260fe --- /dev/null +++ b/src/plugins/diffeditor/descriptionwidgetwatcher.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2018 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of Qt Creator. +** +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +****************************************************************************/ + +#pragma once + +#include "diffeditor_global.h" + +#include <QObject> + +namespace Core { +class IDocument; +class IEditor; +} +namespace TextEditor { class TextEditorWidget; } + +namespace DiffEditor { + +class DiffEditorController; + +class DIFFEDITOR_EXPORT DescriptionWidgetWatcher : public QObject +{ + Q_OBJECT +public: + explicit DescriptionWidgetWatcher(DiffEditorController *controller); + QList<TextEditor::TextEditorWidget *> descriptionWidgets() const; + +signals: + void descriptionWidgetAdded(TextEditor::TextEditorWidget *editor); + void descriptionWidgetRemoved(TextEditor::TextEditorWidget *editor); + +private: + TextEditor::TextEditorWidget *descriptionWidget(Core::IEditor *editor) const; + + QList<TextEditor::TextEditorWidget *> m_widgets; + Core::IDocument *m_document = nullptr; +}; + +} // namespace DiffEditor diff --git a/src/plugins/diffeditor/diffeditor.cpp b/src/plugins/diffeditor/diffeditor.cpp index d3654d5439..6288f2405b 100644 --- a/src/plugins/diffeditor/diffeditor.cpp +++ b/src/plugins/diffeditor/diffeditor.cpp @@ -81,22 +81,11 @@ public: virtual QSize sizeHint() const override; -signals: - void requestBranchList(); - protected: - void mouseMoveEvent(QMouseEvent *e) override; - void mouseReleaseEvent(QMouseEvent *e) override; - void setDisplaySettings(const DisplaySettings &ds) override; void setMarginSettings(const MarginSettings &ms) override; - bool findContentsUnderCursor(const QTextCursor &cursor); - void highlightCurrentContents(); - void handleCurrentContents(); - private: - QTextCursor m_currentCursor; Core::IContext *m_context; }; @@ -153,68 +142,6 @@ void DescriptionEditorWidget::setMarginSettings(const MarginSettings &ms) TextEditorWidget::setMarginSettings(MarginSettings()); } -void DescriptionEditorWidget::mouseMoveEvent(QMouseEvent *e) -{ - if (e->buttons()) { - TextEditorWidget::mouseMoveEvent(e); - return; - } - - Qt::CursorShape cursorShape; - - const QTextCursor cursor = cursorForPosition(e->pos()); - if (findContentsUnderCursor(cursor)) { - highlightCurrentContents(); - cursorShape = Qt::PointingHandCursor; - } else { - setExtraSelections(OtherSelection, QList<QTextEdit::ExtraSelection>()); - cursorShape = Qt::IBeamCursor; - } - - TextEditorWidget::mouseMoveEvent(e); - viewport()->setCursor(cursorShape); -} - -void DescriptionEditorWidget::mouseReleaseEvent(QMouseEvent *e) -{ - if (e->button() == Qt::LeftButton && !(e->modifiers() & Qt::ShiftModifier)) { - const QTextCursor cursor = cursorForPosition(e->pos()); - if (findContentsUnderCursor(cursor)) { - handleCurrentContents(); - e->accept(); - return; - } - } - - TextEditorWidget::mouseReleaseEvent(e); -} - -bool DescriptionEditorWidget::findContentsUnderCursor(const QTextCursor &cursor) -{ - m_currentCursor = cursor; - return cursor.block().text() == Constants::EXPAND_BRANCHES; -} - -void DescriptionEditorWidget::highlightCurrentContents() -{ - QTextEdit::ExtraSelection sel; - sel.cursor = m_currentCursor; - sel.cursor.select(QTextCursor::LineUnderCursor); - sel.format.setUnderlineStyle(QTextCharFormat::SingleUnderline); - const QColor textColor = TextEditorSettings::fontSettings().formatFor(C_TEXT).foreground(); - sel.format.setUnderlineColor(textColor.isValid() ? textColor : palette().color(QPalette::Foreground)); - setExtraSelections(TextEditorWidget::OtherSelection, - QList<QTextEdit::ExtraSelection>() << sel); -} - -void DescriptionEditorWidget::handleCurrentContents() -{ - m_currentCursor.select(QTextCursor::LineUnderCursor); - m_currentCursor.removeSelectedText(); - m_currentCursor.insertText("Branches: Expanding..."); - emit requestBranchList(); -} - ///////////////////////////////// DiffEditor ////////////////////////////////// DiffEditor::DiffEditor() @@ -296,8 +223,6 @@ void DiffEditor::setDocument(QSharedPointer<DiffEditorDocument> doc) m_document = doc; - connect(m_descriptionWidget, &DescriptionEditorWidget::requestBranchList, - m_document.data(), &DiffEditorDocument::requestMoreInformation); connect(m_document.data(), &DiffEditorDocument::documentChanged, this, &DiffEditor::documentHasChanged); connect(m_document.data(), &DiffEditorDocument::descriptionChanged, diff --git a/src/plugins/diffeditor/diffeditor.pro b/src/plugins/diffeditor/diffeditor.pro index e9cf72b7fe..5c8c904495 100644 --- a/src/plugins/diffeditor/diffeditor.pro +++ b/src/plugins/diffeditor/diffeditor.pro @@ -1,7 +1,9 @@ DEFINES += DIFFEDITOR_LIBRARY include(../../qtcreatorplugin.pri) -HEADERS += diffeditor_global.h \ +HEADERS += \ + descriptionwidgetwatcher.h \ + diffeditor_global.h \ diffeditor.h \ diffeditorconstants.h \ diffeditorcontroller.h \ @@ -17,7 +19,9 @@ HEADERS += diffeditor_global.h \ unifieddiffeditorwidget.h \ diffeditoricons.h -SOURCES += diffeditor.cpp \ +SOURCES += \ + descriptionwidgetwatcher.cpp \ + diffeditor.cpp \ diffeditorcontroller.cpp \ diffeditordocument.cpp \ diffeditorfactory.cpp \ diff --git a/src/plugins/diffeditor/diffeditor.qbs b/src/plugins/diffeditor/diffeditor.qbs index 1c190a8dd2..8d0a1a1820 100644 --- a/src/plugins/diffeditor/diffeditor.qbs +++ b/src/plugins/diffeditor/diffeditor.qbs @@ -14,6 +14,8 @@ QtcPlugin { ] files: [ + "descriptionwidgetwatcher.cpp", + "descriptionwidgetwatcher.h", "diffeditor.cpp", "diffeditor.h", "diffeditor.qrc", diff --git a/src/plugins/diffeditor/diffeditorconstants.h b/src/plugins/diffeditor/diffeditorconstants.h index c44a5fb84d..e1c9870c98 100644 --- a/src/plugins/diffeditor/diffeditorconstants.h +++ b/src/plugins/diffeditor/diffeditorconstants.h @@ -41,7 +41,5 @@ const char UNIFIED_VIEW_ID[] = "DiffEditor.Unified"; const char G_TOOLS_DIFF[] = "QtCreator.Group.Tools.Options"; -const char EXPAND_BRANCHES[] = "Branches: <Expand>"; - } // namespace Constants } // namespace DiffEditor diff --git a/src/plugins/diffeditor/diffeditorcontroller.cpp b/src/plugins/diffeditor/diffeditorcontroller.cpp index bb2738b985..2cf36902af 100644 --- a/src/plugins/diffeditor/diffeditorcontroller.cpp +++ b/src/plugins/diffeditor/diffeditorcontroller.cpp @@ -65,12 +65,6 @@ bool DiffEditorController::ignoreWhitespace() const return m_document->ignoreWhitespace(); } -QString DiffEditorController::revisionFromDescription() const -{ - // TODO: This is specific for git and does not belong here at all! - return m_document->description().mid(7, 12); -} - QString DiffEditorController::makePatch(int fileIndex, int chunkIndex, PatchOptions options) const { @@ -105,18 +99,9 @@ void DiffEditorController::setDescription(const QString &description) m_document->setDescription(description); } -void DiffEditorController::branchesReceived(const QString &branches) -{ - QString tmp = m_document->description(); - tmp.replace(Constants::EXPAND_BRANCHES, branches); - m_document->setDescription(tmp); -} - -void DiffEditorController::requestMoreInformation() +QString DiffEditorController::description() const { - const QString rev = revisionFromDescription(); - if (!rev.isEmpty()) - emit requestInformationForCommit(rev); + return m_document->description(); } /** diff --git a/src/plugins/diffeditor/diffeditorcontroller.h b/src/plugins/diffeditor/diffeditorcontroller.h index e5d5ca7418..4578a7f82a 100644 --- a/src/plugins/diffeditor/diffeditorcontroller.h +++ b/src/plugins/diffeditor/diffeditorcontroller.h @@ -51,8 +51,6 @@ public: int contextLineCount() const; bool ignoreWhitespace() const; - QString revisionFromDescription() const; - enum PatchOption { NoOption = 0, Revert = 1, @@ -65,13 +63,12 @@ public: const QString &displayName); static DiffEditorController *controller(Core::IDocument *document); - void branchesReceived(const QString &branches); void requestChunkActions(QMenu *menu, int fileIndex, int chunkIndex); bool chunkExists(int fileIndex, int chunkIndex) const; + Core::IDocument *document() const; signals: void chunkActionsRequested(QMenu *menu, int fileIndex, int chunkIndex); - void requestInformationForCommit(const QString &revision); protected: // reloadFinished() should be called @@ -84,14 +81,11 @@ protected: const QString &baseDirectory = QString(), const QString &startupFile = QString()); void setDescription(const QString &description); + QString description() const; void forceContextLineCount(int lines); - Core::IDocument *document() const; private: - void requestMoreInformation(); - Internal::DiffEditorDocument *const m_document; - bool m_isReloading = false; friend class Internal::DiffEditorDocument; diff --git a/src/plugins/diffeditor/diffeditordocument.cpp b/src/plugins/diffeditor/diffeditordocument.cpp index 0845f3ef03..224d63dc2b 100644 --- a/src/plugins/diffeditor/diffeditordocument.cpp +++ b/src/plugins/diffeditor/diffeditordocument.cpp @@ -69,11 +69,6 @@ void DiffEditorDocument::setController(DiffEditorController *controller) if (m_controller) m_controller->deleteLater(); m_controller = controller; - - if (m_controller) { - connect(this, &DiffEditorDocument::requestMoreInformation, - m_controller, &DiffEditorController::requestMoreInformation); - } } DiffEditorController *DiffEditorDocument::controller() const diff --git a/src/plugins/diffeditor/diffeditordocument.h b/src/plugins/diffeditor/diffeditordocument.h index 2a5293dfaf..a9dff53faa 100644 --- a/src/plugins/diffeditor/diffeditordocument.h +++ b/src/plugins/diffeditor/diffeditordocument.h @@ -90,7 +90,6 @@ signals: void temporaryStateChanged(); void documentChanged(); void descriptionChanged(); - void requestMoreInformation(); private: void beginReload(); |