1 /***************************************************************************
2 * Copyright 2007 Dukju Ahn <dukjuahn@gmail.com> *
3 * Copyright 2008 Andreas Pakulat <apaku@gmx.de> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 ***************************************************************************/
12 #include "kdevsvnplugin.h"
14 #include <QtDesigner/QExtensionFactory>
17 #include <QTextStream>
20 #include <kparts/part.h>
21 #include <kparts/partmanager.h>
22 #include <kparts/mainwindow.h>
23 #include <kaboutdata.h>
24 #include <ktexteditor/document.h>
25 #include <ktexteditor/markinterface.h>
26 #include <kpluginfactory.h>
27 #include <kpluginloader.h>
29 #include <kurlrequester.h>
31 #include <kurlrequesterdialog.h>
33 #include <ktemporaryfile.h>
34 #include <kmessagebox.h>
36 #include <interfaces/iuicontroller.h>
37 #include <interfaces/idocumentcontroller.h>
38 #include <interfaces/idocument.h>
39 #include <interfaces/iplugincontroller.h>
40 #include <interfaces/icore.h>
41 #include <interfaces/iruncontroller.h>
42 #include <outputview/ioutputview.h>
43 #include <project/projectmodel.h>
44 #include <interfaces/context.h>
45 #include <interfaces/contextmenuextension.h>
46 #include <vcs/vcsrevision.h>
47 #include <vcs/vcsevent.h>
48 #include <vcs/vcsrevision.h>
49 #include <vcs/vcsmapping.h>
50 #include <vcs/vcsstatusinfo.h>
51 #include <vcs/vcsannotation.h>
52 #include <vcs/widgets/vcsannotationwidget.h>
53 #include <vcs/widgets/vcseventwidget.h>
54 #include <vcs/widgets/vcsdiffwidget.h>
55 #include <vcs/widgets/vcscommitdialog.h>
57 #include "kdevsvncpp/apr.hpp"
59 #include "svncommitjob.h"
60 #include "svnstatusjob.h"
61 #include "svnaddjob.h"
62 #include "svnrevertjob.h"
63 #include "svnremovejob.h"
64 #include "svnupdatejob.h"
65 #include "svninfojob.h"
66 #include "svndiffjob.h"
67 #include "svncopyjob.h"
68 #include "svnmovejob.h"
69 #include "svnlogjob.h"
70 #include "svnblamejob.h"
71 #include "svnimportjob.h"
72 #include "svncheckoutjob.h"
74 #include "svnoutputdelegate.h"
75 #include "svnoutputmodel.h"
76 #include "svnimportmetadatawidget.h"
77 #include "svncheckoutmetadatawidget.h"
79 K_PLUGIN_FACTORY(KDevSvnFactory
, registerPlugin
<KDevSvnPlugin
>(); )
80 K_EXPORT_PLUGIN(KDevSvnFactory(KAboutData("kdevsubversion","kdevsubversion", ki18n("Subversion"), "0.1", ki18n("Support for Subversion version control systems"), KAboutData::License_GPL
)))
82 KDevSvnPlugin::KDevSvnPlugin( QObject
*parent
, const QVariantList
& )
83 : KDevelop::IPlugin(KDevSvnFactory::componentData(), parent
)
84 , m_outputmodel(0), m_outputdelegate(0), m_factory(0)
86 KDEV_USE_EXTENSION_INTERFACE( KDevelop::IBasicVersionControl
)
87 KDEV_USE_EXTENSION_INTERFACE( KDevelop::ICentralizedVersionControl
)
89 qRegisterMetaType
<KDevelop::VcsStatusInfo
>();
90 qRegisterMetaType
<SvnInfoHolder
>();
91 qRegisterMetaType
<KDevelop::VcsEvent
>();
92 qRegisterMetaType
<KDevelop::VcsRevision
>();
93 qRegisterMetaType
<KDevelop::VcsRevision::RevisionSpecialType
>();
94 qRegisterMetaType
<KDevelop::VcsAnnotation
>();
95 qRegisterMetaType
<KDevelop::VcsAnnotationLine
>();
96 m_outputmodel
= new SvnOutputModel( this, this );
98 IPlugin
* plugin
= core()->pluginController()->pluginForExtension( "org.kdevelop.IOutputView" );
102 m_outputdelegate
= new SvnOutputDelegate( this );
103 KDevelop::IOutputView
* iface
= plugin
->extension
<KDevelop::IOutputView
>();
104 int tvid
= iface
->registerToolView( "Subversion", KDevelop::IOutputView::OneView
, KIcon("vcs_commit") );
105 int id
= iface
->registerOutputInToolView( tvid
, "Output", KDevelop::IOutputView::AllowUserClose
| KDevelop::IOutputView::AutoScroll
);
106 iface
->setModel( id
, m_outputmodel
);
107 iface
->setDelegate( id
, m_outputdelegate
);
111 KDevSvnPlugin::~KDevSvnPlugin()
115 bool KDevSvnPlugin::isVersionControlled( const KUrl
& localLocation
)
117 SvnInfoJob
* job
= new SvnInfoJob( this );
119 job
->setLocation( localLocation
);
122 QVariant result
= job
->fetchResults();
123 if( result
.isValid() )
125 SvnInfoHolder h
= qVariantValue
<SvnInfoHolder
>( result
);
126 return !h
.name
.isEmpty();
130 kDebug(9510) << "Couldn't execute job";
135 KDevelop::VcsJob
* KDevSvnPlugin::repositoryLocation( const KUrl
& localLocation
)
137 SvnInfoJob
* job
= new SvnInfoJob( this );
139 job
->setLocation( localLocation
);
140 job
->setProvideInformation( SvnInfoJob::RepoUrlOnly
);
144 KDevelop::VcsJob
* KDevSvnPlugin::status( const KUrl::List
& localLocations
,
145 KDevelop::IBasicVersionControl::RecursionMode mode
)
147 SvnStatusJob
* job
= new SvnStatusJob( this );
148 job
->setLocations( localLocations
);
149 job
->setRecursive( ( mode
== KDevelop::IBasicVersionControl::Recursive
) );
153 KDevelop::VcsJob
* KDevSvnPlugin::add( const KUrl::List
& localLocations
,
154 KDevelop::IBasicVersionControl::RecursionMode recursion
)
156 SvnAddJob
* job
= new SvnAddJob( this );
157 job
->setLocations( localLocations
);
158 job
->setRecursive( ( recursion
== KDevelop::IBasicVersionControl::Recursive
) );
162 KDevelop::VcsJob
* KDevSvnPlugin::remove( const KUrl::List
& localLocations
)
164 SvnRemoveJob
* job
= new SvnRemoveJob( this );
165 job
->setLocations( localLocations
);
169 KDevelop::VcsJob
* KDevSvnPlugin::edit( const KUrl
& /*localLocation*/ )
174 KDevelop::VcsJob
* KDevSvnPlugin::unedit( const KUrl
& /*localLocation*/ )
179 KDevelop::VcsJob
* KDevSvnPlugin::localRevision( const KUrl
& localLocation
, KDevelop::VcsRevision::RevisionType type
)
181 SvnInfoJob
* job
= new SvnInfoJob( this );
183 job
->setLocation( localLocation
);
184 job
->setProvideInformation( SvnInfoJob::RevisionOnly
);
185 job
->setProvideRevisionType( type
);
189 KDevelop::VcsJob
* KDevSvnPlugin::copy( const KUrl
& localLocationSrc
, const KUrl
& localLocationDstn
)
191 SvnCopyJob
* job
= new SvnCopyJob( this );
192 job
->setSourceLocation( localLocationSrc
);
193 job
->setDestinationLocation( localLocationDstn
);
197 KDevelop::VcsJob
* KDevSvnPlugin::move( const KUrl
& localLocationSrc
, const KUrl
& localLocationDst
)
199 SvnMoveJob
* job
= new SvnMoveJob( this );
200 job
->setSourceLocation( localLocationSrc
);
201 job
->setDestinationLocation( localLocationDst
);
205 KDevelop::VcsJob
* KDevSvnPlugin::revert( const KUrl::List
& localLocations
,
206 KDevelop::IBasicVersionControl::RecursionMode recursion
)
208 SvnRevertJob
* job
= new SvnRevertJob( this );
209 job
->setLocations( localLocations
);
210 job
->setRecursive( ( recursion
== KDevelop::IBasicVersionControl::Recursive
) );
214 KDevelop::VcsJob
* KDevSvnPlugin::update( const KUrl::List
& localLocations
,
215 const KDevelop::VcsRevision
& rev
,
216 KDevelop::IBasicVersionControl::RecursionMode recursion
)
218 SvnUpdateJob
* job
= new SvnUpdateJob( this );
219 job
->setLocations( localLocations
);
220 job
->setRevision( rev
);
221 job
->setRecursive( ( recursion
== KDevelop::IBasicVersionControl::Recursive
) );
225 KDevelop::VcsJob
* KDevSvnPlugin::commit( const QString
& message
, const KUrl::List
& localLocations
,
226 KDevelop::IBasicVersionControl::RecursionMode recursion
)
228 SvnCommitJob
* job
= new SvnCommitJob( this );
229 kDebug(9510) << "Commiting locations:" << localLocations
<< endl
;
230 job
->setUrls( localLocations
);
231 job
->setCommitMessage( message
) ;
232 job
->setRecursive( ( recursion
== KDevelop::IBasicVersionControl::Recursive
) );
236 KDevelop::VcsJob
* KDevSvnPlugin::diff( const KDevelop::VcsLocation
& src
,
237 const KDevelop::VcsLocation
& dst
,
238 const KDevelop::VcsRevision
& srcRevision
,
239 const KDevelop::VcsRevision
& dstRevision
,
240 KDevelop::VcsDiff::Type diffType
,
241 KDevelop::IBasicVersionControl::RecursionMode recurse
)
243 SvnDiffJob
* job
= new SvnDiffJob( this );
244 job
->setSource( src
);
245 job
->setDestination( dst
);
246 job
->setSrcRevision( srcRevision
);
247 job
->setDstRevision( dstRevision
);
248 job
->setDiffType( diffType
);
249 job
->setRecursive( ( recurse
== KDevelop::IBasicVersionControl::Recursive
) );
253 KDevelop::VcsJob
* KDevSvnPlugin::log( const KUrl
& localLocation
, const KDevelop::VcsRevision
& rev
, unsigned long limit
)
255 SvnLogJob
* job
= new SvnLogJob( this );
256 job
->setLocation( localLocation
);
257 job
->setStartRevision( rev
);
258 job
->setLimit( limit
);
262 KDevelop::VcsJob
* KDevSvnPlugin::log( const KUrl
& localLocation
,
263 const KDevelop::VcsRevision
& startRev
,
264 const KDevelop::VcsRevision
& endRev
)
266 SvnLogJob
* job
= new SvnLogJob( this );
267 job
->setLocation( localLocation
);
268 job
->setStartRevision( startRev
);
269 job
->setEndRevision( endRev
);
273 KDevelop::VcsJob
* KDevSvnPlugin::annotate( const KUrl
& localLocation
,
274 const KDevelop::VcsRevision
& rev
)
276 SvnBlameJob
* job
= new SvnBlameJob( this );
277 job
->setLocation( localLocation
);
278 job
->setEndRevision( rev
);
282 KDevelop::VcsJob
* KDevSvnPlugin::merge( const KDevelop::VcsLocation
& localOrRepoLocationSrc
,
283 const KDevelop::VcsLocation
& localOrRepoLocationDst
,
284 const KDevelop::VcsRevision
& srcRevision
,
285 const KDevelop::VcsRevision
& dstRevision
,
286 const KUrl
& localLocation
)
288 // TODO implement merge
289 Q_UNUSED( localOrRepoLocationSrc
)
290 Q_UNUSED( localOrRepoLocationDst
)
291 Q_UNUSED( srcRevision
)
292 Q_UNUSED( dstRevision
)
293 Q_UNUSED( localLocation
)
297 KDevelop::VcsJob
* KDevSvnPlugin::resolve( const KUrl::List
& /*localLocations*/,
298 KDevelop::IBasicVersionControl::RecursionMode
/*recursion*/ )
303 KDevelop::VcsJob
* KDevSvnPlugin::import( const KDevelop::VcsMapping
& mapping
, const QString
& msg
)
305 SvnImportJob
* job
= new SvnImportJob( this );
306 job
->setMapping( mapping
);
307 job
->setMessage( msg
);
311 KDevelop::VcsJob
* KDevSvnPlugin::checkout( const KDevelop::VcsMapping
& mapping
)
313 SvnCheckoutJob
* job
= new SvnCheckoutJob( this );
314 job
->setMapping( mapping
);
319 const KUrl
KDevSvnPlugin::urlFocusedDocument()
321 KParts::ReadOnlyPart
*part
=
322 dynamic_cast<KParts::ReadOnlyPart
*>( core()->partManager()->activePart() );
324 if (part
->url().isLocalFile() ) {
331 KDevelop::ContextMenuExtension
KDevSvnPlugin::contextMenuExtension( KDevelop::Context
* context
)
333 KUrl::List ctxUrlList
;
334 if( context
->type() == KDevelop::Context::ProjectItemContext
)
336 KDevelop::ProjectItemContext
*itemCtx
= dynamic_cast<KDevelop::ProjectItemContext
*>(context
);
339 QList
<KDevelop::ProjectBaseItem
*> baseItemList
= itemCtx
->items();
342 foreach( KDevelop::ProjectBaseItem
* _item
, baseItemList
)
344 if( _item
->folder() ){
345 KDevelop::ProjectFolderItem
*folderItem
= dynamic_cast<KDevelop::ProjectFolderItem
*>(_item
);
346 ctxUrlList
<< folderItem
->url();
348 else if( _item
->file() ){
349 KDevelop::ProjectFileItem
*fileItem
= dynamic_cast<KDevelop::ProjectFileItem
*>(_item
);
350 ctxUrlList
<< fileItem
->url();
354 }else if( context
->type() == KDevelop::Context::EditorContext
)
356 KDevelop::EditorContext
*itemCtx
= dynamic_cast<KDevelop::EditorContext
*>(context
);
357 ctxUrlList
<< itemCtx
->url();
358 }else if( context
->type() == KDevelop::Context::FileContext
)
360 KDevelop::FileContext
*itemCtx
= dynamic_cast<KDevelop::FileContext
*>(context
);
361 ctxUrlList
+= itemCtx
->urls();
365 KDevelop::ContextMenuExtension menuExt
;
367 bool hasVersionControlledEntries
= false;
368 foreach( KUrl url
, ctxUrlList
)
370 if( isVersionControlled( url
) )
372 hasVersionControlledEntries
= true;
376 if( ctxUrlList
.isEmpty() )
377 return IPlugin::contextMenuExtension( context
);
380 m_ctxUrlList
= ctxUrlList
;
381 QList
<QAction
*> actions
;
383 QMenu
* menu
= new QMenu("Subversion");
384 kDebug() << "version controlled?" << hasVersionControlledEntries
;
385 if( hasVersionControlledEntries
)
387 // action = new KAction(i18n("Commit..."), this);
388 // connect( action, SIGNAL(triggered()), this, SLOT(ctxCommit()) );
389 // menuExt.addAction( KDevelop::ContextMenuExtension::VcsGroup, action );
391 // action = new KAction(i18n("Add to Repository"), this);
392 // connect( action, SIGNAL(triggered()), this, SLOT(ctxAdd()) );
393 // menuExt.addAction( KDevelop::ContextMenuExtension::VcsGroup, action );
395 // action = new KAction(i18n("Remove from Repository"), this);
396 // connect( action, SIGNAL(triggered()), this, SLOT(ctxRemove()) );
397 // menuExt.addAction( KDevelop::ContextMenuExtension::VcsGroup, action );
399 // action = new KAction(i18n("Update to Head"), this);
400 // connect( action, SIGNAL(triggered()), this, SLOT(ctxUpdate()) );
401 // menuExt.addAction( KDevelop::ContextMenuExtension::VcsGroup, action );
403 // action = new KAction(i18n("Revert"), this);
404 // connect( action, SIGNAL(triggered()), this, SLOT(ctxRevert()) );
405 // menuExt.addAction( KDevelop::ContextMenuExtension::VcsGroup, action );
407 // action = new KAction(i18n("Diff to Head"), this);
408 // connect( action, SIGNAL(triggered()), this, SLOT(ctxDiffHead()) );
409 // menuExt.addAction( KDevelop::ContextMenuExtension::VcsGroup, action );
411 // action = new KAction(i18n("Diff to Base"), this);
412 // connect( action, SIGNAL(triggered()), this, SLOT(ctxDiffBase()) );
413 // menuExt.addAction( KDevelop::ContextMenuExtension::VcsGroup, action );
415 action
= new KAction(i18n("Copy..."), this);
416 connect( action
, SIGNAL(triggered()), this, SLOT(ctxCopy()) );
417 menu
->addAction( action
);
419 action
= new KAction(i18n("Move..."), this);
420 connect( action
, SIGNAL(triggered()), this, SLOT(ctxMove()) );
421 menu
->addAction( action
);
423 // action = new KAction(i18n("History..."), this);
424 // connect( action, SIGNAL(triggered()), this, SLOT(ctxHistory()) );
425 // menuExt.addAction( KDevelop::ContextMenuExtension::VcsGroup, action );
427 // action = new KAction(i18n("Annotation..."), this);
428 // connect( action, SIGNAL(triggered()), this, SLOT(ctxBlame()) );
429 // menuExt.addAction( KDevelop::ContextMenuExtension::VcsGroup, action );
434 action
= new KAction(i18n("Import..."), this);
435 connect( action
, SIGNAL(triggered()), this, SLOT(ctxImport()) );
436 menu
->addAction( action
);
437 action
= new KAction(i18n("Checkout..."), this);
438 connect( action
, SIGNAL(triggered()), this, SLOT(ctxCheckout()) );
439 menu
->addAction( action
);
441 // action = new QAction(i18n("Blame/Annotate..."), this);
442 // connect( action, SIGNAL(triggered()), this, SLOT(ctxBlame()) );
443 // actions << action;
445 // action = new QAction(i18n("Cat..."), this);
446 // connect( action, SIGNAL(triggered()), this, SLOT(ctxCat()) );
447 // actions << action;
449 // action = new QAction(i18n("Diff to..."), this);
450 // connect( action, SIGNAL(triggered()), this, SLOT(ctxDiff()) );
451 // actions << action;
453 // action = new QAction(i18n("Information..."), this);
454 // connect( action, SIGNAL(triggered()), this, SLOT(ctxInfo()) );
455 // actions << action;
457 // action = new QAction(i18n("Status..."), this);
458 // connect( action, SIGNAL(triggered()), this, SLOT(ctxStatus()) );
459 // actions << action;
461 menuExt
.addAction( KDevelop::ContextMenuExtension::ExtensionGroup
, menu
->menuAction() );
466 void KDevSvnPlugin::ctxHistory()
468 if( m_ctxUrlList
.count() > 1 ){
469 KMessageBox::error( 0, i18n("Please select only one item for this operation") );
472 KDevelop::VcsRevision start
;
473 start
.setRevisionValue( qVariantFromValue
<KDevelop::VcsRevision::RevisionSpecialType
>( KDevelop::VcsRevision::Head
),
474 KDevelop::VcsRevision::Special
);
475 KDevelop::VcsJob
*job
= log( m_ctxUrlList
.first(), start
, 0 );
476 KDialog
* dlg
= new KDialog();
477 dlg
->setButtons( KDialog::Close
);
478 dlg
->setCaption( i18n( "Subversion Log (%1)", m_ctxUrlList
.first().path() ) );
479 KDevelop::VcsEventWidget
* logWidget
= new KDevelop::VcsEventWidget( m_ctxUrlList
.first(), job
, dlg
);
480 dlg
->setMainWidget( logWidget
);
481 connect( dlg
, SIGNAL( destroyed( QObject
* ) ), job
, SLOT( deleteLater() ) );
484 void KDevSvnPlugin::ctxBlame()
486 if( m_ctxUrlList
.count() > 1 ){
487 KMessageBox::error( 0, i18n("Please select only one item for this operation") );
491 if( !m_ctxUrlList
.first().isLocalFile() )
493 KMessageBox::error( 0, i18n("Annotate is only supported on local files") );
497 KDevelop::IDocument
* doc
= core()->documentController()->documentForUrl( m_ctxUrlList
.first() );
499 doc
= core()->documentController()->openDocument( m_ctxUrlList
.first() );
501 if( doc
&& doc
->textDocument() )
503 KDevelop::VcsRevision head
;
504 head
.setRevisionValue( qVariantFromValue
<KDevelop::VcsRevision::RevisionSpecialType
>( KDevelop::VcsRevision::Head
),
505 KDevelop::VcsRevision::Special
);
506 KDevelop::VcsJob
* job
= annotate( m_ctxUrlList
.first(), head
);
507 KTextEditor::MarkInterface
* markiface
= 0;
508 //qobject_cast<KTextEditor::MarkInterface*>(doc->textDocument());
511 //@TODO: Work with Kate devs towards a new interface for adding
512 // annotation information to the KTE's in KDE 4.1
515 KDialog
* dlg
= new KDialog();
516 dlg
->setButtons( KDialog::Close
);
517 dlg
->setCaption( i18n("Annotation (%1)", m_ctxUrlList
.first().prettyUrl() ) );
518 KDevelop::VcsAnnotationWidget
* w
= new KDevelop::VcsAnnotationWidget( m_ctxUrlList
.first(), job
, dlg
);
519 dlg
->setMainWidget( w
);
520 connect( dlg
, SIGNAL( destroyed( QObject
* ) ), job
, SLOT( deleteLater() ) );
525 KMessageBox::error( 0, i18n("Cannot execute annotate action because the "
526 "document wasn't found or was not a text "
527 "document:\n%1", m_ctxUrlList
.first().prettyUrl() ) );
531 void KDevSvnPlugin::ctxCommit()
533 if( !m_ctxUrlList
.isEmpty() )
535 KDevelop::VcsCommitDialog
* dlg
= new KDevelop::VcsCommitDialog( this, core()->uiController()->activeMainWindow() );
536 dlg
->setCommitCandidates( m_ctxUrlList
);
537 dlg
->setRecursive( true );
538 connect( dlg
, SIGNAL( doCommit( KDevelop::VcsCommitDialog
* ) ), this, SLOT( doCommit( KDevelop::VcsCommitDialog
* ) ) );
539 connect( dlg
, SIGNAL( cancelCommit( KDevelop::VcsCommitDialog
* ) ), this, SLOT( cancelCommit( KDevelop::VcsCommitDialog
* ) ) );
545 void KDevSvnPlugin::doCommit( KDevelop::VcsCommitDialog
* dlg
)
547 KDevelop::IBasicVersionControl::RecursionMode mode
;
548 if( dlg
->recursive() )
550 mode
= KDevelop::IBasicVersionControl::Recursive
;
553 mode
= KDevelop::IBasicVersionControl::NonRecursive
;
555 KDevelop::ICore::self()->runController()->registerJob( commit( dlg
->message(), dlg
->checkedUrls(), mode
) );
559 void KDevSvnPlugin::cancelCommit( KDevelop::VcsCommitDialog
* dlg
)
564 void KDevSvnPlugin::ctxUpdate()
566 KDevelop::VcsRevision rev
;
567 rev
.setRevisionValue( qVariantFromValue
<KDevelop::VcsRevision::RevisionSpecialType
>( KDevelop::VcsRevision::Head
), KDevelop::VcsRevision::Special
);
568 KDevelop::ICore::self()->runController()->registerJob( update( m_ctxUrlList
, rev
) );
571 void KDevSvnPlugin::ctxAdd()
573 KDevelop::ICore::self()->runController()->registerJob( add( m_ctxUrlList
) );
575 void KDevSvnPlugin::ctxRemove()
577 KDevelop::ICore::self()->runController()->registerJob( remove( m_ctxUrlList
) );
580 void KDevSvnPlugin::ctxRevert()
582 //@TODO: If one of the urls is a directory maybe ask whether all files in the dir should be reverted?
583 KDevelop::ICore::self()->runController()->registerJob( revert( m_ctxUrlList
) );
586 void KDevSvnPlugin::ctxDiff()
589 if( m_ctxUrlList
.count() > 1 ){
590 KMessageBox::error( 0, i18n("Please select only one item for this operation") );
595 void KDevSvnPlugin::ctxDiffHead()
597 if( m_ctxUrlList
.count() > 1 ){
598 KMessageBox::error( 0, i18n("Please select only one item for this operation") );
601 KDevelop::VcsRevision srcRev
,dstRev
;
602 srcRev
.setRevisionValue( qVariantFromValue
<KDevelop::VcsRevision::RevisionSpecialType
>(KDevelop::VcsRevision::Head
), KDevelop::VcsRevision::Special
);
603 dstRev
.setRevisionValue( qVariantFromValue
<KDevelop::VcsRevision::RevisionSpecialType
>(KDevelop::VcsRevision::Working
), KDevelop::VcsRevision::Special
);
604 KDevelop::VcsJob
* job
= diff( m_ctxUrlList
.first(), m_ctxUrlList
.first(), srcRev
, dstRev
);
606 //TODO: Fix this, the job should execute asynchronously via runcontroller
608 if( job
->status() == KDevelop::VcsJob::JobSucceeded
)
610 KDevelop::VcsDiff d
= job
->fetchResults().value
<KDevelop::VcsDiff
>();
611 QString diff
= d
.diff();
612 core()->documentController()->openDocumentFromText( diff
);
615 kDebug(9510) << "Ooops couldn't diff";
619 void KDevSvnPlugin::ctxDiffBase()
621 if( m_ctxUrlList
.count() > 1 ){
622 KMessageBox::error( 0, i18n("Please select only one item for this operation") );
625 KDevelop::VcsRevision srcRev
,dstRev
;
626 srcRev
.setRevisionValue( qVariantFromValue
<KDevelop::VcsRevision::RevisionSpecialType
>(KDevelop::VcsRevision::Base
), KDevelop::VcsRevision::Special
);
627 dstRev
.setRevisionValue( qVariantFromValue
<KDevelop::VcsRevision::RevisionSpecialType
>(KDevelop::VcsRevision::Working
), KDevelop::VcsRevision::Special
);
628 KDevelop::VcsJob
* job
= diff( m_ctxUrlList
.first(), m_ctxUrlList
.first(), srcRev
, dstRev
);
630 //TODO: same as above ctxDiffHead
632 if( job
->status() == KDevelop::VcsJob::JobSucceeded
)
634 KDevelop::VcsDiff d
= job
->fetchResults().value
<KDevelop::VcsDiff
>();
635 QString diff
= d
.diff();
636 core()->documentController()->openDocumentFromText( diff
);
639 kDebug(9510) << "Ooops couldn't diff";
643 void KDevSvnPlugin::ctxInfo()
645 if( m_ctxUrlList
.count() > 1 ){
646 KMessageBox::error( 0, i18n("Please select only one item for this operation") );
650 void KDevSvnPlugin::ctxStatus()
652 if( m_ctxUrlList
.count() > 1 ){
653 KMessageBox::error( 0, i18n("Please select only one item for this operation") );
658 void KDevSvnPlugin::ctxCopy()
660 if( m_ctxUrlList
.count() > 1 ){
661 KMessageBox::error( 0, i18n("Please select only one item for this operation") );
664 KUrl source
= m_ctxUrlList
.first();
665 if( source
.isLocalFile() )
667 QString dir
= source
.path();
668 bool isFile
= QFileInfo( source
.path() ).isFile();
671 dir
= source
.directory();
673 KUrlRequesterDialog
dlg( dir
, i18n("Destination file/directory"), 0 );
676 dlg
.urlRequester()->setMode( KFile::File
| KFile::Directory
| KFile::LocalOnly
);
679 dlg
.urlRequester()->setMode( KFile::Directory
| KFile::LocalOnly
);
681 if( dlg
.exec() == QDialog::Accepted
)
683 KDevelop::ICore::self()->runController()->registerJob( copy( source
, dlg
.selectedUrl() ) );
687 KMessageBox::error( 0, i18n("Copying only works on local files") );
693 void KDevSvnPlugin::ctxMove()
695 if( m_ctxUrlList
.count() > 1 ){
696 KMessageBox::error( 0, i18n("Please select only one item for this operation") );
699 KUrl source
= m_ctxUrlList
.first();
700 if( source
.isLocalFile() )
702 QString dir
= source
.path();
703 bool isFile
= QFileInfo( source
.path() ).isFile();
706 dir
= source
.directory();
708 KUrlRequesterDialog
dlg( dir
, i18n("Destination file/directory"), 0 );
711 dlg
.urlRequester()->setMode( KFile::File
| KFile::Directory
| KFile::LocalOnly
);
714 dlg
.urlRequester()->setMode( KFile::Directory
| KFile::LocalOnly
);
716 if( dlg
.exec() == QDialog::Accepted
)
718 KDevelop::ICore::self()->runController()->registerJob( move( source
, dlg
.selectedUrl() ) );
722 KMessageBox::error( 0, i18n("Moving only works on local files/dirs") );
727 void KDevSvnPlugin::ctxCat()
729 if( m_ctxUrlList
.count() > 1 ){
730 KMessageBox::error( 0, i18n("Please select only one item for this operation") );
736 SvnOutputModel
* KDevSvnPlugin::outputModel() const
738 return m_outputmodel
;
742 QString
KDevSvnPlugin::name() const
744 return i18n("Subversion");
747 KDevelop::VcsImportMetadataWidget
* KDevSvnPlugin::createImportMetadataWidget( QWidget
* parent
)
749 return new SvnImportMetadataWidget( parent
);
752 void KDevSvnPlugin::ctxImport( )
754 if( m_ctxUrlList
.count() > 1 ){
755 KMessageBox::error( 0, i18n("Please select only one item for this operation") );
759 dlg
.setCaption(i18n("Import into Subversion repository"));
760 SvnImportMetadataWidget
* widget
= new SvnImportMetadataWidget(&dlg
);
761 widget
->setSourceLocation( KDevelop::VcsLocation( m_ctxUrlList
.first() ) );
762 widget
->setSourceLocationEditable( false );
763 dlg
.setMainWidget( widget
);
764 if( dlg
.exec() == QDialog::Accepted
)
766 KDevelop::ICore::self()->runController()->registerJob( import( widget
->mapping(), widget
->message() ) );
770 void KDevSvnPlugin::ctxCheckout( )
772 if( m_ctxUrlList
.count() > 1 ){
773 KMessageBox::error( 0, i18n("Please select only one item for this operation") );
777 dlg
.setCaption(i18n("Checkout from Subversion repository"));
778 SvnCheckoutMetadataWidget
* widget
= new SvnCheckoutMetadataWidget(&dlg
);
779 KUrl tmp
= m_ctxUrlList
.first();
781 widget
->setDestinationLocation( tmp
);
782 dlg
.setMainWidget( widget
);
783 if( dlg
.exec() == QDialog::Accepted
)
785 KDevelop::ICore::self()->runController()->registerJob( checkout( widget
->mapping() ) );
789 #include "kdevsvnplugin.moc"