Skip to content

Commit e5cf3e5

Browse files
committed
bk/2024-06-15-0037
1 parent 0417b10 commit e5cf3e5

File tree

4 files changed

+142
-18
lines changed

4 files changed

+142
-18
lines changed

Src/Chat/DelphiCopilot.Chat.View.dfm

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ object DelphiCopilotChatView: TDelphiCopilotChatView
221221
Left = 936
222222
Top = 8
223223
Width = 26
224-
Height = 73
224+
Height = 95
225225
Margins.Left = 0
226226
Margins.Top = 0
227227
Margins.Right = 0
@@ -232,12 +232,12 @@ object DelphiCopilotChatView: TDelphiCopilotChatView
232232
TabOrder = 3
233233
DesignSize = (
234234
26
235-
73)
235+
95)
236236
object ShapeCommands: TShape
237237
Left = 0
238238
Top = 0
239239
Width = 26
240-
Height = 73
240+
Height = 95
241241
Margins.Left = 0
242242
Margins.Top = 0
243243
Margins.Right = 0
@@ -246,6 +246,7 @@ object DelphiCopilotChatView: TDelphiCopilotChatView
246246
Brush.Style = bsClear
247247
Pen.Color = clGray
248248
Pen.Style = psInsideFrame
249+
ExplicitHeight = 73
249250
end
250251
object btnCopy: TSpeedButton
251252
AlignWithMargins = True
@@ -324,7 +325,7 @@ object DelphiCopilotChatView: TDelphiCopilotChatView
324325
object btnMoreActions: TSpeedButton
325326
AlignWithMargins = True
326327
Left = 0
327-
Top = 46
328+
Top = 69
328329
Width = 26
329330
Height = 23
330331
Cursor = crHandPoint
@@ -338,6 +339,51 @@ object DelphiCopilotChatView: TDelphiCopilotChatView
338339
Flat = True
339340
PopupMenu = pMenuMoreActions
340341
OnClick = btnMoreActionsClick
342+
ExplicitTop = 46
343+
end
344+
object btnCreateNewUnit: TSpeedButton
345+
AlignWithMargins = True
346+
Left = 0
347+
Top = 46
348+
Width = 26
349+
Height = 23
350+
Cursor = crHandPoint
351+
Hint = 'Create new unit with selected code'
352+
Margins.Left = 0
353+
Margins.Top = 0
354+
Margins.Right = 0
355+
Margins.Bottom = 0
356+
Align = alTop
357+
Flat = True
358+
Glyph.Data = {
359+
36030000424D3603000000000000360000002800000010000000100000000100
360+
1800000000000003000000000000000000000000000000000000FF00FFFF00FF
361+
FF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00
362+
FFFF00FFFF00FFFF00FFFF00FFFF00FFFF00FFAD7384B58484B58484B58484B5
363+
8484B58484B58484B58484B58484B58484B58484B58484FF00FFFF00FFFF00FF
364+
FF00FFAD7384FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
365+
FFFFFFFFB58484FF00FFFF00FFFF00FFFF00FFAD7384FFFFFFFFFFFFFFFFFFFF
366+
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB58484FF00FFFF00FFFF00FF
367+
FF00FFAD7384FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
368+
FFFFFFFFB58484FF00FFFF00FFFF00FFFF00FFAD7384FFFFFFFFFFFFFFFFFFFF
369+
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB58484FF00FFFF00FFFF00FF
370+
FF00FFAD7384FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
371+
FFFFFFFFB58484FF00FFFF00FFFF00FFFF00FFAD7384FFFFFFFFFFFFFFFFFFFF
372+
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFB58484FF00FFFF00FFFF00FF
373+
FF00FFAD7384FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
374+
FFFFFFFFB58484FF00FFFF00FFFF00FF3184FF3184FF3184FFF7F7F7F7F7F7F7
375+
F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7F7B58484FF00FFFF00FFFF00FF
376+
3184FF42B5F73184FFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEFEF
377+
EFEFEFEFB58484FF00FF3184FF3184FF3184FF42B5F73184FF3184FF3184FFE7
378+
E7E7E7E7E7E7E7E7E7E7E7B58473B5948CB58C84B58484FF00FF3184FF8CD6F7
379+
B5DEF7B5DEF7B5DEF78CD6F73184FFDEDEDEDEDEDEDEDEDEC6C6C6B58473FFFF
380+
FFFFFFFFB58484FF00FF3184FF3184FF3184FFB5DEF73184FF3184FF3184FFD6
381+
D6D6D6D6D6D6D6D6C6C6C6B58473FFFFFFB58484FF00FFFF00FFFF00FFFF00FF
382+
3184FFB5DEF73184FFCECECECECECECECECECECECECECECEC6C6C6B58473B584
383+
84FF00FFFF00FFFF00FFFF00FFFF00FF3184FF3184FF3184FFEFD6C6EFD6C6EF
384+
D6C6EFD6C6EFD6C6D6BDB5B58473FF00FFFF00FFFF00FFFF00FF}
385+
OnClick = btnCreateNewUnitClick
386+
ExplicitTop = 55
341387
end
342388
end
343389
object ImageList1: TImageList
@@ -528,10 +574,13 @@ object DelphiCopilotChatView: TDelphiCopilotChatView
528574
Images = ImageList1
529575
Left = 824
530576
Top = 40
531-
object CreateNewUnitWithSelectedCode1: TMenuItem
532-
Caption = 'Create new unit with selected code'
533-
ImageIndex = 0
534-
OnClick = CreateNewUnitWithSelectedCode1Click
577+
object SaveContentToFile1: TMenuItem
578+
Caption = 'Save content to file'
579+
OnClick = SaveContentToFile1Click
580+
end
581+
object ClearContent1: TMenuItem
582+
Caption = 'Clear content'
583+
OnClick = ClearContent1Click
535584
end
536585
end
537586
end

