Commit 42e0e229 authored by Eike Ziller's avatar Eike Ziller

Make SubmitEditorFile dependency on VcsBaseSubmitEditor explicit

No use trying to hide it.

Change-Id: Id81fdf1eef704dec6d4e83ee69bec10b1244b202
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent aec91247
......@@ -29,6 +29,12 @@
#include "submiteditorfile.h"
#include "vcsbasesubmiteditor.h"
#include <utils/fileutils.h>
#include <QFileInfo>
using namespace VcsBase;
using namespace VcsBase::Internal;
......@@ -39,10 +45,11 @@ using namespace VcsBase::Internal;
submit editor files.
*/
SubmitEditorFile::SubmitEditorFile(const QString &mimeType, QObject *parent) :
SubmitEditorFile::SubmitEditorFile(const QString &mimeType, VcsBaseSubmitEditor *parent) :
Core::IDocument(parent),
m_mimeType(mimeType),
m_modified(false)
m_modified(false),
m_editor(parent)
{
setTemporary(true);
}
......@@ -57,7 +64,16 @@ void SubmitEditorFile::setModified(bool modified)
bool SubmitEditorFile::save(QString *errorString, const QString &fileName, bool autoSave)
{
emit saveMe(errorString, fileName, autoSave);
const QString fName = fileName.isEmpty() ? filePath() : fileName;
Utils::FileSaver saver(fName, QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
saver.write(m_editor->fileContents());
if (!saver.finalize(errorString))
return false;
if (autoSave)
return true;
const QFileInfo fi(fName);
setFilePath(fi.absoluteFilePath());
setModified(false);
if (!errorString->isEmpty())
return false;
emit changed();
......
......@@ -33,6 +33,8 @@
#include <coreplugin/idocument.h>
namespace VcsBase {
class VcsBaseSubmitEditor;
namespace Internal {
class SubmitEditorFile : public Core::IDocument
......@@ -40,7 +42,7 @@ class SubmitEditorFile : public Core::IDocument
Q_OBJECT
public:
explicit SubmitEditorFile(const QString &mimeType,
QObject *parent = 0);
VcsBaseSubmitEditor *parent = 0);
QString defaultPath() const { return QString(); }
QString suggestedFileName() const { return QString(); }
......@@ -54,12 +56,10 @@ public:
void setModified(bool modified = true);
signals:
void saveMe(QString *errorString, const QString &fileName, bool autoSave);
private:
const QString m_mimeType;
bool m_modified;
VcsBaseSubmitEditor *m_editor;
};
......
......@@ -146,7 +146,7 @@ struct VcsBaseSubmitEditorPrivate
{
VcsBaseSubmitEditorPrivate(const VcsBaseSubmitEditorParameters *parameters,
SubmitEditorWidget *editorWidget,
QObject *q);
VcsBaseSubmitEditor *q);
SubmitEditorWidget *m_widget;
QToolBar *m_toolWidget;
......@@ -163,7 +163,7 @@ struct VcsBaseSubmitEditorPrivate
VcsBaseSubmitEditorPrivate::VcsBaseSubmitEditorPrivate(const VcsBaseSubmitEditorParameters *parameters,
SubmitEditorWidget *editorWidget,
QObject *q) :
VcsBaseSubmitEditor *q) :
m_widget(editorWidget),
m_toolWidget(0),
m_parameters(parameters),
......@@ -194,8 +194,6 @@ VcsBaseSubmitEditor::VcsBaseSubmitEditor(const VcsBaseSubmitEditorParameters *pa
d->m_file->setModified(false);
// We are always clean to prevent the editor manager from asking to save.
connect(d->m_file, SIGNAL(saveMe(QString*,QString,bool)),
this, SLOT(save(QString*,QString,bool)));
connect(d->m_widget, SIGNAL(diffSelected(QList<int>)), this, SLOT(slotDiffSelectedVcsFiles(QList<int>)));
connect(d->m_widget->descriptionEdit(), SIGNAL(textChanged()), this, SLOT(slotDescriptionChanged()));
......@@ -515,21 +513,6 @@ void VcsBaseSubmitEditor::slotDiffSelectedVcsFiles(const QList<int> &rawList)
emit diffSelectedFiles(rowsToFiles(rawList));
}
bool VcsBaseSubmitEditor::save(QString *errorString, const QString &fileName, bool autoSave)
{
const QString fName = fileName.isEmpty() ? d->m_file->filePath() : fileName;
Utils::FileSaver saver(fName, QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text);
saver.write(fileContents());
if (!saver.finalize(errorString))
return false;
if (autoSave)
return true;
const QFileInfo fi(fName);
d->m_file->setFilePath(fi.absoluteFilePath());
d->m_file->setModified(false);
return true;
}
QByteArray VcsBaseSubmitEditor::fileContents() const
{
return d->m_widget->descriptionText().toLocal8Bit();
......
......@@ -44,6 +44,7 @@ QT_END_NAMESPACE
namespace VcsBase {
namespace Internal {
class CommonVcsSettings;
class SubmitEditorFile;
}
struct VcsBaseSubmitEditorPrivate;
class SubmitEditorWidget;
......@@ -143,7 +144,6 @@ signals:
private slots:
void slotDiffSelectedVcsFiles(const QList<int> &rawList);
bool save(QString *errorString, const QString &fileName, bool autoSave);
void slotDescriptionChanged();
void slotCheckSubmitMessage();
void slotInsertNickName();
......@@ -168,6 +168,7 @@ private:
QString promptForNickName();
VcsBaseSubmitEditorPrivate *d;
friend class Internal::SubmitEditorFile; // for the file contents
};
} // namespace VcsBase
......
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