Skip to content

Commit

Permalink
Minor fixes:
Browse files Browse the repository at this point in the history
- A drop-down has been added to clear all button to clear question or answer individually.
- DblClick on question in history will bring back question to question area.
- Added a new menu item to Clear the whole history with add yes-no question.
  • Loading branch information
AliDehbansiahkarbon committed May 3, 2023
1 parent 70f40c2 commit 718c49c
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 32 deletions.
34 changes: 31 additions & 3 deletions Forms/UChatGPTQFrame.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ object Fram_Question: TFram_Question
object Btn_Clear: TButton
Left = 271
Top = 8
Width = 74
Width = 78
Height = 27
Caption = 'Clear All'
DropDownMenu = pmClear
Style = bsSplitButton
TabOrder = 2
OnClick = Btn_ClearClick
end
Expand Down Expand Up @@ -196,8 +198,6 @@ object Fram_Question: TFram_Question
Font.Height = -13
Font.Name = 'Segoe UI'
Font.Style = [fsBold]
Lines.Strings = (
'')
ParentFont = False
ParentShowHint = False
ScrollBars = ssVertical
Expand Down Expand Up @@ -485,5 +485,33 @@ object Fram_Question: TFram_Question
Caption = 'Search'
OnClick = SearchMnuClick
end
object N1: TMenuItem
Caption = '-'
end
object Clearallhistoryitems1: TMenuItem
Bitmap.Data = {
F6000000424DF600000000000000760000002800000010000000100000000100
0400000000008000000000000000000000001000000000000000000000000000
80000080000000808000800000008000800080800000C0C0C000808080000000
FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
7777777777777777777777778777777777777777177777777777777711777781
7777777781877818777777777118711777777777781111777777777778111777
7777777781111877777777771187118777777777777771187777777777777711
8777777777777777777777777777777777777777777777777777}
Caption = 'Clear all the history items!'
OnClick = Clearallhistoryitems1Click
end
end
object pmClear: TPopupMenu
Left = 336
Top = 232
object ClearQuestion1: TMenuItem
Caption = 'Clear Question'
OnClick = ClearQuestion1Click
end
object ClearAnswer1: TMenuItem
Caption = 'Clear Answers'
OnClick = ClearAnswer1Click
end
end
end
90 changes: 72 additions & 18 deletions Forms/UChatGPTQFrame.pas
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ TFram_Question = class(TFrame)
mmoYouChatAnswer: TMemo;
ActivityIndicator1: TActivityIndicator;
GetQuestion: TMenuItem;
pmClear: TPopupMenu;
ClearQuestion1: TMenuItem;
ClearAnswer1: TMenuItem;
Clearallhistoryitems1: TMenuItem;
N1: TMenuItem;
procedure Btn_AskClick(Sender: TObject);
procedure Btn_ClipboardClick(Sender: TObject);
procedure CopytoClipboard1Click(Sender: TObject);
Expand Down Expand Up @@ -126,6 +131,10 @@ TFram_Question = class(TFrame)
procedure pgcMainChanging(Sender: TObject; var AllowChange: Boolean);
procedure pgcAnswersChange(Sender: TObject);
procedure GetQuestionClick(Sender: TObject);
procedure ClearQuestion1Click(Sender: TObject);
procedure ClearAnswer1Click(Sender: TObject);
procedure HistoryDBGridDblClick(Sender: TObject);
procedure Clearallhistoryitems1Click(Sender: TObject);
private
FChatGPTTrd: TExecutorTrd;
{$IF CompilerVersion >= 32.0}
Expand All @@ -149,6 +158,7 @@ TFram_Question = class(TFrame)
procedure HighlightCellTextFuzzy(AGrid: TDbGrid; const ARect: TRect; AField: TField; AMatchedIndexes : TList; AState: TGridDrawState ;
ACaseSensitive: Boolean; ABkColor: TColor; ASelectedBkColor: TColor);
procedure EnableUI(ATaskName: string);
procedure ClearAnswers;
public
procedure InitialFrame;
procedure InitialClassViewMenueItems(AClassList: TClassList);
Expand Down Expand Up @@ -381,9 +391,42 @@ procedure TFram_Question.ClassViewMenuItemClick(Sender: TObject);
end;
end;

procedure TFram_Question.Clearallhistoryitems1Click(Sender: TObject);
begin
if FDQryHistory.IsEmpty then
Exit;

if MessageDlg('Are you sure you want to clear all history items?', TMsgDlgType.mtWarning, [mbYes, mbNo], 0, mbNo) = mrYes then
begin
FDConnection.ExecSQL('Delete from TbHistory');
FDQryHistory.Close;
FDQryHistory.Open;
mmoHistoryDetail.Clear;
FCellCloseBtn.Parent := Self;
end;
end;

