2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2008-12-02 16:19:05 +01:00
|
|
|
|
2016-02-03 12:15:21 +01:00
|
|
|
#pragma once
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-12-08 14:26:41 +01:00
|
|
|
#include "vcsbase_global.h"
|
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
#include <coreplugin/icontext.h>
|
2017-06-15 13:37:33 +02:00
|
|
|
#include <coreplugin/iversioncontrol.h>
|
|
|
|
#include <coreplugin/vcsmanager.h>
|
2021-05-04 05:54:54 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include <extensionsystem/iplugin.h>
|
|
|
|
|
2016-02-03 12:15:21 +01:00
|
|
|
#include <QSharedDataPointer>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-03-20 14:20:28 +01:00
|
|
|
QT_BEGIN_NAMESPACE
|
2009-12-08 14:26:41 +01:00
|
|
|
class QAction;
|
2009-03-20 14:20:28 +01:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2022-07-29 15:56:28 +02:00
|
|
|
namespace Utils { class Environment; }
|
2010-05-21 17:46:00 +02:00
|
|
|
|
2013-03-25 11:36:51 +01:00
|
|
|
namespace Core {
|
2014-11-16 12:05:34 +02:00
|
|
|
class Context;
|
2013-03-25 11:36:51 +01:00
|
|
|
class IVersionControl;
|
2014-02-11 13:00:35 +01:00
|
|
|
class IDocument;
|
2016-07-20 13:44:47 +02:00
|
|
|
} // namespace Core
|
2009-12-08 14:26:41 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
namespace VcsBase {
|
2012-01-07 03:35:54 +01:00
|
|
|
|
2015-09-16 14:54:58 +02:00
|
|
|
namespace Internal { class State; }
|
2009-12-08 14:26:41 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
class VcsBaseSubmitEditor;
|
2013-10-14 15:38:00 +02:00
|
|
|
class VcsBasePluginPrivate;
|
2012-01-07 12:31:48 +01:00
|
|
|
class VcsBasePluginStateData;
|
2022-08-01 11:49:33 +02:00
|
|
|
class VcsCommand;
|
2009-12-08 14:26:41 +01:00
|
|
|
|
2011-03-28 14:19:17 +02:00
|
|
|
// Documentation inside.
|
2012-01-07 12:31:48 +01:00
|
|
|
class VCSBASE_EXPORT VcsBasePluginState
|
2009-12-08 14:26:41 +01:00
|
|
|
{
|
|
|
|
public:
|
2012-01-07 12:31:48 +01:00
|
|
|
VcsBasePluginState();
|
|
|
|
VcsBasePluginState(const VcsBasePluginState &);
|
|
|
|
VcsBasePluginState &operator=(const VcsBasePluginState &);
|
|
|
|
~VcsBasePluginState();
|
2009-12-08 14:26:41 +01:00
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
bool isEmpty() const;
|
|
|
|
bool hasFile() const;
|
2010-03-25 16:23:37 +01:00
|
|
|
bool hasPatchFile() const;
|
2009-12-08 14:26:41 +01:00
|
|
|
bool hasProject() const;
|
|
|
|
bool hasTopLevel() const;
|
|
|
|
|
|
|
|
// Current file.
|
|
|
|
QString currentFile() const;
|
|
|
|
QString currentFileName() const;
|
2021-07-30 16:46:27 +02:00
|
|
|
Utils::FilePath currentFileDirectory() const;
|
|
|
|
Utils::FilePath currentFileTopLevel() const;
|
2009-12-08 14:26:41 +01:00
|
|
|
// Convenience: Returns file relative to top level.
|
|
|
|
QString relativeCurrentFile() const;
|
|
|
|
|
2010-03-25 16:23:37 +01:00
|
|
|
// If the current file looks like a patch and there is a top level,
|
|
|
|
// it will end up here (for VCS that offer patch functionality).
|
|
|
|
QString currentPatchFile() const;
|
|
|
|
QString currentPatchFileDisplayName() const;
|
|
|
|
|
2009-12-08 14:26:41 +01:00
|
|
|
// Current project.
|
2021-07-30 16:46:27 +02:00
|
|
|
Utils::FilePath currentProjectPath() const;
|
2009-12-08 14:26:41 +01:00
|
|
|
QString currentProjectName() const;
|
2021-07-30 16:46:27 +02:00
|
|
|
Utils::FilePath currentProjectTopLevel() const;
|
2009-12-08 14:26:41 +01:00
|
|
|
/* Convenience: Returns project path relative to top level if it
|
2013-08-06 15:14:54 +03:00
|
|
|
* differs from top level (else empty string) as an argument list to do
|
2009-12-08 14:26:41 +01:00
|
|
|
* eg a 'vcs diff <args>' */
|
2013-08-06 15:14:54 +03:00
|
|
|
QString relativeCurrentProject() const;
|
2009-12-08 14:26:41 +01:00
|
|
|
|
|
|
|
// Top level directory for actions on the top level. Preferably
|
|
|
|
// the file one.
|
2021-07-30 16:46:27 +02:00
|
|
|
Utils::FilePath topLevel() const;
|
2009-12-08 14:26:41 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
bool equals(const VcsBasePluginState &rhs) const;
|
2009-12-08 14:26:41 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
friend VCSBASE_EXPORT QDebug operator<<(QDebug in, const VcsBasePluginState &state);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2021-12-06 05:11:04 +01:00
|
|
|
friend bool operator==(const VcsBasePluginState &s1, const VcsBasePluginState &s2)
|
|
|
|
{ return s1.equals(s2); }
|
|
|
|
friend bool operator!=(const VcsBasePluginState &s1, const VcsBasePluginState &s2)
|
|
|
|
{ return !s1.equals(s2); }
|
|
|
|
|
2009-12-08 14:26:41 +01:00
|
|
|
private:
|
2020-01-23 17:22:05 +01:00
|
|
|
friend class VcsBasePluginPrivate;
|
2009-12-08 14:26:41 +01:00
|
|
|
bool equals(const Internal::State &s) const;
|
|
|
|
void setState(const Internal::State &s);
|
2009-03-19 17:40:01 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
QSharedDataPointer<VcsBasePluginStateData> data;
|
2009-12-08 14:26:41 +01:00
|
|
|
};
|
|
|
|
|
2020-01-22 13:29:46 +01:00
|
|
|
// Convenience that searches for the repository specifically for version control
|
|
|
|
// systems that do not have directories like "CVS" in each managed subdirectory
|
|
|
|
// but have a directory at the top of the repository like ".git" containing
|
|
|
|
// a well known file. See implementation for gory details.
|
2021-07-29 17:54:14 +02:00
|
|
|
VCSBASE_EXPORT Utils::FilePath findRepositoryForFile(const Utils::FilePath &fileOrDir,
|
|
|
|
const QString &checkFile);
|
2020-01-22 13:29:46 +01:00
|
|
|
|
|
|
|
// Set up the environment for a version control command line call.
|
|
|
|
// Sets up SSH graphical password prompting (note that the latter
|
|
|
|
// requires a terminal-less process) and sets LANG to 'C' to force English
|
|
|
|
// (suppress LOCALE warnings/parse commands output) if desired.
|
2022-07-13 17:54:59 +02:00
|
|
|
VCSBASE_EXPORT void setProcessEnvironment(Utils::Environment *e);
|
2020-01-22 13:29:46 +01:00
|
|
|
// Sets the source of editor contents, can be directory or file.
|
|
|
|
VCSBASE_EXPORT void setSource(Core::IDocument *document, const QString &source);
|
|
|
|
// Returns the source of editor contents.
|
|
|
|
VCSBASE_EXPORT QString source(Core::IDocument *document);
|
|
|
|
|
2020-01-30 12:31:47 +01:00
|
|
|
class VCSBASE_EXPORT VcsBasePluginPrivate : public Core::IVersionControl
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2009-12-08 14:26:41 +01:00
|
|
|
protected:
|
2020-01-30 12:31:47 +01:00
|
|
|
explicit VcsBasePluginPrivate(const Core::Context &context);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
public:
|
2020-01-23 17:22:05 +01:00
|
|
|
void extensionsInitialized();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
const VcsBasePluginState ¤tState() const;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2022-08-01 11:49:33 +02:00
|
|
|
/*!
|
|
|
|
* Return a VcsCommand capable of checking out \a url into \a baseDirectory, where
|
|
|
|
* a new subdirectory with \a localName will be created.
|
|
|
|
*
|
|
|
|
* \a extraArgs are passed on to the command being run.
|
|
|
|
*/
|
|
|
|
virtual VcsCommand *createInitialCheckoutCommand(const QString &url,
|
|
|
|
const Utils::FilePath &baseDirectory,
|
|
|
|
const QString &localName,
|
|
|
|
const QStringList &extraArgs);
|
2018-08-28 00:03:59 +03:00
|
|
|
// Display name of the commit action
|
2017-09-08 12:52:35 +02:00
|
|
|
virtual QString commitDisplayName() const;
|
2018-08-28 00:03:59 +03:00
|
|
|
|
2022-10-16 05:58:20 +03:00
|
|
|
void commitFromEditor();
|
2022-10-22 22:16:44 +03:00
|
|
|
virtual bool activateCommit() = 0;
|
2018-08-28 00:03:59 +03:00
|
|
|
|
|
|
|
protected:
|
2017-09-08 12:52:35 +02:00
|
|
|
// Prompt to save all files before commit:
|
|
|
|
bool promptBeforeCommit();
|
|
|
|
|
2010-01-11 15:22:17 +01:00
|
|
|
// Convenience slot for "Delete current file" action. Prompts to
|
2012-01-07 12:31:48 +01:00
|
|
|
// delete the file via VcsManager.
|
2010-01-11 15:22:17 +01:00
|
|
|
void promptToDeleteCurrentFile();
|
2010-02-01 12:43:56 +01:00
|
|
|
// Prompt to initialize version control in a directory, initially
|
2010-01-12 16:45:21 +01:00
|
|
|
// pointing to the current project.
|
|
|
|
void createRepository();
|
2010-01-11 15:22:17 +01:00
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
enum ActionState { NoVcsEnabled, OtherVcsEnabled, VcsEnabled };
|
2009-03-19 17:40:01 +01:00
|
|
|
|
2013-04-18 12:06:43 +02:00
|
|
|
// Sets the current submit editor for this specific version control plugin.
|
|
|
|
// The plugin automatically checks if the submit editor is closed and calls
|
|
|
|
// submitEditorAboutToClose().
|
2013-10-07 13:34:40 +02:00
|
|
|
// The function raiseSubmitEditor can be used to check for a running submit editor and raise it.
|
2013-04-18 12:06:43 +02:00
|
|
|
void setSubmitEditor(VcsBaseSubmitEditor *submitEditor);
|
|
|
|
// Current submit editor set through setSubmitEditor, if it wasn't closed inbetween
|
|
|
|
VcsBaseSubmitEditor *submitEditor() const;
|
|
|
|
// Tries to raise the submit editor set through setSubmitEditor. Returns true if that was found.
|
|
|
|
bool raiseSubmitEditor() const;
|
|
|
|
|
2009-12-08 14:26:41 +01:00
|
|
|
// Implement to enable the plugin menu actions according to state.
|
|
|
|
virtual void updateActions(ActionState as) = 0;
|
2022-10-16 05:58:20 +03:00
|
|
|
virtual void discardCommit();
|
2009-03-20 14:20:28 +01:00
|
|
|
|
2009-12-08 14:26:41 +01:00
|
|
|
// A helper to enable the VCS menu action according to state:
|
2012-01-07 12:31:48 +01:00
|
|
|
// NoVcsEnabled -> visible, enabled if repository creation is supported
|
|
|
|
// OtherVcsEnabled -> invisible
|
2010-01-12 16:45:21 +01:00
|
|
|
// Else: -> fully enabled.
|
|
|
|
// Returns whether actions should be set up further.
|
|
|
|
bool enableMenuAction(ActionState as, QAction *in) const;
|
2009-03-20 14:20:28 +01:00
|
|
|
|
2016-02-03 12:15:21 +01:00
|
|
|
private:
|
2020-01-30 12:31:47 +01:00
|
|
|
void slotStateChanged(const Internal::State &s, Core::IVersionControl *vc);
|
2009-03-20 14:20:28 +01:00
|
|
|
|
2020-01-23 17:22:05 +01:00
|
|
|
bool supportsRepositoryCreation() const;
|
|
|
|
|
|
|
|
QPointer<VcsBaseSubmitEditor> m_submitEditor;
|
|
|
|
Core::Context m_context;
|
|
|
|
VcsBasePluginState m_state;
|
|
|
|
int m_actionState = -1;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
2012-01-07 12:31:48 +01:00
|
|
|
} // namespace VcsBase
|