Ignore:
Timestamp:
Feb 13, 2012, 3:50:17 PM (13 years ago)
Author:
chronos
Message:
  • Modified: Selection of Analyzer and Producer is now done in main menu.
  • Added: Options form for application wide user settings.
  • Added: Multilanguage interface support. Can be change in main options dialog.
  • Added: Source icons used for actions.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/IDE/Forms/UMainForm.pas

    r34 r35  
    99  UCompiler, Registry, ComCtrls, ExtCtrls, SynEdit, SynHighlighterPas,
    1010  UCDManager, UProject, FileUtil, Menus, ActnList, UCDClient, UCDMaster,
    11   UCDConjoinForm, UCDWindowList, UCDLayout, UCDCustomize, UCompiledForm,
    12   UCodeTreeForm, URegistry, ULastOpenedList, UApplicationInfo, UDebugLog,
    13   UAnalyzer, UProducer;
     11  UCDConjoinForm, UCDWindowList, UCDLayout, UCDCustomize, UCoolTranslator,
     12  UCompiledForm, UCodeTreeForm, URegistry, ULastOpenedList, UApplicationInfo,
     13  UDebugLog, UAnalyzer, UProducer;
    1414
    1515const
    1616  RegistryRootKey = HKEY_CURRENT_USER;
    17   RegistryKey = 'Software\Transpascal';
    1817
    1918type
     
    2221  TMainForm = class(TForm)
    2322    ABuild: TAction;
     23    AViewCompiledSoruce: TAction;
     24    AViewCodeTree: TAction;
     25    AViewOptions: TAction;
    2426    AViewMessages: TAction;
    2527    AViewSourceEditor: TAction;
     
    3638    AProjectClose: TAction;
    3739    ActionList1: TActionList;
    38     Button1: TButton;
    39     CheckBoxLogParsing: TCheckBox;
    40     ComboBoxAnalyzer: TComboBox;
    41     ComboBoxProducer: TComboBox;
     40    CoolTranslator1: TCoolTranslator;
    4241    DebugLog1: TDebugLog;
    4342    ImageList1: TImageList;
    44     Label1: TLabel;
    45     Label2: TLabel;
    4643    MainMenu1: TMainMenu;
    4744    MenuItem1: TMenuItem;
     
    5552    MenuItem17: TMenuItem;
    5653    MenuItem18: TMenuItem;
     54    MenuItem19: TMenuItem;
    5755    MenuItem2: TMenuItem;
     56    MenuItem20: TMenuItem;
     57    MenuItem21: TMenuItem;
     58    MenuItem22: TMenuItem;
     59    MenuItem23: TMenuItem;
     60    MenuItemAnalyzer: TMenuItem;
     61    MenuItemProducer: TMenuItem;
    5862    MenuItem3: TMenuItem;
    5963    MenuItem4: TMenuItem;
     
    6670    MenuItemOpenRecent: TMenuItem;
    6771    OpenDialog1: TOpenDialog;
    68     PageControl1: TPageControl;
    69     PageControl2: TPageControl;
     72    PageControlRight: TPageControl;
     73    PageControlBottom: TPageControl;
    7074    SaveDialog1: TSaveDialog;
    7175    Splitter1: TSplitter;
     76    Splitter2: TSplitter;
    7277    Splitter3: TSplitter;
    7378    TabSheet1: TTabSheet;
     
    7681    TabSheet4: TTabSheet;
    7782    ToolBar1: TToolBar;
     83    ToolButton1: TToolButton;
     84    ToolButton2: TToolButton;
     85    ToolButton3: TToolButton;
     86    ToolButton4: TToolButton;
     87    ToolButton5: TToolButton;
     88    ToolButton6: TToolButton;
     89    ToolButton7: TToolButton;
     90    ToolButton8: TToolButton;
    7891    procedure AAboutExecute(Sender: TObject);
    7992    procedure AExitExecute(Sender: TObject);
     
    8598    procedure AProjectSaveExecute(Sender: TObject);
    8699    procedure ABuildExecute(Sender: TObject);
     100    procedure AViewCodeTreeExecute(Sender: TObject);
     101    procedure AViewCompiledSoruceExecute(Sender: TObject);
     102    procedure AViewMessagesExecute(Sender: TObject);
     103    procedure AViewOptionsExecute(Sender: TObject);
     104    procedure AViewProjectExecute(Sender: TObject);
     105    procedure AViewSourceEditorExecute(Sender: TObject);
    87106    procedure ComboBox1Change(Sender: TObject);
    88107    procedure ComboBoxProducerChange(Sender: TObject);
     
    93112  private
    94113    LastOpenedFiles: TLastOpenedList;
    95     ReopenLastOpenedFile: Boolean;
    96114    procedure CompilerDebugLog(Text: string);
     115    procedure MenuItemAnalyzerClick(Sender: TObject);
     116    procedure MenuItemProducerClick(Sender: TObject);
    97117    procedure OpenRecentClick(Sender: TObject);
    98118    procedure DockInit;
    99     procedure LoadFromRegistry;
    100     procedure SaveToRegistry;
     119    procedure LoadFromRegistry(Root: HKEY; Key: string);
     120    procedure SaveToRegistry(Root: HKEY; Key: string);
    101121    procedure OpenProject(FileName: string);
     122    procedure UpdateMenu;
    102123  public
     124    SelectedAnalyzerIndex: Integer;
     125    SelectedProducerIndex: Integer;
     126    ReopenLastOpenedFile: Boolean;
     127    LogParsing: Boolean;
    103128    Project: TProject;
    104129    Compiler: TCompiler;
    105130    function GetSource(Name: string; var SourceCode: string): Boolean;
     131    procedure UpdateInterface;
    106132  end;
    107133
     
    115141
    116142uses
    117   UMessagesForm, UCodeForm, UProjectManager, UCommon, UAboutForm;
     143  UMessagesForm, UCodeForm, UProjectManager, UCommon, UAboutForm, UFormOptions;
    118144
    119145resourcestring
     
    127153
    128154  // Compile project file
    129   if (ComboBoxAnalyzer.Items.Count > 0) and (ComboBoxAnalyzer.ItemIndex <> -1) and
    130     (ComboBoxProducer.Items.Count > 0) and (ComboBoxProducer.ItemIndex <> -1) then begin
    131     Compiler.Producer := TProducer(Compiler.Producers[ComboBoxProducer.ItemIndex]);
    132     Compiler.Analyzer := TAnalyzer(Compiler.Analyzers[ComboBoxAnalyzer.ItemIndex]);
     155    Compiler.Producer := TProducer(Compiler.Producers[SelectedProducerIndex]);
     156    Compiler.Analyzer := TAnalyzer(Compiler.Analyzers[SelectedAnalyzerIndex]);
    133157    Compiler.Analyzer.OnGetSource := GetSource;
    134158    Compiler.Init;
    135159
    136     if CheckBoxLogParsing.Checked then
     160    if LogParsing then
    137161      Compiler.Analyzer.OnDebugLog := CompilerDebugLog
    138162      else Compiler.Analyzer.OnDebugLog := nil;
     
    145169    ProjectManager.TreeViewProjectChange(Self, ProjectManager.TreeViewProject.Selected);
    146170    MessagesForm.Reload;
    147   end;
     171end;
     172
     173procedure TMainForm.AViewCodeTreeExecute(Sender: TObject);
     174begin
     175  PageControlRight.TabIndex := 1;
     176end;
     177
     178procedure TMainForm.AViewCompiledSoruceExecute(Sender: TObject);
     179begin
     180  PageControlBottom.TabIndex := 1;
     181end;
     182
     183procedure TMainForm.AViewMessagesExecute(Sender: TObject);
     184begin
     185  PageControlBottom.TabIndex := 0;
     186end;
     187
     188procedure TMainForm.AViewOptionsExecute(Sender: TObject);
     189begin
     190  FormOptions.ShowModal;
     191end;
     192
     193procedure TMainForm.AViewProjectExecute(Sender: TObject);
     194begin
     195  PageControlRight.TabIndex := 0;
     196end;
     197
     198procedure TMainForm.AViewSourceEditorExecute(Sender: TObject);
     199begin
     200
    148201end;
    149202
     
    164217    F.Free;
    165218  end else Result := False;
     219end;
     220
     221procedure TMainForm.UpdateInterface;
     222var
     223  I: Integer;
     224  Title: string;
     225begin
     226  Title := ApplicationInfo.Name;
     227  if Project.Name <> '' then Title := Project.Name + ' - ' + Title;
     228  if Project.Modified then Title := Title + ' *';
     229  Caption := Title;
     230  AProjectClose.Enabled := Project.Active;
     231  AProjectSave.Enabled := Project.Active and Project.Modified;
     232  AProjectSaveAs.Enabled := Project.Active;
     233  (*AProgramRun.Enabled := Project.Active and (BrainFuckInterpreter.State = rsStopped);
     234  AProgramPause.Enabled := Project.Active and (BrainFuckInterpreter.State = rsRunning);
     235  AProgramStop.Enabled := Project.Active and (BrainFuckInterpreter.State <> rsStopped);*)
     236  UpdateMenu;
    166237end;
    167238
     
    222293end;
    223294
    224 procedure TMainForm.LoadFromRegistry;
     295procedure TMainForm.LoadFromRegistry(Root: HKEY; Key: string);
    225296begin
    226297  with TRegistryEx.Create do
    227298    try
    228       RootKey := HKEY_CURRENT_USER;
    229       OpenKey(RegistryKey, True);
     299      RootKey := Root;
     300      OpenKey(Key, True);
    230301      ReopenLastOpenedFile := ReadBoolWithDefault('ReopenLastOpenedFile', True);
    231       ComboBoxProducer.ItemIndex := ReadIntegerWithDefault('ProducerType', 0);
    232       with ComboBoxProducer do
    233         if (ItemIndex = -1) and (Items.Count > 0) then ItemIndex := 0;
    234       ComboBoxAnalyzer.ItemIndex := ReadIntegerWithDefault('AnalyzerType', 0);
    235       with ComboBoxAnalyzer do
    236         if (ItemIndex = -1) and (Items.Count > 0) then ItemIndex := 0;
    237       CheckBoxLogParsing.Checked := ReadBoolWithDefault('LogParsing', False);
     302      SelectedProducerIndex := ReadIntegerWithDefault('ProducerType', 0);
     303      SelectedAnalyzerIndex := ReadIntegerWithDefault('AnalyzerType', 0);
     304      LogParsing := ReadBoolWithDefault('LogParsing', False);
     305      if ValueExists('LanguageCode') then
     306        CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(ReadStringWithDefault('LanguageCode', ''))
     307        else CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode('');
    238308    finally
    239309      Free;
    240310    end;
    241   LastOpenedFiles.LoadFromRegistry(RegistryRootKey, RegistryKey);
    242 end;
    243 
    244 procedure TMainForm.SaveToRegistry;
     311  LastOpenedFiles.LoadFromRegistry(RegistryRootKey, Key);
     312end;
     313
     314procedure TMainForm.SaveToRegistry(Root: HKEY; Key: string);
    245315begin
    246316  with TRegistryEx.Create do
    247317    try
    248       RootKey := RegistryRootKey;
    249       OpenKey(RegistryKey, True);
     318      RootKey := Root;
     319      OpenKey(Key, True);
    250320      WriteBool('ReopenLastOpenedFile', ReopenLastOpenedFile);
    251       WriteInteger('ProducerType', ComboBoxProducer.ItemIndex);
    252       WriteInteger('AnalyzerType', ComboBoxAnalyzer.ItemIndex);
    253       WriteBool('LogParsing', CheckBoxLogParsing.Checked);
     321      WriteInteger('ProducerType', SelectedProducerIndex);
     322      WriteInteger('AnalyzerType', SelectedAnalyzerIndex);
     323      WriteBool('LogParsing', LogParsing);
     324      if Assigned(CoolTranslator1.Language) and (CoolTranslator1.Language.Code <> '') then
     325        WriteString('LanguageCode', CoolTranslator1.Language.Code)
     326        else DeleteValue('LanguageCode');
    254327    finally
    255328      Free;
    256329    end;
    257   LastOpenedFiles.SaveToRegistry(RegistryRootKey, RegistryKey);
     330  LastOpenedFiles.SaveToRegistry(RegistryRootKey, Key);
    258331  LastOpenedFiles.ReloadMenu;
    259332end;
     
    265338  LastOpenedFiles.ReloadMenu;
    266339  ProjectManager.UpdateProjectTree;
    267   Caption := ApplicationInfo.Name + ' - ' + Project.Name;
     340  UpdateInterface;
     341end;
     342
     343procedure TMainForm.MenuItemAnalyzerClick(Sender: TObject);
     344begin
     345  with TMenuItem(Sender) do begin
     346    SelectedAnalyzerIndex := MenuIndex;
     347    UpdateMenu;
     348  end;
     349end;
     350
     351procedure TMainForm.MenuItemProducerClick(Sender: TObject);
     352begin
     353  with TMenuItem(Sender) do begin
     354    SelectedProducerIndex := MenuIndex;
     355    UpdateMenu;
     356  end;
     357end;
     358
     359procedure TMainForm.UpdateMenu;
     360var
     361  I: Integer;
     362  NewMenuItem: TMenuItem;
     363begin
     364  MenuItemAnalyzer.Clear;
     365  for I := 0 to Compiler.Analyzers.Count - 1 do begin
     366    NewMenuItem := TMenuItem.Create(MenuItemAnalyzer);
     367    NewMenuItem.Caption := TAnalyzer(Compiler.Analyzers[I]).Name;
     368    NewMenuItem.OnClick := MenuItemAnalyzerClick;
     369    if I = SelectedAnalyzerIndex then NewMenuItem.Checked := True;
     370    MenuItemAnalyzer.Add(NewMenuItem);
     371  end;
     372  MenuItemProducer.Clear;
     373  for I := 0 to Compiler.Producers.Count - 1 do begin
     374    NewMenuItem := TMenuItem.Create(MenuItemProducer);
     375    NewMenuItem.Caption := TProducer(Compiler.Producers[I]).Name;
     376    NewMenuItem.OnClick := MenuItemProducerClick;
     377    if I = SelectedProducerIndex then NewMenuItem.Checked := True;
     378    MenuItemProducer.Add(NewMenuItem);
     379  end;
    268380end;
    269381
     
    271383begin
    272384  Project.Save;
    273   SaveToRegistry;
     385  SaveToRegistry(RegistryRootKey, ApplicationInfo.RegistryKey);
    274386end;
    275387
     
    284396  LastOpenedFiles.MenuItem := MenuItemOpenRecent;
    285397  LastOpenedFiles.ClickAction := OpenRecentClick;
    286 
    287   ComboBoxProducer.Clear;
    288   for I := 0 to Compiler.Producers.Count - 1 do
    289     ComboBoxProducer.AddItem(TProducer(Compiler.Producers[I]).Name, nil);
    290 
    291   ComboBoxAnalyzer.Clear;
    292   for I := 0 to Compiler.Analyzers.Count - 1 do
    293     ComboBoxAnalyzer.AddItem(TAnalyzer(Compiler.Analyzers[I]).Name, nil);
    294398end;
    295399
     
    316420  NewProjectFile: TProjectFile;
    317421begin
    318   LoadFromRegistry;
     422  LoadFromRegistry(RegistryRootKey, ApplicationInfo.RegistryKey);
    319423  DockInit;
    320424
Note: See TracChangeset for help on using the changeset viewer.