2008-12-02 12:01:29 +01:00
|
|
|
/***************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2009-01-13 19:21:51 +01:00
|
|
|
** Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** Contact: Qt Software Information (qt-info@nokia.com)
|
|
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
|
|
|
|
** Non-Open Source Usage
|
|
|
|
|
**
|
2008-12-02 12:01:29 +01:00
|
|
|
** Licensees may use this file in accordance with the Qt Beta Version
|
|
|
|
|
** License Agreement, Agreement version 2.2 provided with the Software or,
|
|
|
|
|
** alternatively, in accordance with the terms contained in a written
|
2008-12-02 14:17:16 +01:00
|
|
|
** agreement between you and Nokia.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
**
|
2008-12-02 12:01:29 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU General
|
|
|
|
|
** Public License versions 2.0 or 3.0 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL included in the packaging
|
|
|
|
|
** of this file. Please review the following information to ensure GNU
|
|
|
|
|
** General Public Licensing requirements will be met:
|
|
|
|
|
**
|
|
|
|
|
** http://www.fsf.org/licensing/licenses/info/GPLv2.html and
|
|
|
|
|
** http://www.gnu.org/copyleft/gpl.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2008-12-02 14:17:16 +01:00
|
|
|
** rights. These rights are described in the Nokia Qt GPL Exception
|
2008-12-16 17:20:00 +01:00
|
|
|
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
|
|
|
|
***************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "vcsbasesubmiteditor.h"
|
|
|
|
|
#include "submiteditorfile.h"
|
|
|
|
|
|
|
|
|
|
#include <coreplugin/ifile.h>
|
|
|
|
|
#include <coreplugin/icore.h>
|
|
|
|
|
#include <coreplugin/uniqueidmanager.h>
|
2009-01-13 13:39:31 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <utils/submiteditorwidget.h>
|
|
|
|
|
#include <find/basetextfind.h>
|
|
|
|
|
|
2009-01-09 17:52:41 +01:00
|
|
|
#include <projectexplorer/projectexplorer.h>
|
|
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <QtCore/QDebug>
|
2009-01-09 17:52:41 +01:00
|
|
|
#include <QtCore/QDir>
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <QtCore/QFile>
|
|
|
|
|
#include <QtCore/QFileInfo>
|
|
|
|
|
#include <QtCore/QPointer>
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <QtCore/QTextStream>
|
2009-01-19 12:39:20 +01:00
|
|
|
#include <QtGui/QStyle>
|
|
|
|
|
#include <QtGui/QToolBar>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
enum { debug = 0 };
|
2008-12-02 17:05:53 +01:00
|
|
|
enum { wantToolBar = 0 };
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
namespace VCSBase {
|
|
|
|
|
|
2009-01-20 11:52:04 +01:00
|
|
|
struct VCSBaseSubmitEditorPrivate
|
|
|
|
|
{
|
2008-12-02 12:01:29 +01:00
|
|
|
VCSBaseSubmitEditorPrivate(const VCSBaseSubmitEditorParameters *parameters,
|
|
|
|
|
Core::Utils::SubmitEditorWidget *editorWidget,
|
|
|
|
|
QObject *q);
|
|
|
|
|
|
|
|
|
|
Core::Utils::SubmitEditorWidget *m_widget;
|
|
|
|
|
QToolBar *m_toolWidget;
|
|
|
|
|
const VCSBaseSubmitEditorParameters *m_parameters;
|
|
|
|
|
QString m_displayName;
|
|
|
|
|
VCSBase::Internal::SubmitEditorFile *m_file;
|
|
|
|
|
QList<int> m_contexts;
|
|
|
|
|
|
|
|
|
|
QPointer<QAction> m_diffAction;
|
2009-01-13 14:06:42 +01:00
|
|
|
QPointer<QAction> m_submitAction;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
VCSBaseSubmitEditorPrivate::VCSBaseSubmitEditorPrivate(const VCSBaseSubmitEditorParameters *parameters,
|
|
|
|
|
Core::Utils::SubmitEditorWidget *editorWidget,
|
|
|
|
|
QObject *q) :
|
|
|
|
|
m_widget(editorWidget),
|
|
|
|
|
m_toolWidget(0),
|
|
|
|
|
m_parameters(parameters),
|
2009-01-13 14:06:42 +01:00
|
|
|
m_file(new VCSBase::Internal::SubmitEditorFile(QLatin1String(m_parameters->mimeType), q))
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-20 11:52:04 +01:00
|
|
|
m_contexts << Core::ICore::instance()->uniqueIDManager()->uniqueIdentifier(m_parameters->context);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VCSBaseSubmitEditor::VCSBaseSubmitEditor(const VCSBaseSubmitEditorParameters *parameters,
|
|
|
|
|
Core::Utils::SubmitEditorWidget *editorWidget) :
|
|
|
|
|
m_d(new VCSBaseSubmitEditorPrivate(parameters, editorWidget, this))
|
|
|
|
|
{
|
|
|
|
|
m_d->m_file->setModified(false);
|
|
|
|
|
// We are always clean to prevent the editor manager from asking to save.
|
|
|
|
|
connect(m_d->m_file, SIGNAL(saveMe(QString)), this, SLOT(save(QString)));
|
|
|
|
|
|
|
|
|
|
connect(m_d->m_widget, SIGNAL(diffSelected(QStringList)), this, SLOT(slotDiffSelectedVCSFiles(QStringList)));
|
|
|
|
|
connect(m_d->m_widget->descriptionEdit(), SIGNAL(textChanged()), this, SLOT(slotDescriptionChanged()));
|
|
|
|
|
|
|
|
|
|
Aggregation::Aggregate *aggregate = new Aggregation::Aggregate;
|
|
|
|
|
aggregate->add(new Find::BaseTextFind(m_d->m_widget->descriptionEdit()));
|
|
|
|
|
aggregate->add(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VCSBaseSubmitEditor::~VCSBaseSubmitEditor()
|
|
|
|
|
{
|
|
|
|
|
delete m_d->m_toolWidget;
|
|
|
|
|
delete m_d->m_widget;
|
|
|
|
|
delete m_d;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-13 14:06:42 +01:00
|
|
|
void VCSBaseSubmitEditor::registerActions(QAction *editorUndoAction, QAction *editorRedoAction,
|
|
|
|
|
QAction *submitAction, QAction *diffAction)\
|
|
|
|
|
{
|
|
|
|
|
m_d->m_widget->registerActions(editorUndoAction, editorRedoAction, submitAction, diffAction);
|
|
|
|
|
m_d->m_diffAction = diffAction;
|
|
|
|
|
m_d->m_submitAction = submitAction;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VCSBaseSubmitEditor::unregisterActions(QAction *editorUndoAction, QAction *editorRedoAction,
|
|
|
|
|
QAction *submitAction, QAction *diffAction)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_widget->unregisterActions(editorUndoAction, editorRedoAction, submitAction, diffAction);
|
|
|
|
|
m_d->m_diffAction = m_d->m_submitAction = 0;
|
|
|
|
|
}
|
2009-01-12 17:44:04 +01:00
|
|
|
int VCSBaseSubmitEditor::fileNameColumn() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_widget->fileNameColumn();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VCSBaseSubmitEditor::setFileNameColumn(int c)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_widget->setFileNameColumn(c);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-13 10:06:06 +01:00
|
|
|
QAbstractItemView::SelectionMode VCSBaseSubmitEditor::fileListSelectionMode() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_widget->fileListSelectionMode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VCSBaseSubmitEditor::setFileListSelectionMode(QAbstractItemView::SelectionMode sm)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_widget->setFileListSelectionMode(sm);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void VCSBaseSubmitEditor::slotDescriptionChanged()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VCSBaseSubmitEditor::createNew(const QString &contents)
|
|
|
|
|
{
|
|
|
|
|
setFileContents(contents);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VCSBaseSubmitEditor::open(const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
if (fileName.isEmpty())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
const QFileInfo fi(fileName);
|
|
|
|
|
if (!fi.isFile() || !fi.isReadable())
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
QFile file(fileName);
|
|
|
|
|
if (!file.open(QIODevice::ReadOnly|QIODevice::Text)) {
|
|
|
|
|
qWarning("Unable to open %s: %s", qPrintable(fileName), qPrintable(file.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const QString text = QString::fromLocal8Bit(file.readAll());
|
|
|
|
|
if (!createNew(text))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
m_d->m_file->setFileName(fi.absoluteFilePath());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::IFile *VCSBaseSubmitEditor::file()
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString VCSBaseSubmitEditor::displayName() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_displayName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void VCSBaseSubmitEditor::setDisplayName(const QString &title)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_displayName = title;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VCSBaseSubmitEditor::duplicateSupported() const
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Core::IEditor *VCSBaseSubmitEditor::duplicate(QWidget * /*parent*/)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *VCSBaseSubmitEditor::kind() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_parameters->kind;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 17:05:53 +01:00
|
|
|
static QToolBar *createToolBar(const QWidget *someWidget, QAction *submitAction, QAction *diffAction)
|
|
|
|
|
{
|
|
|
|
|
// Create
|
|
|
|
|
QToolBar *toolBar = new QToolBar;
|
|
|
|
|
toolBar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
|
|
|
|
|
const int size = someWidget->style()->pixelMetric(QStyle::PM_SmallIconSize);
|
|
|
|
|
toolBar->setIconSize(QSize(size, size));
|
|
|
|
|
toolBar->addSeparator();
|
|
|
|
|
|
|
|
|
|
if (submitAction)
|
|
|
|
|
toolBar->addAction(submitAction);
|
|
|
|
|
if (diffAction)
|
|
|
|
|
toolBar->addAction(diffAction);
|
|
|
|
|
return toolBar;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QToolBar *VCSBaseSubmitEditor::toolBar()
|
|
|
|
|
{
|
2008-12-02 17:05:53 +01:00
|
|
|
if (!wantToolBar)
|
|
|
|
|
return 0;
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
if (m_d->m_toolWidget)
|
|
|
|
|
return m_d->m_toolWidget;
|
|
|
|
|
|
|
|
|
|
if (!m_d->m_diffAction && !m_d->m_submitAction)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
// Create
|
2008-12-02 17:05:53 +01:00
|
|
|
m_d->m_toolWidget = createToolBar(m_d->m_widget, m_d->m_submitAction, m_d->m_diffAction);
|
|
|
|
|
return m_d->m_toolWidget;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<int> VCSBaseSubmitEditor::context() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_contexts;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QWidget *VCSBaseSubmitEditor::widget()
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QByteArray VCSBaseSubmitEditor::saveState() const
|
|
|
|
|
{
|
|
|
|
|
return QByteArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VCSBaseSubmitEditor::restoreState(const QByteArray &/*state*/)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-03 13:21:50 +01:00
|
|
|
QStringList VCSBaseSubmitEditor::checkedFiles() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-12 17:44:04 +01:00
|
|
|
return m_d->m_widget->checkedFiles();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-12 17:44:04 +01:00
|
|
|
void VCSBaseSubmitEditor::setFileModel(QAbstractItemModel *m)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-12 17:44:04 +01:00
|
|
|
m_d->m_widget->setFileModel(m);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-12 17:44:04 +01:00
|
|
|
QAbstractItemModel *VCSBaseSubmitEditor::fileModel() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-12 17:44:04 +01:00
|
|
|
return m_d->m_widget->fileModel();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-03 13:21:50 +01:00
|
|
|
void VCSBaseSubmitEditor::slotDiffSelectedVCSFiles(const QStringList &rawList)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-01-12 17:44:04 +01:00
|
|
|
emit diffSelectedFiles(rawList);
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VCSBaseSubmitEditor::save(const QString &fileName)
|
|
|
|
|
{
|
|
|
|
|
const QString fName = fileName.isEmpty() ? m_d->m_file->fileName() : fileName;
|
|
|
|
|
QFile file(fName);
|
|
|
|
|
if (!file.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text)) {
|
|
|
|
|
qWarning("Unable to open %s: %s", qPrintable(fName), qPrintable(file.errorString()));
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
file.write(fileContents().toLocal8Bit());
|
|
|
|
|
if (!file.flush())
|
|
|
|
|
return false;
|
|
|
|
|
file.close();
|
|
|
|
|
const QFileInfo fi(fName);
|
|
|
|
|
m_d->m_file->setFileName(fi.absoluteFilePath());
|
|
|
|
|
m_d->m_file->setModified(false);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString VCSBaseSubmitEditor::fileContents() const
|
|
|
|
|
{
|
|
|
|
|
return m_d->m_widget->trimmedDescriptionText();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool VCSBaseSubmitEditor::setFileContents(const QString &contents)
|
|
|
|
|
{
|
|
|
|
|
m_d->m_widget->setDescriptionText(contents);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 17:05:53 +01:00
|
|
|
QIcon VCSBaseSubmitEditor::diffIcon()
|
|
|
|
|
{
|
|
|
|
|
return QIcon(QLatin1String(":/vcsbase/images/diff.png"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QIcon VCSBaseSubmitEditor::submitIcon()
|
|
|
|
|
{
|
|
|
|
|
return QIcon(QLatin1String(":/vcsbase/images/submit.png"));
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-09 17:52:41 +01:00
|
|
|
QStringList VCSBaseSubmitEditor::currentProjectFiles(bool nativeSeparators, QString *name)
|
|
|
|
|
{
|
|
|
|
|
if (name)
|
|
|
|
|
name->clear();
|
|
|
|
|
ProjectExplorer::ProjectExplorerPlugin *projectExplorer = ExtensionSystem::PluginManager::instance()->getObject<ProjectExplorer::ProjectExplorerPlugin>();
|
|
|
|
|
if (!projectExplorer)
|
|
|
|
|
return QStringList();
|
|
|
|
|
QStringList files;
|
|
|
|
|
if (const ProjectExplorer::Project *currentProject = projectExplorer->currentProject()) {
|
|
|
|
|
files << currentProject->files(ProjectExplorer::Project::ExcludeGeneratedFiles);
|
|
|
|
|
if (name)
|
|
|
|
|
*name = currentProject->name();
|
|
|
|
|
} else {
|
|
|
|
|
if (const ProjectExplorer::SessionManager *session = projectExplorer->session()) {
|
|
|
|
|
if (name)
|
|
|
|
|
*name = session->file()->fileName();
|
|
|
|
|
const QList<ProjectExplorer::Project *> projects = session->projects();
|
|
|
|
|
foreach (ProjectExplorer::Project *project, projects)
|
|
|
|
|
files << project->files(ProjectExplorer::Project::ExcludeGeneratedFiles);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (nativeSeparators && !files.empty()) {
|
|
|
|
|
const QStringList::iterator end = files.end();
|
|
|
|
|
for (QStringList::iterator it = files.begin(); it != end; ++it)
|
|
|
|
|
*it = QDir::toNativeSeparators(*it);
|
|
|
|
|
}
|
|
|
|
|
return files;
|
|
|
|
|
}
|
2008-12-03 13:21:50 +01:00
|
|
|
} // namespace VCSBase
|