Changeset 61


Ignore:
Timestamp:
Jul 17, 2012, 9:15:42 AM (12 years ago)
Author:
chronos
Message:
  • Added: Form with text output of executed external producer tool.
  • Fixed: Template for new unit mustn't initialize new project but only add unit file to project.
  • Added: Project manager file deletion and rename.
Location:
trunk
Files:
7 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Compiler/Target/Delphi/UProducerPascal.pas

    r58 r61  
    5757  {$IFDEF Windows}
    5858  CompilerPath := 'c:\Program Files\Embarcadero\RAD Studio\9.0\bin\DCC32.EXE';
     59  CompilerParameters := '"%0:s"';
    5960  {$ENDIF}
    6061  {$IFDEF Linux}
  • trunk/Compiler/UProducer.pas

    r59 r61  
    66
    77uses
    8   USourceCode, Classes, SysUtils, StrUtils, SpecializedList;
     8  USourceCode, Classes, SysUtils, StrUtils, SpecializedList, Process,
     9  FileUtil, Forms;
    910
    1011type
    1112
    1213  TWriteTargetEvent = function (Name: string; const Code: string): Boolean of object;
     14  TStringEvent = procedure (Value: string) of object;
    1315
    1416  { TProducer }
     
    1618  TProducer = class
    1719  private
     20    FOnProcessOutput: TStringEvent;
    1821    FOnWriteTarget: TWriteTargetEvent;
    1922  public
     23    Process: TProcess;
    2024    TextSource: TStringList;
    2125    IndentationLength: Integer;
    2226    Indentation: Integer;
    2327    CompilerPath: string;
     28    CompilerParameters: string;
    2429    procedure Emit(AText: string);
    2530    procedure EmitLn(AText: string = '');
    2631    procedure AssignToStringList(Target: TStringList); virtual; abstract;
    2732    procedure Produce(Module: TModule); virtual; abstract;
     33    procedure ExternalExecute(CommandLine: string);
    2834    constructor Create;
    2935    destructor Destroy; override;
    3036    property OnWriteTarget: TWriteTargetEvent read FOnWriteTarget write FOnWriteTarget;
     37    property OnProcessOutput: TStringEvent read FOnProcessOutput write FOnProcessOutput;
    3138  end;
    3239
     
    4148end;
    4249
     50procedure TProducer.ExternalExecute(CommandLine: string);
     51var
     52  Buffer: string;
     53  Count: Integer;
     54  Text: string;
     55  Line: string;
     56begin
     57  if not FileExistsUTF8(CompilerPath) then Exit;
     58  Text := '';
     59  try
     60    Process := TProcess.Create(nil);
     61    //if Path <> '' then
     62    //  Process.CurrentDirectory := Path;
     63    //Path := '';
     64    //if Environment <> '' then
     65    //  Process.Environment.Text := Environment;
     66    //Environment := '';
     67    Process.CommandLine := CommandLine;
     68    Process.Options := [poUsePipes, poNoConsole];
     69    Process.Execute;
     70    Application.ProcessMessages;
     71    while Process.Running or (Process.Output.NumBytesAvailable > 0) or
     72    (Process.Stderr.NumBytesAvailable > 0) do
     73    begin
     74      if Process.Output.NumBytesAvailable > 0 then begin
     75        SetLength(Buffer, 1000);
     76        Count := Process.Output.Read(Buffer[1], Length(Buffer));
     77        SetLength(Buffer, Count);
     78        Text := Text + Buffer;
     79        while Pos(LineEnding, Text) > 0 do begin
     80          Line := Copy(Text, 1, Pos(LineEnding, Text) - 1);
     81          Delete(Text, 1, Length(Line) + Length(LineEnding));
     82          if Assigned(FOnProcessOutput) then
     83            FOnProcessOutput(Line);
     84        end;
     85      end;
     86
     87      if Process.Stderr.NumBytesAvailable > 0 then begin
     88        SetLength(Buffer, 1000);
     89        Count := Process.Stderr.Read(Buffer[1], Length(Buffer));
     90        SetLength(Buffer, Count);
     91        Text := Text + Buffer;
     92        while Pos(LineEnding, Text) > 0 do begin
     93          Line := Copy(Text, 1, Pos(LineEnding, Text) - 1);
     94          Delete(Text, 1, Length(Line) + Length(LineEnding));
     95          if Assigned(FOnProcessOutput) then
     96            FOnProcessOutput(Line);
     97        end;
     98      end;
     99      Sleep(10);
     100      Application.ProcessMessages;
     101    end;
     102  finally
     103    if Assigned(FOnProcessOutput) then
     104      FOnProcessOutput(Text);
     105    FreeAndNil(Process);
     106  end;
     107end;
     108
    43109constructor TProducer.Create;
    44110begin
    45111  TextSource := TStringList.Create;
    46112  IndentationLength := 2;
     113  CompilerParameters := '%0:s';
    47114end;
    48115
  • trunk/IDE/Forms/UFormMain.lfm

    r60 r61  
    116116    Top = 26
    117117    Width = 200
    118     ActivePage = TabSheetTargetProject
     118    ActivePage = TabSheetExternalProducer
    119119    Align = alRight
    120     TabIndex = 2
     120    TabIndex = 3
    121121    TabOrder = 3
    122122    TabPosition = tpRight
     
    129129    object TabSheetTargetProject: TTabSheet
    130130      Caption = 'Target project'
     131    end
     132    object TabSheetExternalProducer: TTabSheet
     133      Caption = 'External producer'
    131134    end
    132135  end
  • trunk/IDE/Forms/UFormMain.lrt

    r50 r61  
    33TFORMMAIN.TABSHEETCODETREE.CAPTION=Code Tree
    44TFORMMAIN.TABSHEETTARGETPROJECT.CAPTION=Target project
     5TFORMMAIN.TABSHEETEXTERNALPRODUCER.CAPTION=External producer
    56TFORMMAIN.TABSHEETMESSAGES.CAPTION=Messages
    67TFORMMAIN.TABSHEETBREAKPOINTS.CAPTION=Breakpoints
  • trunk/IDE/Forms/UFormMain.pas

    r60 r61  
    9090    Splitter2: TSplitter;
    9191    Splitter3: TSplitter;
     92    TabSheetExternalProducer: TTabSheet;
    9293    TabSheetProject: TTabSheet;
    9394    TabSheetCodeTree: TTabSheet;
     
    143144    procedure UpdateMenu;
    144145    procedure UpdateTitle;
     146    procedure ProducerProcessOutput(Text: string);
    145147  public
    146148    procedure LoadFromRegistry(Root: HKEY; Key: string);
     
    162164  UCore, UFormMessages, UFormSourceCode, UFormProject, UCommon, UFormAbout, UFormOptions,
    163165  UFormTargets, UTarget, UExecutor, UFormProjectNew,
    164   UFormTargetProject;
     166  UFormTargetProject, UFormExternalProducerOutput;
    165167
    166168{ TFormMain }
     
    189191      Compiler.Compile;
    190192      TargetProject.Files.LoadFromList(Compiler.TargetFiles.Files);
     193      TargetProject.MainSource := TProjectFile(TargetProject.Files.First);
    191194      FormTargetProject.UpdateInterface;
     195
     196      FormExternalProducerOutput.Memo1.Clear;
     197      if Assigned(Compiler.Target.Producer) then
     198      with Compiler.Target.Producer do begin
     199        FormExternalProducerOutput.Memo1.Lines.Add(CompilerPath + ' ' + Format(CompilerParameters, [TargetProject.MainSource.AbsoluteFileName]));
     200        ExternalExecute(CompilerPath + ' ' + Format(CompilerParameters, [TargetProject.MainSource.AbsoluteFileName]));
     201      end;
    192202    end;
    193203    FormProject.TreeViewProjectChange(Self, FormProject.TreeViewProject.Selected);
     
    344354  FormTargetCode.Align := alClient;
    345355  FormTargetCode.Show;
     356  FormExternalProducerOutput.ManualDock(TabSheetExternalProducer, nil, alClient);
     357  FormExternalProducerOutput.Align := alClient;
     358  FormExternalProducerOutput.Show;
    346359  PageControlRight.TabIndex := 0;
    347360  PageControlBottom.TabIndex := 0;
     
    446459end;
    447460
     461procedure TFormMain.ProducerProcessOutput(Text: string);
     462begin
     463  FormExternalProducerOutput.Memo1.Lines.Add(Text);
     464end;
     465
    448466procedure TFormMain.FormClose(Sender: TObject; var Action: TCloseAction);
    449467begin
     
    453471
    454472procedure TFormMain.FormCreate(Sender: TObject);
    455 begin
     473var
     474  I: Integer;
     475begin
     476  with Core.Compiler.Targets do
     477  for I := 0 to Count - 1 do
     478  with TTarget(Items[I]) do
     479  if Assigned(Producer) then
     480    Producer.OnProcessOutput := ProducerProcessOutput;
    456481end;
    457482
     
    517542  if FormProjectNew.ShowModal = mrOk then begin
    518543    if Assigned(FormProjectNew.ListView1.Selected) then begin
    519       Core.ProjectNew;
     544      if TProjectTemplate(FormProjectNew.ListView1.Selected.Data).IsProject then
     545        Core.ProjectNew;
    520546      TProjectTemplate(FormProjectNew.ListView1.Selected.Data).InitProject(Core.Project);
    521547    end;
  • trunk/IDE/Forms/UFormProject.lfm

    r57 r61  
    1919    TabOrder = 0
    2020    OnChange = TreeViewProjectChange
     21    OnDblClick = TreeViewProjectDblClick
    2122    Options = [tvoAutoItemHeight, tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips, tvoThemedDraw]
    2223  end
  • trunk/IDE/Forms/UFormProject.pas

    r56 r61  
    2929    procedure AShowExecute(Sender: TObject);
    3030    procedure TreeViewProjectChange(Sender: TObject; Node: TTreeNode);
     31    procedure TreeViewProjectDblClick(Sender: TObject);
    3132  private
    3233    procedure UpdateProjectFiles(Node: TTreeNode; Files: TProjectFileList);
     
    4647  UCore, UFormMain, UFormSourceCode, UFormTargetCode, UFormCodeTree;
    4748
     49resourcestring
     50  SRenameSourceFile = 'Rename source file';
     51  SEnterNewFileName = 'Enter new file name';
     52
    4853{ TFormProject }
    4954
     
    5459  if Assigned(Node) then begin
    5560    if TProjectFile(Node.Data) is TProjectFile then begin
    56       ProjectFile := TProjectFile(Node.Data);
    57       SynEditSource.Lines.Assign(TProjectFile(Node.Data).Source);
     61      TreeViewProject.PopupMenu := PopupMenuFile;
     62      AShow.Execute;
    5863(*        if FileExists(TProjectFile(Node.Data).ProducedFileName) then
    5964        CompiledForm.SynEdit1.Lines.LoadFromFile(FileName) else
     
    7883      //CodeTreeForm.TreeView1.Assign(TProducerTreeView(Compiler.Producer).TreeView);
    7984      *)
    80     end;
     85    end else
     86      TreeViewProject.PopupMenu := nil;
    8187  end;
     88end;
     89
     90procedure TFormProject.TreeViewProjectDblClick(Sender: TObject);
     91begin
     92  AShow.Execute;
    8293end;
    8394
     
    95106procedure TFormProject.ADeleteExecute(Sender: TObject);
    96107begin
    97 
     108  if Assigned(TreeViewProject.Selected) then
     109    Core.Project.Files.Remove(TreeViewProject.Selected.Data);
     110  UpdateProjectTree;
    98111end;
    99112
    100113procedure TFormProject.ARenameExecute(Sender: TObject);
     114var
     115  NewName: string;
    101116begin
    102 
     117  if Assigned(TreeViewProject.Selected) then begin
     118    NewName := TProjectFile(TreeViewProject.Selected.Data).FileName;
     119    if InputQuery(SRenameSourceFile, SEnterNewFileName, NewName) then
     120      TProjectFile(TreeViewProject.Selected.Data).FileName := NewName;
     121    UpdateProjectTree;
     122  end;
    103123end;
    104124
    105125procedure TFormProject.AShowExecute(Sender: TObject);
    106126begin
    107 
     127  if Assigned(TreeViewProject.Selected) then
     128  FormSourceCode.SynEditSource.Lines.Assign(TProjectFile(TreeViewProject.Selected.Data).Source);
    108129end;
    109130
  • trunk/IDE/Forms/UFormProjectNew.pas

    r57 r61  
    7474    with Core do
    7575    for I := 0 to ProjectTemplates.Count - 1 do
    76     with TProjectTemplate(ProjectTemplates[I]) do begin
     76    with TProjectTemplate(ProjectTemplates[I]) do
     77    if (not Assigned(Core.Project) and IsProject) or Assigned(Core.Project) then begin
    7778      NewItem := ListView1.Items.Add;
    7879      NewItem.Caption := Name;
  • trunk/IDE/Languages/Transpascal.cs.po

    r60 r61  
    108108msgstr "Cesta překladače:"
    109109
     110#: tformexternalproduceroutput.caption
     111msgctxt "tformexternalproduceroutput.caption"
     112msgid "External producer"
     113msgstr "Vnější generátor"
     114
    110115#: tformmain.aabout.caption
    111116msgctxt "tformmain.aabout.caption"
     
    319324msgstr "Strom kódu"
    320325
     326#: tformmain.tabsheetexternalproducer.caption
     327msgctxt "tformmain.tabsheetexternalproducer.caption"
     328msgid "External producer"
     329msgstr "Vnější generátor"
     330
    321331#: tformmain.tabsheetmessages.caption
    322332msgctxt "tformmain.tabsheetmessages.caption"
     
    460470msgctxt "tformtargetoptions.buttonexecutorselect.caption"
    461471msgid "Select..."
    462 msgstr ""
     472msgstr "Výběr..."
    463473
    464474#: tformtargetoptions.buttonproducerselect.caption
    465475msgctxt "tformtargetoptions.buttonproducerselect.caption"
    466476msgid "Select..."
    467 msgstr ""
     477msgstr "Výběr..."
    468478
    469479#: tformtargetoptions.caption
    470480msgctxt "tformtargetoptions.caption"
    471481msgid "Target options"
    472 msgstr ""
     482msgstr "Volby cíle"
    473483
    474484#: tformtargetoptions.label1.caption
    475485msgid "Name:"
    476 msgstr ""
     486msgstr "Jméno:"
    477487
    478488#: tformtargetoptions.label2.caption
     
    483493#: tformtargetoptions.label3.caption
    484494msgid "Executor path:"
    485 msgstr ""
     495msgstr "Cesta vykonávače:"
    486496
    487497#: tformtargetoptions.labelname.caption
    488498msgid "    "
    489 msgstr ""
     499msgstr "   "
    490500
    491501#: tformtargetproject.caption
     
    501511msgctxt "tformtargets.atargetoptions.hint"
    502512msgid "Target options"
    503 msgstr ""
     513msgstr "Volby cíle"
    504514
    505515#: tformtargets.caption
     
    514524
    515525#: tformtargets.listview1.columns[1].caption
    516 #, fuzzy
    517526#| msgid "Execution path"
    518527msgctxt "tformtargets.listview1.columns[1].caption"
    519528msgid "Compiler path"
    520 msgstr "Cesta vykonání"
     529msgstr "Cesta překladače"
    521530
    522531#: tformtargets.listview1.columns[2].caption
    523532msgid "Executor path"
    524 msgstr ""
     533msgstr "Cesta vykonávače"
    525534
    526535#: tmainform.aabout.caption
     
    845854msgstr "Nový projekt"
    846855
     856#: uformproject.senternewfilename
     857msgid "Enter new file name"
     858msgstr "Zadejte nové jméno souboru"
     859
     860#: uformproject.srenamesourcefile
     861msgid "Rename source file"
     862msgstr "Přejmenování zdrojového souboru"
     863
    847864#: uformtargets.scompileroptions
    848865msgctxt "uformtargets.scompileroptions"
     
    865882msgstr "Nový projekt"
    866883
     884#: uprojecttemplates.sconsoleapplication
     885msgid "Console application"
     886msgstr "Konzolová aplikace"
     887
     888#: uprojecttemplates.sguiapplication
     889msgid "GUI application"
     890msgstr "GUI aplikace"
     891
     892#: uprojecttemplates.spackage
     893msgid "Package"
     894msgstr "Balíček"
     895
     896#: uprojecttemplates.sunit
     897msgid "Unit"
     898msgstr "Jednotka"
     899
  • trunk/IDE/Languages/Transpascal.po

    r60 r61  
    100100msgstr ""
    101101
     102#: tformexternalproduceroutput.caption
     103msgctxt "tformexternalproduceroutput.caption"
     104msgid "External producer"
     105msgstr ""
     106
    102107#: tformmain.aabout.caption
    103108msgctxt "TFORMMAIN.AABOUT.CAPTION"
     
    310315msgstr ""
    311316
     317#: tformmain.tabsheetexternalproducer.caption
     318msgctxt "TFORMMAIN.TABSHEETEXTERNALPRODUCER.CAPTION"
     319msgid "External producer"
     320msgstr ""
     321
    312322#: tformmain.tabsheetmessages.caption
    313323msgctxt "TFORMMAIN.TABSHEETMESSAGES.CAPTION"
     
    833843msgstr ""
    834844
     845#: uformproject.senternewfilename
     846msgid "Enter new file name"
     847msgstr ""
     848
     849#: uformproject.srenamesourcefile
     850msgid "Rename source file"
     851msgstr ""
     852
    835853#: uformtargets.scompileroptions
    836854msgctxt "uformtargets.scompileroptions"
     
    853871msgstr ""
    854872
     873#: uprojecttemplates.sconsoleapplication
     874msgid "Console application"
     875msgstr ""
     876
     877#: uprojecttemplates.sguiapplication
     878msgid "GUI application"
     879msgstr ""
     880
     881#: uprojecttemplates.spackage
     882msgid "Package"
     883msgstr ""
     884
     885#: uprojecttemplates.sunit
     886msgid "Unit"
     887msgstr ""
     888
  • trunk/IDE/Transpascal.lpi

    r60 r61  
    106106      </Item7>
    107107    </RequiredPackages>
    108     <Units Count="17">
     108    <Units Count="18">
    109109      <Unit0>
    110110        <Filename Value="Transpascal.lpr"/>
     
    166166        <IsPartOfProject Value="True"/>
    167167        <ComponentName Value="FormCodeTree"/>
     168        <HasResources Value="True"/>
    168169        <ResourceBaseClass Value="Form"/>
    169170        <UnitName Value="UFormCodeTree"/>
     
    228229        <UnitName Value="UFormTargetOptions"/>
    229230      </Unit16>
     231      <Unit17>
     232        <Filename Value="Forms\UFormExternalProducerOutput.pas"/>
     233        <IsPartOfProject Value="True"/>
     234        <ComponentName Value="FormExternalProducerOutput"/>
     235        <ResourceBaseClass Value="Form"/>
     236        <UnitName Value="UFormExternalProducerOutput"/>
     237      </Unit17>
    230238    </Units>
    231239  </ProjectOptions>
  • trunk/IDE/Transpascal.lpr

    r60 r61  
    1414  UFormAbout, UFormOptions, UFormTargets,
    1515UFormProjectNew, UProjectTemplates, UFormTargetProject, UCore,
    16 UFormTargetOptions;
     16UFormTargetOptions, UFormExternalProducerOutput;
    1717
    1818{$R *.res}
     
    3232
    3333  Application.Initialize;
     34  Application.CreateForm(TCore, Core);
    3435  Application.CreateForm(TFormMain, FormMain);
    3536  Application.CreateForm(TFormProject, FormProject);
     
    4344  Application.CreateForm(TFormProjectNew, FormProjectNew);
    4445  Application.CreateForm(TFormTargetProject, FormTargetProject);
    45   Application.CreateForm(TCore, Core);
    4646  Application.CreateForm(TFormTargetOptions, FormTargetOptions);
     47  Application.CreateForm(TFormExternalProducerOutput, FormExternalProducerOutput
     48    );
    4749  Application.Run;
    4850end.
  • trunk/IDE/UProject.pas

    r57 r61  
    9898    Name: string;
    9999    Description: TStringList;
     100    IsProject: Boolean;
    100101    procedure InitProject(var Project: TProject); virtual;
    101102    constructor Create; virtual;
  • trunk/IDE/UProjectTemplates.pas

    r54 r61  
    4141implementation
    4242
     43resourcestring
     44  SConsoleApplication = 'Console application';
     45  SUnit = 'Unit';
     46  SPackage = 'Package';
     47  SGUIApplication = 'GUI application';
     48
    4349{ TProjectTemplateUnit }
    4450
     
    4652begin
    4753  inherited Create;
    48   Name := 'Unit';
     54  Name := SUnit;
     55  IsProject := False;
    4956end;
    5057
     
    6471    Add('end.');
    6572  end;
    66   Project.MainSource := NewFile;
    6773end;
    6874
     
    7278begin
    7379  inherited Create;
    74   Name := 'Package';
     80  Name := SPackage;
     81  IsProject := True;
    7582end;
    7683
     
    97104begin
    98105  inherited Create;
    99   Name := 'GUI application';
     106  Name := SGUIApplication;
     107  IsProject := True;
    100108end;
    101109
     
    128136begin
    129137  inherited Create;
    130   Name := 'Console application';
     138  Name := SConsoleApplication;
     139  IsProject := True;
    131140end;
    132141
Note: See TracChangeset for help on using the changeset viewer.