Copilot: Take advantage of IOptionPage::setWidgetCreator()

Less boilerplate for the implementation add user code access to
IOptionPage::{apply,finish} is planned to be removed.

Change-Id: I03bbde071fdf673bee0568baa9ae9fab8d816590
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
hjk
2023-04-20 10:40:54 +02:00
parent 8745813721
commit 8d1307552b
4 changed files with 11 additions and 31 deletions

View File

@@ -17,11 +17,10 @@ using namespace LanguageClient;
namespace Copilot { namespace Copilot {
class CopilotOptionsPageWidget : public QWidget class CopilotOptionsPageWidget : public Core::IOptionsPageWidget
{ {
public: public:
CopilotOptionsPageWidget(QWidget *parent = nullptr) CopilotOptionsPageWidget()
: QWidget(parent)
{ {
using namespace Layouting; using namespace Layouting;
@@ -73,6 +72,12 @@ file from the Copilot neovim plugin.
updateAuthWidget); updateAuthWidget);
updateAuthWidget(); updateAuthWidget();
} }
void apply() final
{
CopilotSettings::instance().apply();
CopilotSettings::instance().writeSettings(Core::ICore::settings());
}
}; };
CopilotOptionsPage::CopilotOptionsPage() CopilotOptionsPage::CopilotOptionsPage()
@@ -82,25 +87,9 @@ CopilotOptionsPage::CopilotOptionsPage()
setCategory("ZY.Copilot"); setCategory("ZY.Copilot");
setDisplayCategory("Copilot"); setDisplayCategory("Copilot");
setCategoryIconPath(":/copilot/images/settingscategory_copilot.png"); setCategoryIconPath(":/copilot/images/settingscategory_copilot.png");
setWidgetCreator([] { return new CopilotOptionsPageWidget; });
} }
CopilotOptionsPage::~CopilotOptionsPage() {}
void CopilotOptionsPage::init() {}
QWidget *CopilotOptionsPage::widget()
{
return new CopilotOptionsPageWidget();
}
void CopilotOptionsPage::apply()
{
CopilotSettings::instance().apply();
CopilotSettings::instance().writeSettings(Core::ICore::settings());
}
void CopilotOptionsPage::finish() {}
CopilotOptionsPage &CopilotOptionsPage::instance() CopilotOptionsPage &CopilotOptionsPage::instance()
{ {
static CopilotOptionsPage settingsPage; static CopilotOptionsPage settingsPage;

View File

@@ -11,15 +11,8 @@ class CopilotOptionsPage : public Core::IOptionsPage
{ {
public: public:
CopilotOptionsPage(); CopilotOptionsPage();
~CopilotOptionsPage() override;
static CopilotOptionsPage &instance(); static CopilotOptionsPage &instance();
void init();
QWidget *widget() override;
void apply() override;
void finish() override;
}; };
} // namespace Copilot } // Copilot

View File

@@ -50,7 +50,7 @@ void CopilotPlugin::initialize()
void CopilotPlugin::extensionsInitialized() void CopilotPlugin::extensionsInitialized()
{ {
CopilotOptionsPage::instance().init(); (void)CopilotOptionsPage::instance();
} }
void CopilotPlugin::restartClient() void CopilotPlugin::restartClient()

View File

@@ -9,8 +9,6 @@
#include <QPointer> #include <QPointer>
namespace TextEditor { class TextEditorWidget; }
namespace Copilot { namespace Copilot {
namespace Internal { namespace Internal {