Ignore:
Timestamp:
Nov 30, 2017, 12:02:32 AM (7 years ago)
Author:
chronos
Message:
  • Added: New project Close action.
  • Added: Track project Modified flag and offer project save if modified project is closed.
  • Added: Remember last opened project file.
Location:
branches/generator/Forms
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/generator/Forms/UFormGrammer.pas

    r124 r126  
    6262procedure TFormGrammer.SaveData(Grammer: TGrammer);
    6363begin
     64  Grammer.Modified := True;
    6465  if ComboBoxStartRule.ItemIndex <> -1 then
    6566    Grammer.TopRule := TRule(ComboBoxStartRule.Items.Objects[ComboBoxStartRule.ItemIndex])
  • branches/generator/Forms/UFormMain.lfm

    r124 r126  
    55  Width = 1050
    66  Caption = 'Language generator'
    7   ClientHeight = 653
     7  ClientHeight = 644
    88  ClientWidth = 1050
    99  Menu = MainMenu1
    1010  OnClose = FormClose
     11  OnCloseQuery = FormCloseQuery
    1112  OnShow = FormShow
    12   LCLVersion = '1.6.4.0'
     13  LCLVersion = '1.8.0.4'
    1314  object MemoBNF: TMemo
    1415    Left = 0
    15     Height = 618
     16    Height = 609
    1617    Top = 35
    1718    Width = 1050
    1819    Align = alClient
     20    ReadOnly = True
    1921    ScrollBars = ssAutoBoth
    2022    TabOrder = 0
     
    6971      Caption = 'File'
    7072      object MenuItem11: TMenuItem
    71         Action = ANew
     73        Action = AProjectNew
    7274      end
    7375      object MenuItem4: TMenuItem
    74         Action = AOpen
     76        Action = AProjectOpen
    7577      end
    7678      object MenuItem10: TMenuItem
    77         Action = ASave
     79        Action = AProjectSave
    7880      end
    7981      object MenuItem5: TMenuItem
    80         Action = ASaveAs
     82        Action = AProjectSaveAs
     83      end
     84      object MenuItem13: TMenuItem
     85        Action = AProjectClose
    8186      end
    8287      object MenuItem12: TMenuItem
     
    119124      OnExecute = AExitExecute
    120125    end
    121     object AOpen: TAction
     126    object AProjectOpen: TAction
    122127      Caption = 'Open...'
    123128      Hint = 'Open...'
    124129      ImageIndex = 4
    125       OnExecute = AOpenExecute
     130      OnExecute = AProjectOpenExecute
    126131    end
    127     object ASaveAs: TAction
     132    object AProjectSaveAs: TAction
    128133      Caption = 'Save as...'
    129134      Hint = 'Save as...'
    130135      ImageIndex = 5
    131       OnExecute = ASaveAsExecute
     136      OnExecute = AProjectSaveAsExecute
    132137    end
    133138    object ABuildCompiler: TAction
     
    136141      OnExecute = ABuildCompilerExecute
    137142    end
    138     object ASave: TAction
     143    object AProjectSave: TAction
    139144      Caption = 'Save'
    140145      ImageIndex = 5
    141       OnExecute = ASaveExecute
     146      OnExecute = AProjectSaveExecute
    142147    end
    143     object ANew: TAction
     148    object AProjectNew: TAction
    144149      Caption = 'New'
    145150      ImageIndex = 10
    146       OnExecute = ANewExecute
     151      OnExecute = AProjectNewExecute
    147152    end
    148153    object AGrammerSettings: TAction
    149154      Caption = 'Settings'
    150155      OnExecute = AGrammerSettingsExecute
     156    end
     157    object AProjectClose: TAction
     158      Caption = 'Close'
     159      OnExecute = AProjectCloseExecute
    151160    end
    152161  end
  • branches/generator/Forms/UFormMain.pas

    r124 r126  
    1515  TFormMain = class(TForm)
    1616    ABuildCompiler: TAction;
     17    AProjectClose: TAction;
    1718    AGrammerSettings: TAction;
    18     ANew: TAction;
    19     ASave: TAction;
     19    AProjectNew: TAction;
     20    AProjectSave: TAction;
    2021    AExit: TAction;
    21     AOpen: TAction;
    22     ASaveAs: TAction;
     22    AProjectOpen: TAction;
     23    AProjectSaveAs: TAction;
    2324    ARules: TAction;
    2425    ActionList1: TActionList;
     
    3031    MenuItem11: TMenuItem;
    3132    MenuItem12: TMenuItem;
     33    MenuItem13: TMenuItem;
    3234    MenuItem2: TMenuItem;
    3335    MenuItem3: TMenuItem;
     
    4648    procedure AExitExecute(Sender: TObject);
    4749    procedure AGrammerSettingsExecute(Sender: TObject);
    48     procedure ANewExecute(Sender: TObject);
    49     procedure AOpenExecute(Sender: TObject);
    5050    procedure ARulesExecute(Sender: TObject);
    51     procedure ASaveAsExecute(Sender: TObject);
    52     procedure ASaveExecute(Sender: TObject);
     51    procedure AProjectNewExecute(Sender: TObject);
     52    procedure AProjectOpenExecute(Sender: TObject);
     53    procedure AProjectCloseExecute(Sender: TObject);
     54    procedure AProjectSaveAsExecute(Sender: TObject);
     55    procedure AProjectSaveExecute(Sender: TObject);
    5356    procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
     57    procedure FormCloseQuery(Sender: TObject; var CanClose: boolean);
    5458    procedure FormShow(Sender: TObject);
    5559  private
     
    7175  UFormRules, UCore, UFormGrammer;
    7276
    73 { TFormMain }
     77resourcestring
     78  SUnsavedChanges = 'Unsaved changes';
     79  SDoYouWantToSaveProject = 'There are unsaved changes in project. Do you want to save them?';
     80  SNewGrammer = 'New grammer.xtg';
     81
     82  { TFormMain }
    7483
    7584procedure TFormMain.ARulesExecute(Sender: TObject);
     
    8190  FormRules.ShowModal;
    8291  ReloadMemo;
     92  UpdateInterface;
    8393  FreeAndNil(FormRules);
    8494end;
    8595
    86 procedure TFormMain.ASaveAsExecute(Sender: TObject);
     96procedure TFormMain.AProjectSaveAsExecute(Sender: TObject);
    8797begin
    8898  SaveDialog1.FileName := Core.Grammer.FileName;
    8999  if SaveDialog1.Execute then begin
     100    Core.LastOpenedFile := SaveDialog1.FileName;
    90101    Core.Grammer.SaveToXmlFile(SaveDialog1.FileName);
    91102    UpdateInterface;
     
    93104end;
    94105
    95 procedure TFormMain.ASaveExecute(Sender: TObject);
     106procedure TFormMain.AProjectSaveExecute(Sender: TObject);
    96107begin
    97108  Core.Grammer.SaveToXmlFile(Core.Grammer.FileName);
     
    104115end;
    105116
     117procedure TFormMain.FormCloseQuery(Sender: TObject; var CanClose: boolean);
     118begin
     119  AProjectClose.Execute;
     120  if Assigned(Core.Grammer) then CanClose := False;
     121end;
     122
    106123procedure TFormMain.FormShow(Sender: TObject);
    107124begin
    108125  Core.PersistentForm1.Load(Self, True);
     126  Core.Initialize;
    109127  ReloadMemo;
    110128  UpdateInterface;
     
    113131procedure TFormMain.ReloadMemo;
    114132begin
    115   MemoBNF.Lines.Text := Core.Grammer.GetString;
     133  if Assigned(Core.Grammer) then
     134    MemoBNF.Lines.Text := Core.Grammer.GetString
     135    else MemoBNF.Lines.Clear;
    116136end;
    117137
    118138procedure TFormMain.UpdateInterface;
    119 begin
    120   Caption := Core.Grammer.FileName + ' - ' + Application.Title;
     139var
     140  NewTitle: string;
     141begin
     142  NewTitle := Application.Title;
     143  if Assigned(Core.Grammer) then begin
     144    NewTitle := ExtractFileNameWithoutExt(ExtractFileName(Core.Grammer.FileName)) + ' - ' + NewTitle;
     145    if Core.Grammer.Modified then NewTitle := NewTitle + '*';
     146  end;
     147  Caption := NewTitle;
     148  AProjectClose.Enabled := Assigned(Core.Grammer);
     149  AProjectSave.Enabled := Assigned(Core.Grammer) and Core.Grammer.Modified;
     150  AProjectSaveAs.Enabled := Assigned(Core.Grammer);
     151  AGrammerSettings.Enabled := Assigned(Core.Grammer);
     152  ABuildCompiler.Enabled := Assigned(Core.Grammer);
     153  ARules.Enabled := Assigned(Core.Grammer);
    121154end;
    122155
     
    134167  if FormGrammer.ShowModal = mrOk then begin
    135168    FormGrammer.SaveData(Core.Grammer);
     169    UpdateInterface;
    136170  end;
    137171  FreeAndNil(FormGrammer);
    138172end;
    139173
    140 procedure TFormMain.ANewExecute(Sender: TObject);
    141 begin
    142   Core.Grammer.Rules.Clear;
    143   ReloadMemo;
    144   UpdateInterface;
     174procedure TFormMain.AProjectNewExecute(Sender: TObject);
     175begin
     176  AProjectClose.Execute;
     177  if not Assigned(Core.Grammer) then begin
     178    Core.Grammer := TGrammer.Create;
     179    Core.Grammer.FileName := SNewGrammer;
     180    ReloadMemo;
     181    UpdateInterface;
     182  end;
    145183end;
    146184
     
    150188end;
    151189
    152 procedure TFormMain.AOpenExecute(Sender: TObject);
    153 begin
    154   OpenDialog1.FileName := Core.Grammer.FileName;
    155   if OpenDialog1.Execute then begin
    156     Core.Grammer.LoadFromXmlFile(OpenDialog1.FileName);
     190procedure TFormMain.AProjectOpenExecute(Sender: TObject);
     191begin
     192  AProjectClose.Execute;
     193  if not Assigned(Core.Grammer) then begin
     194    OpenDialog1.FileName := Core.LastOpenedFile;
     195    if OpenDialog1.Execute then begin
     196      Core.LastOpenedFile := OpenDialog1.FileName;
     197      Core.Grammer := TGrammer.Create;
     198      Core.Grammer.LoadFromXmlFile(OpenDialog1.FileName);
     199      ReloadMemo;
     200      UpdateInterface;
     201    end;
     202  end;
     203end;
     204
     205procedure TFormMain.AProjectCloseExecute(Sender: TObject);
     206var
     207  DialogResult: TModalResult;
     208begin
     209  if not Assigned(Core.Grammer) then Exit;
     210
     211  DialogResult := mrNo;
     212  if Core.Grammer.Modified then begin
     213    DialogResult := MessageDlg(SUnsavedChanges, SDoYouWantToSaveProject, mtConfirmation, [mbYes, mbNo, mbCancel], 0);
     214    if DialogResult = mrYes then begin
     215      AProjectSave.Execute;
     216    end;
     217  end;
     218  if (DialogResult = mrNo) or (DialogResult = mrYes) then begin
     219    FreeAndNil(Core.Grammer);
    157220    ReloadMemo;
    158221    UpdateInterface;
  • branches/generator/Forms/UFormRule.pas

    r123 r126  
    9696procedure TFormRule.SaveData(Rule: TRule);
    9797begin
     98  Rule.Grammer.Modified := True;
    9899  Rule.Name := EditName.Text;
    99100  Rule.CreateSourceNode := CheckBoxCreateNode.Checked;
  • branches/generator/Forms/UFormRuleItem.pas

    r124 r126  
    143143procedure TFormRuleItem.SaveData(RuleItem: TRuleItem);
    144144begin
     145  RuleItem.Grammer.Modified := True;
    145146  TFormRuleItems(FormRuleItems).SaveData(RuleItem.SubItems);
    146147  RuleItem.RuleItemType := TRuleItemType(ComboBoxType.ItemIndex);
  • branches/generator/Forms/UFormRuleItems.pas

    r122 r126  
    130130    mtConfirmation, mbYesNo, 0) = mrYes then
    131131  for I := ListView1.Items.Count - 1 downto 0 do
    132   if ListView1.Items[I].Selected then
     132  if ListView1.Items[I].Selected then begin
    133133    RuleItems.ParentRule.Items.Remove(TRuleItem(ListView1.Items[I].Data));
     134    RuleItems.Grammer.Modified := True;
     135  end;
    134136  ReloadList;
    135137end;
  • branches/generator/Forms/UFormRules.pas

    r122 r126  
    121121    mtConfirmation, mbYesNo, 0) = mrYes then
    122122  for I := ListView1.Items.Count - 1 downto 0 do
    123   if ListView1.Items[I].Selected then
     123  if ListView1.Items[I].Selected then begin
     124    Rules.Grammer.Modified := True;
    124125    Rules.Remove(TRule(ListView1.Items[I].Data));
     126  end;
    125127  ReloadList;
    126128end;
Note: See TracChangeset for help on using the changeset viewer.