Ignore:
Timestamp:
Aug 6, 2012, 2:35:22 PM (12 years ago)
Author:
chronos
Message:
  • Added: Registration of new file templates for modules.
  • Added: Program stores last opened file list in registry.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/StudioPackage/Forms/UFormMain.pas

    r14 r15  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
    9   ActnList, ComCtrls, ExtCtrls, UDataModule;
     9  ActnList, ComCtrls, ExtCtrls, ULastOpenedList, UCoolTranslator, UDataModule,
     10  URegistry;
    1011
    1112type
     
    4445    AClipboardCut: TAction;
    4546    ActionListMain: TActionList;
     47    LastOpenedList1: TLastOpenedList;
    4648    MainMenu: TMainMenu;
    4749    MenuItem15: TMenuItem;
     
    6062    MenuItem27: TMenuItem;
    6163    MenuItem28: TMenuItem;
    62     MenuItem29: TMenuItem;
     64    MenuItemFileOpenRecent: TMenuItem;
    6365    MenuItem30: TMenuItem;
    6466    MenuItem31: TMenuItem;
     
    8991    PageControlBottom: TPageControl;
    9092    PageControlCenter: TPageControl;
     93    PopupMenuRecentFiles: TPopupMenu;
    9194    SaveDialogFile: TSaveDialog;
    9295    Splitter1: TSplitter;
     
    102105    procedure AFileNewExecute(Sender: TObject);
    103106    procedure AFileOpenExecute(Sender: TObject);
     107    procedure AFileOpenRecentExecute(Sender: TObject);
     108    procedure AFileSaveAsExecute(Sender: TObject);
     109    procedure AFileSaveExecute(Sender: TObject);
    104110    procedure AViewModulesExecute(Sender: TObject);
    105111    procedure AViewSettingsExecute(Sender: TObject);
     
    108114    procedure FormDestroy(Sender: TObject);
    109115    procedure FormShow(Sender: TObject);
     116    procedure LastOpenedList1Change(Sender: TObject);
     117    procedure MenuItemFileOpenRecentClick(Sender: TObject);
    110118  private
    111119    procedure DockInit;
    112120  public
     121    procedure UpdateInterface;
    113122    procedure OpenedFileChange(Sender: TObject);
     123    procedure LoadFromRegistry(Context: TRegistryContext);
     124    procedure SaveToRegistry(Context: TRegistryContext);
    114125  end;
    115126
     
    117128  FormMain: TFormMain;
    118129
     130
    119131implementation
    120132
     
    122134
    123135uses
    124   UFormSourceCode, UFormSettings, UFormModuleList;
     136  UFormSourceCode, UFormSettings, UFormModuleList, UFormNewFile, USource;
    125137
    126138{ TFormMain }
     
    133145procedure TFormMain.AFileCloseExecute(Sender: TObject);
    134146begin
    135   DataModule1.OpenedFiles.CloseFile(DataModule1.OpenedFiles.Selected.FileName);
     147  DataModule1.OpenedFiles.CloseFile(DataModule1.OpenedFiles.Selected);
    136148end;
    137149
    138150procedure TFormMain.AFileNewExecute(Sender: TObject);
    139 begin
    140   DataModule1.OpenedFiles.NewFile;
     151var
     152  NewFile: TSource;
     153begin
     154  if FormNewFile.ShowModal = mrOk then
     155    if Assigned(FormNewFile.ListView1.Selected) then begin
     156      NewFile := TFileTemplate(FormNewFile.ListView1.Selected.Data).Execute;
     157      DataModule1.OpenedFiles.OpenFile(NewFile);
     158    end;
    141159end;
    142160
     
    145163  OpenDialogFile.Filter := DataModule1.FileTypes.GetDialogFilter;
    146164  if OpenDialogFile.Execute then begin
    147     DataModule1.OpenedFiles.OpenFile(OpenDialogFile.FileName);
    148   end;
     165    LastOpenedList1.AddItem(OpenDialogFile.FileName);
     166    DataModule1.OpenedFiles.OpenFileName(OpenDialogFile.FileName);
     167  end;
     168end;
     169
     170procedure TFormMain.AFileOpenRecentExecute(Sender: TObject);
     171begin
     172  if Sender is TMenuItem then
     173    DataModule1.OpenedFiles.OpenFileName(TMenuItem(Sender).Caption);
     174end;
     175
     176procedure TFormMain.AFileSaveAsExecute(Sender: TObject);
     177begin
     178  SaveDialogFile.FileName := DataModule1.OpenedFiles.Selected.Name;
     179  if SaveDialogFile.Execute then begin
     180    LastOpenedList1.AddItem(SaveDialogFile.FileName);
     181    DataModule1.OpenedFiles.Selected.Name := SaveDialogFile.FileName;
     182  end;
     183end;
     184
     185procedure TFormMain.AFileSaveExecute(Sender: TObject);
     186begin
     187
    149188end;
    150189
     
    177216begin
    178217  DockInit;
     218  UpdateInterface;
     219end;
     220
     221procedure TFormMain.LastOpenedList1Change(Sender: TObject);
     222begin
     223  LastOpenedList1.LoadToMenuItem(PopupMenuRecentFiles.Items, AFileOpenRecentExecute);
     224  LastOpenedList1.LoadToMenuItem(MenuItemFileOpenRecent, AFileOpenRecentExecute);
     225end;
     226
     227procedure TFormMain.MenuItemFileOpenRecentClick(Sender: TObject);
     228begin
     229
    179230end;
    180231
     
    186237}end;
    187238
     239procedure TFormMain.UpdateInterface;
     240begin
     241  AFileClose.Enabled := Assigned(DataModule1.OpenedFiles.Selected);
     242  AFileSave.Enabled := Assigned(DataModule1.OpenedFiles.Selected);
     243  AFileSaveAs.Enabled := Assigned(DataModule1.OpenedFiles.Selected);
     244end;
     245
    188246procedure TFormMain.OpenedFileChange(Sender: TObject);
    189247var
     
    193251  with DataModule1.OpenedFiles do begin
    194252    for I := 0 to Count - 1 do
    195     with TOpenedFile(Items[I]) do begin
     253    with TSource(Items[I]) do begin
    196254      if not Assigned(Form.Parent) then begin
    197255        NewTabSheet := PageControlCenter.AddTabSheet;
    198         NewTabSheet.Caption := ExtractFileName(FileName);
     256        NewTabSheet.Caption := ExtractFileName(Name);
    199257        //NewTabSheet.PopupMenu := ;
    200258        Form.ManualDock(NewTabSheet, nil, alClient);
     
    206264end;
    207265
     266procedure TFormMain.LoadFromRegistry(Context: TRegistryContext);
     267begin
     268  LastOpenedList1.LoadFromRegistry(Context.RootKey, Context.Key + '\RecentFiles');
     269end;
     270
     271procedure TFormMain.SaveToRegistry(Context: TRegistryContext);
     272begin
     273  LastOpenedList1.SaveToRegistry(Context.RootKey, Context.Key + '\RecentFiles');
     274end;
     275
    208276end.
    209277
Note: See TracChangeset for help on using the changeset viewer.