Changeset 51 for trunk/Forms


Ignore:
Timestamp:
Jul 26, 2012, 2:07:15 PM (12 years ago)
Author:
chronos
Message:
  • Modified: Non visual related code moved to data module Core in UCore unit.
Location:
trunk/Forms
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Forms/UFormMain.lfm

    r49 r51  
    941941    Images = ImageListMain
    942942    left = 216
    943     top = 240
     943    top = 192
    944944    object AProjectOpen: TAction
    945945      Category = 'Project'
     
    19281928    top = 240
    19291929  end
    1930   object CoolTranslator1: TCoolTranslator
    1931     POFilesFolder = 'Languages'
    1932     left = 216
    1933     top = 184
    1934   end
    19351930  object TimerRefresh: TTimer
    19361931    OnTimer = TimerRefreshTimer
    19371932    left = 56
    1938     top = 296
    1939   end
    1940   object ApplicationInfo: TApplicationInfo
    1941     Identification = 1
    1942     VersionMajor = 1
    1943     VersionMinor = 0
    1944     VersionBugFix = 0
    1945     VersionSuffix = 'alfa'
    1946     CompanyName = 'Chronosoft'
    1947     CompanyHomePage = 'http://svn.zdechov.net/trac/LazFuck'
    1948     HomePage = 'http://svn.zdechov.net/trac/LazFuck'
    1949     AuthorsName = 'Chronos'
    1950     EmailContact = 'robie@centrum.cz'
    1951     AppName = 'LazFuck'
    1952     ReleaseDate = 41102
    1953     RegistryKey = '\Software\Chronosoft\LazFuck'
    1954     RegistryRoot = rrKeyCurrentUser
    1955     left = 216
    19561933    top = 296
    19571934  end
  • trunk/Forms/UFormMain.pas

    r48 r51  
    77uses
    88  Classes, SysUtils, FileUtil, SynEdit, Forms, Controls, Graphics, Dialogs,
    9   Menus, ActnList, StdCtrls, ComCtrls, ExtCtrls, UTargetInterpretter,
    10   UCoolTranslator, StrUtils, SpecializedList, UTarget, UApplicationInfo,
    11   Registry, URegistry, ULastOpenedList, Process;
    12 
    13 const
    14   RegistryRoot = HKEY_CURRENT_USER;
     9  Menus, ActnList, StdCtrls, ComCtrls, ExtCtrls,
     10  StrUtils, SpecializedList, UTarget,
     11  Registry, URegistry, Process;
    1512
    1613type
     
    1916
    2017  TMainForm = class(TForm)
    21     ApplicationInfo: TApplicationInfo;
    2218    AProgramShowExecutionPoint: TAction;
    2319    AShowSourcePosition: TAction;
     
    4339    AProjectOpen: TAction;
    4440    ActionList1: TActionList;
    45     CoolTranslator1: TCoolTranslator;
    4641    ImageListMain: TImageList;
    4742    MainMenu1: TMainMenu;
     
    145140  private
    146141    FCurrentTarget: TTarget;
     142    procedure SetCurrentTarget(AValue: TTarget);
    147143    procedure AProjectOpenRecentExecute(Sender: TObject);
    148144    procedure TargetStateChanged(Sender: TObject);
     
    150146    procedure MenuItemTargetClick(Sender: TObject);
    151147    procedure ProjectOpen(FileName: string);
    152     procedure SetCurrentTarget(AValue: TTarget);
    153148    procedure UpdateToolBarHints;
    154149    procedure DockInit;
    155150    procedure LastOpenedListChange(Sender: TObject);
    156151  public
    157     Modified: Boolean;
    158     ProjectFileName: string;
    159     Targets: TTargetList;
    160     LastOpenedList: TLastOpenedList;
    161     OpenProjectOnStart: Boolean;
    162152    procedure LoadFromRegistry(Root: HKEY; Key: string);
    163153    procedure SaveToRegistry(Root: HKEY; Key: string);
     
    177167
    178168uses
    179   UFormCPU, UFormOptions, UFormMessages, UTargetJava,
    180   UTargetDelphi, UTargetPHP, UTargetC, UFormTargets, UFormOutput, UFormInput,
    181   UFormMemory, UFormSourceCode, UFormTargetCode;
     169  UCore, UFormCPU, UFormOptions, UFormMessages, UFormTargets, UFormOutput, UFormInput,
     170  UFormMemory, UFormSourceCode, UFormTargetCode, UTargetInterpretter;
    182171
    183172resourcestring
     
    189178{ TMainForm }
    190179
     180procedure TMainForm.SetCurrentTarget(AValue: TTarget);
     181var
     182  I: Integer;
     183begin
     184  if FCurrentTarget = AValue then Exit;
     185  FCurrentTarget := AValue;
     186  for I := 0 to Core.Targets.Count - 1 do
     187    TTarget(Core.Targets[I]).OnChangeState := nil;
     188  FCurrentTarget.OnChangeState := TargetStateChanged;
     189  FCurrentTarget.Messages.OnChange := MessagesChanged;
     190  UpdateTargetList;
     191  UpdateInterface;
     192end;
     193
    191194procedure TMainForm.FormShow(Sender: TObject);
    192195begin
    193   LoadFromRegistry(RegistryRoot, ApplicationInfo.RegistryKey);
     196  LoadFromRegistry(HKEY(Core.ApplicationInfo.RegistryRoot), Core.ApplicationInfo.RegistryKey);
    194197  PageControlMain.TabIndex := 0;
    195   if OpenProjectOnStart and (LastOpenedList.Items.Count > 0) then
    196     ProjectOpen(LastOpenedList.Items[0])
     198  if Core.OpenProjectOnStart and (Core.LastOpenedList.Items.Count > 0) then
     199    ProjectOpen(Core.LastOpenedList.Items[0])
    197200    else AProjectNew.Execute;
    198201  UpdateInterface;
     
    228231  if Sender is TMenuItem then
    229232  with TMenuItem(Sender) do begin
    230     CurrentTarget := TTarget(Targets[MenuIndex]);
     233    CurrentTarget := TTarget(Core.Targets[MenuIndex]);
    231234    Checked := True;
    232235    for I := 0 to Parent.Count - 1 do
     
    239242  AProjectClose.Execute;
    240243  FormSourceCode.MemoSource.Lines.LoadFromFile(UTF8Decode(FileName));
    241   LastOpenedList.AddItem(FileName);
    242   ProjectFileName := FileName;
    243   Modified := False;
     244  Core.LastOpenedList.AddItem(FileName);
     245  Core.ProjectFileName := FileName;
     246  Core.Modified := False;
    244247  CurrentTarget.Compiled := False;
    245   UpdateInterface;
    246 end;
    247 
    248 procedure TMainForm.SetCurrentTarget(AValue: TTarget);
    249 var
    250   I: Integer;
    251 begin
    252   if FCurrentTarget = AValue then Exit;
    253   FCurrentTarget := AValue;
    254   for I := 0 to Targets.Count - 1 do
    255     TTarget(Targets[I]).OnChangeState := nil;
    256   FCurrentTarget.OnChangeState := TargetStateChanged;
    257   FCurrentTarget.Messages.OnChange := MessagesChanged;
    258   UpdateTargetList;
    259248  UpdateInterface;
    260249end;
     
    297286procedure TMainForm.LastOpenedListChange(Sender: TObject);
    298287begin
    299   LastOpenedList.LoadToMenuItem(MenuItemOpenRecent, AProjectOpenRecentExecute);
    300   LastOpenedList.LoadToMenuItem(PopupMenuRecentFiles.Items, AProjectOpenRecentExecute);
     288  Core.LastOpenedList.LoadToMenuItem(MenuItemOpenRecent, AProjectOpenRecentExecute);
     289  Core.LastOpenedList.LoadToMenuItem(PopupMenuRecentFiles.Items, AProjectOpenRecentExecute);
    301290end;
    302291
     
    309298    RootKey := Root;
    310299    OpenKey(Key, True);
    311     OpenProjectOnStart := ReadBoolWithDefault('OpenProjectOnStart', True);
     300    Core.OpenProjectOnStart := ReadBoolWithDefault('OpenProjectOnStart', True);
    312301    if ValueExists('LanguageCode') then
    313       CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode(ReadStringWithDefault('LanguageCode', ''))
    314       else CoolTranslator1.Language := CoolTranslator1.Languages.SearchByCode('');
     302      Core.CoolTranslator1.Language := Core.CoolTranslator1.Languages.SearchByCode(ReadStringWithDefault('LanguageCode', ''))
     303      else Core.CoolTranslator1.Language := Core.CoolTranslator1.Languages.SearchByCode('');
    315304    TargetName := ReadStringWithDefault('TargetName', 'Interpretter');
    316     CurrentTarget := Targets.FindByName(TargetName);
    317     if not Assigned(CurrentTarget) then CurrentTarget := TTarget(Targets[0]);
     305    CurrentTarget := Core.Targets.FindByName(TargetName);
     306    if not Assigned(CurrentTarget) then CurrentTarget := TTarget(Core.Targets[0]);
    318307  finally
    319308    Free;
    320309  end;
    321   LastOpenedList.LoadFromRegistry(Root, Key);
    322   Targets.LoadFromRegistry(Root, Key);
     310  Core.LastOpenedList.LoadFromRegistry(Root, Key);
     311  Core.Targets.LoadFromRegistry(Root, Key);
    323312end;
    324313
    325314procedure TMainForm.SaveToRegistry(Root: HKEY; Key: string);
    326315begin
    327   Targets.SaveToRegistry(Root, Key);
    328   LastOpenedList.SaveToRegistry(Root, Key);
     316  Core.Targets.SaveToRegistry(Root, Key);
     317  Core.LastOpenedList.SaveToRegistry(Root, Key);
    329318  with TRegistryEx.Create do
    330319  try
    331320    RootKey := Root;
    332321    OpenKey(Key, True);
    333     WriteBool('OpenProjectOnStart', OpenProjectOnStart);
    334     if Assigned(CoolTranslator1.Language) and (CoolTranslator1.Language.Code <> '') then
    335       WriteString('LanguageCode', CoolTranslator1.Language.Code)
     322    WriteBool('OpenProjectOnStart', Core.OpenProjectOnStart);
     323    if Assigned(Core.CoolTranslator1.Language) and (Core.CoolTranslator1.Language.Code <> '') then
     324      WriteString('LanguageCode', Core.CoolTranslator1.Language.Code)
    336325      else DeleteValue('LanguageCode');
    337326    WriteString('TargetName', CurrentTarget.Name);
     
    345334  Title: string;
    346335begin
    347   AProjectSave.Enabled := Modified;
    348   Title := ApplicationInfo.AppName;
    349   if ProjectFileName <> '' then Title := ProjectFileName + ' - ' + Title;
    350   if Modified then Title := Title + ' *';
     336  AProjectSave.Enabled := Core.Modified;
     337  Title := Core.ApplicationInfo.AppName;
     338  if Core.ProjectFileName <> '' then Title := Core.ProjectFileName + ' - ' + Title;
     339  if Core.Modified then Title := Title + ' *';
    351340  Caption := Title;
    352   FormSourceCode.MemoSource.Enabled := ProjectFileName <> '';
    353   AProjectClose.Enabled := ProjectFileName <> '';
     341  FormSourceCode.MemoSource.Enabled := Core.ProjectFileName <> '';
     342  AProjectClose.Enabled := Core.ProjectFileName <> '';
    354343  AProgramRun.Enabled := (tcRun in CurrentTarget.Capabilities) and
    355     (ProjectFileName <> '') and (CurrentTarget.State = rsStopped) or (CurrentTarget.State = rsPaused);
     344    (Core.ProjectFileName <> '') and (CurrentTarget.State = rsStopped) or (CurrentTarget.State = rsPaused);
    356345  AProgramPause.Enabled := (tcPause in CurrentTarget.Capabilities) and
    357     (ProjectFileName <> '') and (CurrentTarget.State = rsRunning);
     346    (Core.ProjectFileName <> '') and (CurrentTarget.State = rsRunning);
    358347  AProgramStop.Enabled := (tcStop in CurrentTarget.Capabilities) and
    359     (ProjectFileName <> '') and (CurrentTarget.State <> rsStopped);
     348    (Core.ProjectFileName <> '') and (CurrentTarget.State <> rsStopped);
    360349  AProgramCompile.Enabled := (tcCompile in CurrentTarget.Capabilities) and
    361     (ProjectFileName <> '');
     350    (Core.ProjectFileName <> '');
    362351  AProgramStepInto.Enabled := (tcStepInto in CurrentTarget.Capabilities) and
    363     (ProjectFileName <> '') and ((CurrentTarget.State = rsPaused) or (CurrentTarget.State = rsStopped));
     352    (Core.ProjectFileName <> '') and ((CurrentTarget.State = rsPaused) or (CurrentTarget.State = rsStopped));
    364353  AProgramStepOut.Enabled := (tcStepOut in CurrentTarget.Capabilities) and
    365     (ProjectFileName <> '') and (CurrentTarget.State = rsPaused);
     354    (Core.ProjectFileName <> '') and (CurrentTarget.State = rsPaused);
    366355  AProgramRunToCursor.Enabled := (tcRunToCursor in CurrentTarget.Capabilities) and
    367     (ProjectFileName <> '') and ((CurrentTarget.State = rsPaused) or (CurrentTarget.State = rsStopped));
     356    (Core.ProjectFileName <> '') and ((CurrentTarget.State = rsPaused) or (CurrentTarget.State = rsStopped));
    368357  AProgramStepOver.Enabled := (tcStepOver in CurrentTarget.Capabilities) and
    369     (ProjectFileName <> '') and ((CurrentTarget.State = rsPaused) or (CurrentTarget.State = rsStopped));
     358    (Core.ProjectFileName <> '') and ((CurrentTarget.State = rsPaused) or (CurrentTarget.State = rsStopped));
    370359  AProgramShowExecutionPoint.Enabled := (tcPause in CurrentTarget.Capabilities) and
    371     (ProjectFileName <> '') and (CurrentTarget.State = rsPaused);
     360    (Core.ProjectFileName <> '') and (CurrentTarget.State = rsPaused);
    372361  AShowSourcePosition.Enabled := CurrentTarget.Compiled;
    373362  AShowTargetPosition.Enabled := CurrentTarget.Compiled;
     
    385374  I: Integer;
    386375begin
    387   Targets.LoadToMenuItem(MenuItemTarget, MenuItemTargetClick, CurrentTarget);
    388   Targets.LoadToMenuItem(PopupMenuTargets.Items, MenuItemTargetClick, CurrentTarget);
     376  Core.Targets.LoadToMenuItem(MenuItemTarget, MenuItemTargetClick, CurrentTarget);
     377  Core.Targets.LoadToMenuItem(PopupMenuTargets.Items, MenuItemTargetClick, CurrentTarget);
    389378
    390379  // Update toolbutton
    391   I := Targets.IndexOf(CurrentTarget);
     380  I := Core.Targets.IndexOf(CurrentTarget);
    392381  if I <> -1 then
    393   with TTarget(Targets[I]) do begin
     382  with TTarget(Core.Targets[I]) do begin
    394383    ToolButtonTarget.ImageIndex := ImageIndex;
    395384    ToolButtonTarget.Caption := Name;
     
    400389procedure TMainForm.FormCreate(Sender: TObject);
    401390begin
    402   Targets := TTargetList.Create;
    403   Targets.Add(TTargetInterpretter.Create);
    404   Targets.Add(TTargetDelphi.Create);
    405   Targets.Add(TTargetPHP.Create);
    406   Targets.Add(TTargetC.Create);
    407   Targets.Add(TTargetJava.Create);
    408391  UpdateTargetList;
    409   LastOpenedList := TLastOpenedList.Create(nil);
    410   LastOpenedList.OnChange := LastOpenedListChange;
     392  Core.LastOpenedList.OnChange := LastOpenedListChange;
    411393end;
    412394
    413395procedure TMainForm.FormDestroy(Sender: TObject);
    414396begin
    415   SaveToRegistry(RegistryRoot, ApplicationInfo.RegistryKey);
    416   LastOpenedList.Free;
    417   Targets.Free;
     397  SaveToRegistry(HKEY(Core.ApplicationInfo.RegistryRoot), Core.ApplicationInfo.RegistryKey);
    418398end;
    419399
     
    461441procedure TMainForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);
    462442begin
    463   if Modified then AProjectSaveAs.Execute;
     443  if Core.Modified then AProjectSaveAs.Execute;
    464444end;
    465445
     
    483463    Optimization := coNormal;
    484464    SourceCode := FormSourceCode.MemoSource.Text;
    485     ProjectFileName := Self.ProjectFileName;
    486     ProgramName := ExtractFileNameOnly(Self.ProjectFileName);
     465    ProjectFileName := Core.ProjectFileName;
     466    ProgramName := ExtractFileNameOnly(Core.ProjectFileName);
    487467    CurrentTarget.Messages.AddMessage('Compiling...');
    488468    Compile;
     
    568548procedure TMainForm.AProjectCloseExecute(Sender: TObject);
    569549begin
    570   if Modified then AProjectSaveAs.Execute;
     550  if Core.Modified then AProjectSaveAs.Execute;
    571551  AProgramStop.Execute;
    572   ProjectFileName := '';
     552  Core.ProjectFileName := '';
    573553  FormSourceCode.MemoSource.Clear;
    574   Modified := False;
     554  Core.Modified := False;
    575555  UpdateInterface;
    576556end;
     
    579559begin
    580560  AProjectClose.Execute;
    581   ProjectFileName := 'Examples' + DirectorySeparator + SNewProject + '.b';
     561  Core.ProjectFileName := 'Examples' + DirectorySeparator + SNewProject + '.b';
    582562  FormSourceCode.MemoSource.Clear;
    583   Modified := False;
     563  Core.Modified := False;
    584564  CurrentTarget.Compiled := False;
    585565  UpdateInterface;
     
    588568procedure TMainForm.AProjectOpenRecentExecute(Sender: TObject);
    589569begin
    590   ProjectOpen(LastOpenedList.Items[TMenuItem(Sender).MenuIndex]);
     570  ProjectOpen(Core.LastOpenedList.Items[TMenuItem(Sender).MenuIndex]);
    591571end;
    592572
     
    594574begin
    595575  AProjectClose.Execute;
    596   OpenDialog1.FileName := ProjectFileName;
     576  OpenDialog1.FileName := Core.ProjectFileName;
    597577  if OpenDialog1.Execute then begin
    598578    ProjectOpen(OpenDialog1.FileName);
     
    602582procedure TMainForm.AProjectSaveAsExecute(Sender: TObject);
    603583begin
    604   SaveDialog1.FileName := ProjectFileName;
     584  SaveDialog1.FileName := Core.ProjectFileName;
    605585  if SaveDialog1.Execute then begin
    606586    FormSourceCode.MemoSource.Lines.SaveToFile(UTF8Decode(SaveDialog1.FileName));
    607     ProjectFileName := SaveDialog1.FileName;
    608     LastOpenedList.AddItem(SaveDialog1.FileName);
    609     Modified := False;
     587    Core.ProjectFileName := SaveDialog1.FileName;
     588    Core.LastOpenedList.AddItem(SaveDialog1.FileName);
     589    Core.Modified := False;
    610590    UpdateInterface;
    611591  end;
     
    614594procedure TMainForm.AProjectSaveExecute(Sender: TObject);
    615595begin
    616   if Modified then AProjectSaveAs.Execute;
     596  if Core.Modified then AProjectSaveAs.Execute;
    617597end;
    618598
  • trunk/Forms/UFormOptions.pas

    r37 r51  
    4040
    4141uses
    42   UFormMain, ULanguages;
     42  UCore, ULanguages;
    4343
    4444{ TOptionsForm }
     
    4646procedure TOptionsForm.FormShow(Sender: TObject);
    4747begin
    48   MainForm.CoolTranslator1.LanguageListToStrings(ComboBoxLanguage.Items);
    49   ComboBoxLanguage.ItemIndex := ComboBoxLanguage.Items.IndexOfObject(MainForm.CoolTranslator1.Language);
     48  Core.CoolTranslator1.LanguageListToStrings(ComboBoxLanguage.Items);
     49  ComboBoxLanguage.ItemIndex := ComboBoxLanguage.Items.IndexOfObject(Core.CoolTranslator1.Language);
    5050  if ComboBoxLanguage.ItemIndex = -1 then ComboBoxLanguage.ItemIndex := 0;
    51   CheckBox1.Checked := MainForm.OpenProjectOnStart;
     51  CheckBox1.Checked := Core.OpenProjectOnStart;
    5252end;
    5353
     
    5555begin
    5656  if ComboBoxLanguage.ItemIndex <> -1 then
    57     MainForm.CoolTranslator1.Language := TLanguage(ComboBoxLanguage.Items.Objects[ComboBoxLanguage.ItemIndex]);
    58   MainForm.OpenProjectOnStart := CheckBox1.Checked;
     57    Core.CoolTranslator1.Language := TLanguage(ComboBoxLanguage.Items.Objects[ComboBoxLanguage.ItemIndex]);
     58  Core.OpenProjectOnStart := CheckBox1.Checked;
    5959end;
    6060
  • trunk/Forms/UFormSourceCode.pas

    r47 r51  
    6464
    6565uses
    66   UFormMain;
     66  UCore, UFormMain;
    6767
    6868resourcestring
     
    168168procedure TFormSourceCode.MemoSourceChange(Sender: TObject);
    169169begin
    170   MainForm.Modified := True;
     170  Core.Modified := True;
    171171  MainForm.CurrentTarget.Compiled := False;
    172172  MainForm.UpdateInterface;
  • trunk/Forms/UFormTargets.pas

    r50 r51  
    3131
    3232uses
    33   UFormMain, UTarget, UFormTargetOptions;
     33  UCore, UTarget, UFormTargetOptions;
    3434
    3535{ TFormCompilers }
     
    4242procedure TFormCompilers.ListView1Data(Sender: TObject; Item: TListItem);
    4343begin
    44   if (Item.Index >= 0) and (Item.Index < MainForm.Targets.Count) then
    45   with TTarget(MainForm.Targets[Item.Index]) do begin
     44  if (Item.Index >= 0) and (Item.Index < Core.Targets.Count) then
     45  with TTarget(Core.Targets[Item.Index]) do begin
    4646    Item.Caption := Name;
    47     Item.Data := MainForm.Targets[Item.Index];
     47    Item.Data := Core.Targets[Item.Index];
    4848    Item.SubItems.Add(ExecutorPath);
    4949    Item.SubItems.Add(CompilerPath);
     
    6262procedure TFormCompilers.ReloadList;
    6363begin
    64   ListView1.Items.Count := MainForm.Targets.Count;
     64  ListView1.Items.Count := Core.Targets.Count;
    6565  ListView1.Refresh;
    6666end;
Note: See TracChangeset for help on using the changeset viewer.