From 56889eac7853e374702cec2d32bc3f4b7b796df9 Mon Sep 17 00:00:00 2001 From: n7800 <14154601-n7800@users.noreply.gitlab.com> Date: Fri, 20 Jun 2025 12:20:49 +0500 Subject: [PATCH 1/2] Cody/Dictionary: Using constants in code --- .../codetools/ide/codyidentifiersdlg.pas | 6 +++--- components/codetools/ide/codyopts.pas | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/components/codetools/ide/codyidentifiersdlg.pas b/components/codetools/ide/codyidentifiersdlg.pas index 279b4bccd5..a6c3b00c14 100644 --- a/components/codetools/ide/codyidentifiersdlg.pas +++ b/components/codetools/ide/codyidentifiersdlg.pas @@ -796,8 +796,8 @@ end; constructor TCodyUnitDictionary.Create; begin inherited Create; - FSaveIntervalInS:=60*3; // every 3 minutes - FLoadAfterStartInS:=3; + FSaveIntervalInS:=cDefSaveIntervalInS; + FLoadAfterStartInS:=cDefLoadDelayInS; InitCriticalSection(fCritSec); fQueuedTools:=TAVLTree.Create; CodeToolBoss.AddHandlerToolTreeChanging(@ToolTreeChanged); @@ -977,7 +977,7 @@ begin ButtonPanel1.HelpButton.OnClick:=@ButtonPanel1HelpButtonClick; ButtonPanel1.OKButton.Caption:=crsUseIdentifier; ButtonPanel1.OKButton.OnClick:=@UseIdentifierClick; - FMaxItems:=40; + FMaxItems:=cDefMaxListItems; FilterEdit.TextHint:=crsFilter; FItems:=TObjectList.Create; HideOtherProjectsCheckBox.Checked:=true; diff --git a/components/codetools/ide/codyopts.pas b/components/codetools/ide/codyopts.pas index e6a5f3ff7f..7b4d6b2ffd 100644 --- a/components/codetools/ide/codyopts.pas +++ b/components/codetools/ide/codyopts.pas @@ -15,6 +15,12 @@ uses const CodyConfigVersion = 1; + +const + cDefLoadDelayInS = 10; + cDefSaveIntervalInS = 600; + cDefMaxListItems = 50; + var CodyMiscOptionID: integer = 1000; type @@ -157,8 +163,8 @@ var begin Cfg:=GetIDEConfigStorage(Filename,false); try - Cfg.SetDeleteValue('UnitDictionary/LoadDelay',UDLoadDelayInS,10); - Cfg.SetDeleteValue('UnitDictionary/SaveInterval',UDSaveIntervalInS,600); + Cfg.SetDeleteValue('UnitDictionary/LoadDelay', UDLoadDelayInS, cDefLoadDelayInS); + Cfg.SetDeleteValue('UnitDictionary/SaveInterval',UDSaveIntervalInS,cDefSaveIntervalInS); Cfg.SetDeleteValue('Uses/PreferImplementationSection',PreferImplementationUsesSection,false); finally Cfg.Free; @@ -172,8 +178,8 @@ begin Clear; Cfg:=GetIDEConfigStorage(Filename,true); try - UDLoadDelayInS:=Cfg.GetValue('UnitDictionary/LoadDelay',10); - UDSaveIntervalInS:=Cfg.GetValue('UnitDictionary/SaveInterval',600); + UDLoadDelayInS :=Cfg.GetValue('UnitDictionary/LoadDelay', cDefLoadDelayInS); + UDSaveIntervalInS:=Cfg.GetValue('UnitDictionary/SaveInterval',cDefSaveIntervalInS); PreferImplementationUsesSection:=Cfg.GetValue('Uses/PreferImplementationSection',false); //debugln(['TCodyMiscOptions.LoadFromFile UDSaveIntervalInS=',UDSaveIntervalInS,' LoadDelay=',UDLoadDelayInS]); finally @@ -183,8 +189,8 @@ end; procedure TCodyMiscOptions.Clear; begin - UDLoadDelayInS:=10; - UDSaveIntervalInS:=600; + UDLoadDelayInS := cDefLoadDelayInS; + UDSaveIntervalInS := cDefSaveIntervalInS; end; procedure TCodyMiscOptions.Apply; From 12698b8db628d15185b26f716504bbf62c82fd57 Mon Sep 17 00:00:00 2001 From: n7800 <14154601-n7800@users.noreply.gitlab.com> Date: Fri, 20 Jun 2025 12:20:50 +0500 Subject: [PATCH 2/2] Cody/Dictionary: Minor refactoring --- .../codetools/ide/codyidentifiersdlg.pas | 107 +++++++++--------- components/codetools/ide/codyopts.pas | 26 ++--- 2 files changed, 60 insertions(+), 73 deletions(-) diff --git a/components/codetools/ide/codyidentifiersdlg.pas b/components/codetools/ide/codyidentifiersdlg.pas index a6c3b00c14..eb665cd776 100644 --- a/components/codetools/ide/codyidentifiersdlg.pas +++ b/components/codetools/ide/codyidentifiersdlg.pas @@ -879,49 +879,49 @@ end; procedure TCodyIdentifiersDlg.DeletePackageClick(Sender: TObject); var - Identifier: string; - UnitFilename: string; - GroupName: string; - GroupFilename: string; - Group: TUDUnitGroup; - s: String; + lId: TCodyIdentifier; + lMsg: string; + lGroup: TUDUnitGroup; begin - if not FindSelectedItem(Identifier, UnitFilename, GroupName, GroupFilename) - then exit; - if GroupFilename='' then exit; - s:=Format(crsReallyDeleteThePackageFromTheDatabaseNoteThisDoe, [#13, #13, - #13, GroupFilename]); - if IDEMessageDialog(crsDeletePackage, s, mtConfirmation, [mbYes, mbNo], '')<> - mrYes - then exit; - Group:=CodyUnitDictionary.FindGroupWithFilename(GroupFilename); - if Group=nil then exit; - CodyUnitDictionary.DeleteGroup(Group,true); + lId := FindSelectedIdentifier; + if lId = nil then exit; + if lId.GroupFile = '' then exit; + + // confirm + lMsg := Format(crsReallyDeleteThePackageFromTheDatabaseNoteThisDoe, + [LineEnding, LineEnding, LineEnding, lId.GroupFile]); + if IDEMessageDialog(crsDeletePackage, lMsg, mtConfirmation, mbYesNo) <> mrYes then exit; + + // delete + lGroup := CodyUnitDictionary.FindGroupWithFilename(lId.GroupFile); + if lGroup = nil then exit; + CodyUnitDictionary.DeleteGroup(lGroup, true); + UpdateGeneralInfo; UpdateItemsList; end; procedure TCodyIdentifiersDlg.DeleteUnitClick(Sender: TObject); var - Identifier: string; - UnitFilename: string; - GroupName: string; - GroupFilename: string; - CurUnit: TUDUnit; - s: String; + lId: TCodyIdentifier; + lMsg: string; + lUnit: TUDUnit; begin - if not FindSelectedItem(Identifier, UnitFilename, GroupName, GroupFilename) - then exit; - s:=Format(crsReallyDeleteTheUnitFromTheDatabaseNoteThisDoesNo, [#13, #13, - #13, UnitFilename]); - if GroupFilename<>'' then - s+=#13+Format(crsIn, [GroupFilename]); - if IDEMessageDialog(crsDeleteUnit, s, mtConfirmation, [mbYes, mbNo], '')<> - mrYes - then exit; - CurUnit:=CodyUnitDictionary.FindUnitWithFilename(UnitFilename); - if CurUnit=nil then exit; - CodyUnitDictionary.DeleteUnit(CurUnit,true); + lId := FindSelectedIdentifier; + if lId = nil then exit; + + // confirm + lMsg := Format(crsReallyDeleteTheUnitFromTheDatabaseNoteThisDoesNo, + [LineEnding, LineEnding, LineEnding, lId.UnitFile]); + if lId.GroupFile <> '' then + lMsg := lMsg + LineEnding + Format(crsIn, [lId.GroupFile]); + if IDEMessageDialog(crsDeleteUnit, lMsg, mtConfirmation, mbYesNo) <> mrYes then exit; + + // delete + lUnit := CodyUnitDictionary.FindUnitWithFilename(lId.UnitFile); + if lUnit = nil then exit; + CodyUnitDictionary.DeleteUnit(lUnit, true); + UpdateGeneralInfo; UpdateItemsList; end; @@ -1338,14 +1338,11 @@ begin end; function TCodyIdentifiersDlg.FindSelectedIdentifier: TCodyIdentifier; -var - i: Integer; begin - Result:=nil; - if FItems=nil then exit; - i:=ItemsListBox.ItemIndex; - if (i<0) or (i>=FItems.Count) then exit; - Result:=TCodyIdentifier(FItems[i]); + if assigned(FItems) and InRange(ItemsListBox.ItemIndex, 0, FItems.Count - 1) then + result := TCodyIdentifier(FItems[ItemsListBox.ItemIndex]) + else + result := nil; end; function TCodyIdentifiersDlg.FindSelectedItem(out Identifier, UnitFilename, @@ -1353,19 +1350,21 @@ function TCodyIdentifiersDlg.FindSelectedItem(out Identifier, UnitFilename, var Item: TCodyIdentifier; begin - Result:=false; - Identifier:=''; - UnitFilename:=''; - GroupName:=''; - GroupFilename:=''; - Item:=FindSelectedIdentifier; - if Item=nil then exit; - Identifier:=Item.Identifier; - UnitFilename:=Item.UnitFile; - GroupName:=Item.GroupName; - GroupFilename:=Item.GroupFile; + Item := FindSelectedIdentifier; + result := assigned(Item); + if result then + begin + Identifier := Item.Identifier; + UnitFilename := Item.UnitFile; + GroupName := Item.GroupName; + GroupFilename := Item.GroupFile; + end else begin + Identifier := ''; + UnitFilename := ''; + GroupName := ''; + GroupFilename := ''; + end; //debugln(['TCodyIdentifiersDlg.FindSelectedItem ',Identifier,' Unit=',UnitFilename,' Pkg=',GroupFilename]); - Result:=true; end; function TCodyIdentifiersDlg.Init: boolean; diff --git a/components/codetools/ide/codyopts.pas b/components/codetools/ide/codyopts.pas index 7b4d6b2ffd..10f35afab3 100644 --- a/components/codetools/ide/codyopts.pas +++ b/components/codetools/ide/codyopts.pas @@ -23,10 +23,8 @@ const var CodyMiscOptionID: integer = 1000; + type - - { TCodyMiscOptions } - TCodyMiscOptions = class(TPersistent) private FChangeStep: integer; @@ -67,8 +65,6 @@ var implementation -{ TCodyMiscOptions } - procedure TCodyMiscOptions.SetModified(AValue: boolean); begin if AValue then @@ -110,29 +106,21 @@ begin end; procedure TCodyMiscOptions.Assign(Source: TPersistent); -var - aSource: TCodyMiscOptions; begin if Source is TCodyMiscOptions then begin - aSource:=TCodyMiscOptions(Source); - UDSaveIntervalInS:=aSource.UDSaveIntervalInS; - UDLoadDelayInS:=aSource.UDLoadDelayInS; + UDSaveIntervalInS := TCodyMiscOptions(Source).UDSaveIntervalInS; + UDLoadDelayInS := TCodyMiscOptions(Source).UDLoadDelayInS; end else inherited Assign(Source); end; function TCodyMiscOptions.Equals(Obj: TObject): boolean; -var - Src: TCodyMiscOptions; begin - Result:=false; - if not (Obj is TCodyMiscOptions) then exit; - Src:=TCodyMiscOptions(Obj); - if (UDLoadDelayInS<>Src.UDLoadDelayInS) - or (UDSaveIntervalInS<>Src.UDSaveIntervalInS) - then exit; - Result:=true; + Result := + (Obj is TCodyMiscOptions) and // "is" also checks for nil + (UDLoadDelayInS = TCodyMiscOptions(Obj).UDLoadDelayInS ) and + (UDSaveIntervalInS = TCodyMiscOptions(Obj).UDSaveIntervalInS); end; procedure TCodyMiscOptions.SaveSafe;