Changeset View
Changeset View
Standalone View
Standalone View
plugins/projectmanagerview/projectmanagerviewplugin.cpp
Show All 26 Lines | |||||
27 | #include <QMimeData> | 27 | #include <QMimeData> | ||
28 | #include <QUrl> | 28 | #include <QUrl> | ||
29 | 29 | | |||
30 | #include <KActionCollection> | 30 | #include <KActionCollection> | ||
31 | #include <KLocalizedString> | 31 | #include <KLocalizedString> | ||
32 | #include <KMessageBox> | 32 | #include <KMessageBox> | ||
33 | #include <KParts/MainWindow> | 33 | #include <KParts/MainWindow> | ||
34 | #include <KPluginFactory> | 34 | #include <KPluginFactory> | ||
35 | #include <KIO/Paste> | ||||
36 | #include <KFileItem> | ||||
37 | #include <KUrlMimeData> | ||||
35 | 38 | | |||
36 | #include <project/projectmodel.h> | 39 | #include <project/projectmodel.h> | ||
37 | #include <project/projectbuildsetmodel.h> | 40 | #include <project/projectbuildsetmodel.h> | ||
38 | #include <interfaces/icore.h> | 41 | #include <interfaces/icore.h> | ||
39 | #include <interfaces/iproject.h> | 42 | #include <interfaces/iproject.h> | ||
40 | #include <project/interfaces/iprojectfilemanager.h> | 43 | #include <project/interfaces/iprojectfilemanager.h> | ||
41 | #include <project/interfaces/ibuildsystemmanager.h> | 44 | #include <project/interfaces/ibuildsystemmanager.h> | ||
42 | #include <interfaces/iuicontroller.h> | 45 | #include <interfaces/iuicontroller.h> | ||
Show All 10 Lines | |||||
53 | #include "projectmanagerview.h" | 56 | #include "projectmanagerview.h" | ||
54 | #include "debug.h" | 57 | #include "debug.h" | ||
55 | 58 | | |||
56 | using namespace KDevelop; | 59 | using namespace KDevelop; | ||
57 | 60 | | |||
58 | Q_LOGGING_CATEGORY(PLUGIN_PROJECTMANAGERVIEW, "kdevplatform.plugins.projectmanagerview") | 61 | Q_LOGGING_CATEGORY(PLUGIN_PROJECTMANAGERVIEW, "kdevplatform.plugins.projectmanagerview") | ||
59 | K_PLUGIN_FACTORY_WITH_JSON(ProjectManagerFactory, "kdevprojectmanagerview.json", registerPlugin<ProjectManagerViewPlugin>();) | 62 | K_PLUGIN_FACTORY_WITH_JSON(ProjectManagerFactory, "kdevprojectmanagerview.json", registerPlugin<ProjectManagerViewPlugin>();) | ||
60 | 63 | | |||
61 | class KDevProjectManagerViewFactory: public KDevelop::IToolViewFactory | 64 | class KDevProjectManagerViewFactory: public KDevelop::IToolViewFactory | ||
mwolff: instead of static, wrap it in an anonymous namespace
the result is the same, but I much prefer… | |||||
62 | { | 65 | { | ||
63 | public: | 66 | public: | ||
64 | KDevProjectManagerViewFactory( ProjectManagerViewPlugin *plugin ): mplugin( plugin ) | 67 | KDevProjectManagerViewFactory( ProjectManagerViewPlugin *plugin ): mplugin( plugin ) | ||
65 | {} | 68 | {} | ||
66 | QWidget* create( QWidget *parent = 0 ) override | 69 | QWidget* create( QWidget *parent = 0 ) override | ||
67 | { | 70 | { | ||
68 | return new ProjectManagerView( mplugin, parent ); | 71 | return new ProjectManagerView( mplugin, parent ); | ||
69 | } | 72 | } | ||
▲ Show 20 Lines • Show All 159 Lines • ▼ Show 20 Line(s) | 228 | foreach( ProjectBaseItem* item, items ) { | |||
229 | 232 | | |||
230 | //needsCloseProjects if items are limited to top level folders (Project Folders) | 233 | //needsCloseProjects if items are limited to top level folders (Project Folders) | ||
231 | needsCloseProjects &= item->folder() && !item->folder()->parent(); | 234 | needsCloseProjects &= item->folder() && !item->folder()->parent(); | ||
232 | 235 | | |||
233 | //needsFolderItems if items are limited to folders | 236 | //needsFolderItems if items are limited to folders | ||
234 | needsFolderItems &= (bool)item->folder(); | 237 | needsFolderItems &= (bool)item->folder(); | ||
235 | 238 | | |||
236 | //needsRemove if items are limited to non-top-level folders or files that don't belong to targets | 239 | //needsRemove if items are limited to non-top-level folders or files that don't belong to targets | ||
237 | needsRemoveAndRename &= (item->folder() && item->parent()) || (item->file() && !item->parent()->target()); | 240 | needsRemoveAndRename &= (item->folder() && item->parent()) || (item->file() && !item->parent()->target()); | ||
this means we cannot paste into the project root, no? since the project root has no parent, but is a folder? mwolff: this means we cannot paste into the project root, no? since the project root has no parent, but… | |||||
No, this means we cannot cut/rename/delete the project root. I didn't invent this logic, it has been there and worked well for a few years already. aspotashev: No, this means we cannot cut/rename/delete the project root. I didn't invent this logic, it has… | |||||
238 | 241 | | |||
239 | //needsRemoveTargets if items are limited to file items with target parents | 242 | //needsRemoveTargets if items are limited to file items with target parents | ||
240 | needsRemoveTargetFiles &= (item->file() && item->parent()->target()); | 243 | needsRemoveTargetFiles &= (item->file() && item->parent()->target()); | ||
241 | } | 244 | } | ||
242 | 245 | | |||
243 | if ( needsCreateFile ) { | 246 | if ( needsCreateFile ) { | ||
244 | QAction* action = new QAction( i18n( "Create File..." ), this ); | 247 | QAction* action = new QAction( i18n( "Create File..." ), this ); | ||
245 | action->setIcon(QIcon::fromTheme(QStringLiteral("document-new"))); | 248 | action->setIcon(QIcon::fromTheme(QStringLiteral("document-new"))); | ||
Show All 38 Lines | 284 | if ( needsFolderItems ) { | |||
284 | connect( action, &QAction::triggered, this, &ProjectManagerViewPlugin::reloadFromContextMenu ); | 287 | connect( action, &QAction::triggered, this, &ProjectManagerViewPlugin::reloadFromContextMenu ); | ||
285 | menuExt.addAction( ContextMenuExtension::FileGroup, action ); | 288 | menuExt.addAction( ContextMenuExtension::FileGroup, action ); | ||
286 | } | 289 | } | ||
287 | if ( needsRemoveAndRename ) { | 290 | if ( needsRemoveAndRename ) { | ||
288 | QAction* remove = new QAction( i18n( "Remove" ), this ); | 291 | QAction* remove = new QAction( i18n( "Remove" ), this ); | ||
289 | remove->setIcon(QIcon::fromTheme(QStringLiteral("user-trash"))); | 292 | remove->setIcon(QIcon::fromTheme(QStringLiteral("user-trash"))); | ||
290 | connect( remove, &QAction::triggered, this, &ProjectManagerViewPlugin::removeFromContextMenu ); | 293 | connect( remove, &QAction::triggered, this, &ProjectManagerViewPlugin::removeFromContextMenu ); | ||
291 | menuExt.addAction( ContextMenuExtension::FileGroup, remove ); | 294 | menuExt.addAction( ContextMenuExtension::FileGroup, remove ); | ||
295 | | ||||
296 | QAction* cut = KStandardAction::cut(this, SLOT(cutFromContextMenu()), this); | ||||
297 | cut->setShortcutContext(Qt::WidgetShortcut); | ||||
298 | menuExt.addAction(ContextMenuExtension::FileGroup, cut); | ||||
299 | | ||||
292 | QAction* rename = new QAction( i18n( "Rename..." ), this ); | 300 | QAction* rename = new QAction( i18n( "Rename..." ), this ); | ||
293 | rename->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); | 301 | rename->setIcon(QIcon::fromTheme(QStringLiteral("edit-rename"))); | ||
294 | connect( rename, &QAction::triggered, this, &ProjectManagerViewPlugin::renameItemFromContextMenu ); | 302 | connect( rename, &QAction::triggered, this, &ProjectManagerViewPlugin::renameItemFromContextMenu ); | ||
295 | menuExt.addAction( ContextMenuExtension::FileGroup, rename ); | 303 | menuExt.addAction( ContextMenuExtension::FileGroup, rename ); | ||
296 | } | 304 | } | ||
297 | if ( needsRemoveTargetFiles ) { | 305 | if ( needsRemoveTargetFiles ) { | ||
298 | QAction* remove = new QAction( i18n( "Remove From Target" ), this ); | 306 | QAction* remove = new QAction( i18n( "Remove From Target" ), this ); | ||
299 | remove->setIcon(QIcon::fromTheme(QStringLiteral("user-trash"))); | 307 | remove->setIcon(QIcon::fromTheme(QStringLiteral("user-trash"))); | ||
▲ Show 20 Lines • Show All 351 Lines • ▼ Show 20 Line(s) | 658 | { | |||
651 | ProjectFileItem* f=createFile(folder); | 659 | ProjectFileItem* f=createFile(folder); | ||
652 | if(f) | 660 | if(f) | ||
653 | item->project()->buildSystemManager()->addFilesToTarget(QList<ProjectFileItem*>() << f, item->target()); | 661 | item->project()->buildSystemManager()->addFilesToTarget(QList<ProjectFileItem*>() << f, item->target()); | ||
654 | } | 662 | } | ||
655 | } | 663 | } | ||
656 | } | 664 | } | ||
657 | } | 665 | } | ||
658 | 666 | | |||
659 | void ProjectManagerViewPlugin::copyFromContextMenu() | 667 | QMimeData* ProjectManagerViewPlugin::createClipboardMimeData(bool cut) | ||
660 | { | 668 | { | ||
661 | KDevelop::ProjectItemContext* ctx = dynamic_cast<KDevelop::ProjectItemContext*>(ICore::self()->selectionController()->currentSelection()); | 669 | KDevelop::ProjectItemContext* ctx = dynamic_cast<KDevelop::ProjectItemContext*>( | ||
670 | ICore::self()->selectionController()->currentSelection()); | ||||
kfunk: Could do `auto ctx = ...` | |||||
662 | QList<QUrl> urls; | 671 | QList<QUrl> urls; | ||
672 | QList<QUrl> mostLocalUrls; | ||||
673 | bool dummy; | ||||
kfunk: Not needed | |||||
663 | foreach (ProjectBaseItem* item, ctx->items()) { | 674 | foreach (ProjectBaseItem* item, ctx->items()) { | ||
664 | if (item->folder() || item->file()) { | 675 | if (item->folder() || item->file()) { | ||
665 | urls << item->path().toUrl(); | 676 | const QUrl& url = item->path().toUrl(); | ||
677 | urls << url; | ||||
678 | mostLocalUrls << KFileItem(url).mostLocalUrl(dummy); | ||||
kfunk: `KFileItem(url).mostLocalUrl()` should work? | |||||
666 | } | 679 | } | ||
667 | } | 680 | } | ||
668 | qCDebug(PLUGIN_PROJECTMANAGERVIEW) << urls; | 681 | qCDebug(PLUGIN_PROJECTMANAGERVIEW) << urls; | ||
669 | if (!urls.isEmpty()) { | 682 | | ||
670 | QMimeData* data = new QMimeData; | 683 | if (urls.isEmpty()) { | ||
671 | data->setUrls(urls); | 684 | return nullptr; | ||
672 | qApp->clipboard()->setMimeData(data); | 685 | } | ||
686 | | ||||
687 | QMimeData* mimeData = new QMimeData; | ||||
688 | KIO::setClipboardDataCut(mimeData, cut); | ||||
689 | KUrlMimeData::setUrls(urls, mostLocalUrls, mimeData); | ||||
690 | return mimeData; | ||||
673 | } | 691 | } | ||
692 | | ||||
693 | void ProjectManagerViewPlugin::copyFromContextMenu() | ||||
694 | { | ||||
695 | qApp->clipboard()->setMimeData(createClipboardMimeData(false)); | ||||
696 | } | ||||
697 | | ||||
698 | void ProjectManagerViewPlugin::cutFromContextMenu() | ||||
699 | { | ||||
700 | qApp->clipboard()->setMimeData(createClipboardMimeData(true)); | ||||
674 | } | 701 | } | ||
675 | 702 | | |||
676 | void ProjectManagerViewPlugin::pasteFromContextMenu() | 703 | void ProjectManagerViewPlugin::pasteFromContextMenu() | ||
677 | { | 704 | { | ||
678 | KDevelop::ProjectItemContext* ctx = dynamic_cast<KDevelop::ProjectItemContext*>(ICore::self()->selectionController()->currentSelection()); | 705 | KDevelop::ProjectItemContext* ctx = dynamic_cast<KDevelop::ProjectItemContext*>(ICore::self()->selectionController()->currentSelection()); | ||
679 | if (ctx->items().count() != 1) | 706 | if (ctx->items().count() != 1) | ||
680 | return; //do nothing if multiple or none items are selected | 707 | return; //do nothing if multiple or none items are selected | ||
681 | 708 | | |||
Show All 23 Lines | 729 | foreach (ProjectBaseItem *item, destItem->children()) { | |||
705 | } | 732 | } | ||
706 | } | 733 | } | ||
707 | } | 734 | } | ||
708 | viewCtx->view()->selectItems(newItems); | 735 | viewCtx->view()->selectItems(newItems); | ||
709 | } | 736 | } | ||
710 | } | 737 | } | ||
711 | } | 738 | } | ||
712 | 739 | | |||
713 | 740 | | |||
Can be a free function inside namespace {}. I'd also rename to createSeparatorAction kfunk: Can be a free function inside `namespace {}`.
I'd also rename to `createSeparatorAction` | |||||
Changed to a static function instead because namespace {} takes more lines of code and is harder to read. aspotashev: Changed to a static function instead because namespace {} takes more lines of code and is… | |||||
714 | #include "projectmanagerviewplugin.moc" | 741 | #include "projectmanagerviewplugin.moc" | ||
715 | 742 | |
instead of static, wrap it in an anonymous namespace
the result is the same, but I much prefer the C++ way of doing this