From 73cf43f32370d8986b4c06511b95771582cc421d Mon Sep 17 00:00:00 2001 From: jkobus Date: Tue, 11 Feb 2014 13:00:35 +0100 Subject: Add DiffEditorManager, refactoring. GitDiffSwitcher operates now on IDocument. GitDiffHandler operates now on DiffEditorController. "source" property now attached to editor's document (VcsBasePlugin). Change-Id: Ie2570a597b8b992ac1dc33b9179eca459c8a751a Reviewed-by: Tobias Hunger Reviewed-by: Jarek Kobus --- src/plugins/diffeditor/diffeditor.cpp | 104 +++++++++++++++------------------- 1 file changed, 45 insertions(+), 59 deletions(-) (limited to 'src/plugins/diffeditor/diffeditor.cpp') diff --git a/src/plugins/diffeditor/diffeditor.cpp b/src/plugins/diffeditor/diffeditor.cpp index 682abc27b9..6e23f0558f 100644 --- a/src/plugins/diffeditor/diffeditor.cpp +++ b/src/plugins/diffeditor/diffeditor.cpp @@ -118,7 +118,7 @@ void DescriptionEditorWidget::setDisplaySettings(const DisplaySettings &ds) DiffEditor::DiffEditor() : IEditor(0) - , m_document(new Internal::DiffEditorDocument(QLatin1String(Constants::DIFF_EDITOR_MIMETYPE))) + , m_document(new DiffEditorDocument(QLatin1String(Constants::DIFF_EDITOR_MIMETYPE))) , m_descriptionWidget(0) , m_diffWidget(0) , m_diffEditorController(0) @@ -163,9 +163,13 @@ void DiffEditor::ctor() m_descriptionWidget->setCodeStyle(TextEditorSettings::codeStyle()); m_descriptionWidget->baseTextDocument()->setFontSettings(TextEditorSettings::fontSettings()); - m_diffEditorController = m_document->diffEditorController(); + m_diffEditorController = m_document->controller(); m_diffWidget->setDiffEditorController(m_diffEditorController); + connect(m_diffEditorController, SIGNAL(cleared(QString)), + this, SLOT(slotCleared(QString))); + connect(m_diffEditorController, SIGNAL(diffContentsChanged(QList,QString)), + this, SLOT(slotDiffContentsChanged(QList,QString))); connect(m_diffEditorController, SIGNAL(currentDiffFileIndexChanged(int)), this, SLOT(activateEntry(int))); connect(m_diffEditorController, SIGNAL(descriptionChanged(QString)), @@ -209,11 +213,6 @@ Core::Id DiffEditor::id() const return Constants::DIFF_EDITOR_ID; } -QTextCodec *DiffEditor::codec() const -{ - return m_diffWidget->codec(); -} - static QToolBar *createToolBar(const QWidget *someWidget) { // Create @@ -275,24 +274,50 @@ QWidget *DiffEditor::toolBar() m_toggleDescriptionAction = m_toolBar->addWidget(toggleDescription); slotDescriptionVisibilityChanged(); - if (m_diffEditorController) { - connect(whitespaceButton, SIGNAL(clicked(bool)), - m_diffEditorController, SLOT(setIgnoreWhitespaces(bool))); - connect(contextSpinBox, SIGNAL(valueChanged(int)), - m_diffEditorController, SLOT(setContextLinesNumber(int))); - connect(toggleSync, SIGNAL(clicked(bool)), - m_diffEditorController, SLOT(setHorizontalScrollBarSynchronization(bool))); - connect(toggleDescription, SIGNAL(clicked(bool)), - m_diffEditorController, SLOT(setDescriptionVisible(bool))); - // TODO: synchronize in opposite direction too - } + connect(whitespaceButton, SIGNAL(clicked(bool)), + m_diffEditorController, SLOT(setIgnoreWhitespaces(bool))); + connect(contextSpinBox, SIGNAL(valueChanged(int)), + m_diffEditorController, SLOT(setContextLinesNumber(int))); + connect(toggleSync, SIGNAL(clicked(bool)), + m_diffEditorController, SLOT(setHorizontalScrollBarSynchronization(bool))); + connect(toggleDescription, SIGNAL(clicked(bool)), + m_diffEditorController, SLOT(setDescriptionVisible(bool))); + // TODO: synchronize in opposite direction too return m_toolBar; } -void DiffEditor::setDiff(const QList &diffFileList, - const QString &workingDirectory) +DiffEditorController * DiffEditor::controller() const +{ + return m_diffEditorController; +} + +void DiffEditor::updateEntryToolTip() +{ + const QString &toolTip = m_entriesComboBox->itemData( + m_entriesComboBox->currentIndex(), Qt::ToolTipRole).toString(); + m_entriesComboBox->setToolTip(toolTip); +} + +void DiffEditor::entryActivated(int index) { + updateEntryToolTip(); + m_diffEditorController->setCurrentDiffFileIndex(index); +} + +void DiffEditor::slotCleared(const QString &message) +{ + Q_UNUSED(message) + + m_entriesComboBox->clear(); + updateEntryToolTip(); +} + +void DiffEditor::slotDiffContentsChanged(const QList &diffFileList, + const QString &workingDirectory) +{ + Q_UNUSED(workingDirectory) + m_entriesComboBox->clear(); const int count = diffFileList.count(); for (int i = 0; i < count; i++) { @@ -331,42 +356,6 @@ void DiffEditor::setDiff(const QList &d m_entriesComboBox->setItemData(m_entriesComboBox->count() - 1, itemToolTip, Qt::ToolTipRole); } updateEntryToolTip(); - if (m_diffEditorController) - m_diffEditorController->setDiffContents(diffFileList, workingDirectory); -} - -void DiffEditor::setDescription(const QString &description) -{ - if (m_diffEditorController) - m_diffEditorController->setDescription(description); -} - -void DiffEditor::setDescriptionEnabled(bool on) -{ - if (m_diffEditorController) - m_diffEditorController->setDescriptionEnabled(on); -} - -void DiffEditor::clear(const QString &message) -{ - m_entriesComboBox->clear(); - updateEntryToolTip(); - if (m_diffEditorController) - m_diffEditorController->clear(message); -} - -void DiffEditor::updateEntryToolTip() -{ - const QString &toolTip = m_entriesComboBox->itemData( - m_entriesComboBox->currentIndex(), Qt::ToolTipRole).toString(); - m_entriesComboBox->setToolTip(toolTip); -} - -void DiffEditor::entryActivated(int index) -{ - updateEntryToolTip(); - if (m_diffEditorController) - m_diffEditorController->setCurrentDiffFileIndex(index); } void DiffEditor::activateEntry(int index) @@ -384,9 +373,6 @@ void DiffEditor::slotDescriptionChanged(const QString &description) void DiffEditor::slotDescriptionVisibilityChanged() { - if (!m_diffEditorController) - return; - const bool visible = m_diffEditorController->isDescriptionVisible(); const bool enabled = m_diffEditorController->isDescriptionEnabled(); -- cgit v1.2.1