Meson: Move some code out of visible plugin setup

Background for the activity here is that this plugin's setup activities
take on my machine around 0.2s on Creator during Creator startup and
I'd like to reduce that a bit.

Change-Id: I880a0b5ce5c4dce52a041b6a3ef9dc3cef346adb
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
hjk
2023-09-28 07:56:57 +02:00
parent 7bf1b6e586
commit 071416fde3
3 changed files with 17 additions and 32 deletions

View File

@@ -12,36 +12,20 @@
#include "toolssettingsaccessor.h" #include "toolssettingsaccessor.h"
#include "toolssettingspage.h" #include "toolssettingspage.h"
#include <coreplugin/icore.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <projectexplorer/projectmanager.h> #include <projectexplorer/projectmanager.h>
#include <projectexplorer/runcontrol.h> #include <projectexplorer/runcontrol.h>
#include <utils/fsengine/fileiconprovider.h> #include <utils/fsengine/fileiconprovider.h>
using namespace Core;
using namespace ProjectExplorer; using namespace ProjectExplorer;
using namespace Utils; using namespace Utils;
namespace MesonProjectManager::Internal { namespace MesonProjectManager::Internal {
class MesonProjectPluginPrivate : public QObject class MesonProjectPluginPrivate
{ {
Q_OBJECT
public: public:
MesonProjectPluginPrivate()
{
MesonTools::setTools(m_toolsSettings.loadMesonTools(ICore::dialogParent()));
connect(ICore::instance(),
&ICore::saveSettingsRequested,
this,
&MesonProjectPluginPrivate::saveAll);
}
~MesonProjectPluginPrivate() {}
private:
ToolsSettingsPage m_toolslSettingsPage; ToolsSettingsPage m_toolslSettingsPage;
ToolsSettingsAccessor m_toolsSettings; ToolsSettingsAccessor m_toolsSettings;
MesonBuildStepFactory m_buildStepFactory; MesonBuildStepFactory m_buildStepFactory;
@@ -50,11 +34,6 @@ private:
MesonActionsManager m_actions; MesonActionsManager m_actions;
MachineFileManager m_machineFilesManager; MachineFileManager m_machineFilesManager;
SimpleTargetRunnerFactory m_mesonRunWorkerFactory{{m_runConfigurationFactory.runConfigurationId()}}; SimpleTargetRunnerFactory m_mesonRunWorkerFactory{{m_runConfigurationFactory.runConfigurationId()}};
void saveAll()
{
m_toolsSettings.saveMesonTools(MesonTools::tools(), ICore::dialogParent());
}
}; };
MesonProjectPlugin::~MesonProjectPlugin() MesonProjectPlugin::~MesonProjectPlugin()
@@ -72,5 +51,3 @@ void MesonProjectPlugin::initialize()
} }
} // MesonProjectManager::Internal } // MesonProjectManager::Internal
#include "mesonprojectplugin.moc"

View File

@@ -6,6 +6,7 @@
#include "mesonpluginconstants.h" #include "mesonpluginconstants.h"
#include "mesonprojectmanagertr.h" #include "mesonprojectmanagertr.h"
#include <coreplugin/icore.h>
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <utils/filepath.h> #include <utils/filepath.h>
@@ -16,6 +17,7 @@
#include <iterator> #include <iterator>
#include <vector> #include <vector>
using namespace Core;
using namespace Utils; using namespace Utils;
namespace MesonProjectManager { namespace MesonProjectManager {
@@ -30,11 +32,16 @@ ToolsSettingsAccessor::ToolsSettingsAccessor()
{ {
setDocType("QtCreatorMesonTools"); setDocType("QtCreatorMesonTools");
setApplicationDisplayName(QGuiApplication::applicationDisplayName()); setApplicationDisplayName(QGuiApplication::applicationDisplayName());
setBaseFilePath(Core::ICore::userResourcePath(Constants::ToolsSettings::FILENAME)); setBaseFilePath(ICore::userResourcePath(Constants::ToolsSettings::FILENAME));
MesonTools::setTools(loadMesonTools());
QObject::connect(ICore::instance(), &ICore::saveSettingsRequested, [this] {
saveMesonTools(MesonTools::tools());
});
} }
void ToolsSettingsAccessor::saveMesonTools(const std::vector<MesonTools::Tool_t> &tools, void ToolsSettingsAccessor::saveMesonTools(const std::vector<MesonTools::Tool_t> &tools)
QWidget *parent)
{ {
using namespace Constants; using namespace Constants;
Store data; Store data;
@@ -51,13 +58,13 @@ void ToolsSettingsAccessor::saveMesonTools(const std::vector<MesonTools::Tool_t>
entry_count++; entry_count++;
} }
data.insert(ToolsSettings::ENTRY_COUNT, entry_count); data.insert(ToolsSettings::ENTRY_COUNT, entry_count);
saveSettings(data, parent); saveSettings(data, ICore::dialogParent());
} }
std::vector<MesonTools::Tool_t> ToolsSettingsAccessor::loadMesonTools(QWidget *parent) std::vector<MesonTools::Tool_t> ToolsSettingsAccessor::loadMesonTools()
{ {
using namespace Constants; using namespace Constants;
auto data = restoreSettings(parent); auto data = restoreSettings(ICore::dialogParent());
auto entry_count = data.value(ToolsSettings::ENTRY_COUNT, 0).toInt(); auto entry_count = data.value(ToolsSettings::ENTRY_COUNT, 0).toInt();
std::vector<MesonTools::Tool_t> result; std::vector<MesonTools::Tool_t> result;
for (auto toolIndex = 0; toolIndex < entry_count; toolIndex++) { for (auto toolIndex = 0; toolIndex < entry_count; toolIndex++) {

View File

@@ -14,8 +14,9 @@ class ToolsSettingsAccessor final : public Utils::UpgradingSettingsAccessor
{ {
public: public:
ToolsSettingsAccessor(); ToolsSettingsAccessor();
void saveMesonTools(const std::vector<MesonTools::Tool_t> &tools, QWidget *parent);
std::vector<MesonTools::Tool_t> loadMesonTools(QWidget *parent); void saveMesonTools(const std::vector<MesonTools::Tool_t> &tools);
std::vector<MesonTools::Tool_t> loadMesonTools();
}; };
} // namespace Internal } // namespace Internal