@@ -47,6 +47,11 @@ TFormMain = class(TForm)
4747 Ribbon: TUIRibbon;
4848 CmdPasteSpecial: TAction;
4949 CmdFont: TRibbonFontAction;
50+ CmdOpen: TFileOpen;
51+ CmdRecentItems: TAction;
52+ CmdSave: TAction;
53+ CmdSaveAs: TFileSaveAs;
54+ CmdNew: TAction;
5055 procedure RichEditSelectionChange (Sender: TObject);
5156 procedure RichEditChange (Sender: TObject);
5257 procedure RichEditContextPopup (Sender: TObject; MousePos: TPoint;
@@ -67,12 +72,25 @@ TFormMain = class(TForm)
6772 procedure CmdFontChanged (const Args: TUICommandFontEventArgs);
6873 procedure RibbonLoaded (Sender: TObject);
6974 procedure CommandCreated (const Sender: TUIRibbon; const Command: TUICommand);
75+ procedure CmdOpenAccept (Sender: TObject);
76+ procedure CmdRecentItemsExecute (Sender: TObject);
77+ procedure CmdSaveAsAccept (Sender: TObject);
78+ procedure CmdNewExecute (Sender: TObject);
79+ procedure CmdSaveExecute (Sender: TObject);
7080 private
7181 { Private declarations }
7282 FRichEditEx: TRichEditEx;
7383 FPrintPreviewMode: Boolean;
84+ // / The path of the currently opened file
85+ FCurrentfilePath: String;
7486 procedure UpdateRibbonControls ;
7587 procedure PopulateListGallery ;
88+ // / Loads a file into the editor and adds the file path to the recent items.
89+ // / <param name="pFilePath">The path of the file that should be loaded.</param>
90+ procedure Load (const pFilePath: string);
91+ // / Loads the editor contents to a file.
92+ // / <param name="pFilePath">The path of the file to that the editor content should be saved.</param>
93+ procedure Save (const pFilePath: string);
7694 public
7795 { Public declarations }
7896 constructor Create(Owner: TComponent); override;
@@ -265,10 +283,6 @@ procedure TFormMain.CommandCreated(const Sender: TUIRibbon; const Command: TUICo
265283 CmdPicas,
266284 CmdPoints,
267285 CmdHelp,
268- CmdNew,
269- CmdOpen,
270- CmdSave,
271- CmdSaveAs,
272286 CmdRichTextDocument,
273287 CmdOfficeOpenXMLDocument,
274288 CmdOpenDocumentText,
@@ -299,6 +313,11 @@ destructor TFormMain.Destroy;
299313 inherited ;
300314end ;
301315
316+ procedure TFormMain.CmdRecentItemsExecute (Sender: TObject);
317+ begin
318+ Load(Ribbon.GetSelectedRecentItem.LabelText);
319+ end ;
320+
302321procedure TFormMain.CmdFontChanged (const Args: TUICommandFontEventArgs);
303322var
304323 CharFormat: TCharFormat2;
@@ -400,4 +419,44 @@ procedure TFormMain.UpdateRibbonControls;
400419 CmdRedo.Enabled := FRichEditEx.CanRedo;
401420end ;
402421
422+ procedure TFormMain.CmdNewExecute (Sender: TObject);
423+ begin
424+ RichEdit.Clear();
425+ fCurrentFilePath := ' ' ;
426+ end ;
427+
428+ procedure TFormMain.CmdOpenAccept (Sender: TObject);
429+ begin
430+ Load(CmdOpen.Dialog.FileName);
431+ end ;
432+
433+ procedure TFormMain.CmdSaveAsAccept (Sender: TObject);
434+ begin
435+ Save(CmdSaveAs.Dialog.FileName);
436+ end ;
437+
438+ procedure TFormMain.CmdSaveExecute (Sender: TObject);
439+ begin
440+ if FCurrentfilePath.IsEmpty then
441+ CmdSaveAs.Execute()
442+ else
443+ Save(FCurrentfilePath);
444+ end ;
445+
446+ procedure TFormMain.Load (const pFilePath: string);
447+ begin
448+ RichEdit.Lines.LoadFromFile(pFilePath);
449+ Ribbon.AddToRecentItems(pFilePath);
450+ FCurrentfilePath := pFilePath;
451+ end ;
452+
453+ procedure TFormMain.Save (const pFilePath: string);
454+ begin
455+ RichEdit.Lines.SaveToFile(pFilePath);
456+ FCurrentfilePath := pFilePath;
457+ end ;
458+
459+
460+
461+
403462end .
0 commit comments