mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-05-28 03:10:28 -04:00
Add button for save and load Custom Template
This commit is contained in:
parent
1e0063a7bb
commit
8e61651bae
@ -19,7 +19,9 @@
|
|||||||
|
|
||||||
#include "QodeAssistSettings.hpp"
|
#include "QodeAssistSettings.hpp"
|
||||||
|
|
||||||
|
#include <QFileDialog>
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
#include <QJsonParseError>
|
||||||
#include <QtWidgets/qmessagebox.h>
|
#include <QtWidgets/qmessagebox.h>
|
||||||
#include <coreplugin/dialogs/ioptionspage.h>
|
#include <coreplugin/dialogs/ioptionspage.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
@ -199,6 +201,9 @@ QodeAssistSettings::QodeAssistSettings()
|
|||||||
"stream": true
|
"stream": true
|
||||||
})");
|
})");
|
||||||
|
|
||||||
|
saveCustomTemplateButton.m_buttonText = (Tr::tr("Save Custom Template to JSON"));
|
||||||
|
loadCustomTemplateButton.m_buttonText = (Tr::tr("Load Custom Template from JSON"));
|
||||||
|
|
||||||
const auto &manager = LLMProvidersManager::instance();
|
const auto &manager = LLMProvidersManager::instance();
|
||||||
if (!manager.getProviderNames().isEmpty()) {
|
if (!manager.getProviderNames().isEmpty()) {
|
||||||
const auto providerNames = manager.getProviderNames();
|
const auto providerNames = manager.getProviderNames();
|
||||||
@ -246,7 +251,10 @@ QodeAssistSettings::QodeAssistSettings()
|
|||||||
Form{Column{Row{selectModels, modelName}}}},
|
Form{Column{Row{selectModels, modelName}}}},
|
||||||
Group{title(Tr::tr("FIM Prompt Settings")),
|
Group{title(Tr::tr("FIM Prompt Settings")),
|
||||||
Form{Column{fimPrompts,
|
Form{Column{fimPrompts,
|
||||||
Row{customJsonTemplate, Space{40}},
|
Column{customJsonTemplate,
|
||||||
|
Row{saveCustomTemplateButton,
|
||||||
|
loadCustomTemplateButton,
|
||||||
|
Stretch{1}}},
|
||||||
readFullFile,
|
readFullFile,
|
||||||
maxFileThreshold,
|
maxFileThreshold,
|
||||||
readStringsBeforeCursor,
|
readStringsBeforeCursor,
|
||||||
@ -312,6 +320,15 @@ void QodeAssistSettings::setupConnections()
|
|||||||
connect(&useSpecificInstructions, &Utils::BoolAspect::volatileValueChanged, this, [this]() {
|
connect(&useSpecificInstructions, &Utils::BoolAspect::volatileValueChanged, this, [this]() {
|
||||||
specificInstractions.setEnabled(useSpecificInstructions.volatileValue());
|
specificInstractions.setEnabled(useSpecificInstructions.volatileValue());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
connect(&saveCustomTemplateButton,
|
||||||
|
&ButtonAspect::clicked,
|
||||||
|
this,
|
||||||
|
&QodeAssistSettings::saveCustomTemplate);
|
||||||
|
connect(&loadCustomTemplateButton,
|
||||||
|
&ButtonAspect::clicked,
|
||||||
|
this,
|
||||||
|
&QodeAssistSettings::loadCustomTemplate);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QodeAssistSettings::updateProviderSettings()
|
void QodeAssistSettings::updateProviderSettings()
|
||||||
@ -407,6 +424,64 @@ void QodeAssistSettings::resetSettingsToDefaults()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void QodeAssistSettings::saveCustomTemplate()
|
||||||
|
{
|
||||||
|
QString fileName = QFileDialog::getSaveFileName(nullptr,
|
||||||
|
Tr::tr("Save JSON Template"),
|
||||||
|
QString(),
|
||||||
|
Tr::tr("JSON Files (*.json)"));
|
||||||
|
if (fileName.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QFile file(fileName);
|
||||||
|
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||||
|
QTextStream out(&file);
|
||||||
|
out << customJsonTemplate.value();
|
||||||
|
file.close();
|
||||||
|
QMessageBox::information(nullptr,
|
||||||
|
Tr::tr("Save Successful"),
|
||||||
|
Tr::tr("JSON template has been saved successfully."));
|
||||||
|
} else {
|
||||||
|
QMessageBox::critical(nullptr,
|
||||||
|
Tr::tr("Save Failed"),
|
||||||
|
Tr::tr("Failed to save JSON template."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void QodeAssistSettings::loadCustomTemplate()
|
||||||
|
{
|
||||||
|
QString fileName = QFileDialog::getOpenFileName(nullptr,
|
||||||
|
Tr::tr("Load JSON Template"),
|
||||||
|
QString(),
|
||||||
|
Tr::tr("JSON Files (*.json)"));
|
||||||
|
if (fileName.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QFile file(fileName);
|
||||||
|
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
QTextStream in(&file);
|
||||||
|
QString jsonContent = in.readAll();
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
QJsonParseError parseError;
|
||||||
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonContent.toUtf8(), &parseError);
|
||||||
|
if (parseError.error == QJsonParseError::NoError) {
|
||||||
|
customJsonTemplate.setValue(jsonContent);
|
||||||
|
QMessageBox::information(nullptr,
|
||||||
|
Tr::tr("Load Successful"),
|
||||||
|
Tr::tr("JSON template has been loaded successfully."));
|
||||||
|
} else {
|
||||||
|
QMessageBox::critical(nullptr,
|
||||||
|
Tr::tr("Invalid JSON"),
|
||||||
|
Tr::tr("The selected file contains invalid JSON."));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
QMessageBox::critical(nullptr,
|
||||||
|
Tr::tr("Load Failed"),
|
||||||
|
Tr::tr("Failed to load JSON template."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class QodeAssistSettingsPage : public Core::IOptionsPage
|
class QodeAssistSettingsPage : public Core::IOptionsPage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -98,6 +98,8 @@ public:
|
|||||||
Utils::BoolAspect multiLineCompletion{this};
|
Utils::BoolAspect multiLineCompletion{this};
|
||||||
|
|
||||||
Utils::StringAspect customJsonTemplate{this};
|
Utils::StringAspect customJsonTemplate{this};
|
||||||
|
ButtonAspect saveCustomTemplateButton{this};
|
||||||
|
ButtonAspect loadCustomTemplateButton{this};
|
||||||
Utils::StringAspect apiKey{this};
|
Utils::StringAspect apiKey{this};
|
||||||
|
|
||||||
ButtonAspect resetToDefaults{this};
|
ButtonAspect resetToDefaults{this};
|
||||||
@ -109,6 +111,8 @@ private:
|
|||||||
void showModelSelectionDialog();
|
void showModelSelectionDialog();
|
||||||
Utils::Environment getEnvironmentWithProviderPaths() const;
|
Utils::Environment getEnvironmentWithProviderPaths() const;
|
||||||
void resetSettingsToDefaults();
|
void resetSettingsToDefaults();
|
||||||
|
void saveCustomTemplate();
|
||||||
|
void loadCustomTemplate();
|
||||||
};
|
};
|
||||||
|
|
||||||
QodeAssistSettings &settings();
|
QodeAssistSettings &settings();
|
||||||
|
Loading…
Reference in New Issue
Block a user