mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-05-28 03:10:28 -04:00
feat: Add project settings panel
This commit is contained in:
parent
dc06ea2ed5
commit
7dee6f62c0
@ -34,6 +34,7 @@
|
||||
#include "core/ChangesManager.h"
|
||||
#include "settings/CodeCompletionSettings.hpp"
|
||||
#include "settings/GeneralSettings.hpp"
|
||||
#include "settings/ProjectSettings.hpp"
|
||||
|
||||
using namespace LanguageServerProtocol;
|
||||
using namespace TextEditor;
|
||||
@ -237,7 +238,11 @@ void QodeAssistClient::cancelRunningRequest(TextEditor::TextEditorWidget *editor
|
||||
|
||||
bool QodeAssistClient::isEnabled(ProjectExplorer::Project *project) const
|
||||
{
|
||||
return Settings::generalSettings().enableQodeAssist();
|
||||
if (!project)
|
||||
return Settings::generalSettings().enableQodeAssist();
|
||||
|
||||
Settings::ProjectSettings settings(project);
|
||||
return settings.isEnabled();
|
||||
}
|
||||
|
||||
void QodeAssistClient::setupConnections()
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "QodeAssistClient.hpp"
|
||||
#include "chat/ChatOutputPane.h"
|
||||
#include "chat/NavigationPanel.hpp"
|
||||
#include "settings/ProjectSettingsPanel.hpp"
|
||||
|
||||
#include "providers/Providers.hpp"
|
||||
#include "templates/Templates.hpp"
|
||||
@ -102,6 +103,8 @@ public:
|
||||
m_chatOutputPane = new Chat::ChatOutputPane(this);
|
||||
m_navigationPanel = new Chat::NavigationPanel();
|
||||
|
||||
Settings::setupProjectPanel();
|
||||
|
||||
ConfigurationManager::instance().init();
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,8 @@ add_library(QodeAssistSettings STATIC
|
||||
CodeCompletionSettings.hpp CodeCompletionSettings.cpp
|
||||
ChatAssistantSettings.hpp ChatAssistantSettings.cpp
|
||||
SettingsDialog.hpp SettingsDialog.cpp
|
||||
ProjectSettings.hpp ProjectSettings.cpp
|
||||
ProjectSettingsPanel.hpp ProjectSettingsPanel.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(QodeAssistSettings
|
||||
|
72
settings/ProjectSettings.cpp
Normal file
72
settings/ProjectSettings.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Petr Mironychev
|
||||
*
|
||||
* This file is part of QodeAssist.
|
||||
*
|
||||
* QodeAssist is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QodeAssist is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ProjectSettings.hpp"
|
||||
|
||||
#include "GeneralSettings.hpp"
|
||||
#include "SettingsConstants.hpp"
|
||||
#include "SettingsTr.hpp"
|
||||
#include <projectexplorer/project.h>
|
||||
|
||||
namespace QodeAssist::Settings {
|
||||
|
||||
ProjectSettings::ProjectSettings(ProjectExplorer::Project *project)
|
||||
{
|
||||
setAutoApply(true);
|
||||
|
||||
useGlobalSettings.setSettingsKey(Constants::QODE_ASSIST_USE_GLOBAL_SETTINGS);
|
||||
useGlobalSettings.setDefaultValue(true);
|
||||
|
||||
enableQodeAssist.setSettingsKey(Constants::QODE_ASSIST_ENABLE_IN_PROJECT);
|
||||
enableQodeAssist.setDisplayName(Tr::tr("Enable Qode Assist"));
|
||||
enableQodeAssist.setLabelText(Tr::tr("Enable Qode Assist"));
|
||||
enableQodeAssist.setDefaultValue(false);
|
||||
|
||||
Utils::Store map = Utils::storeFromVariant(
|
||||
project->namedSettings(Constants::QODE_ASSIST_PROJECT_SETTINGS_ID));
|
||||
fromMap(map);
|
||||
|
||||
enableQodeAssist.addOnChanged(this, [this, project] { save(project); });
|
||||
useGlobalSettings.addOnChanged(this, [this, project] { save(project); });
|
||||
}
|
||||
|
||||
void ProjectSettings::setUseGlobalSettings(bool useGlobal)
|
||||
{
|
||||
useGlobalSettings.setValue(useGlobal);
|
||||
}
|
||||
|
||||
bool ProjectSettings::isEnabled() const
|
||||
{
|
||||
if (useGlobalSettings())
|
||||
return generalSettings().enableQodeAssist();
|
||||
return enableQodeAssist();
|
||||
}
|
||||
|
||||
void ProjectSettings::save(ProjectExplorer::Project *project)
|
||||
{
|
||||
Utils::Store map;
|
||||
toMap(map);
|
||||
project
|
||||
->setNamedSettings(Constants::QODE_ASSIST_PROJECT_SETTINGS_ID, Utils::variantFromStore(map));
|
||||
|
||||
// This triggers a restart
|
||||
generalSettings().apply();
|
||||
}
|
||||
|
||||
} // namespace QodeAssist::Settings
|
43
settings/ProjectSettings.hpp
Normal file
43
settings/ProjectSettings.hpp
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Petr Mironychev
|
||||
*
|
||||
* This file is part of QodeAssist.
|
||||
*
|
||||
* QodeAssist is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QodeAssist is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <utils/aspects.h>
|
||||
|
||||
namespace ProjectExplorer {
|
||||
class Project;
|
||||
}
|
||||
|
||||
namespace QodeAssist::Settings {
|
||||
|
||||
class ProjectSettings : public Utils::AspectContainer
|
||||
{
|
||||
public:
|
||||
explicit ProjectSettings(ProjectExplorer::Project *project);
|
||||
void save(ProjectExplorer::Project *project);
|
||||
|
||||
void setUseGlobalSettings(bool useGlobalSettings);
|
||||
bool isEnabled() const;
|
||||
|
||||
Utils::BoolAspect enableQodeAssist{this};
|
||||
Utils::BoolAspect useGlobalSettings{this};
|
||||
};
|
||||
|
||||
} // namespace QodeAssist::Settings
|
91
settings/ProjectSettingsPanel.cpp
Normal file
91
settings/ProjectSettingsPanel.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Petr Mironychev
|
||||
*
|
||||
* This file is part of QodeAssist.
|
||||
*
|
||||
* QodeAssist is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QodeAssist is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "ProjectSettingsPanel.hpp"
|
||||
|
||||
#include <projectexplorer/project.h>
|
||||
#include <projectexplorer/projectpanelfactory.h>
|
||||
#include <projectexplorer/projectsettingswidget.h>
|
||||
#include <utils/layoutbuilder.h>
|
||||
|
||||
#include "ProjectSettings.hpp"
|
||||
#include "SettingsConstants.hpp"
|
||||
#include "SettingsTr.hpp"
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
namespace QodeAssist::Settings {
|
||||
|
||||
class ProjectSettingsWidget final : public ProjectExplorer::ProjectSettingsWidget
|
||||
{
|
||||
public:
|
||||
ProjectSettingsWidget()
|
||||
{
|
||||
setGlobalSettingsId(Constants::QODE_ASSIST_GENERAL_OPTIONS_ID);
|
||||
setUseGlobalSettingsCheckBoxVisible(true);
|
||||
}
|
||||
};
|
||||
|
||||
static ProjectSettingsWidget *createProjectPanel(Project *project)
|
||||
{
|
||||
using namespace Layouting;
|
||||
|
||||
auto widget = new ProjectSettingsWidget;
|
||||
auto settings = new ProjectSettings(project);
|
||||
settings->setParent(widget);
|
||||
|
||||
QObject::connect(
|
||||
widget,
|
||||
&ProjectSettingsWidget::useGlobalSettingsChanged,
|
||||
settings,
|
||||
&ProjectSettings::setUseGlobalSettings);
|
||||
|
||||
widget->setUseGlobalSettings(settings->useGlobalSettings());
|
||||
widget->setEnabled(!settings->useGlobalSettings());
|
||||
|
||||
QObject::connect(
|
||||
widget, &ProjectSettingsWidget::useGlobalSettingsChanged, widget, [widget](bool useGlobal) {
|
||||
widget->setEnabled(!useGlobal);
|
||||
});
|
||||
|
||||
Column{
|
||||
settings->enableQodeAssist,
|
||||
}
|
||||
.attachTo(widget);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
class ProjectPanelFactory final : public ProjectExplorer::ProjectPanelFactory
|
||||
{
|
||||
public:
|
||||
ProjectPanelFactory()
|
||||
{
|
||||
setPriority(1000);
|
||||
setDisplayName(Tr::tr("Qode Assist"));
|
||||
setCreateWidgetFunction(&createProjectPanel);
|
||||
}
|
||||
};
|
||||
|
||||
void setupProjectPanel()
|
||||
{
|
||||
static ProjectPanelFactory theProjectPanelFactory;
|
||||
}
|
||||
|
||||
} // namespace QodeAssist::Settings
|
26
settings/ProjectSettingsPanel.hpp
Normal file
26
settings/ProjectSettingsPanel.hpp
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2024 Petr Mironychev
|
||||
*
|
||||
* This file is part of QodeAssist.
|
||||
*
|
||||
* QodeAssist is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* QodeAssist is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with QodeAssist. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace QodeAssist::Settings {
|
||||
|
||||
void setupProjectPanel();
|
||||
|
||||
} // namespace QodeAssist::Settings
|
@ -24,6 +24,12 @@ namespace QodeAssist::Constants {
|
||||
const char ACTION_ID[] = "QodeAssist.Action";
|
||||
const char MENU_ID[] = "QodeAssist.Menu";
|
||||
|
||||
// project settings
|
||||
|
||||
const char QODE_ASSIST_PROJECT_SETTINGS_ID[] = "QodeAssist.ProjectSettings";
|
||||
const char QODE_ASSIST_USE_GLOBAL_SETTINGS[] = "QodeAssist.UseGlobalSettings";
|
||||
const char QODE_ASSIST_ENABLE_IN_PROJECT[] = "QodeAssist.EnableInProject";
|
||||
|
||||
// new settings
|
||||
const char CC_PROVIDER[] = "QodeAssist.ccProvider";
|
||||
const char CC_MODEL[] = "QodeAssist.ccModel";
|
||||
|
Loading…
Reference in New Issue
Block a user