Changeset 5 for trunk/UKConfig.pas


Ignore:
Timestamp:
May 1, 2014, 11:31:03 PM (11 years ago)
Author:
chronos
Message:
  • Added: Compare form to show differences between two linux versions.
  • Added: Faster binary search through TConfigMenu tree.
  • Added: Some actions icons.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UKConfig.pas

    r4 r5  
    4141    procedure LoadTreeNode(Node: TTreeNode; Options: TLoadTreeOptions = []); virtual;
    4242    procedure LoadStats(List: TStrings); virtual;
     43    procedure GetNodes(List: TStrings); virtual;
    4344    procedure SaveToList(List: TStrings); virtual;
    44     procedure PrepareMoveList(var List: TObjectMoves); virtual;
     45    procedure PrepareMoveList(Lookup: TStringList; var List: TObjectMoves); virtual;
     46    function GetCount: Integer; virtual;
    4547    function GetTopNode: TMenuNode; virtual;
    4648    function FindNode(ID: string): TMenuNode; virtual;
     
    6365    TopNode: TMenuNode;
    6466    BaseDir: string;
     67    procedure PrepareMoveList(var List: TObjectMoves);
     68    procedure CompareStringLists(List1, List2: TStringList; Missing1,
     69      Missing2: TStrings);
    6570    procedure LoadFromDir(Dir: string; Arch: string);
    6671    property OnLog: TOnLogEvent read FOnLog write FOnLog;
     
    133138end;
    134139
     140procedure TMenuNode.GetNodes(List: TStrings);
     141var
     142  I: Integer;
     143begin
     144  if ID <> '' then List.AddObject(ID, Self);
     145  for I := 0 to Items.Count - 1 do
     146  with TMenuNode(Items[I]) do begin
     147    GetNodes(List);
     148  end;
     149end;
     150
    135151procedure TMenuNode.SaveToList(List: TStrings);
    136152var
     
    144160end;
    145161
    146 procedure TMenuNode.PrepareMoveList(var List: TObjectMoves);
     162procedure TMenuNode.PrepareMoveList(Lookup: TStringList; var List: TObjectMoves);
    147163var
    148164  I: Integer;
    149165  Node: TMenuNode;
    150166  NewMove: TObjectMove;
     167  Index: Integer;
    151168begin
    152169  if Depends.Count > 0 then begin
    153     Node := GetTopNode.FindNode(Depends[0]);
     170    Index := Lookup.IndexOf(Depends[0]);
     171    if Index <> -1 then Node := TMenuNode(Lookup.Objects[Index])
     172      else Node := nil;
    154173    if Assigned(Node) and (Parent <> Node) then begin
    155174      NewMove.Source := Self;
     
    160179  end else
    161180  if Condition <> '' then begin
    162     Node := GetTopNode.FindNode(Condition);
     181    Index := Lookup.IndexOf(Condition);
     182    if Index <> -1 then Node := TMenuNode(Lookup.Objects[Index])
     183      else Node := nil;
    163184    if Assigned(Node) and (Parent <> Node) then begin
    164185      NewMove.Source := Self;
     
    171192  while I < Items.Count do
    172193  with TMenuNode(Items[I]) do begin
    173     PrepareMoveList(List);
     194    PrepareMoveList(Lookup, List);
    174195    Inc(I);
     196  end;
     197end;
     198
     199function TMenuNode.GetCount: Integer;
     200var
     201  I: Integer;
     202begin
     203  Result := 1;
     204  for I := 0 to Items.Count - 1 do
     205  with TMenuNode(Items[I]) do begin
     206    Result := Result + GetCount;
    175207  end;
    176208end;
     
    460492end;
    461493
     494procedure TConfigMenu.PrepareMoveList(var List: TObjectMoves);
     495var
     496  Lookup: TStringList;
     497begin
     498  try
     499    Lookup := TStringList.Create;
     500    Lookup.OwnsObjects := False;
     501    TopNode.GetNodes(Lookup);
     502    Lookup.Sorted := True;
     503    TopNode.PrepareMoveList(Lookup, List);
     504  finally
     505    Lookup.Free;
     506  end;
     507end;
     508
     509procedure TConfigMenu.CompareStringLists(List1, List2: TStringList;
     510  Missing1, Missing2: TStrings);
     511var
     512  I: Integer;
     513  J: Integer;
     514begin
     515  List1.Sort;
     516  List2.Sort;
     517  I := 0;
     518  J := 0;
     519  while (I < List1.Count) and (J < List2.Count) do
     520  begin
     521    if List1[I] < List2[J] then
     522    begin
     523      Missing2.Add(List1[I]);
     524      Inc(I);
     525    end
     526    else if List1[I] > List2[J] then
     527    begin
     528      Missing1.Add(List2[J]);
     529      Inc(J);
     530    end
     531    else
     532    begin
     533      Inc(I);
     534      Inc(J);
     535    end;
     536  end;
     537  for I := I to List1.Count - 1 do
     538    Missing2.Add(List1[I]);
     539  for J := J to List2.Count - 1 do
     540    Missing1.Add(List2[J]);
     541end;
     542
    462543procedure TConfigMenu.LoadFromDir(Dir: string; Arch: string);
    463544var
     
    473554  ParseFile(BaseDir + DirectorySeparator + 'Kconfig');
    474555
    475   TopNode.PrepareMoveList(Moves);
     556  PrepareMoveList(Moves);
    476557  for I := 0 to Length(Moves) - 1 do
    477558  with Moves[I] do begin
Note: See TracChangeset for help on using the changeset viewer.