Src/Chat/DelphiCopilot.Chat.View.pas

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ TDelphiCopilotChatView = class(TDockableForm)
6060
ShapeCommands: TShape;
6161
btnSend: TButton;
6262
pMenuMoreActions: TPopupMenu;
63-
CreateNewUnitWithSelectedCode1: TMenuItem;
63+
SaveContentToFile1: TMenuItem;
64+
btnCreateNewUnit: TSpeedButton;
65+
ClearContent1: TMenuItem;
6466
procedure FormShow(Sender: TObject);
6567
procedure cBoxSizeFontKeyPress(Sender: TObject; var Key: Char);
6668
procedure Cut1Click(Sender: TObject);
@@ -79,7 +81,9 @@ TDelphiCopilotChatView = class(TDockableForm)
7981
procedure Gemini1Click(Sender: TObject);
8082
procedure pMenuCurrentAIPopup(Sender: TObject);
8183
procedure btnMoreActionsClick(Sender: TObject);
82-
procedure CreateNewUnitWithSelectedCode1Click(Sender: TObject);
84+
procedure SaveContentToFile1Click(Sender: TObject);
85+
procedure btnCreateNewUnitClick(Sender: TObject);
86+
procedure ClearContent1Click(Sender: TObject);
8387
private
8488
FChat: TDelphiCopilotChat;
8589
FSettings: TDelphiCopilotSettings;
@@ -92,6 +96,7 @@ TDelphiCopilotChatView = class(TDockableForm)
9296
procedure AddResponseLine(const ALineStr: string);
9397
procedure Last;
9498
function GetSelectedTextOrAll: string;
99+
function GetSelectedTextOrAllOrAbort: string;
95100
procedure GetSelectedBlockForQuestion;
96101
procedure WaitingFormOFF;
97102
procedure WaitingFormON;
@@ -466,15 +471,52 @@ function TDelphiCopilotChatView.GetSelectedTextOrAll: string;
466471
Result := mmReturn.Lines.Text;
467472
end;
468473

469-
procedure TDelphiCopilotChatView.btnCopyClick(Sender: TObject);
474+
function TDelphiCopilotChatView.GetSelectedTextOrAllOrAbort: string;
470475
begin
471-
Clipboard.AsText := Self.GetSelectedTextOrAll;
476+
Result := Self.GetSelectedTextOrAll;
477+
if Result.Trim.IsEmpty then
478+
TUtils.ShowMsgAndAbort('There is no data to be used in this action');
472479
end;
473480

474481
procedure TDelphiCopilotChatView.btnInsertAtCursorClick(Sender: TObject);
482+
var
483+
LText: string;
475484
begin
485+
LText := Self.GetSelectedTextOrAllOrAbort;
476486
TUtilsOTA.DeleteBlockTextSelectedInEditor;
477-
TUtilsOTA.InsertBlockTextIntoEditor(Self.GetSelectedTextOrAll);
487+
TUtilsOTA.InsertBlockTextIntoEditor(LText);
488+
end;
489+
490+
procedure TDelphiCopilotChatView.btnCopyClick(Sender: TObject);
491+
var
492+
LText: string;
493+
begin
494+
LText := Self.GetSelectedTextOrAllOrAbort;
495+
Clipboard.AsText := LText;
496+
end;
497+
498+
procedure TDelphiCopilotChatView.btnCreateNewUnitClick(Sender: TObject);
499+
var
500+
LText: string;
501+
begin
502+
LText := Self.GetSelectedTextOrAllOrAbort;
503+
TDelphiCopilotModuleCreator.New.CreateNewUnit(LText);
504+
end;
505+
506+
procedure TDelphiCopilotChatView.SaveContentToFile1Click(Sender: TObject);
507+
var
508+
LFileName: string;
509+
begin
510+
Self.GetSelectedTextOrAllOrAbort;
511+
512+
LFileName := TUtils.GetFileName('rtf');
513+
mmReturn.Lines.SaveToFile(LFileName);
514+
TUtils.ShowV('File saved successfully');
515+
end;
516+
517+
procedure TDelphiCopilotChatView.ClearContent1Click(Sender: TObject);
518+
begin
519+
mmReturn.Lines.Clear;
478520
end;
479521

