-
Notifications
You must be signed in to change notification settings - Fork 4
/
umain.pas
114 lines (87 loc) · 3.53 KB
/
umain.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
unit Umain;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LazLoggerBase, FileUtil, Forms, Controls, Graphics,
Dialogs, LCLType, Spin, StdCtrls, Buttons, ExtCtrls, IDECommands,
IDEWindowIntf, LazIDEIntf, SrcEditorIntf, MenuIntf, UQuestion, USetting;
var
Frm_Question: TFrm_Question;
Frm_QuestionCreator: TIDEWindowCreator; // set by Register procedure
procedure ShowQuestionForm(Sender: TObject);
procedure ShowSettingForm(Sender: TObject);
procedure Register;
implementation
resourcestring
SCaption = 'ASK';
const
FORM_NAME='Frm_Question'; //should be distinct of design time form.Name
procedure ShowQuestionForm(Sender: TObject);
begin
IDEWindowCreators.ShowForm(Frm_QuestionCreator.FormName, True);
end;
procedure CreateFrm_Question(Sender: TObject; aFormName: string; var AForm: TCustomForm; DoDisableAutoSizing: boolean);
begin
if CompareText(aFormName, FORM_NAME) <> 0 then
begin
DebugLn(['ERROR: There is already a form with this name']);
Exit;
end;
IDEWindowCreators.CreateForm(AForm, TFrm_Question, DoDisableAutoSizing, LazarusIDE.OwningComponent);
AForm.Name := aFormName;
AForm.Caption := 'ChatGPT';
Frm_Question := AForm as TFrm_Question;
end;
procedure ShowSettingForm(Sender: TObject);
var
LvSettingFrm: TFrm_Setting;
begin
LvSettingFrm := TFrm_Setting.Create(Application);
try
TSingletonSettingObj.Instance.ReadConfig;
with TSingletonSettingObj.Instance do
begin
LvSettingFrm.edt_Url.Text := URL;
LvSettingFrm.edt_ApiKey.Text := ApiKey;
LvSettingFrm.cbbModel.Text := Model;
LvSettingFrm.edt_MaxToken.Text := IntToStr(MaxToken);
LvSettingFrm.edt_Temperature.Text := IntToStr(Temperature);
LvSettingFrm.edtTimeout.Text := IntToStr(TimeOut);
LvSettingFrm.chk_AnimatedLetters.Checked := AnimatedLetters;
end;
LvSettingFrm.ShowModal;
finally
LvSettingFrm.Free;
end;
end;
procedure Register;
var
LvCommandCategory: TIDECommandCategory;
LvIDECommand, LvIDESettingCommand: TIDECommand;
LvMenuItemCaption: string;
LvMenuSection, LvChatGPTHeaderMenu: TIDEMenuSection;
begin
LvMenuItemCaption := SCaption;
// Find shortcut category
LvCommandCategory := IDECommandList.FindCategoryByName(CommandCategoryCodeTools);
// Register shortcut
LvIDECommand := RegisterIDECommand(LvCommandCategory, 'ChatGPTCommandShrtCt',
LvMenuItemCaption, IDEShortCut(VK_C, [ssShift, ssAlt, ssCtrl]), // <- set here your default shortcut
CleanIDEShortCut, nil, @ShowQuestionForm);
// Register menu section
LvMenuSection := RegisterIDEMenuSection(itmCustomTools, 'ChatGPTSec');
// Register menu item in tools menu and under our created section.
LvChatGPTHeaderMenu := RegisterIDESubMenu(LvMenuSection, 'ChatPGTSubMenu', 'ChatGPT', nil, nil);
RegisterIDEMenuCommand(LvChatGPTHeaderMenu, 'ChatGPTCommandShrtCt', LvMenuItemCaption, nil, nil, LvIDECommand);
LvIDESettingCommand := RegisterIDECommand(LvCommandCategory, 'ChatGPTCommandShrtCt',
'Setting', IDEShortCut(VK_S, [ssShift, ssAlt, ssCtrl]), // <- set here your default shortcut
CleanIDEShortCut, nil, @ShowSettingForm);
RegisterIDEMenuCommand(LvChatGPTHeaderMenu, 'ChatGPTSettingShrtCt', 'Setting', nil, nil, LvIDESettingCommand);
// register dockable Window
Frm_QuestionCreator := IDEWindowCreators.Add(FORM_NAME, @CreateFrm_Question,
nil, '100', '100', '420', '620' // default place at left=100, top=100, right=300, bottom=300
// you can also define percentage values of screen or relative positions, see wiki
);
TSingletonSettingObj.Instance.ReadConfig;
end;
end.