procedure TFram_Question.ClearAnswer1Click(Sender: TObject);
begin
ClearAnswers;
end;

procedure TFram_Question.ClearAnswers;
begin
mmoAnswer.Lines.Clear;
mmoWriteSonicAnswer.Lines.Clear;
mmoYouChatAnswer.Lines.Clear;
end;

procedure TFram_Question.ClearQuestion1Click(Sender: TObject);
begin
mmoQuestion.Clear;
end;

procedure TFram_Question.CloseBtnClick(Sender: TObject);
begin
FDQryHistory.Delete;
if FDQryHistory.RecordCount > 0 then
FDQryHistory.Delete;
end;

procedure TFram_Question.CopyToClipBoard;
Expand Down Expand Up @@ -434,7 +477,7 @@ procedure TFram_Question.DrawColumnCell(Sender: TObject; const Rect: TRect; Data
LvMatchedIndexes: TList;
begin
//================= Drawing delete button ============================
if (not FDQryHistoryHID.IsNull) and (Column.Title.Caption = '^_^') Then
if (not FDQryHistory.IsEmpty) and (not FDQryHistoryHID.IsNull) and (Column.Title.Caption = '^_^') Then
begin
DataRect := FHistoryGrid.CellRect(Column.Index + 1, FHistoryGrid.Row);
If FCellCloseBtn.Parent <> FHistoryGrid Then
Expand Down Expand Up @@ -720,6 +763,16 @@ procedure TFram_Question.HighlightCellTextFuzzy(AGrid: TDbGrid; const ARect: TRe
end;
end;

procedure TFram_Question.HistoryDBGridDblClick(Sender: TObject);
begin
if (FDQryHistory.Active) and (FDQryHistory.RecordCount > 0) then
begin
mmoQuestion.Lines.Clear;
mmoQuestion.Lines.Add(FDQryHistory.FieldByName('Question').AsString);
pgcMain.ActivePageIndex := 0;
end;
end;

procedure TFram_Question.InitialClassViewMenueItems(AClassList: TClassList);
var
LvKey: Integer;
Expand Down Expand Up @@ -755,24 +808,24 @@ procedure TFram_Question.InitialClassViewMenueItems(AClassList: TClassList);
AddMenuItem(TSingletonSettingObj.Instance.PredefinedQuestions.Items[LvKey].Caption);

// Add Convert commands
LvMenuItem := TMenuItem.Create(Self);
LvMenuItem.Caption := 'Convert to';
pmClassOperations.Items.Add(LvMenuItem);

AddSubMenu('C#', LvMenuItem, CSharpClick);
AddSubMenu('Java', LvMenuItem, JavaClick);
AddSubMenu('Python', LvMenuItem, PythonClick);
AddSubMenu('Javascript', LvMenuItem, JavascriptClick);
AddSubMenu('C', LvMenuItem, CClick);
AddSubMenu('C++', LvMenuItem, CPlusPlusClick);
AddSubMenu('Go', LvMenuItem, GoClick);
AddSubMenu('Rust', LvMenuItem, RustClick);
LvMenuItem := TMenuItem.Create(Self);
LvMenuItem.Caption := 'Convert to';
pmClassOperations.Items.Add(LvMenuItem);

AddSubMenu('C#', LvMenuItem, CSharpClick);
AddSubMenu('Java', LvMenuItem, JavaClick);
AddSubMenu('Python', LvMenuItem, PythonClick);
AddSubMenu('Javascript', LvMenuItem, JavascriptClick);
AddSubMenu('C', LvMenuItem, CClick);
AddSubMenu('C++', LvMenuItem, CPlusPlusClick);
AddSubMenu('Go', LvMenuItem, GoClick);
AddSubMenu('Rust', LvMenuItem, RustClick);

// Add Custom Commands
LvMenuItem := TMenuItem.Create(Self);
LvMenuItem.Caption := 'Custom Command';
LvMenuItem.OnClick := CustomCommandClick;
pmClassOperations.Items.Add(LvMenuItem);
LvMenuItem := TMenuItem.Create(Self);
LvMenuItem.Caption := 'Custom Command';
LvMenuItem.OnClick := CustomCommandClick;
pmClassOperations.Items.Add(LvMenuItem);
end;

procedure TFram_Question.InitialFrame;
Expand All @@ -794,6 +847,7 @@ procedure TFram_Question.InitialFrame;
Parent := pnlHistoryTop;
Align := alClient;
DataSource := DSHistory;
OnDblClick := HistoryDBGridDblClick;
Options := [dgTitles, dgIndicator, dgColumnResize, dgColLines, dgRowLines, dgTabs, dgRowSelect, dgConfirmDelete, dgCancelOnExit, dgTitleClick, dgTitleHotTrack];

with Columns.Add do
Expand Down
4 changes: 0 additions & 4 deletions Forms/UChatGPTQuestion.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,6 @@ object FrmChatGPT: TFrmChatGPT
Left = 281
ExplicitLeft = 281
end
inherited ActivityIndicator1: TActivityIndicator
ExplicitWidth = 24
ExplicitHeight = 24
end
end
end
end
5 changes: 3 additions & 2 deletions Forms/UChatGPTQuestion.pas
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ procedure TFrmChatGPT.FormShow(Sender: TObject);
tsWriteSonicAnswer.TabVisible := (CompilerVersion >= 32) and (TSingletonSettingObj.Instance.EnableWriteSonic);
tsYouChat.TabVisible := (CompilerVersion >= 32) and (TSingletonSettingObj.Instance.EnableYouChat);
mmoQuestion.Lines.Clear;
mmoQuestion.Lines.Add(TSingletonSettingObj.Instance.MainFormLastQuestion);
if not TSingletonSettingObj.Instance.MainFormLastQuestion.Trim.IsEmpty then
mmoQuestion.Lines.Add(TSingletonSettingObj.Instance.MainFormLastQuestion);
Cs.Leave;
ActivityIndicator1.Visible := False;
FreeAndNil(pgcMain);
Expand All @@ -72,7 +73,7 @@ procedure TFrmChatGPT.SaveLastQuestion;
try
LvRegKey.CloseKey;
LvRegKey.RootKey := HKEY_CURRENT_USER;
if LvRegKey.OpenKey('\SOFTWARE\ChatGPTWizard', True) then
if (LvRegKey.OpenKey('\SOFTWARE\ChatGPTWizard', True)) and (not Trim(Fram_Question.mmoQuestion.Text).IsEmpty) then
LvRegKey.WriteString('ChatGPTMainFormLastQuestion', Fram_Question.mmoQuestion.text);
finally
LvRegKey.Free;
Expand Down
6 changes: 3 additions & 3 deletions Forms/UChatGPTSetting.pas
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ procedure TSingletonSettingObj.ReadRegistry;
FTimeOut := 20;

if ValueExists('ChatGPTMainFormLastQuestion') then
FMainFormLastQuestion := ReadString('ChatGPTMainFormLastQuestion')
FMainFormLastQuestion := ReadString('ChatGPTMainFormLastQuestion').Trim
else
FMainFormLastQuestion := 'Create a class to make a Zip file in Delphi.';

Expand Down Expand Up @@ -611,7 +611,7 @@ procedure TSingletonSettingObj.WriteToRegistry;
WriteInteger('ChatGPTHighlightColor', FHighlightColor);
WriteBool('ChatGPTAnimatedLetters', FAnimatedLetters);
WriteInteger('ChatGPTTimeOut', FTimeOut);
WriteString('ChatGPTMainFormLastQuestion', FMainFormLastQuestion);
WriteString('ChatGPTMainFormLastQuestion', FMainFormLastQuestion.Trim);

WriteBool('ChatGPTEnableWriteSonic', FEnableWriteSonic);
WriteString('ChatGPTWriteSonicAPIKey', FWriteSonicAPIKey);
Expand Down Expand Up @@ -902,7 +902,7 @@ procedure TFrm_Setting.AddAllDefinedQuestions;
procedure TFrm_Setting.AddQuestion(AQuestionpair: TQuestionPair);
var
LvPanel: Tpanel;
LvLabeledEditCaption, LvLabeledEditQuestion: TLabeledEdit;
LvLabeledEditCaption: TLabeledEdit;
I, LvCounter: Integer;
LvH: Integer;
begin
Expand Down
3 changes: 1 addition & 2 deletions Utils/UHistory.pas
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ THistoryDBGrid = class(TDBGrid)
Public
// The inherited method is declared as protected.
// Used Reintroduce to hide compiler warnings.
Function CellRect(ACol,Arow : Longint): TRect; Reintroduce;
function CellRect(ACol,Arow : Longint): TRect; Reintroduce;

//Fit columns.
procedure FitGrid;

// Expose Row and Col properties
Property Row;
Property Col;

Published
Property RowHeight : Integer Read FRowHeight Write SetRowHeight ;
end;
Expand Down

0 comments on commit 718c49c

Please sign in to comment.