{* * @(#) sdesignm.pas - System Designer program ('control' module). * (c) 1997 Ivan Maidanski http://ivmai.chat.ru * Freeware program source. All rights reserved. ** * Language: Delphi * Tested with: Borland Delphi DeskTop 2.01 for Windows 95 * Last modified: 1997-04-18 14:50:00 GMT+04:00 *} unit SDesignM; interface uses Forms, Dialogs, Menus, Classes, SysUtils, SDesignF; {$EXTENDEDSYNTAX ON} {$LONGSTRINGS ON} type TDesignerForm = class(TForm) DesignerMenu: TMainMenu; FileMenu: TMenuItem; NewItem: TMenuItem; OpenItem: TMenuItem; OpenFileDlg: TOpenDialog; SaveItem: TMenuItem; SaveAsItem: TMenuItem; CloseItem: TMenuItem; FileItemSeparator: TMenuItem; ExitItem: TMenuItem; EditMenu: TMenuItem; UndoItem: TMenuItem; RedoItem: TMenuItem; EditItemSeparator: TMenuItem; CutItem: TMenuItem; CopyItem: TMenuItem; PasteItem: TMenuItem; DeleteItem: TMenuItem; SelectItemSeparator: TMenuItem; SelectItem: TMenuItem; DataMenu: TMenuItem; InsertItem: TMenuItem; DataItemSeparator: TMenuItem; ModifyItem: TMenuItem; RenameItem: TMenuItem; SearchItemSeparator: TMenuItem; FindItem: TMenuItem; ReplaceItem: TMenuItem; SearchAgainItem: TMenuItem; HelpMenu: TMenuItem; ContentsItem: TMenuItem; TopicSearchItem: TMenuItem; HelpItemSeparator: TMenuItem; AboutItem: TMenuItem; procedure FormCreate(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure ExitClick(Sender: TObject); procedure AboutClick(Sender: TObject); procedure NewFileClick(Sender: TObject); procedure OpenFileClick(Sender: TObject); procedure SaveFileClick(Sender: TObject); procedure SaveFileAsClick(Sender: TObject); procedure CloseFileClick(Sender: TObject); procedure CutClick(Sender: TObject); procedure CopyClick(Sender: TObject); procedure PasteClick(Sender: TObject); procedure DeleteClick(Sender: TObject); procedure InsertClick(Sender: TObject); procedure ModifyClick(Sender: TObject); procedure RenameClick(Sender: TObject); procedure FindClick(Sender: TObject); private ProjectList: TList; ProjectNum: Integer; function CurrentProject: TProjectForm; procedure MenuUpdateOnOpen; procedure MenuUpdateOnFocused; procedure MenuUpdateOnChanged; procedure MenuUpdateOnCloseAll; public procedure NewProject(const FName: String; ReadOnly: Boolean); procedure ChildFocused(ChildForm: TProjectForm); procedure ChildChanged(ChildForm: TProjectForm); procedure ChildClosed(ChildForm: TProjectForm); end; var DesignerForm: TDesignerForm; implementation {$R sdesignm.dfm} {$BOOLEVAL OFF} uses SDesignA; procedure TDesignerForm.FormCreate(Sender: TObject); begin ProjectList:=TList.Create; ProjectNum:=0; end; procedure TDesignerForm.FormCloseQuery(Sender: TObject; var CanClose: Boolean); var Cur: Integer; begin with ProjectList do begin for Cur:=Count-1 downto 0 do TProjectForm(Items[Cur]).Close; if Count>0 then CanClose:=False; end; end; procedure TDesignerForm.FormClose(Sender: TObject; var Action: TCloseAction); begin ProjectList.Free; end; procedure TDesignerForm.ExitClick(Sender: TObject); begin Close; end; procedure TDesignerForm.AboutClick(Sender: TObject); begin AboutForm.ShowModal; end; procedure TDesignerForm.NewFileClick(Sender: TObject); begin NewProject('',False); end; procedure TDesignerForm.OpenFileClick(Sender: TObject); begin with OpenFileDlg do if Execute then try NewProject(FileName,ofReadOnly in Options); except on EInOutError do MessageDlg('Cannot open file '''+FileName+'''.', mtInformation,[mbOk],0); end; end; procedure TDesignerForm.SaveFileClick(Sender: TObject); begin CurrentProject.SaveClick; end; procedure TDesignerForm.SaveFileAsClick(Sender: TObject); begin CurrentProject.SaveAsClick; end; procedure TDesignerForm.CloseFileClick(Sender: TObject); begin CurrentProject.Close; end; procedure TDesignerForm.CutClick(Sender: TObject); begin CurrentProject.CutToClipboardClick; end; procedure TDesignerForm.CopyClick(Sender: TObject); begin CurrentProject.CopyToClipboardClick; end; procedure TDesignerForm.PasteClick(Sender: TObject); begin CurrentProject.PasteFromClipboardClick; end; procedure TDesignerForm.DeleteClick(Sender: TObject); begin CurrentProject.DeleteItemClick; end; procedure TDesignerForm.InsertClick(Sender: TObject); begin CurrentProject.InsertItemClick; end; procedure TDesignerForm.ModifyClick(Sender: TObject); begin CurrentProject.ModifyItemClick; end; procedure TDesignerForm.RenameClick(Sender: TObject); begin CurrentProject.RenameItemClick; end; procedure TDesignerForm.FindClick(Sender: TObject); begin CurrentProject.FindItemClick; end; function TDesignerForm.CurrentProject: TProjectForm; begin CurrentProject:=TProjectForm(ProjectList.Items[0]); end; procedure TDesignerForm.NewProject(const FName: String; ReadOnly: Boolean); begin Inc(ProjectNum); ProjectList.Insert(0,TProjectForm.CreateForm(Self,FName, ReadOnly,ProjectNum)); MenuUpdateOnOpen; end; procedure TDesignerForm.ChildFocused(ChildForm: TProjectForm); begin with ProjectList do if IndexOf(ChildForm)>=0 then begin Remove(ChildForm); Insert(0,ChildForm); MenuUpdateOnFocused; end; end; procedure TDesignerForm.ChildChanged(ChildForm: TProjectForm); begin if ProjectList.IndexOf(ChildForm)>=0 then MenuUpdateOnChanged; end; procedure TDesignerForm.ChildClosed(ChildForm: TProjectForm); begin with ProjectList do begin Remove(ChildForm); if Count>0 then MenuUpdateOnFocused else MenuUpdateOnCloseAll; end; end; procedure TDesignerForm.MenuUpdateOnOpen; begin CloseItem.Enabled:=True; SaveAsItem.Enabled:=True; CopyItem.Enabled:=True; FindItem.Enabled:=True; ModifyItem.Enabled:=not CurrentProject.IsReadOnly; CutItem.Enabled:=ModifyItem.Enabled; PasteItem.Enabled:=ModifyItem.Enabled; DeleteItem.Enabled:=ModifyItem.Enabled; InsertItem.Enabled:=ModifyItem.Enabled; RenameItem.Enabled:=ModifyItem.Enabled; ReplaceItem.Enabled:=ModifyItem.Enabled; SaveItem.Enabled:=False; end; procedure TDesignerForm.MenuUpdateOnFocused; begin ModifyItem.Enabled:=not CurrentProject.IsReadOnly; CutItem.Enabled:=ModifyItem.Enabled; PasteItem.Enabled:=ModifyItem.Enabled; DeleteItem.Enabled:=ModifyItem.Enabled; InsertItem.Enabled:=ModifyItem.Enabled; RenameItem.Enabled:=ModifyItem.Enabled; ReplaceItem.Enabled:=ModifyItem.Enabled; SaveItem.Enabled:=CurrentProject.IsModified; end; procedure TDesignerForm.MenuUpdateOnChanged; begin SaveItem.Enabled:=CurrentProject.IsModified; end; procedure TDesignerForm.MenuUpdateOnCloseAll; begin CloseItem.Enabled:=False; SaveAsItem.Enabled:=False; CopyItem.Enabled:=False; FindItem.Enabled:=False; ModifyItem.Enabled:=False; CutItem.Enabled:=False; PasteItem.Enabled:=False; DeleteItem.Enabled:=False; InsertItem.Enabled:=False; RenameItem.Enabled:=False; ReplaceItem.Enabled:=False; SaveItem.Enabled:=False; end; end.