Skip to content

Commit 1afcf17

Browse files
committed
bk/2024-06-14-1528
1 parent db21896 commit 1afcf17

9 files changed

Lines changed: 360 additions & 14 deletions

Package/DelphiCopilot.dpk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ contains
5555
DelphiCopilot.AI.Gemini in '..\Src\AI\DelphiCopilot.AI.Gemini.pas',
5656
DelphiCopilot.AI.ChatGPT in '..\Src\AI\DelphiCopilot.AI.ChatGPT.pas',
5757
DelphiCopilot.AI.Interfaces in '..\Src\AI\DelphiCopilot.AI.Interfaces.pas',
58-
DelphiCopilot.Interfaces in '..\Src\Interfaces\DelphiCopilot.Interfaces.pas';
58+
DelphiCopilot.Interfaces in '..\Src\Interfaces\DelphiCopilot.Interfaces.pas',
59+
DelphiCopilot.ModuleCreator.OTA in '..\Src\ModuleCreator\DelphiCopilot.ModuleCreator.OTA.pas',
60+
DelphiCopilot.ModuleCreator in '..\Src\ModuleCreator\DelphiCopilot.ModuleCreator.pas',
61+
DelphiCopilot.ModuleCreator.Interfaces in '..\Src\ModuleCreator\DelphiCopilot.ModuleCreator.Interfaces.pas',
62+
ClientTest in '..\Src\Test\ClientTest.pas';
5963

6064
end.

Package/DelphiCopilot.dproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@
152152
<DCCReference Include="..\Src\AI\DelphiCopilot.AI.ChatGPT.pas"/>
153153
<DCCReference Include="..\Src\AI\DelphiCopilot.AI.Interfaces.pas"/>
154154
<DCCReference Include="..\Src\Interfaces\DelphiCopilot.Interfaces.pas"/>
155+
<DCCReference Include="..\Src\ModuleCreator\DelphiCopilot.ModuleCreator.OTA.pas"/>
156+
<DCCReference Include="..\Src\ModuleCreator\DelphiCopilot.ModuleCreator.pas"/>
157+
<DCCReference Include="..\Src\ModuleCreator\DelphiCopilot.ModuleCreator.Interfaces.pas"/>
158+
<DCCReference Include="..\Src\Test\ClientTest.pas"/>
155159
<BuildConfiguration Include="Release">
156160
<Key>Cfg_2</Key>
157161
<CfgParent>Base</CfgParent>

Src/Chat/DelphiCopilot.Chat.View.dfm

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ object DelphiCopilotChatView: TDelphiCopilotChatView
7575
ParentCtl3D = False
7676
ParentFont = False
7777
ParentShowHint = False
78-
PopupMenu = PopupMenu1
78+
PopupMenu = pMenuMemoReturn
7979
ScrollBars = ssBoth
8080
ShowHint = True
8181
TabOrder = 1
@@ -221,7 +221,7 @@ object DelphiCopilotChatView: TDelphiCopilotChatView
221221
Left = 936
222222
Top = 8
223223
Width = 26
224-
Height = 70
224+
Height = 73
225225
Margins.Left = 0
226226
Margins.Top = 0
227227
Margins.Right = 0
@@ -230,11 +230,19 @@ object DelphiCopilotChatView: TDelphiCopilotChatView
230230
BevelOuter = bvNone
231231
ParentBackground = False
232232
TabOrder = 3
233+
DesignSize = (
234+
26
235+
73)
233236
object ShapeCommands: TShape
234-
Left = 1
237+
Left = 0
235238
Top = 0
236-
Width = 24
237-
Height = 65
239+
Width = 26
240+
Height = 73
241+
Margins.Left = 0
242+
Margins.Top = 0
243+
Margins.Right = 0
244+
Margins.Bottom = 0
245+
Anchors = [akLeft, akTop, akRight, akBottom]
238246
Brush.Style = bsClear
239247
Pen.Color = clGray
240248
Pen.Style = psInsideFrame
@@ -315,7 +323,8 @@ object DelphiCopilotChatView: TDelphiCopilotChatView
315323
Align = alTop
316324
Caption = '...'
317325
Flat = True
318-
PopupMenu = PopupMenu1
326+
PopupMenu = pMenuMoreActions
327+
OnClick = btnMoreActionsClick
319328
end
320329
end
321330
object ImageList1: TImageList
@@ -989,7 +998,7 @@ object DelphiCopilotChatView: TDelphiCopilotChatView
989998
FF80803FC03FFF8FFF80807FFFFFFFFF00000000000000000000000000000000
990999
000000000000}
9911000
end
992-
object PopupMenu1: TPopupMenu
1001+
object pMenuMemoReturn: TPopupMenu
9931002
Left = 96
9941003
Top = 296
9951004
object Cut1: TMenuItem
@@ -1030,4 +1039,12 @@ object DelphiCopilotChatView: TDelphiCopilotChatView
10301039
OnClick = Gemini1Click
10311040
end
10321041
end
1042+
object pMenuMoreActions: TPopupMenu
1043+
Left = 904
1044+
Top = 80
1045+
object CreateNewUnitWithSelectedCode1: TMenuItem
1046+
Caption = 'Create new unit with selected code'
1047+
OnClick = CreateNewUnitWithSelectedCode1Click
1048+
end
1049+
end
10331050
end

