Commit c0952e22 authored by Tobias Hunger's avatar Tobias Hunger

ICore: Move handling of New File/Project dialog into ICore

ICore only used to pass this on to MainWindow.

Change-Id: I3c4a214330713928a50a291e3c5c6624310db03a
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 5e61c2df
......@@ -34,6 +34,8 @@
#include <app/app_version.h>
#include <extensionsystem/pluginmanager.h>
#include <utils/qtcassert.h>
#include <QSysInfo>
#include <QApplication>
......@@ -283,6 +285,7 @@
specified by \a additionalContexts changed.
*/
#include "dialogs/newdialog.h"
#include "mainwindow.h"
#include "documentmanager.h"
......@@ -301,6 +304,7 @@ namespace Core {
// The Core Singleton
static ICore *m_instance = 0;
static MainWindow *m_mainwindow;
static bool m_isNewItemDialogRunning = false;
ICore *ICore::instance()
{
......@@ -309,7 +313,7 @@ ICore *ICore::instance()
bool ICore::isNewItemDialogRunning()
{
return m_mainwindow->isNewItemDialogRunning();
return m_isNewItemDialogRunning;
}
ICore::ICore(MainWindow *mainwindow)
......@@ -334,7 +338,14 @@ void ICore::showNewItemDialog(const QString &title,
const QString &defaultLocation,
const QVariantMap &extraVariables)
{
m_mainwindow->showNewItemDialog(title, factories, defaultLocation, extraVariables);
QTC_ASSERT(!m_isNewItemDialogRunning, return);
auto newDialog = new NewDialog(dialogParent());
connect(newDialog, &QObject::destroyed, &ICore::newItemDialogClosed);
newDialog->setWizardFactories(factories, defaultLocation, extraVariables);
newDialog->setWindowTitle(title);
newDialog->showDialog();
newItemDialogOpened();
}
bool ICore::showOptionsDialog(const Id page, QWidget *parent)
......@@ -541,4 +552,16 @@ void ICore::saveSettings()
ICore::settings(QSettings::UserScope)->sync();
}
void ICore::newItemDialogOpened()
{
m_isNewItemDialogRunning = true;
emit instance()->newItemDialogRunningChanged();
}
void ICore::newItemDialogClosed()
{
m_isNewItemDialogRunning = false;
emit instance()->newItemDialogRunningChanged();
}
} // namespace Core
......@@ -136,6 +136,10 @@ signals:
void contextAboutToChange(const QList<Core::IContext *> &context);
void contextChanged(const QList<Core::IContext *> &context, const Core::Context &additionalContexts);
void themeChanged();
private:
static void newItemDialogOpened();
static void newItemDialogClosed();
};
} // namespace Core
......
......@@ -237,11 +237,6 @@ void MainWindow::setOverrideColor(const QColor &color)
m_overrideColor = color;
}
bool MainWindow::isNewItemDialogRunning() const
{
return !m_newDialog.isNull();
}
MainWindow::~MainWindow()
{
// explicitly delete window support, because that calls methods from ICore that call methods
......@@ -492,7 +487,13 @@ void MainWindow::registerDefaultActions()
cmd = ActionManager::registerAction(m_newAction, Constants::NEW);
cmd->setDefaultKeySequence(QKeySequence::New);
mfile->addAction(cmd, Constants::G_FILE_NEW);
connect(m_newAction, SIGNAL(triggered()), this, SLOT(newFile()));
connect(m_newAction, &QAction::triggered, this, []() {
ICore::showNewItemDialog(tr("New File or Project", "Title of dialog"),
IWizardFactory::allWizardFactories(), QString());
});
connect(ICore::instance(), &ICore::newItemDialogRunningChanged, m_newAction, [this]() {
m_newAction->setEnabled(!ICore::isNewItemDialogRunning());
});
// Open Action
icon = QIcon::fromTheme(QLatin1String("document-open"), QIcon(QLatin1String(Constants::ICON_OPENFILE)));
......@@ -732,11 +733,6 @@ void MainWindow::registerDefaultActions()
}
}
void MainWindow::newFile()
{
showNewItemDialog(tr("New File or Project", "Title of dialog"), IWizardFactory::allWizardFactories(), QString());
}
void MainWindow::openFile()
{
openFiles(EditorManager::getOpenFileNames(), ICore::SwitchMode);
......@@ -813,21 +809,6 @@ void MainWindow::setFocusToEditor()
EditorManagerPrivate::doEscapeKeyFocusMoveMagic();
}
void MainWindow::showNewItemDialog(const QString &title,
const QList<IWizardFactory *> &factories,
const QString &defaultLocation,
const QVariantMap &extraVariables)
{
QTC_ASSERT(!m_newDialog, return);
m_newAction->setEnabled(false);
m_newDialog = new NewDialog(this);
connect(m_newDialog.data(), SIGNAL(destroyed()), this, SLOT(newItemDialogFinished()));
m_newDialog->setWizardFactories(factories, defaultLocation, extraVariables);
m_newDialog->setWindowTitle(title);
m_newDialog->showDialog();
emit newItemDialogRunningChanged();
}
bool MainWindow::showOptionsDialog(Id page, QWidget *parent)
{
emit m_coreImpl->optionsDialogRequested();
......
......@@ -33,7 +33,6 @@
#include "icontext.h"
#include "icore.h"
#include "dialogs/newdialog.h"
#include <utils/appmainwindow.h>
#include <utils/fileutils.h>
......@@ -109,21 +108,13 @@ public:
void setOverrideColor(const QColor &color);
bool isNewItemDialogRunning() const;
signals:
void newItemDialogRunningChanged();
public slots:
void newFile();
void openFileWith();
void exit();
void showNewItemDialog(const QString &title,
const QList<IWizardFactory *> &factories,
const QString &defaultLocation = QString(),
const QVariantMap &extraVariables = QVariantMap());
bool showOptionsDialog(Id page = Id(), QWidget *parent = 0);
bool showWarningWithOptions(const QString &title, const QString &text,
......@@ -177,7 +168,6 @@ private:
RightPaneWidget *m_rightPaneWidget;
StatusBarWidget *m_outputView;
VersionDialog *m_versionDialog;
QPointer<NewDialog> m_newDialog;
QList<IContext *> m_activeContext;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment