mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-24 00:49:45 +02:00
Cody/Dictionary: Minor refactoring
This commit is contained in:
parent
56889eac78
commit
12698b8db6
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user