Src/Chat/DelphiCopilot.Chat.View.pas

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,14 @@ interface
2727
DelphiCopilot.Types,
2828
DelphiCopilot.Consts,
2929
DelphiCopilot.Chat,
30-
DelphiCopilot.Settings;
30+
DelphiCopilot.Settings,
31+
DelphiCopilot.ModuleCreator,
32+
ClientTest;
3133

3234
type
3335
TDelphiCopilotChatView = class(TDockableForm)
3436
ImageList1: TImageList;
35-
PopupMenu1: TPopupMenu;
37+
pMenuMemoReturn: TPopupMenu;
3638
Cut1: TMenuItem;
3739
Copy1: TMenuItem;
3840
Paste1: TMenuItem;
@@ -58,6 +60,8 @@ TDelphiCopilotChatView = class(TDockableForm)
5860
btnMoreActions: TSpeedButton;
5961
ShapeCommands: TShape;
6062
btnSend: TButton;
63+
pMenuMoreActions: TPopupMenu;
64+
CreateNewUnitWithSelectedCode1: TMenuItem;
6165
procedure FormShow(Sender: TObject);
6266
procedure cBoxSizeFontKeyPress(Sender: TObject; var Key: Char);
6367
procedure Cut1Click(Sender: TObject);
@@ -75,6 +79,8 @@ TDelphiCopilotChatView = class(TDockableForm)
7579
procedure lbCurrentAIClick(Sender: TObject);
7680
procedure Gemini1Click(Sender: TObject);
7781
procedure pMenuCurrentAIPopup(Sender: TObject);
82+
procedure btnMoreActionsClick(Sender: TObject);
83+
procedure CreateNewUnitWithSelectedCode1Click(Sender: TObject);
7884
private
7985
FChat: TDelphiCopilotChat;
8086
FSettings: TDelphiCopilotSettings;
@@ -111,7 +117,6 @@ implementation
111117
DelphiCopilot.Utils,
112118
DelphiCopilot.Utils.OTA;
113119

114-
115120
{$R *.dfm}
116121

