Skip to content

Commit 7b35f98

Browse files
author
Joachim Marder
committed
The commands CmdRecentItems, CmdOpen, CmdSave, CmdSaveAs, and CmdNew are now implemented.
1 parent 19aed92 commit 7b35f98

File tree

3 files changed

+844
-753
lines changed

3 files changed

+844
-753
lines changed

Samples/High Level/07 Text Pad with Action List/FMain.dfm

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,5 +182,37 @@ object FormMain: TFormMain
182182
Caption = 'Font'
183183
OnChanged = CmdFontChanged
184184
end
185+
object CmdOpen: TFileOpen
186+
Category = 'File'
187+
Caption = '&Open...'
188+
Dialog.DefaultExt = 'RTF'
189+
Dialog.Filter = 'All Files (*.*)|*.*'
190+
Hint = 'Open|Opens an existing file'
191+
ImageIndex = 7
192+
ShortCut = 16463
193+
OnAccept = CmdOpenAccept
194+
end
195+
object CmdRecentItems: TAction
196+
Category = 'File'
197+
Caption = 'Open Recent File'
198+
OnExecute = CmdRecentItemsExecute
199+
end
200+
object CmdSave: TAction
201+
Category = 'File'
202+
Caption = '&Save'
203+
OnExecute = CmdSaveExecute
204+
end
205+
object CmdSaveAs: TFileSaveAs
206+
Category = 'File'
207+
Caption = 'Save &As...'
208+
Hint = 'Save As|Saves the active file with a new name'
209+
ImageIndex = 30
210+
OnAccept = CmdSaveAsAccept
211+
end
212+
object CmdNew: TAction
213+
Category = 'File'
214+
Caption = '&New'
215+
OnExecute = CmdNewExecute
216+
end
185217
end
186218
end

Samples/High Level/07 Text Pad with Action List/FMain.pas

Lines changed: 63 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
300314
end;
301315

316+
procedure TFormMain.CmdRecentItemsExecute(Sender: TObject);
317+
begin
318+
Load(Ribbon.GetSelectedRecentItem.LabelText);
319+
end;
320+
302321
procedure TFormMain.CmdFontChanged(const Args: TUICommandFontEventArgs);
303322
var
304323
CharFormat: TCharFormat2;
@@ -400,4 +419,44 @@ procedure TFormMain.UpdateRibbonControls;
400419
CmdRedo.Enabled := FRichEditEx.CanRedo;
401420
end;
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+
403462
end.

0 commit comments

Comments
 (0)