480522
procedure TDelphiCopilotChatView.btnMoreActionsClick(Sender: TObject);
@@ -536,11 +578,6 @@ procedure TDelphiCopilotChatView.Gemini1Click(Sender: TObject);
536578
Self.ConfLabelCurrentAI;
537579
end;
538580

539-
procedure TDelphiCopilotChatView.CreateNewUnitWithSelectedCode1Click(Sender: TObject);
540-
begin
541-
TDelphiCopilotModuleCreator.New.CreateNewUnit(Self.GetSelectedTextOrAll);
542-
end;
543-
544581
initialization
545582

546583
finalization

Src/Types/DelphiCopilot.Types.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ interface
1616
TDelphiCopilotEscope = (FileCurrent = 0, FilesInGroup = 1, FilesInProject = 2, FilesOpened = 3, FilesInDirectories = 4);
1717
TC4DExtensionsFiles = (None, PAS, DFM, FMX, DPR, DPK, DPROJ, ZIP, BMP, INI, ALL);
1818
TC4DExtensionsOfFiles = set of TC4DExtensionsFiles;
19+
TC4DExtensionsCommons = (rtf);
1920
TDelphiCopilotListUsesKind = (Normal, Directiva);
2021
TDelphiCopilotFavorite = (None, Yes, No);
2122
TDelphiCopilotFileNotification = (None, FileOpened, FileClosing);

Src/Utils/DelphiCopilot.Utils.pas

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ TUtils = class
2626
class function ShowMsgInternal(const AMsg, ADetails: string; const AIcon: TDelphiCopilotIcon;
2727
const AButtons: TC4DButtons; const ABtnFocu: TC4DBtnFocu; const AWinControlFocu: TWinControl): Boolean;
2828
public
29+
class function GetFileName(const AExtension: string): string;
2930
class procedure MemoFocusOnTheEnd(const AMemo: TMemo);
3031
class function IfThenColor(const Conditional: Boolean; const AColorTrue, AColorFalse: TColor): TColor;
3132
class function GetFormFromComponent(const AWinControl: TWinControl): TForm;
@@ -132,6 +133,42 @@ implementation
132133
DelphiCopilot.Consts,
133134
DelphiCopilot.WaitingScreen;
134135

136+
class function TUtils.GetFileName(const AExtension: string): string;
137+
var
138+
LFileName: string;
139+
LSaveDialog: TSaveDialog;
140+
LAsteriskAndExtension: string;
141+
begin
142+
Result := '';
143+
LAsteriskAndExtension := '*.' + AExtension.ToLower;
144+
LFileName := Format('%S-%s.%s', ['Copilot4D', FormatDateTime('yyyyMMdd-hhnnss', now), AExtension.ToLower]);
145+
146+
LSaveDialog := TSaveDialog.Create(nil);
147+
try
148+
LSaveDialog.Title := 'Save file in';
149+
LSaveDialog.DefaulText := LAsteriskAndExtension;
150+
LSaveDialog.Filter := format('File %s (%s)|%s|All files (*.*)|*.*',
151+
[AExtension.ToUpper, LAsteriskAndExtension, LAsteriskAndExtension]);
152+
//LSaveDialog.InitialDir := 'C:\Temp\';
153+
LSaveDialog.FileName := LFileName;
154+
155+
if not(LSaveDialog.Execute) then
156+
Abort;
157+
158+
if FileExists(LSaveDialog.FileName) then
159+
begin
160+
if not(TUtils.ShowQuestion('There is already a file with the same name in this location.' + sLineBreak +
161+
'Do you want to replace it?'))
162+
then
163+
Abort;
164+
end;
165+
166+
Result := LSaveDialog.FileName;
167+
finally
168+
LSaveDialog.Free;
169+
end;
170+
end;
171+
135172
class procedure TUtils.MemoFocusOnTheEnd(const AMemo: TMemo);
136173
begin
137174
TThread.CreateAnonymousThread(

0 commit comments

Comments
 (0)