From 55c21cecdfd1fe9b192860dc4ed0847ee8df2a57 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Mon, 15 Nov 2021 14:31:19 +0100 Subject: [PATCH] QtDesignStudio: Split "New Files" from "New Project" Just having the "New Project" dialog there is confusing to many users and they do not know how to add new files. Upstream in master we can remove the condition and split the dialog also for Qt Creator. Task-number: QDS-5494 Change-Id: I9a21f27fad932759fcfc412ecfac7f3f6d2bcfee Reviewed-by: Eike Ziller Reviewed-by: Qt CI Bot Reviewed-by: Samuel Ghinet --- src/plugins/coreplugin/coreconstants.h | 1 + src/plugins/coreplugin/mainwindow.cpp | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/plugins/coreplugin/coreconstants.h b/src/plugins/coreplugin/coreconstants.h index 51cfbfc382f..f74c212a838 100644 --- a/src/plugins/coreplugin/coreconstants.h +++ b/src/plugins/coreplugin/coreconstants.h @@ -87,6 +87,7 @@ const char ZOOM_OUT[] = "QtCreator.ZoomOut"; const char ZOOM_RESET[] = "QtCreator.ZoomReset"; const char NEW[] = "QtCreator.New"; +const char NEW_FILE[] = "QtCreator.NewFile"; const char OPEN[] = "QtCreator.Open"; const char OPEN_WITH[] = "QtCreator.OpenWith"; const char REVERTTOSAVED[] = "QtCreator.RevertToSaved"; diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index 83d5a257a57..d2043b733ae 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -527,7 +527,9 @@ void MainWindow::registerDefaultActions() // New File Action QIcon icon = QIcon::fromTheme(QLatin1String("document-new"), Utils::Icons::NEWFILE.icon()); - QString newActionText = isQtDesignStudio() ? tr("&New Project...") : tr("&New File or Project..."); + + const bool isQDS = isQtDesignStudio(); + const QString newActionText = isQDS ? tr("&New Project...") : tr("&New File or Project..."); m_newAction = new QAction(icon, newActionText, this); cmd = ActionManager::registerAction(m_newAction, Constants::NEW); cmd->setDefaultKeySequence(QKeySequence::New); @@ -541,6 +543,24 @@ void MainWindow::registerDefaultActions() } }); + if (isQDS) { + auto action = new QAction(icon, tr("New File..."), this); + cmd = ActionManager::registerAction(action, Constants::NEW_FILE); + mfile->addAction(cmd, Constants::G_FILE_NEW); + connect(action, &QAction::triggered, this, []() { + if (!ICore::isNewItemDialogRunning()) { + ICore::showNewItemDialog( + tr("New File", "Title of dialog"), + Utils::filtered(Core::IWizardFactory::allWizardFactories(), + Utils::equal(&Core::IWizardFactory::kind, + Core::IWizardFactory::FileWizard)), + FilePath()); + } else { + ICore::raiseWindow(ICore::newItemDialog()); + } + }); + } + // Open Action icon = QIcon::fromTheme(QLatin1String("document-open"), Utils::Icons::OPENFILE.icon()); m_openAction = new QAction(icon, tr("&Open File or Project..."), this);