Changeset View
Changeset View
Standalone View
Standalone View
kdevplatform/vcs/vcspluginhelper.cpp
1 | /*************************************************************************** | 1 | /*************************************************************************** | ||
---|---|---|---|---|---|
2 | * Copyright 2008 Andreas Pakulat <apaku@gmx.de> * | 2 | * Copyright 2008 Andreas Pakulat <apaku@gmx.de> * | ||
3 | * Copyright 2010 Aleix Pol Gonzalez <aleixpol@kde.org> * | 3 | * Copyright 2010 Aleix Pol Gonzalez <aleixpol@kde.org> * | ||
4 | * Copyright 2017-2018 Friedrich W. H. Kossebau <kossebau@kde.org> * | ||||
4 | * * | 5 | * * | ||
5 | * This program is free software; you can redistribute it and/or modify * | 6 | * 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 | * 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 | * the Free Software Foundation; either version 2 of the License, or * | ||
8 | * (at your option) any later version. * | 9 | * (at your option) any later version. * | ||
9 | * * | 10 | * * | ||
10 | ***************************************************************************/ | 11 | ***************************************************************************/ | ||
11 | 12 | | |||
Show All 11 Lines | |||||
23 | 24 | | |||
24 | #include <KLocalizedString> | 25 | #include <KLocalizedString> | ||
25 | #include <KMessageBox> | 26 | #include <KMessageBox> | ||
26 | #include <KParts/MainWindow> | 27 | #include <KParts/MainWindow> | ||
27 | #include <KTextEditor/AnnotationInterface> | 28 | #include <KTextEditor/AnnotationInterface> | ||
28 | #include <KTextEditor/Document> | 29 | #include <KTextEditor/Document> | ||
29 | #include <KTextEditor/ModificationInterface> | 30 | #include <KTextEditor/ModificationInterface> | ||
30 | #include <KTextEditor/View> | 31 | #include <KTextEditor/View> | ||
32 | #include <ktexteditor_version.h> | ||||
31 | 33 | | |||
32 | #include <interfaces/context.h> | 34 | #include <interfaces/context.h> | ||
33 | #include <interfaces/contextmenuextension.h> | 35 | #include <interfaces/contextmenuextension.h> | ||
34 | #include <interfaces/icore.h> | 36 | #include <interfaces/icore.h> | ||
35 | #include <interfaces/idocument.h> | 37 | #include <interfaces/idocument.h> | ||
36 | #include <interfaces/idocumentcontroller.h> | 38 | #include <interfaces/idocumentcontroller.h> | ||
37 | #include <interfaces/iplugin.h> | 39 | #include <interfaces/iplugin.h> | ||
38 | #include <interfaces/iplugincontroller.h> | 40 | #include <interfaces/iplugincontroller.h> | ||
39 | #include <interfaces/iproject.h> | 41 | #include <interfaces/iproject.h> | ||
40 | #include <interfaces/iprojectcontroller.h> | 42 | #include <interfaces/iprojectcontroller.h> | ||
41 | #include <interfaces/iruncontroller.h> | 43 | #include <interfaces/iruncontroller.h> | ||
42 | #include <interfaces/isession.h> | 44 | #include <interfaces/isession.h> | ||
43 | #include <interfaces/iuicontroller.h> | 45 | #include <interfaces/iuicontroller.h> | ||
44 | #include <util/path.h> | 46 | #include <util/path.h> | ||
45 | #include <util/scopeddialog.h> | 47 | #include <util/scopeddialog.h> | ||
46 | #include <vcs/interfaces/ibasicversioncontrol.h> | 48 | #include <vcs/interfaces/ibasicversioncontrol.h> | ||
47 | #include <vcs/models/vcsannotationmodel.h> | 49 | #include <vcs/models/vcsannotationmodel.h> | ||
50 | #if KTEXTEDITOR_VERSION >= QT_VERSION_CHECK(5,52,0) | ||||
51 | #include <vcs/widgets/vcsannotationitemdelegate.h> | ||||
52 | #endif | ||||
48 | #include <vcs/widgets/vcseventwidget.h> | 53 | #include <vcs/widgets/vcseventwidget.h> | ||
49 | #include <vcs/widgets/vcscommitdialog.h> | 54 | #include <vcs/widgets/vcscommitdialog.h> | ||
50 | #include <vcs/vcsjob.h> | 55 | #include <vcs/vcsjob.h> | ||
51 | #include <vcs/vcsrevision.h> | 56 | #include <vcs/vcsrevision.h> | ||
52 | #include <vcs/vcslocation.h> | 57 | #include <vcs/vcslocation.h> | ||
53 | #include <vcs/vcsdiff.h> | 58 | #include <vcs/vcsdiff.h> | ||
54 | 59 | | |||
55 | #include "interfaces/idistributedversioncontrol.h" | 60 | #include "interfaces/idistributedversioncontrol.h" | ||
▲ Show 20 Lines • Show All 301 Lines • ▼ Show 20 Line(s) | |||||
357 | void VcsPluginHelper::annotation() | 362 | void VcsPluginHelper::annotation() | ||
358 | { | 363 | { | ||
359 | SINGLEURL_SETUP_VARS | 364 | SINGLEURL_SETUP_VARS | ||
360 | KDevelop::IDocument* doc = ICore::self()->documentController()->documentForUrl(url); | 365 | KDevelop::IDocument* doc = ICore::self()->documentController()->documentForUrl(url); | ||
361 | 366 | | |||
362 | if (!doc) | 367 | if (!doc) | ||
363 | doc = ICore::self()->documentController()->openDocument(url); | 368 | doc = ICore::self()->documentController()->openDocument(url); | ||
364 | 369 | | |||
370 | KTextEditor::View* view = doc ? doc->activeTextView() : nullptr; | ||||
365 | KTextEditor::AnnotationInterface* annotateiface = qobject_cast<KTextEditor::AnnotationInterface*>(doc->textDocument()); | 371 | KTextEditor::AnnotationInterface* annotateiface = qobject_cast<KTextEditor::AnnotationInterface*>(doc->textDocument()); | ||
366 | KTextEditor::AnnotationViewInterface* viewiface = qobject_cast<KTextEditor::AnnotationViewInterface*>(doc->activeTextView()); | 372 | KTextEditor::AnnotationViewInterface* viewiface = qobject_cast<KTextEditor::AnnotationViewInterface*>(view); | ||
367 | if (viewiface && viewiface->isAnnotationBorderVisible()) { | 373 | if (viewiface && viewiface->isAnnotationBorderVisible()) { | ||
368 | viewiface->setAnnotationBorderVisible(false); | 374 | viewiface->setAnnotationBorderVisible(false); | ||
369 | return; | 375 | return; | ||
370 | } | 376 | } | ||
371 | 377 | | |||
372 | if (doc && doc->textDocument() && iface) { | 378 | if (doc && doc->textDocument() && iface) { | ||
373 | KDevelop::VcsJob* job = iface->annotate(url); | 379 | KDevelop::VcsJob* job = iface->annotate(url); | ||
374 | if( !job ) | 380 | if( !job ) | ||
375 | { | 381 | { | ||
376 | qCWarning(VCS) << "Couldn't create annotate job for:" << url << "with iface:" << iface << dynamic_cast<KDevelop::IPlugin*>( iface ); | 382 | qCWarning(VCS) << "Couldn't create annotate job for:" << url << "with iface:" << iface << dynamic_cast<KDevelop::IPlugin*>( iface ); | ||
377 | return; | 383 | return; | ||
378 | } | 384 | } | ||
379 | 385 | | |||
380 | QColor foreground(Qt::black); | 386 | QColor foreground(Qt::black); | ||
381 | QColor background(Qt::white); | 387 | QColor background(Qt::white); | ||
382 | if (KTextEditor::View* view = doc->activeTextView()) { | 388 | if (view) { | ||
383 | KTextEditor::Attribute::Ptr style = view->defaultStyleAttribute(KTextEditor::dsNormal); | 389 | KTextEditor::Attribute::Ptr style = view->defaultStyleAttribute(KTextEditor::dsNormal); | ||
384 | foreground = style->foreground().color(); | 390 | foreground = style->foreground().color(); | ||
385 | if (style->hasProperty(QTextFormat::BackgroundBrush)) { | 391 | if (style->hasProperty(QTextFormat::BackgroundBrush)) { | ||
386 | background = style->background().color(); | 392 | background = style->background().color(); | ||
387 | } | 393 | } | ||
388 | } | 394 | } | ||
389 | 395 | | |||
390 | if (annotateiface && viewiface) { | 396 | if (annotateiface && viewiface) { | ||
391 | // TODO: only create model if there is none yet (e.g. from another view) | 397 | // TODO: only create model if there is none yet (e.g. from another view) | ||
392 | KDevelop::VcsAnnotationModel* model = new KDevelop::VcsAnnotationModel(job, url, doc->textDocument(), | 398 | KDevelop::VcsAnnotationModel* model = new KDevelop::VcsAnnotationModel(job, url, doc->textDocument(), | ||
393 | foreground, background); | 399 | foreground, background); | ||
394 | annotateiface->setAnnotationModel(model); | 400 | annotateiface->setAnnotationModel(model); | ||
401 | | ||||
kfunk: Or simply:
```
#if KTEXTEDITOR_VERSION > QT_VERSION_CHECK(5,40,0)
...
```
in this file. /me… | |||||
402 | #if KTEXTEDITOR_VERSION >= QT_VERSION_CHECK(5,52,0) | ||||
403 | KTextEditor::AnnotationViewInterfaceV2* viewifaceV2 = qobject_cast<KTextEditor::AnnotationViewInterfaceV2*>(view); | ||||
404 | if (viewifaceV2) { | ||||
405 | // TODO: only create delegate if there is none yet | ||||
406 | VcsAnnotationItemDelegate* delegate = new VcsAnnotationItemDelegate(view, model, view); | ||||
407 | viewifaceV2->setAnnotationItemDelegate(delegate); | ||||
408 | viewifaceV2->setAnnotationUniformItemSizes(true); | ||||
409 | } | ||||
410 | #endif | ||||
395 | viewiface->setAnnotationBorderVisible(true); | 411 | viewiface->setAnnotationBorderVisible(true); | ||
396 | // can't use new signal slot syntax here, AnnotationInterface is not a QObject | 412 | // can't use new signal slot syntax here, AnnotationInterface is not a QObject | ||
397 | connect(doc->activeTextView(), | 413 | connect(view, SIGNAL(annotationContextMenuAboutToShow(KTextEditor::View*,QMenu*,int)), | ||
398 | SIGNAL(annotationContextMenuAboutToShow(KTextEditor::View*,QMenu*,int)), | | |||
399 | this, SLOT(annotationContextMenuAboutToShow(KTextEditor::View*,QMenu*,int))); | 414 | this, SLOT(annotationContextMenuAboutToShow(KTextEditor::View*,QMenu*,int))); | ||
400 | connect(doc->activeTextView(), SIGNAL(annotationBorderVisibilityChanged(View*,bool)), | 415 | connect(view, SIGNAL(annotationBorderVisibilityChanged(View*,bool)), | ||
401 | this, SLOT(handleAnnotationBorderVisibilityChanged(View*,bool))); | 416 | this, SLOT(handleAnnotationBorderVisibilityChanged(View*,bool))); | ||
402 | } else { | 417 | } else { | ||
403 | KMessageBox::error(nullptr, i18n("Cannot display annotations, missing interface KTextEditor::AnnotationInterface for the editor.")); | 418 | KMessageBox::error(nullptr, i18n("Cannot display annotations, missing interface KTextEditor::AnnotationInterface for the editor.")); | ||
404 | delete job; | 419 | delete job; | ||
405 | } | 420 | } | ||
406 | } else { | 421 | } else { | ||
407 | KMessageBox::error(nullptr, i18n("Cannot execute annotate action because the " | 422 | KMessageBox::error(nullptr, i18n("Cannot execute annotate action because the " | ||
408 | "document was not found, or was not a text document:\n%1", url.toDisplayString(QUrl::PreferLocalFile))); | 423 | "document was not found, or was not a text document:\n%1", url.toDisplayString(QUrl::PreferLocalFile))); | ||
▲ Show 20 Lines • Show All 98 Lines • Show Last 20 Lines |
Or simply:
in this file. /me doesn't like #ifdefs, #ifs are easier to track since you're getting compiler warnings when the define gets lost for whatever reason.