From b5ede805ebd0ad2a7c7d407229be33af8583c7ce Mon Sep 17 00:00:00 2001 From: Russell Greene Date: Sun, 7 May 2017 00:06:27 -0600 Subject: [PATCH] Add module select widget, add it to launch config dialog --- src/CMakeLists.txt | 2 ++ src/chigraphguiui.rc | 2 +- src/launchconfigurationdialog.cpp | 9 +++++---- src/launchconfigurationdialog.hpp | 8 ++++++-- src/launchconfigurationmanager.cpp | 24 +++++++++++++----------- src/launchconfigurationmanager.hpp | 9 ++++++++- src/mainwindow.cpp | 25 ++++++++++++++++--------- src/mainwindow.hpp | 4 ++-- src/moduleselectwidget.cpp | 28 ++++++++++++++++++++++++++++ src/moduleselectwidget.hpp | 24 ++++++++++++++++++++++++ src/moduletreemodel.cpp | 2 ++ 11 files changed, 107 insertions(+), 30 deletions(-) create mode 100644 src/moduleselectwidget.cpp create mode 100644 src/moduleselectwidget.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 810eeca..7911442 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -78,6 +78,7 @@ set(GUI_SRCS structedit.cpp moduletreemodel.cpp moduleselectiondialog.cpp + moduleselectwidget.cpp ) set(GUI_RESOURCES @@ -103,6 +104,7 @@ set(GUI_HEADERS structedit.hpp moduletreemodel.hpp moduleselectiondialog.hpp + moduleselectwidget.hpp ) add_executable(chigraphgui ${GUI_SRCS} ${GUI_HEADERS} ${GUI_RESOURCES}) diff --git a/src/chigraphguiui.rc b/src/chigraphguiui.rc index 75e3c0a..8132a97 100644 --- a/src/chigraphguiui.rc +++ b/src/chigraphguiui.rc @@ -6,11 +6,11 @@ - Process + diff --git a/src/launchconfigurationdialog.cpp b/src/launchconfigurationdialog.cpp index bf70dae..b25e4c2 100644 --- a/src/launchconfigurationdialog.cpp +++ b/src/launchconfigurationdialog.cpp @@ -1,4 +1,5 @@ #include "launchconfigurationdialog.hpp" +#include "moduleselectwidget.hpp" #include @@ -52,8 +53,8 @@ LaunchConfigurationDialog::LaunchConfigurationDialog(LaunchConfigurationManager& // module { - mModuleEdit = new QLineEdit; - connect(mModuleEdit, &QLineEdit::textChanged, this, + mModuleEdit = new ModuleSelectWidget(manager.context()); + connect(mModuleEdit, &ModuleSelectWidget::moduleChanged, this, &LaunchConfigurationDialog::moduleChanged); layout->addRow(i18n("Module"), mModuleEdit); } @@ -123,8 +124,8 @@ void LaunchConfigurationDialog::argsChanged(const QString& newArgs) { if (currentlyEditing.valid()) { currentlyEditing.setArguments(newArgs); } } -void LaunchConfigurationDialog::moduleChanged(const QString& newModule) { - if (currentlyEditing.valid()) { currentlyEditing.setModule(newModule); } +void LaunchConfigurationDialog::moduleChanged(const boost::filesystem::path& newModule) { + if (currentlyEditing.valid()) { currentlyEditing.setModule(QString::fromStdString(newModule.string())); } } void LaunchConfigurationDialog::nameChanged(const QString& newName) { diff --git a/src/launchconfigurationdialog.hpp b/src/launchconfigurationdialog.hpp index 7e8d9f0..4318346 100644 --- a/src/launchconfigurationdialog.hpp +++ b/src/launchconfigurationdialog.hpp @@ -7,9 +7,13 @@ #include "launchconfigurationmanager.hpp" +#include + class QListWidget; class QLineEdit; +class ModuleSelectWidget; + class LaunchConfigurationDialog : public QDialog { Q_OBJECT public: @@ -21,7 +25,7 @@ private slots: void nameChanged(const QString& newName); void wdChanged(const QString& newWd); - void moduleChanged(const QString& newModule); + void moduleChanged(const boost::filesystem::path& newModule); void argsChanged(const QString& newArgs); private: @@ -30,7 +34,7 @@ private slots: QLineEdit* mNameEdit; QLineEdit* mWdEdit; - QLineEdit* mModuleEdit; + ModuleSelectWidget* mModuleEdit; QLineEdit* mArgsEdit; QListWidget* mConfigList; diff --git a/src/launchconfigurationmanager.cpp b/src/launchconfigurationmanager.cpp index 149f64f..b393efd 100644 --- a/src/launchconfigurationmanager.cpp +++ b/src/launchconfigurationmanager.cpp @@ -1,5 +1,7 @@ #include "launchconfigurationmanager.hpp" +#include + #include #include @@ -8,14 +10,16 @@ LaunchConfiguration::LaunchConfiguration(KConfigGroup grp) : mConfigGroup{grp} {} -LaunchConfigurationManager::LaunchConfigurationManager() { - KConfigGroup config(KSharedConfig::openConfig(), "launchconfigurations"); +LaunchConfigurationManager::LaunchConfigurationManager(chi::Context& context) : mContext{&context} { + KConfigGroup contextConfig(KSharedConfig::openConfig(), context.workspacePath().string().c_str()); + + mConfigGroup = contextConfig.group("launchconfigurations"); - auto configurations = config.readEntry("configurations", QStringList()); - auto currentName = config.readEntry("current", QString()); + auto configurations = mConfigGroup.readEntry("configurations", QStringList()); + auto currentName = mConfigGroup.readEntry("current", QString()); for (const auto& configName : configurations) { - mConfigurations.emplace_back(KConfigGroup{KSharedConfig::openConfig(), configName}); + mConfigurations.emplace_back(mConfigGroup.group(configName)); if (configName == currentName) { mCurrent = mConfigurations[mConfigurations.size() - 1]; } } @@ -26,11 +30,10 @@ LaunchConfiguration LaunchConfigurationManager::newConfiguration() { auto uuid = QUuid::createUuid(); // add it to the list - KConfigGroup configs(KSharedConfig::openConfig(), "launchconfigurations"); - configs.writeEntry("configurations", - configs.readEntry("configurations", QStringList()) << uuid.toString()); + mConfigGroup.writeEntry("configurations", + mConfigGroup.readEntry("configurations", QStringList()) << uuid.toString()); - auto group = KConfigGroup{KSharedConfig::openConfig(), uuid.toString()}; + auto group = mConfigGroup.group(uuid.toString()); mConfigurations.emplace_back(group); @@ -40,6 +43,5 @@ LaunchConfiguration LaunchConfigurationManager::newConfiguration() { void LaunchConfigurationManager::setCurrentConfiguration(LaunchConfiguration config) { mCurrent = config; - KConfigGroup kconfig(KSharedConfig::openConfig(), "launchconfigurations"); - kconfig.writeEntry("current", config.id()); + mConfigGroup.writeEntry("current", config.id()); } diff --git a/src/launchconfigurationmanager.hpp b/src/launchconfigurationmanager.hpp index 2a894e0..7289851 100644 --- a/src/launchconfigurationmanager.hpp +++ b/src/launchconfigurationmanager.hpp @@ -7,6 +7,8 @@ #include +#include + struct LaunchConfiguration { // constructs an invalid configuration LaunchConfiguration() {} @@ -40,7 +42,7 @@ struct LaunchConfiguration { class LaunchConfigurationManager : public QObject { Q_OBJECT public: - LaunchConfigurationManager(); + LaunchConfigurationManager(chi::Context& context); LaunchConfigurationManager(const LaunchConfigurationManager&) = delete; LaunchConfigurationManager(LaunchConfigurationManager&&) = delete; @@ -61,10 +63,15 @@ class LaunchConfigurationManager : public QObject { } return {}; } + + chi::Context& context() const { return *mContext; } private: LaunchConfiguration mCurrent; std::vector mConfigurations; + KConfigGroup mConfigGroup; + + chi::Context* mContext; }; #endif // CHIGRAPHGUI_LAUNCH_CONFIGURATION_HPP diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 80a5caf..4c3d775 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -57,6 +57,7 @@ MainWindow::MainWindow(QWidget* parent) : KXmlGuiWindow(parent) { setWindowIcon(QIcon(":/icons/chigraphsmall.png")); mChigContext = std::make_unique(qApp->arguments()[0].toStdString().c_str()); + mLaunchManager = std::make_unique(*mChigContext); mFunctionTabs = new FunctionTabView; mFunctionTabs->setMovable(true); @@ -222,7 +223,7 @@ MainWindow::MainWindow(QWidget* parent) : KXmlGuiWindow(parent) { runConfigDialogAction->setText(i18n("Configure Launches")); actColl->addAction(QStringLiteral("configure-launches"), runConfigDialogAction); connect(runConfigDialogAction, &QAction::triggered, this, [this] { - LaunchConfigurationDialog d(mLaunchManager); + LaunchConfigurationDialog d(launchManager()); d.exec(); @@ -235,11 +236,11 @@ MainWindow::MainWindow(QWidget* parent) : KXmlGuiWindow(parent) { connect(mConfigSelectAction, static_cast(&KSelectAction::triggered), this, [this](const QString& str) { - mLaunchManager.setCurrentConfiguration(mLaunchManager.configByName(str)); + launchManager().setCurrentConfiguration(launchManager().configByName(str)); }); updateUsableConfigs(); - if (mLaunchManager.currentConfiguration().valid()) { - mConfigSelectAction->setCurrentAction(mLaunchManager.currentConfiguration().name(), + if (launchManager().currentConfiguration().valid()) { + mConfigSelectAction->setCurrentAction(launchManager().currentConfiguration().name(), Qt::CaseSensitive); } @@ -291,6 +292,8 @@ void MainWindow::openWorkspaceDialog() { void MainWindow::openWorkspace(const QUrl& url) { mChigContext = std::make_unique(url.toLocalFile().toStdString()); + mLaunchManager = std::make_unique(*mChigContext); + updateUsableConfigs(); workspaceOpened(*mChigContext); } @@ -298,18 +301,22 @@ void MainWindow::openWorkspace(const QUrl& url) { void MainWindow::moduleDirtied(chi::GraphModule& mod) { mModuleBrowser->moduleDirtied(mod); } void MainWindow::updateUsableConfigs() { - // save the current so we can set it back later - QString selectedText = mConfigSelectAction->currentText(); // repopulate mConfigSelectAction->clear(); - for (const auto& config : mLaunchManager.configurations()) { + for (const auto& config : launchManager().configurations()) { mConfigSelectAction->addAction(config.name()); } - // set it back - mConfigSelectAction->setCurrentAction(selectedText, Qt::CaseSensitive); + auto currentConfig = launchManager().currentConfiguration(); + + if (currentConfig.valid()) { + + // set it to the current config + mConfigSelectAction->setCurrentAction(currentConfig.name(), Qt::CaseSensitive); + + } } void MainWindow::closeEvent(QCloseEvent* event) { diff --git a/src/mainwindow.hpp b/src/mainwindow.hpp index 6984812..e911c70 100644 --- a/src/mainwindow.hpp +++ b/src/mainwindow.hpp @@ -36,7 +36,7 @@ class MainWindow : public KXmlGuiWindow { chi::Context& context() const { return *mChigContext; } FunctionTabView& tabView() const { return *mFunctionTabs; } - LaunchConfigurationManager& launchManager() { return mLaunchManager; } + LaunchConfigurationManager& launchManager() { return *mLaunchManager; } std::pair loadModule(const QString& name); @@ -65,7 +65,7 @@ public slots: void updateUsableConfigs(); - LaunchConfigurationManager mLaunchManager; + std::unique_ptr mLaunchManager; KRecentFilesAction* mOpenRecentAction; // keep this so we can save the entries diff --git a/src/moduleselectwidget.cpp b/src/moduleselectwidget.cpp new file mode 100644 index 0000000..7f881f4 --- /dev/null +++ b/src/moduleselectwidget.cpp @@ -0,0 +1,28 @@ +#include "moduleselectwidget.hpp" + +#include "moduleselectiondialog.hpp" + +ModuleSelectWidget::ModuleSelectWidget(chi::Context& ctx) +{ + connect(this, &QPushButton::clicked, this, [this, &ctx](bool) { + + auto modName = ModuleSelectionDialog::getModule(this, ctx); + + if (modName.empty()) { + return; + } + + setModule(modName); + + }); + + setIcon(QIcon::fromTheme(QStringLiteral("package-available"))); +} + +void ModuleSelectWidget::setModule(const boost::filesystem::path& newModule) +{ + setText(QString::fromStdString(newModule.string())); + + emit moduleChanged(newModule); +} + diff --git a/src/moduleselectwidget.hpp b/src/moduleselectwidget.hpp new file mode 100644 index 0000000..4465216 --- /dev/null +++ b/src/moduleselectwidget.hpp @@ -0,0 +1,24 @@ +#pragma once + +#ifndef CHIGRAPHGUI_MODULE_SELECT_WIDGET_HPP +#define CHIGRAPHGUI_MODULE_SELECT_WIDGET_HPP + +#include + +#include + +#include + +class ModuleSelectWidget : public QPushButton { + Q_OBJECT +public: + + ModuleSelectWidget(chi::Context& ctx); + + void setModule(const boost::filesystem::path& newModule); + +signals: + void moduleChanged(const boost::filesystem::path& moduleName); +}; + +#endif // CHIGRAPHGUI_MODULE_SELECT_WIDGET_HPP diff --git a/src/moduletreemodel.cpp b/src/moduletreemodel.cpp index 5958953..78092c8 100644 --- a/src/moduletreemodel.cpp +++ b/src/moduletreemodel.cpp @@ -230,6 +230,8 @@ QVariant ModuleTreeModel::data(const QModelIndex& index, int role) const { return QIcon::fromTheme(QStringLiteral("code-context")); case WorkspaceTree::STRUCT: return QIcon::fromTheme(QStringLiteral("code-class")); + case WorkspaceTree::FOLDER: + return QIcon::fromTheme(QStringLiteral("stock_folder")); default: return {}; }