forked from qt-creator/qt-creator
Hide reload button for diff editor when there is no reloader
Refactor code a bit. Now DiffEditorController has a pointer to DiffEditorReloader. Change-Id: I224579127f112923bc665cd59717b0c4d833981b Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -210,6 +210,7 @@ DiffEditor::DiffEditor()
|
||||
, m_toolBar(0)
|
||||
, m_entriesComboBox(0)
|
||||
, m_toggleDescriptionAction(0)
|
||||
, m_reloadAction(0)
|
||||
, m_diffEditorSwitcher(0)
|
||||
{
|
||||
ctor();
|
||||
@@ -228,6 +229,7 @@ DiffEditor::DiffEditor(DiffEditor *other)
|
||||
, m_toolBar(0)
|
||||
, m_entriesComboBox(0)
|
||||
, m_toggleDescriptionAction(0)
|
||||
, m_reloadAction(0)
|
||||
, m_diffEditorSwitcher(0)
|
||||
{
|
||||
ctor();
|
||||
@@ -392,13 +394,6 @@ QWidget *DiffEditor::toolBar()
|
||||
QSizePolicy::Expanding); // Mac Qt5
|
||||
m_toolBar->addWidget(contextSpinBox);
|
||||
|
||||
QToolButton *toggleSync = new QToolButton(m_toolBar);
|
||||
toggleSync->setIcon(QIcon(QLatin1String(Core::Constants::ICON_LINK)));
|
||||
toggleSync->setCheckable(true);
|
||||
toggleSync->setChecked(m_guiController->horizontalScrollBarSynchronization());
|
||||
toggleSync->setToolTip(tr("Synchronize Horizontal Scroll Bars"));
|
||||
m_toolBar->addWidget(toggleSync);
|
||||
|
||||
QToolButton *toggleDescription = new QToolButton(m_toolBar);
|
||||
toggleDescription->setIcon(
|
||||
QIcon(QLatin1String(Constants::ICON_TOP_BAR)));
|
||||
@@ -410,7 +405,15 @@ QWidget *DiffEditor::toolBar()
|
||||
QToolButton *reloadButton = new QToolButton(m_toolBar);
|
||||
reloadButton->setIcon(QIcon(QLatin1String(Core::Constants::ICON_RELOAD_GRAY)));
|
||||
reloadButton->setToolTip(tr("Reload Editor"));
|
||||
m_toolBar->addWidget(reloadButton);
|
||||
m_reloadAction = m_toolBar->addWidget(reloadButton);
|
||||
slotReloaderChanged(m_controller->reloader());
|
||||
|
||||
QToolButton *toggleSync = new QToolButton(m_toolBar);
|
||||
toggleSync->setIcon(QIcon(QLatin1String(Core::Constants::ICON_LINK)));
|
||||
toggleSync->setCheckable(true);
|
||||
toggleSync->setChecked(m_guiController->horizontalScrollBarSynchronization());
|
||||
toggleSync->setToolTip(tr("Synchronize Horizontal Scroll Bars"));
|
||||
m_toolBar->addWidget(toggleSync);
|
||||
|
||||
m_diffEditorSwitcher = new QToolButton(m_toolBar);
|
||||
m_toolBar->addWidget(m_diffEditorSwitcher);
|
||||
@@ -432,6 +435,8 @@ QWidget *DiffEditor::toolBar()
|
||||
this, SLOT(slotDiffEditorSwitched()));
|
||||
connect(reloadButton, SIGNAL(clicked()),
|
||||
m_controller, SLOT(requestReload()));
|
||||
connect(m_controller, SIGNAL(reloaderChanged(DiffEditorReloader*)),
|
||||
this, SLOT(slotReloaderChanged(DiffEditorReloader*)));
|
||||
|
||||
return m_toolBar;
|
||||
}
|
||||
@@ -547,6 +552,11 @@ void DiffEditor::slotDescriptionVisibilityChanged()
|
||||
m_toggleDescriptionAction->setVisible(enabled);
|
||||
}
|
||||
|
||||
void DiffEditor::slotReloaderChanged(DiffEditorReloader *reloader)
|
||||
{
|
||||
m_reloadAction->setVisible(reloader);
|
||||
}
|
||||
|
||||
void DiffEditor::slotDiffEditorSwitched()
|
||||
{
|
||||
QWidget *oldEditor = m_currentEditor;
|
||||
|
||||
@@ -83,6 +83,7 @@ private slots:
|
||||
void entryActivated(int index);
|
||||
void slotDescriptionChanged(const QString &description);
|
||||
void slotDescriptionVisibilityChanged();
|
||||
void slotReloaderChanged(DiffEditorReloader *reloader);
|
||||
void slotDiffEditorSwitched();
|
||||
|
||||
private:
|
||||
@@ -105,6 +106,7 @@ private:
|
||||
QToolBar *m_toolBar;
|
||||
QComboBox *m_entriesComboBox;
|
||||
QAction *m_toggleDescriptionAction;
|
||||
QAction *m_reloadAction;
|
||||
QToolButton *m_diffEditorSwitcher;
|
||||
};
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "diffeditorconstants.h"
|
||||
#include "diffeditorcontroller.h"
|
||||
#include "diffeditorreloader.h"
|
||||
|
||||
#include <coreplugin/icore.h>
|
||||
|
||||
@@ -44,7 +45,8 @@ DiffEditorController::DiffEditorController(QObject *parent)
|
||||
: QObject(parent),
|
||||
m_descriptionEnabled(false),
|
||||
m_contextLinesNumber(3),
|
||||
m_ignoreWhitespace(true)
|
||||
m_ignoreWhitespace(true),
|
||||
m_reloader(0)
|
||||
{
|
||||
QSettings *s = Core::ICore::settings();
|
||||
s->beginGroup(QLatin1String(settingsGroupC));
|
||||
@@ -124,6 +126,27 @@ QString DiffEditorController::makePatch(int diffFileIndex,
|
||||
lastChunk && fileData.lastChunkAtTheEndOfFile);
|
||||
}
|
||||
|
||||
DiffEditorReloader *DiffEditorController::reloader() const
|
||||
{
|
||||
return m_reloader;
|
||||
}
|
||||
|
||||
void DiffEditorController::setReloader(DiffEditorReloader *reloader)
|
||||
{
|
||||
if (m_reloader == reloader)
|
||||
return; // nothing changes
|
||||
|
||||
if (m_reloader)
|
||||
m_reloader->setDiffEditorController(0);
|
||||
|
||||
m_reloader = reloader;
|
||||
|
||||
if (m_reloader)
|
||||
m_reloader->setDiffEditorController(this);
|
||||
|
||||
reloaderChanged(m_reloader);
|
||||
}
|
||||
|
||||
void DiffEditorController::clear()
|
||||
{
|
||||
clear(tr("No difference"));
|
||||
@@ -238,7 +261,8 @@ void DiffEditorController::setIgnoreWhitespace(bool ignore)
|
||||
|
||||
void DiffEditorController::requestReload()
|
||||
{
|
||||
emit reloadRequested();
|
||||
if (m_reloader)
|
||||
m_reloader->requestReload();
|
||||
}
|
||||
|
||||
void DiffEditorController::requestChunkActions(QMenu *menu,
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
|
||||
namespace DiffEditor {
|
||||
|
||||
class DiffEditorReloader;
|
||||
|
||||
class DIFFEDITOR_EXPORT DiffEditorController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -55,6 +57,9 @@ public:
|
||||
|
||||
QString makePatch(int diffFileIndex, int chunkIndex, bool revert) const;
|
||||
|
||||
DiffEditorReloader *reloader() const;
|
||||
void setReloader(DiffEditorReloader *reloader);
|
||||
|
||||
public slots:
|
||||
void clear();
|
||||
void clear(const QString &message);
|
||||
@@ -79,11 +84,11 @@ signals:
|
||||
void descriptionEnablementChanged(bool on);
|
||||
void contextLinesNumberChanged(int lines);
|
||||
void ignoreWhitespaceChanged(bool ignore);
|
||||
void reloadRequested();
|
||||
void chunkActionsRequested(QMenu *menu,
|
||||
int diffFileIndex,
|
||||
int chunkIndex);
|
||||
void expandBranchesRequested(const QString &revision);
|
||||
void reloaderChanged(DiffEditorReloader *reloader);
|
||||
|
||||
private:
|
||||
QString prepareBranchesForCommit(const QString &output);
|
||||
@@ -95,6 +100,7 @@ private:
|
||||
bool m_descriptionEnabled;
|
||||
int m_contextLinesNumber;
|
||||
bool m_ignoreWhitespace;
|
||||
DiffEditorReloader *m_reloader;
|
||||
};
|
||||
|
||||
} // namespace DiffEditor
|
||||
|
||||
@@ -195,16 +195,16 @@ void DiffEditorPlugin::diff()
|
||||
const QString documentId = QLatin1String("Diff ") + fileName1
|
||||
+ QLatin1String(", ") + fileName2;
|
||||
DiffEditorDocument *document = DiffEditorManager::find(documentId);
|
||||
if (!document) {
|
||||
QString title = tr("Diff \"%1\", \"%2\"").arg(fileName1).arg(fileName2);
|
||||
document = DiffEditorManager::findOrCreate(documentId, title);
|
||||
if (!document)
|
||||
return;
|
||||
QString title = tr("Diff \"%1\", \"%2\"").arg(fileName1).arg(fileName2);
|
||||
document = DiffEditorManager::findOrCreate(documentId, title);
|
||||
if (!document)
|
||||
return;
|
||||
|
||||
DiffEditorController *controller = document->controller();
|
||||
DiffEditorController *controller = document->controller();
|
||||
if (!controller->reloader()) {
|
||||
SimpleDiffEditorReloader *reloader =
|
||||
new SimpleDiffEditorReloader(controller, fileName1, fileName2);
|
||||
reloader->setDiffEditorController(controller);
|
||||
controller->setReloader(reloader);
|
||||
}
|
||||
|
||||
Core::EditorManager::activateEditorForDocument(document);
|
||||
|
||||
@@ -51,13 +51,14 @@ DiffEditorController *DiffEditorReloader::diffEditorController() const
|
||||
|
||||
void DiffEditorReloader::setDiffEditorController(DiffEditorController *controller)
|
||||
{
|
||||
if (m_controller == controller)
|
||||
return; // nothing changes
|
||||
|
||||
if (m_controller) {
|
||||
disconnect(m_controller, SIGNAL(ignoreWhitespaceChanged(bool)),
|
||||
this, SLOT(requestReload()));
|
||||
disconnect(m_controller, SIGNAL(contextLinesNumberChanged(int)),
|
||||
this, SLOT(requestReload()));
|
||||
disconnect(m_controller, SIGNAL(reloadRequested()),
|
||||
this, SLOT(requestReload()));
|
||||
}
|
||||
|
||||
m_controller = controller;
|
||||
@@ -67,8 +68,6 @@ void DiffEditorReloader::setDiffEditorController(DiffEditorController *controlle
|
||||
this, SLOT(requestReload()));
|
||||
connect(m_controller, SIGNAL(contextLinesNumberChanged(int)),
|
||||
this, SLOT(requestReload()));
|
||||
connect(m_controller, SIGNAL(reloadRequested()),
|
||||
this, SLOT(requestReload()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -45,26 +45,27 @@ public:
|
||||
DiffEditorReloader(QObject *parent = 0);
|
||||
~DiffEditorReloader();
|
||||
|
||||
DiffEditorController *diffEditorController() const;
|
||||
void setDiffEditorController(DiffEditorController *controller);
|
||||
|
||||
bool isReloading() const;
|
||||
|
||||
public slots:
|
||||
void requestReload();
|
||||
|
||||
protected:
|
||||
// reloadFinished() should be called
|
||||
// inside reload() (for synchronous reload)
|
||||
// or later (for asynchronous reload)
|
||||
virtual void reload() = 0;
|
||||
DiffEditorController *diffEditorController() const;
|
||||
void setDiffEditorController(DiffEditorController *diffEditorController);
|
||||
|
||||
protected slots:
|
||||
void reloadFinished();
|
||||
|
||||
private slots:
|
||||
void requestReload();
|
||||
|
||||
private:
|
||||
DiffEditorController *m_controller;
|
||||
bool m_reloading;
|
||||
|
||||
friend class DiffEditorController;
|
||||
};
|
||||
|
||||
} // namespace DiffEditor
|
||||
|
||||
Reference in New Issue
Block a user