117122
procedure RegisterSelf;
@@ -207,7 +212,7 @@ procedure TDelphiCopilotChatView.mmQuestionKeyDown(Sender: TObject; var Key: Wor
207212
begin
208213
btnSend.Click;
209214
Key := 0;
210-
end;
215+
end
211216
end;
212217

213218
procedure TDelphiCopilotChatView.mmQuestionKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
@@ -468,6 +473,11 @@ procedure TDelphiCopilotChatView.btnInsertAtCursorClick(Sender: TObject);
468473
TUtilsOTA.InsertBlockTextIntoEditor(Self.GetSelectedTextOrAll);
469474
end;
470475

476+
procedure TDelphiCopilotChatView.btnMoreActionsClick(Sender: TObject);
477+
begin
478+
pMenuMoreActions.Popup(Mouse.CursorPos.X, Mouse.CursorPos.Y);
479+
end;
480+
471481
procedure TDelphiCopilotChatView.InitializeRichEditReturn;
472482
begin
473483
mmReturn.Lines.Clear;
@@ -522,6 +532,11 @@ procedure TDelphiCopilotChatView.Gemini1Click(Sender: TObject);
522532
Self.ConfLabelCurrentAI;
523533
end;
524534

535+
procedure TDelphiCopilotChatView.CreateNewUnitWithSelectedCode1Click(Sender: TObject);
536+
begin
537+
TDelphiCopilotModuleCreator.New.CreateNewUnit(Self.GetSelectedTextOrAll);
538+
end;
539+
525540
initialization
526541

527542
finalization
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
unit DelphiCopilot.ModuleCreator.Interfaces;
2+
3+
interface
4+
5+
type
6+
IDelphiCopilotModuleCreator = interface
7+
['{9030070E-BD15-4F74-9DA6-DC7357050F43}']
8+
procedure CreateNewUnit(const AContentUnit: string);
9+
end;
10+
11+
implementation
12+
13+
end.
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
unit DelphiCopilot.ModuleCreator.OTA;
2+
3+
interface
4+
5+
uses
6+
System.SysUtils,
7+
System.Classes,
8+
ToolsAPI;
9+
10+
type
11+
TDelphiCopilotModuleCreatorOTA = class(TInterfacedobject, IOTACreator, IOTAModuleCreator)
12+
private
13+
FContentUnit: string;
14+
public
15+
//IOTACreator
16+
function GetCreatorType: string;
17+
function GetExisting: Boolean;
18+
function GetFileSystem: string;
19+
function GetOwner: IOTAModule;
20+
function GetUnnamed: Boolean;
21+
22+
//IOTAModuleCreator
23+
function GetAncestorName: string;
24+
function GetImplFileName: string;
25+
function GetIntfFileName: string;
26+
function GetFormName: string;
27+
function GetMainForm: Boolean;
28+
function GetShowForm: Boolean;
29+
function GetShowSource: Boolean;
30+
function NewFormFile(const FormIdent, AncestorIdent: string): IOTAFile;
31+
function NewImplSource(const ModuleIdent, FormIdent, AncestorIdent: string): IOTAFile;
32+
function NewIntfSource(const ModuleIdent, FormIdent, AncestorIdent: string): IOTAFile;
33+
procedure FormCreated(const FormEditor: IOTAFormEditor);
34+
35+
constructor Create(const AContentUnit: string);
36+
end;
37+
38+
implementation
39+
40+
constructor TDelphiCopilotModuleCreatorOTA.Create(const AContentUnit: string);
41+
begin
42+
FContentUnit := AContentUnit.TrimRight;
43+
end;
44+
45+
function TDelphiCopilotModuleCreatorOTA.GetCreatorType: string;
46+
begin
47+
Result := sApplication;
48+
end;
49+
50+
function TDelphiCopilotModuleCreatorOTA.GetExisting: Boolean;
51+
begin
52+
Result := False;
53+
end;
54+
55+
function TDelphiCopilotModuleCreatorOTA.GetFileSystem: string;
56+
begin
57+
Result := '';
58+
end;
59+
60+
function TDelphiCopilotModuleCreatorOTA.GetOwner: IOTAModule;
61+
begin
62+
Result := GetActiveProject; // (BorlandIDEServices as IOTAModuleServices).MainProjectGroup;
63+
end;
64+
65+
function TDelphiCopilotModuleCreatorOTA.GetUnnamed: Boolean;
66+
begin
67+
Result := True;
68+
end;
69+
70+
{IOTAModuleCreator}
71+
function TDelphiCopilotModuleCreatorOTA.GetAncestorName: string;
72+
begin
73+
Result := '';
74+
end;
75+
76+
function TDelphiCopilotModuleCreatorOTA.GetImplFileName: string;
77+
begin
78+
Result := '';
79+
end;
80+
81+
function TDelphiCopilotModuleCreatorOTA.GetIntfFileName: string;
82+
begin
83+
Result := '';
84+
end;
85+
86+
function TDelphiCopilotModuleCreatorOTA.GetFormName: string;
87+
begin
88+
Result := '';
89+
end;
90+
91+
function TDelphiCopilotModuleCreatorOTA.GetMainForm: Boolean;
92+
begin
93+
Result := False;
94+
end;
95+
96+
function TDelphiCopilotModuleCreatorOTA.GetShowForm: Boolean;
97+
begin
98+
Result := False;
99+
end;
100+
101+
function TDelphiCopilotModuleCreatorOTA.GetShowSource: Boolean;
102+
begin
103+
Result := True;
104+
end;
105+
106+
function TDelphiCopilotModuleCreatorOTA.NewFormFile(const FormIdent, AncestorIdent: string): IOTAFile;
107+
begin
108+
end;
109+
110+
function TDelphiCopilotModuleCreatorOTA.NewImplSource(const ModuleIdent, FormIdent, AncestorIdent: string): IOTAFile;
111+
begin
112+
Result := TOTAFile.Create(FContentUnit);
113+
end;
114+
115+
function TDelphiCopilotModuleCreatorOTA.NewIntfSource(const ModuleIdent, FormIdent, AncestorIdent: string): IOTAFile;
116+
begin
117+
end;
118+
119+
procedure TDelphiCopilotModuleCreatorOTA.FormCreated(const FormEditor: IOTAFormEditor);
120+
begin
121+
end;
122+
123+
end.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
unit DelphiCopilot.ModuleCreator;
2+
3+
interface
4+
5+
uses
6+
System.SysUtils,
7+
System.Classes,
8+
ToolsAPI,
9+
DelphiCopilot.ModuleCreator.Interfaces,
10+
DelphiCopilot.ModuleCreator.OTA,
11+
DelphiCopilot.Utils,
12+
DelphiCopilot.Utils.OTA;
13+
14+
type
15+
IDelphiCopilotModuleCreator = DelphiCopilot.ModuleCreator.Interfaces.IDelphiCopilotModuleCreator;
16+
17+
TDelphiCopilotModuleCreator = class(TInterfacedObject, IDelphiCopilotModuleCreator)
18+
private
19+
protected
20+
procedure CreateNewUnit(const AContentUnit: string);
21+
public
22+
class function New: IDelphiCopilotModuleCreator;
23+
end;
24+
25+
implementation
26+
27+
class function TDelphiCopilotModuleCreator.New: IDelphiCopilotModuleCreator;
28+
begin
29+
Result := Self.Create;
30+
end;
31+
32+
procedure TDelphiCopilotModuleCreator.CreateNewUnit(const AContentUnit: string);
33+
var
34+
LIOTAModuleServices: IOTAModuleServices;
35+
LCodeUnit: TStrings;
36+
begin
37+
LCodeUnit := TStringList.Create;
38+
try
39+
LCodeUnit.Text := AContentUnit.Trim;
40+
41+
if not(LCodeUnit[0].Contains('unit '))then
42+
begin
43+
LCodeUnit.Clear;
44+
LCodeUnit.Add('unit NewUnit;' + sLineBreak);
45+
LCodeUnit.Add('interface' + sLineBreak);
46+
47+
if not(AContentUnit.Contains('implementation')) then
48+
LCodeUnit.Add('implementation' + sLineBreak);
49+
50+
LCodeUnit.Add(AContentUnit.Trim);
51+
end;
52+
53+
if not(LCodeUnit[Pred(LCodeUnit.Count)].Trim.Equals('end.'))then
54+
LCodeUnit.Add(sLineBreak + 'end.');
55+
56+
LIOTAModuleServices := TUtilsOTA.GetIOTAModuleServices;
57+
LIOTAModuleServices.CreateModule(TDelphiCopilotModuleCreatorOTA.Create(LCodeUnit.Text));
58+
finally
59+
LCodeUnit.Free;
60+
end;
61+
end;
62+
63+
end.

0 commit comments

Comments
 (0)