• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdevelop API Reference
  • KDE Home
  • Contact Us
 

kdevplatform/vcs

  • sources
  • kfour-appscomplete
  • kdevelop
  • kdevplatform
  • vcs
  • dvcs
dvcsplugin.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * This file was partly taken from KDevelop's cvs plugin *
3  * Copyright 2007 Robert Gruber <[email protected]> *
4  * *
5  * Adapted for DVCS (added templates) *
6  * Copyright 2008 Evgeniy Ivanov <[email protected]> *
7  * *
8  * This program is free software; you can redistribute it and/or *
9  * modify it under the terms of the GNU General Public License as *
10  * published by the Free Software Foundation; either version 2 of *
11  * the License or (at your option) version 3 or any later version *
12  * accepted by the membership of KDE e.V. (or its successor approved *
13  * by the membership of KDE e.V.), which shall act as a proxy *
14  * defined in Section 14 of version 3 of the license. *
15  * *
16  * This program is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19  * GNU General Public License for more details. *
20  * *
21  * You should have received a copy of the GNU General Public License *
22  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
23  ***************************************************************************/
24 
25 #ifndef DVCS_PLUGIN_CC
26 #define DVCS_PLUGIN_CC
27 
28 #include "dvcsplugin.h"
29 
30 #include <QMenu>
31 #include <QFileInfo>
32 #include <QString>
33 
34 #include <KLocalizedString>
35 #include <KParts/MainWindow>
36 
37 #include <interfaces/iuicontroller.h>
38 #include <interfaces/icore.h>
39 #include <interfaces/context.h>
40 #include <interfaces/contextmenuextension.h>
41 #include <interfaces/idocumentcontroller.h>
42 #include <util/scopeddialog.h>
43 
44 #include "dvcsjob.h"
45 #include "ui/dvcsimportmetadatawidget.h"
46 #include "ui/branchmanager.h"
47 #include <vcs/vcspluginhelper.h>
48 
49 namespace KDevelop
50 {
51 
52 class DistributedVersionControlPluginPrivate
53 {
54 public:
55  explicit DistributedVersionControlPluginPrivate(DistributedVersionControlPlugin * pThis)
56  : m_common(new VcsPluginHelper(pThis, pThis)) {}
57 
58  ~DistributedVersionControlPluginPrivate() { delete m_common; }
59  VcsPluginHelper* m_common;
60 };
61 
62 //class DistributedVersionControlPlugin
63 DistributedVersionControlPlugin::DistributedVersionControlPlugin(QObject *parent, const QString& componentName)
64  : IPlugin(componentName, parent)
65  , d_ptr(new DistributedVersionControlPluginPrivate(this))
66 {}
67 
68 DistributedVersionControlPlugin::~DistributedVersionControlPlugin()
69 {
70  //TODO: Find out why this crashes on the svn tests delete d->m_factory;
71 }
72 
73 // End: KDevelop::IBasicVersionControl
74 
75 
76 // Begin: KDevelop::IDistributedVersionControl
77 
78 // End: KDevelop::IDistributedVersionControl
79 
80 
81 KDevelop::VcsImportMetadataWidget*
82 DistributedVersionControlPlugin::createImportMetadataWidget(QWidget* parent)
83 {
84  return new DvcsImportMetadataWidget(parent);
85 }
86 
87 KDevelop::ContextMenuExtension
88 DistributedVersionControlPlugin::contextMenuExtension(Context* context, QWidget* parent)
89 {
90  Q_D(DistributedVersionControlPlugin);
91 
92  d->m_common->setupFromContext(context);
93  QList<QUrl> const & ctxUrlList = d->m_common->contextUrlList();
94 
95  bool isWorkingDirectory = false;
96  for (const QUrl& url : ctxUrlList) {
97  if (isValidDirectory(url)) {
98  isWorkingDirectory = true;
99  break;
100  }
101  }
102 
103  if (!isWorkingDirectory) { // Not part of a repository
104  return ContextMenuExtension();
105  }
106 
107  QMenu * menu = d->m_common->commonActions(parent);
108  menu->addSeparator();
109  menu->addAction(i18nc("@action:inmenu", "Branches..."), this, SLOT(ctxBranchManager()))->setEnabled(ctxUrlList.count()==1);
110  additionalMenuEntries(menu, ctxUrlList);
111 
112  ContextMenuExtension menuExt;
113  menuExt.addAction(ContextMenuExtension::VcsGroup, menu->menuAction());
114 
115  return menuExt;
116 
117 }
118 
119 void DistributedVersionControlPlugin::additionalMenuEntries(QMenu* /*menu*/, const QList<QUrl>& /*urls*/)
120 {}
121 
122 static QString stripPathToDir(const QString &path)
123 {
124  QFileInfo info = QFileInfo(path);
125  return info.isDir() ? info.absoluteFilePath() : info.absolutePath();
126 }
127 
128 void DistributedVersionControlPlugin::ctxBranchManager()
129 {
130  Q_D(DistributedVersionControlPlugin);
131 
132  QList<QUrl> const & ctxUrlList = d->m_common->contextUrlList();
133  Q_ASSERT(!ctxUrlList.isEmpty());
134 
135  ICore::self()->documentController()->saveAllDocuments();
136 
137  ScopedDialog<BranchManager> branchManager(stripPathToDir(ctxUrlList.front().toLocalFile()),
138  this, core()->uiController()->activeMainWindow());
139  branchManager->exec();
140 }
141 
142 }
143 
144 #endif
dvcsjob.h
QUrl
QFileInfo::isDir
bool isDir() const
KDevelop::VcsImportMetadataWidget
Definition: vcsimportmetadatawidget.h:33
KDevelop::DistributedVersionControlPlugin::isValidDirectory
virtual bool isValidDirectory(const QUrl &dirPath)=0
Checks if dirPath is located in DVCS repository.
QWidget
QMenu::addSeparator
QAction * addSeparator()
QMenu
IPlugin
DvcsImportMetadataWidget
Asks the user for all options needed to import an existing directory into a Git repository.
Definition: dvcsimportmetadatawidget.h:43
QList< QUrl >
KDevelop::DistributedVersionControlPlugin::createImportMetadataWidget
VcsImportMetadataWidget * createImportMetadataWidget(QWidget *parent) override
Used in KDevelop's appwizardplugin (creates import widget)
Definition: dvcsplugin.cpp:82
dvcsplugin.h
QObject
QFileInfo::absoluteFilePath
QString absoluteFilePath() const
QString
KDevelop::DistributedVersionControlPlugin::DistributedVersionControlPlugin
DistributedVersionControlPlugin(QObject *parent, const QString &componentName)
Definition: dvcsplugin.cpp:63
KDevelop::DistributedVersionControlPlugin
DistributedVersionControlPlugin is a base class for git/hg/bzr plugins.
Definition: dvcsplugin.h:47
KDevelop::stripPathToDir
static QString stripPathToDir(const QString &path)
Definition: dvcsplugin.cpp:122
QList::isEmpty
bool isEmpty() const
QUrl::toLocalFile
QString toLocalFile() const
branchmanager.h
QFileInfo::absolutePath
QString absolutePath() const
dvcsimportmetadatawidget.h
vcspluginhelper.h
KDevelop::DistributedVersionControlPlugin::ctxBranchManager
void ctxBranchManager()
Definition: dvcsplugin.cpp:128
KDevelop::DistributedVersionControlPlugin::~DistributedVersionControlPlugin
~DistributedVersionControlPlugin() override
Definition: dvcsplugin.cpp:68
QFileInfo
KDevelop
Definition: dvcsevent.h:33
QMenu::menuAction
QAction * menuAction() const
QMenu::addAction
void addAction(QAction *action)
KDevelop::DistributedVersionControlPlugin::contextMenuExtension
ContextMenuExtension contextMenuExtension(Context *context, QWidget *parent) override
Creates context menu.
Definition: dvcsplugin.cpp:88
QList::front
T & front()
KDevelop::DistributedVersionControlPlugin::additionalMenuEntries
virtual void additionalMenuEntries(QMenu *menu, const QList< QUrl > &urls)
When a plugin wants to add elements to the vcs menu, this method can be overridden.
Definition: dvcsplugin.cpp:119
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Sat Jan 23 2021 09:41:52 by doxygen 1.8.16 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdevplatform/vcs

Skip menu "kdevplatform/vcs"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdevelop API Reference

Skip menu "kdevelop API Reference"
  • kdevplatform
  •   debugger
  •   documentation
  •   interfaces
  •   language
  •     assistant
  •     backgroundparser
  •     checks
  •     classmodel
  •     codecompletion
  •     codegen
  •     duchain
  •     editor
  •     highlighting
  •     interfaces
  •     util
  •   outputview
  •   project
  •   serialization
  •   shell
  •   sublime
  •   tests
  •   util
  •   vcs

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal