2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2011-01-11 16:28:15 +01:00
|
|
|
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2011-11-02 15:59:12 +01:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** This file may be used under the terms of the GNU Lesser General Public
|
|
|
|
|
** License version 2.1 as published by the Free Software Foundation and
|
|
|
|
|
** appearing in the file LICENSE.LGPL included in the packaging of this file.
|
|
|
|
|
** Please review the following information to ensure the GNU Lesser General
|
|
|
|
|
** Public License version 2.1 requirements will be met:
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** In addition, as a special exception, Nokia gives you certain additional
|
2011-04-13 08:42:33 +02:00
|
|
|
** rights. These rights are described in the Nokia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2011-04-13 08:42:33 +02:00
|
|
|
** Other Usage
|
|
|
|
|
**
|
|
|
|
|
** Alternatively, this file may be used in accordance with the terms and
|
|
|
|
|
** conditions contained in a signed written agreement between you and Nokia.
|
|
|
|
|
**
|
2010-12-17 16:01:08 +01:00
|
|
|
** If you have questions regarding the use of this file, please contact
|
2011-11-02 15:59:12 +01:00
|
|
|
** Nokia at qt-info@nokia.com.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-02 16:19:05 +01:00
|
|
|
|
|
|
|
|
#ifndef VCSBASE_BASEEDITOR_H
|
|
|
|
|
#define VCSBASE_BASEEDITOR_H
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#include "vcsbase_global.h"
|
|
|
|
|
|
|
|
|
|
#include <texteditor/basetexteditor.h>
|
|
|
|
|
|
|
|
|
|
#include <QtCore/QSet>
|
|
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QAction;
|
|
|
|
|
class QTextCodec;
|
|
|
|
|
class QTextCursor;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
2012-01-07 03:35:54 +01:00
|
|
|
namespace Core { class IVersionControl; }
|
2009-12-08 16:50:27 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
namespace VcsBase {
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
namespace Internal { class VcsBaseEditorWidgetPrivate; }
|
2011-12-08 13:07:00 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
class DiffHighlighter;
|
|
|
|
|
class BaseAnnotationHighlighter;
|
|
|
|
|
|
2011-03-28 14:19:17 +02:00
|
|
|
// Documentation inside
|
2012-01-07 03:35:54 +01:00
|
|
|
enum EditorContentType
|
|
|
|
|
{
|
2008-12-02 12:01:29 +01:00
|
|
|
RegularCommandOutput,
|
|
|
|
|
LogOutput,
|
|
|
|
|
AnnotateOutput,
|
|
|
|
|
DiffOutput
|
|
|
|
|
};
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
class VCSBASE_EXPORT VcsBaseEditorParameters
|
2011-02-21 16:02:26 +01:00
|
|
|
{
|
2011-12-08 13:07:00 +01:00
|
|
|
public:
|
2008-12-02 12:01:29 +01:00
|
|
|
EditorContentType type;
|
2010-01-08 09:48:54 +01:00
|
|
|
const char *id;
|
|
|
|
|
const char *displayName;
|
2008-12-02 12:01:29 +01:00
|
|
|
const char *context;
|
|
|
|
|
const char *mimeType;
|
|
|
|
|
const char *extension;
|
|
|
|
|
};
|
|
|
|
|
|
2011-03-24 15:44:39 +01:00
|
|
|
class VCSBASE_EXPORT DiffChunk
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
bool isValid() const;
|
|
|
|
|
QByteArray asPatch() const;
|
|
|
|
|
|
|
|
|
|
QString fileName;
|
|
|
|
|
QByteArray chunk;
|
|
|
|
|
};
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
class VCSBASE_EXPORT VcsBaseEditorWidget : public TextEditor::BaseTextEditorWidget
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2009-07-11 09:41:57 +02:00
|
|
|
Q_PROPERTY(QString source READ source WRITE setSource)
|
2009-12-09 12:41:10 +01:00
|
|
|
Q_PROPERTY(QString diffBaseDirectory READ diffBaseDirectory WRITE setDiffBaseDirectory)
|
2009-07-11 09:41:57 +02:00
|
|
|
Q_PROPERTY(QTextCodec *codec READ codec WRITE setCodec)
|
2010-01-07 11:33:30 +01:00
|
|
|
Q_PROPERTY(QString annotateRevisionTextFormat READ annotateRevisionTextFormat WRITE setAnnotateRevisionTextFormat)
|
2010-01-07 17:29:58 +01:00
|
|
|
Q_PROPERTY(QString copyRevisionTextFormat READ copyRevisionTextFormat WRITE setCopyRevisionTextFormat)
|
2010-01-07 11:33:30 +01:00
|
|
|
Q_PROPERTY(bool isFileLogAnnotateEnabled READ isFileLogAnnotateEnabled WRITE setFileLogAnnotateEnabled)
|
2011-03-24 15:44:39 +01:00
|
|
|
Q_PROPERTY(bool revertDiffChunkEnabled READ isRevertDiffChunkEnabled WRITE setRevertDiffChunkEnabled)
|
2008-12-02 12:01:29 +01:00
|
|
|
Q_OBJECT
|
2011-02-21 16:02:26 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
protected:
|
|
|
|
|
// Initialization requires calling init() (which in turns calls
|
|
|
|
|
// virtual functions).
|
2012-01-07 12:31:48 +01:00
|
|
|
explicit VcsBaseEditorWidget(const VcsBaseEditorParameters *type,
|
2008-12-02 12:01:29 +01:00
|
|
|
QWidget *parent);
|
|
|
|
|
public:
|
|
|
|
|
void init();
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
~VcsBaseEditorWidget();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-06-07 14:53:28 +02:00
|
|
|
/* Force read-only: Make it a read-only, temporary file.
|
|
|
|
|
* Should be set to true by version control views. It is not on
|
|
|
|
|
* by default since it should not trigger when patches are opened as
|
|
|
|
|
* files. */
|
|
|
|
|
void setForceReadOnly(bool b);
|
|
|
|
|
bool isForceReadOnly() const;
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QString source() const;
|
|
|
|
|
void setSource(const QString &source);
|
|
|
|
|
|
2010-01-07 11:33:30 +01:00
|
|
|
// Format for "Annotate" revision menu entries. Should contain '%1" placeholder
|
|
|
|
|
QString annotateRevisionTextFormat() const;
|
|
|
|
|
void setAnnotateRevisionTextFormat(const QString &);
|
|
|
|
|
|
2010-08-13 09:12:27 +02:00
|
|
|
// Format for "Annotate Previous" revision menu entries. Should contain '%1" placeholder.
|
|
|
|
|
// Defaults to "annotateRevisionTextFormat" if unset.
|
|
|
|
|
QString annotatePreviousRevisionTextFormat() const;
|
|
|
|
|
void setAnnotatePreviousRevisionTextFormat(const QString &);
|
|
|
|
|
|
2010-01-07 17:29:58 +01:00
|
|
|
// Format for "Copy" revision menu entries. Should contain '%1" placeholder
|
|
|
|
|
QString copyRevisionTextFormat() const;
|
|
|
|
|
void setCopyRevisionTextFormat(const QString &);
|
|
|
|
|
|
2010-01-07 11:33:30 +01:00
|
|
|
// Enable "Annotate" context menu in file log view
|
|
|
|
|
// (set to true if the source is a single file and the VCS implements it)
|
|
|
|
|
bool isFileLogAnnotateEnabled() const;
|
|
|
|
|
void setFileLogAnnotateEnabled(bool e);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QTextCodec *codec() const;
|
|
|
|
|
void setCodec(QTextCodec *);
|
|
|
|
|
|
2009-12-09 12:41:10 +01:00
|
|
|
// Base directory for diff views
|
|
|
|
|
QString diffBaseDirectory() const;
|
|
|
|
|
void setDiffBaseDirectory(const QString &d);
|
|
|
|
|
|
2011-03-24 15:44:39 +01:00
|
|
|
// Diff: Can revert?
|
|
|
|
|
bool isRevertDiffChunkEnabled() const;
|
|
|
|
|
void setRevertDiffChunkEnabled(bool e);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
bool isModified() const;
|
|
|
|
|
|
|
|
|
|
EditorContentType contentType() const;
|
|
|
|
|
|
|
|
|
|
// Utility to find a parameter set by type in an array.
|
2012-01-07 12:31:48 +01:00
|
|
|
static const VcsBaseEditorParameters *
|
|
|
|
|
findType(const VcsBaseEditorParameters *array, int arraySize, EditorContentType et);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
// Utility to find the codec for a source (file or directory), querying
|
|
|
|
|
// the editor manager and the project managers (defaults to system codec).
|
|
|
|
|
// The codec should be set on editors displaying diff or annotation
|
|
|
|
|
// output.
|
2009-01-20 11:52:04 +01:00
|
|
|
static QTextCodec *getCodec(const QString &source);
|
2009-12-08 16:50:27 +01:00
|
|
|
static QTextCodec *getCodec(const QString &workingDirectory, const QStringList &files);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-02-21 16:02:26 +01:00
|
|
|
// Utility to return the widget from the IEditor returned by the editor
|
|
|
|
|
// manager which is a BaseTextEditor.
|
2012-01-07 12:31:48 +01:00
|
|
|
static VcsBaseEditorWidget *getVcsBaseEditor(const Core::IEditor *editor);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-10-01 17:32:26 +02:00
|
|
|
// Utility to find the line number of the current editor. Optionally,
|
|
|
|
|
// pass in the file name to match it. To be used when jumping to current
|
|
|
|
|
// line number in a 'annnotate current file' slot, which checks if the
|
|
|
|
|
// current file originates from the current editor or the project selection.
|
|
|
|
|
static int lineNumberOfCurrentEditor(const QString ¤tFile = QString());
|
|
|
|
|
|
|
|
|
|
//Helper to go to line of editor if it is a text editor
|
|
|
|
|
static bool gotoLineOfEditor(Core::IEditor *e, int lineNumber);
|
|
|
|
|
|
2009-12-08 14:26:41 +01:00
|
|
|
// Convenience functions to determine the source to pass on to a diff
|
|
|
|
|
// editor if one has a call consisting of working directory and file arguments.
|
|
|
|
|
// ('git diff XX' -> 'XX' , 'git diff XX file' -> 'XX/file').
|
|
|
|
|
static QString getSource(const QString &workingDirectory, const QString &fileName);
|
2009-12-09 12:41:10 +01:00
|
|
|
static QString getSource(const QString &workingDirectory, const QStringList &fileNames);
|
2009-12-08 14:26:41 +01:00
|
|
|
// Convenience functions to determine an title/id to identify the editor
|
2010-01-07 11:33:30 +01:00
|
|
|
// from the arguments (','-joined arguments or directory) + revision.
|
2010-01-06 17:24:40 +01:00
|
|
|
static QString getTitleId(const QString &workingDirectory,
|
|
|
|
|
const QStringList &fileNames,
|
|
|
|
|
const QString &revision = QString());
|
2010-11-18 16:58:30 +01:00
|
|
|
|
|
|
|
|
bool setConfigurationWidget(QWidget *w);
|
|
|
|
|
QWidget *configurationWidget() const;
|
|
|
|
|
|
2011-03-31 10:57:33 +02:00
|
|
|
/* Tagging editors: Sometimes, an editor should be re-used, for example, when showing
|
|
|
|
|
* a diff of the same file with different diff-options. In order to be able to find
|
|
|
|
|
* the editor, they get a 'tag' containing type and parameters (dynamic property string). */
|
|
|
|
|
static void tagEditor(Core::IEditor *e, const QString &tag);
|
|
|
|
|
static Core::IEditor* locateEditorByTag(const QString &tag);
|
|
|
|
|
static QString editorTag(EditorContentType t, const QString &workingDirectory, const QStringList &files,
|
|
|
|
|
const QString &revision = QString());
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
signals:
|
2010-01-06 17:24:40 +01:00
|
|
|
// These signals also exist in the opaque editable (IEditor) that is
|
2010-01-07 11:33:30 +01:00
|
|
|
// handled by the editor manager for convenience. They are emitted
|
|
|
|
|
// for LogOutput/AnnotateOutput content types.
|
2008-12-02 12:01:29 +01:00
|
|
|
void describeRequested(const QString &source, const QString &change);
|
2010-01-07 11:33:30 +01:00
|
|
|
void annotateRevisionRequested(const QString &source, const QString &change, int lineNumber);
|
2012-01-07 12:31:48 +01:00
|
|
|
void diffChunkApplied(const VcsBase::DiffChunk &dc);
|
|
|
|
|
void diffChunkReverted(const VcsBase::DiffChunk &dc);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
// Convenience slot to set data read from stdout, will use the
|
|
|
|
|
// documents' codec to decode
|
|
|
|
|
void setPlainTextData(const QByteArray &data);
|
|
|
|
|
|
|
|
|
|
protected:
|
2011-02-21 16:02:26 +01:00
|
|
|
virtual TextEditor::BaseTextEditor *createEditor();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
void contextMenuEvent(QContextMenuEvent *e);
|
|
|
|
|
void mouseMoveEvent(QMouseEvent *e);
|
|
|
|
|
void mouseReleaseEvent(QMouseEvent *e);
|
|
|
|
|
void mouseDoubleClickEvent(QMouseEvent *e);
|
|
|
|
|
void keyPressEvent(QKeyEvent *);
|
|
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
void setFontSettings(const TextEditor::FontSettings &);
|
|
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void describe();
|
|
|
|
|
void slotActivateAnnotation();
|
2009-03-10 11:02:12 +01:00
|
|
|
void slotPopulateDiffBrowser();
|
|
|
|
|
void slotDiffBrowse(int);
|
|
|
|
|
void slotDiffCursorPositionChanged();
|
2010-01-07 11:33:30 +01:00
|
|
|
void slotAnnotateRevision();
|
2010-01-07 17:29:58 +01:00
|
|
|
void slotCopyRevision();
|
2011-08-12 13:42:21 +02:00
|
|
|
void slotApplyDiffChunk();
|
2011-04-21 15:21:50 +02:00
|
|
|
void slotPaste();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-12-08 16:50:27 +01:00
|
|
|
protected:
|
|
|
|
|
/* A helper that can be used to locate a file in a diff in case it
|
2009-12-09 12:41:10 +01:00
|
|
|
* is relative. Tries to derive the directory from base directory,
|
|
|
|
|
* source and version control. */
|
2009-12-08 16:50:27 +01:00
|
|
|
QString findDiffFile(const QString &f, Core::IVersionControl *control = 0) const;
|
|
|
|
|
|
2011-08-12 13:42:21 +02:00
|
|
|
virtual bool canApplyDiffChunk(const DiffChunk &dc) const;
|
2011-05-10 15:19:38 +02:00
|
|
|
// Revert a patch chunk. Default implementation uses patch.exe
|
2011-08-12 13:42:21 +02:00
|
|
|
virtual bool applyDiffChunk(const DiffChunk &dc, bool revert = false) const;
|
2011-03-24 15:44:39 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
private:
|
|
|
|
|
// Implement to return a set of change identifiers in
|
|
|
|
|
// annotation mode
|
|
|
|
|
virtual QSet<QString> annotationChanges() const = 0;
|
|
|
|
|
// Implement to identify a change number at the cursor position
|
|
|
|
|
virtual QString changeUnderCursor(const QTextCursor &) const = 0;
|
|
|
|
|
// Factory functions for highlighters
|
|
|
|
|
virtual DiffHighlighter *createDiffHighlighter() const = 0;
|
|
|
|
|
virtual BaseAnnotationHighlighter *createAnnotationHighlighter(const QSet<QString> &changes) const = 0;
|
|
|
|
|
// Implement to return a local file name from the diff file specification
|
|
|
|
|
// (text cursor at position above change hunk)
|
|
|
|
|
virtual QString fileNameFromDiffSpecification(const QTextBlock &diffFileSpec) const = 0;
|
2010-01-06 17:24:40 +01:00
|
|
|
// Implement to return the previous version[s] of an annotation change
|
2010-01-07 11:33:30 +01:00
|
|
|
// for "Annotate previous version"
|
|
|
|
|
virtual QStringList annotationPreviousVersions(const QString &revision) const;
|
2011-03-24 15:44:39 +01:00
|
|
|
// cut out chunk and determine file name.
|
|
|
|
|
DiffChunk diffChunk(QTextCursor cursor) const;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
void jumpToChangeFromDiff(QTextCursor cursor);
|
2010-01-07 11:33:30 +01:00
|
|
|
QAction *createDescribeAction(const QString &change);
|
2010-08-13 09:12:27 +02:00
|
|
|
QAction *createAnnotateAction(const QString &change, bool previous = false);
|
2010-01-07 17:29:58 +01:00
|
|
|
QAction *createCopyRevisionAction(const QString &change);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
Internal::VcsBaseEditorWidgetPrivate *const d;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
} // namespace VcsBase
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
Q_DECLARE_METATYPE(VcsBase::DiffChunk)
|
2011-03-24 15:44:39 +01:00
|
|
|
|
2008-12-02 16:19:05 +01:00
|
|
|
#endif // VCSBASE_BASEEDITOR_H
|