Changeset 4


Ignore:
Timestamp:
May 1, 2014, 7:29:12 PM (10 years ago)
Author:
chronos
Message:
  • Added: Rearrange items in tree according Depends and Condition.
  • Fixed: Wrong parsing multiline commands.
  • Added: Log and option list forms.
Location:
trunk
Files:
4 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LinuxBuilder.lpi

    r3 r4  
    3333      </Item1>
    3434    </RequiredPackages>
    35     <Units Count="3">
     35    <Units Count="5">
    3636      <Unit0>
    3737        <Filename Value="LinuxBuilder.lpr"/>
     
    5252        <UnitName Value="UKConfig"/>
    5353      </Unit2>
     54      <Unit3>
     55        <Filename Value="UFormList.pas"/>
     56        <IsPartOfProject Value="True"/>
     57        <ComponentName Value="FormList"/>
     58        <ResourceBaseClass Value="Form"/>
     59        <UnitName Value="UFormList"/>
     60      </Unit3>
     61      <Unit4>
     62        <Filename Value="UFormLog.pas"/>
     63        <IsPartOfProject Value="True"/>
     64        <ComponentName Value="FormLog"/>
     65        <ResourceBaseClass Value="Form"/>
     66        <UnitName Value="UFormLog"/>
     67      </Unit4>
    5468    </Units>
    5569  </ProjectOptions>
  • trunk/LinuxBuilder.lpr

    r3 r4  
    88  {$ENDIF}{$ENDIF}
    99  Interfaces, // this includes the LCL widgetset
    10   Forms, UFormMain, UKConfig
     10  Forms, UFormMain, UKConfig, UFormList, UFormLog
    1111  { you can add units after this };
    1212
     
    1717  Application.Initialize;
    1818  Application.CreateForm(TFormMain, FormMain);
     19  Application.CreateForm(TFormList, FormList);
     20  Application.CreateForm(TFormLog, FormLog);
    1921  Application.Run;
    2022end.
  • trunk/UFormMain.lfm

    r3 r4  
    1818    Height = 504
    1919    Top = 0
    20     Width = 840
     20    Width = 520
    2121    Anchors = [akTop, akLeft, akRight, akBottom]
    2222    DefaultItemHeight = 24
     23    ReadOnly = True
     24    RowSelect = True
    2325    TabOrder = 0
     26    OnSelectionChanged = TreeView1SelectionChanged
     27    Options = [tvoAutoItemHeight, tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoRowSelect, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips, tvoThemedDraw]
    2428  end
    2529  object StatusBar1: TStatusBar
     
    4549      Style = tbsCheck
    4650    end
     51    object ToolButton1: TToolButton
     52      Left = 24
     53      Top = 2
     54      Action = AShowList
     55    end
     56  end
     57  object Memo1: TMemo
     58    Left = 536
     59    Height = 498
     60    Top = 0
     61    Width = 312
     62    Anchors = [akTop, akRight, akBottom]
     63    ReadOnly = True
     64    ScrollBars = ssAutoBoth
     65    TabOrder = 3
    4766  end
    4867  object MainMenu1: TMainMenu
     
    6180        Action = AViemSystem
    6281      end
     82      object MenuItem5: TMenuItem
     83        Action = AShowList
     84      end
     85      object MenuItem6: TMenuItem
     86        Action = AShowLog
     87      end
    6388    end
    6489  end
     
    75100      OnExecute = AViemSystemExecute
    76101    end
     102    object AShowList: TAction
     103      Caption = 'Show list'
     104      OnExecute = AShowListExecute
     105    end
     106    object AShowLog: TAction
     107      Caption = 'Show log'
     108      OnExecute = AShowLogExecute
     109    end
    77110  end
    78111  object ImageList1: TImageList
  • trunk/UFormMain.pas

    r3 r4  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
    9   ActnList, ComCtrls, UKConfig;
     9  ActnList, ComCtrls, StdCtrls, UKConfig;
    1010
    1111type
     
    1414
    1515  TFormMain = class(TForm)
     16    AShowList: TAction;
     17    AShowLog: TAction;
    1618    AViemSystem: TAction;
    1719    AOpenDir: TAction;
     
    1921    ImageList1: TImageList;
    2022    MainMenu1: TMainMenu;
     23    Memo1: TMemo;
    2124    MenuItem1: TMenuItem;
    2225    MenuItem2: TMenuItem;
    2326    MenuItem3: TMenuItem;
    2427    MenuItem4: TMenuItem;
     28    MenuItem5: TMenuItem;
     29    MenuItem6: TMenuItem;
    2530    StatusBar1: TStatusBar;
    2631    ToolBar1: TToolBar;
     32    ToolButton1: TToolButton;
    2733    ToolButton2: TToolButton;
    2834    TreeView1: TTreeView;
    2935    procedure AOpenDirExecute(Sender: TObject);
     36    procedure AShowListExecute(Sender: TObject);
     37    procedure AShowLogExecute(Sender: TObject);
    3038    procedure AViemSystemExecute(Sender: TObject);
    3139    procedure FormCreate(Sender: TObject);
    3240    procedure FormDestroy(Sender: TObject);
    3341    procedure FormShow(Sender: TObject);
     42    procedure TreeView1SelectionChanged(Sender: TObject);
    3443  private
    35     { private declarations }
     44    procedure DoLog(Text: string);
    3645  public
    3746    Config: TConfigMenu;
     
    4453implementation
    4554
     55uses
     56  UFormList, UFormLog;
     57
    4658{$R *.lfm}
    4759
     
    5264  Config.LoadFromDir('/home/chronos/Stažené/linux-3.14.1', 'x86');
    5365  Reload;
     66end;
     67
     68procedure TFormMain.TreeView1SelectionChanged(Sender: TObject);
     69begin
     70  if Assigned(TreeView1.Selected) then begin
     71    if Assigned(TreeView1.Selected.Data) then
     72      TMenuNode(TreeView1.Selected.Data).LoadStats(Memo1.Lines)
     73      else Memo1.Lines.Clear;
     74  end;
     75end;
     76
     77procedure TFormMain.DoLog(Text: string);
     78begin
     79  FormLog.Memo1.Lines.Add(Text);
    5480end;
    5581
     
    76102end;
    77103
     104procedure TFormMain.AShowListExecute(Sender: TObject);
     105begin
     106  FormList.Show;
     107end;
     108
     109procedure TFormMain.AShowLogExecute(Sender: TObject);
     110begin
     111  FormLog.Show;
     112end;
     113
    78114procedure TFormMain.AViemSystemExecute(Sender: TObject);
    79115begin
     
    85121begin
    86122  Config := TConfigMenu.Create;
     123  Config.OnLog := DoLog;
    87124end;
    88125
  • trunk/UKConfig.pas

    r2 r4  
    1414  TLoadTreeOption = (toShowSystem);
    1515  TLoadTreeOptions = set of TLoadTreeOption;
     16  TObjectMove = record
     17    Source: TObject;
     18    NewParent: TObject;
     19  end;
     20  TObjectMoves = array of TObjectMove;
    1621
    1722  { TMenuNode }
     
    3338    destructor Destroy; override;
    3439    function GetName: string; virtual;
     40    function GetabsoluteName: string; virtual;
    3541    procedure LoadTreeNode(Node: TTreeNode; Options: TLoadTreeOptions = []); virtual;
    36   end;
     42    procedure LoadStats(List: TStrings); virtual;
     43    procedure SaveToList(List: TStrings); virtual;
     44    procedure PrepareMoveList(var List: TObjectMoves); virtual;
     45    function GetTopNode: TMenuNode; virtual;
     46    function FindNode(ID: string): TMenuNode; virtual;
     47  end;
     48
     49  TOnLogEvent = procedure (Text: string) of object;
    3750
    3851  { TConfigMenu }
     
    4255    CurrentMenu: TMenuNode;
    4356    Arch: string;
     57    FOnLog: TOnLogEvent;
     58    procedure Log(Text: string);
    4459    function IsWhiteSpace(Character: Char): Boolean;
    4560    function GetNextToken(var Text: string): string;
     
    4964    BaseDir: string;
    5065    procedure LoadFromDir(Dir: string; Arch: string);
     66    property OnLog: TOnLogEvent read FOnLog write FOnLog;
    5167  end;
    5268
     
    8197end;
    8298
     99function TMenuNode.GetabsoluteName: string;
     100begin
     101  if Assigned(Parent) then Result := Parent.GetabsoluteName + ' - ';
     102  Result := Result + GetName;
     103end;
     104
    83105procedure TMenuNode.LoadTreeNode(Node: TTreeNode; Options: TLoadTreeOptions);
    84106var
     
    90112    if (Name <> '') or ((Name = '') and (toShowSystem in Options)) then begin
    91113      NewNode := Node.TreeNodes.AddChild(Node, GetName);
     114      NewNode.Data := TMenuNode(Self.Items[I]);
    92115      LoadTreeNode(NewNode, Options);
    93116    end;
     
    95118end;
    96119
     120procedure TMenuNode.LoadStats(List: TStrings);
     121begin
     122  with List do begin
     123    Clear;
     124    Add('ID: ' + ID);
     125    Add('Name: ' + Name);
     126    Add('Depends on: ' + Depends.Text);
     127    Add('Selects: ' + Selects.Text);
     128    Add('Description: ' + Description.Text);
     129    Add('Condition: ' + Condition);
     130    Add('Value type: ' + IntToStr(Integer(ValueType)));
     131    Add('Default value: ' + DefaultValue);
     132  end;
     133end;
     134
     135procedure TMenuNode.SaveToList(List: TStrings);
     136var
     137  I: Integer;
     138begin
     139  if ID <> '' then List.Add(ID);
     140  for I := 0 to Items.Count - 1 do
     141  with TMenuNode(Items[I]) do begin
     142    SaveToList(List);
     143  end;
     144end;
     145
     146procedure TMenuNode.PrepareMoveList(var List: TObjectMoves);
     147var
     148  I: Integer;
     149  Node: TMenuNode;
     150  NewMove: TObjectMove;
     151begin
     152  if Depends.Count > 0 then begin
     153    Node := GetTopNode.FindNode(Depends[0]);
     154    if Assigned(Node) and (Parent <> Node) then begin
     155      NewMove.Source := Self;
     156      NewMove.NewParent := Node;
     157      SetLength(List, Length(List) + 1);
     158      List[Length(List) - 1] := NewMove;
     159    end;
     160  end else
     161  if Condition <> '' then begin
     162    Node := GetTopNode.FindNode(Condition);
     163    if Assigned(Node) and (Parent <> Node) then begin
     164      NewMove.Source := Self;
     165      NewMove.NewParent := Node;
     166      SetLength(List, Length(List) + 1);
     167      List[Length(List) - 1] := NewMove;
     168    end;
     169  end;
     170  I := 0;
     171  while I < Items.Count do
     172  with TMenuNode(Items[I]) do begin
     173    PrepareMoveList(List);
     174    Inc(I);
     175  end;
     176end;
     177
     178function TMenuNode.GetTopNode: TMenuNode;
     179begin
     180  if Assigned(Parent) then Result := Parent.GetTopNode
     181    else Result := Self;
     182end;
     183
     184function TMenuNode.FindNode(ID: string): TMenuNode;
     185var
     186  I: Integer;
     187begin
     188  Result := nil;
     189  if Self.ID = ID then Result := Self
     190  else begin
     191    I := 0;
     192    while (I < Items.Count) do begin
     193      Result := TMenuNode(Items[I]).FindNode(ID);
     194      if Assigned(Result) then Break;
     195      Inc(I);
     196    end;
     197  end;
     198end;
     199
    97200{ TConfigMenu }
     201
     202procedure TConfigMenu.Log(Text: string);
     203begin
     204  if Assigned(FOnLog) then FOnLog(Text);
     205end;
    98206
    99207function TConfigMenu.IsWhiteSpace(Character: Char): Boolean;
     
    155263
    156264begin
     265  Log('FILE ' + FileName);
    157266  try
    158267    Content := TStringList.Create;
     
    165274    for I := 0 to Content.Count - 1 do begin
    166275      Line := MergedLines + Content[I];
     276      MergedLines := '';
    167277      LineIndent := 1;
    168278      while (LineIndent <= Length(Line)) and IsWhiteSpace(Line[LineIndent]) do Inc(LineIndent);
     
    317427        if Command = 'menu' then begin
    318428          Parameter := GetNextToken(Line);
     429          Log('MENU ' + Parameter + ' IN ' + CurrentMenu.GetAbsoluteName);
    319430          NewMenu := TMenuNode.Create;
    320431          NewMenu.Name := Parameter;
    321432          NewMenu.Parent := CurrentMenu;
     433          NewMenu.Condition := Condition;
     434          Condition := '';
    322435          NewItem := NewMenu;
    323436          CurrentMenu.Items.Add(NewMenu);
     
    325438        end else
    326439        if command = 'endmenu' then begin
    327           if Assigned(CurrentMenu.Parent) then
    328             CurrentMenu := CurrentMenu.Parent
    329             else raise Exception.Create('Can''t change menu level up. ' + GetLog);
     440          Log('ENDMENU ' + CurrentMenu.GetAbsoluteName);
     441          if Assigned(CurrentMenu.Parent) then begin
     442            Condition := CurrentMenu.Condition;
     443            CurrentMenu := CurrentMenu.Parent;
     444          end else raise Exception.Create('Can''t change menu level up. ' + GetLog);
    330445        end else
    331446        if Command = 'if' then begin
     
    346461
    347462procedure TConfigMenu.LoadFromDir(Dir: string; Arch: string);
     463var
     464  Moves: TObjectMoves;
     465  I: Integer;
    348466begin
    349467  Self.Arch := Arch;
     
    354472  CurrentMenu := TopNode;
    355473  ParseFile(BaseDir + DirectorySeparator + 'Kconfig');
     474
     475  TopNode.PrepareMoveList(Moves);
     476  for I := 0 to Length(Moves) - 1 do
     477  with Moves[I] do begin
     478    TMenuNode(Source).Parent.Items.OwnsObjects := False;
     479    TMenuNode(Source).Parent.Items.Remove(Source);
     480    TMenuNode(Source).Parent.Items.OwnsObjects := True;
     481    TMenuNode(Source).Parent := TMenuNode(NewParent);
     482    TMenuNode(NewParent).Items.Add(Source);
     483  end;
    356484end;
    357485
Note: See TracChangeset for help on using the changeset viewer.