From d384e2398a21608282cb137aa039707a84c80b4e Mon Sep 17 00:00:00 2001 From: Daniel Trevitz Date: Mon, 4 Jun 2018 18:36:36 -0400 Subject: [PATCH] Create Path When the path listed in a PathChooser does not exist, instead of showing actions on non-existent paths show "Create Folder". Task-number: QTCREATORBUG-20532 Change-Id: I98d149129ad33d7be36bfe13b2c1ab57ee193cf0 Reviewed-by: Eike Ziller --- src/plugins/coreplugin/coreplugin.cpp | 42 +++++++++++++++++---------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/plugins/coreplugin/coreplugin.cpp b/src/plugins/coreplugin/coreplugin.cpp index 3f4b13390d0..c2bec4301cd 100644 --- a/src/plugins/coreplugin/coreplugin.cpp +++ b/src/plugins/coreplugin/coreplugin.cpp @@ -58,8 +58,10 @@ #include #include -#include + #include +#include +#include #include #include @@ -68,9 +70,9 @@ using namespace Core::Internal; using namespace Utils; CorePlugin::CorePlugin() - : m_mainWindow(0) - , m_editMode(0) - , m_locator(0) + : m_mainWindow(nullptr) + , m_editMode(nullptr) + , m_locator(nullptr) { qRegisterMetaType(); qRegisterMetaType(); @@ -87,7 +89,7 @@ CorePlugin::~CorePlugin() DesignMode::destroyModeIfRequired(); delete m_mainWindow; - setCreatorTheme(0); + setCreatorTheme(nullptr); } struct CoreArguments { @@ -261,17 +263,27 @@ void CorePlugin::addToPathChooserContextMenu(Utils::PathChooser *pathChooser, QM QList actions = menu->actions(); QAction *firstAction = actions.isEmpty() ? nullptr : actions.first(); - auto *showInGraphicalShell = new QAction(Core::FileUtils::msgGraphicalShellAction(), menu); - connect(showInGraphicalShell, &QAction::triggered, pathChooser, [pathChooser]() { - Core::FileUtils::showInGraphicalShell(pathChooser, pathChooser->path()); - }); - menu->insertAction(firstAction, showInGraphicalShell); + if (QDir().exists(pathChooser->path())) { + auto *showInGraphicalShell = new QAction(Core::FileUtils::msgGraphicalShellAction(), menu); + connect(showInGraphicalShell, &QAction::triggered, pathChooser, [pathChooser]() { + Core::FileUtils::showInGraphicalShell(pathChooser, pathChooser->path()); + }); + menu->insertAction(firstAction, showInGraphicalShell); - auto *showInTerminal = new QAction(Core::FileUtils::msgTerminalAction(), menu); - connect(showInTerminal, &QAction::triggered, pathChooser, [pathChooser]() { - Core::FileUtils::openTerminal(pathChooser->path()); - }); - menu->insertAction(firstAction, showInTerminal); + auto *showInTerminal = new QAction(Core::FileUtils::msgTerminalAction(), menu); + connect(showInTerminal, &QAction::triggered, pathChooser, [pathChooser]() { + Core::FileUtils::openTerminal(pathChooser->path()); + }); + menu->insertAction(firstAction, showInTerminal); + + } else { + auto *mkPathAct = new QAction(tr("Create Folder"), menu); + connect(mkPathAct, &QAction::triggered, pathChooser, [pathChooser]() { + QDir().mkpath(pathChooser->path()); + pathChooser->triggerChanged(); + }); + menu->insertAction(firstAction, mkPathAct); + } if (firstAction) menu->insertSeparator(firstAction);