forked from qt-creator/qt-creator
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 <eike.ziller@qt.io>
This commit is contained in:
@@ -58,8 +58,10 @@
|
|||||||
#include <utils/theme/theme_p.h>
|
#include <utils/theme/theme_p.h>
|
||||||
|
|
||||||
#include <QtPlugin>
|
#include <QtPlugin>
|
||||||
#include <QDebug>
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QDir>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
|
|
||||||
@@ -68,9 +70,9 @@ using namespace Core::Internal;
|
|||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
CorePlugin::CorePlugin()
|
CorePlugin::CorePlugin()
|
||||||
: m_mainWindow(0)
|
: m_mainWindow(nullptr)
|
||||||
, m_editMode(0)
|
, m_editMode(nullptr)
|
||||||
, m_locator(0)
|
, m_locator(nullptr)
|
||||||
{
|
{
|
||||||
qRegisterMetaType<Id>();
|
qRegisterMetaType<Id>();
|
||||||
qRegisterMetaType<Core::Search::TextPosition>();
|
qRegisterMetaType<Core::Search::TextPosition>();
|
||||||
@@ -87,7 +89,7 @@ CorePlugin::~CorePlugin()
|
|||||||
DesignMode::destroyModeIfRequired();
|
DesignMode::destroyModeIfRequired();
|
||||||
|
|
||||||
delete m_mainWindow;
|
delete m_mainWindow;
|
||||||
setCreatorTheme(0);
|
setCreatorTheme(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CoreArguments {
|
struct CoreArguments {
|
||||||
@@ -261,17 +263,27 @@ void CorePlugin::addToPathChooserContextMenu(Utils::PathChooser *pathChooser, QM
|
|||||||
QList<QAction*> actions = menu->actions();
|
QList<QAction*> actions = menu->actions();
|
||||||
QAction *firstAction = actions.isEmpty() ? nullptr : actions.first();
|
QAction *firstAction = actions.isEmpty() ? nullptr : actions.first();
|
||||||
|
|
||||||
auto *showInGraphicalShell = new QAction(Core::FileUtils::msgGraphicalShellAction(), menu);
|
if (QDir().exists(pathChooser->path())) {
|
||||||
connect(showInGraphicalShell, &QAction::triggered, pathChooser, [pathChooser]() {
|
auto *showInGraphicalShell = new QAction(Core::FileUtils::msgGraphicalShellAction(), menu);
|
||||||
Core::FileUtils::showInGraphicalShell(pathChooser, pathChooser->path());
|
connect(showInGraphicalShell, &QAction::triggered, pathChooser, [pathChooser]() {
|
||||||
});
|
Core::FileUtils::showInGraphicalShell(pathChooser, pathChooser->path());
|
||||||
menu->insertAction(firstAction, showInGraphicalShell);
|
});
|
||||||
|
menu->insertAction(firstAction, showInGraphicalShell);
|
||||||
|
|
||||||
auto *showInTerminal = new QAction(Core::FileUtils::msgTerminalAction(), menu);
|
auto *showInTerminal = new QAction(Core::FileUtils::msgTerminalAction(), menu);
|
||||||
connect(showInTerminal, &QAction::triggered, pathChooser, [pathChooser]() {
|
connect(showInTerminal, &QAction::triggered, pathChooser, [pathChooser]() {
|
||||||
Core::FileUtils::openTerminal(pathChooser->path());
|
Core::FileUtils::openTerminal(pathChooser->path());
|
||||||
});
|
});
|
||||||
menu->insertAction(firstAction, showInTerminal);
|
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)
|
if (firstAction)
|
||||||
menu->insertSeparator(firstAction);
|
menu->insertSeparator(firstAction);
|
||||||
|
|||||||
Reference in New Issue
Block a user