mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-22 13:59:22 +02:00
added mrumenu from Michael
git-svn-id: trunk@32297 -
This commit is contained in:
parent
871b285d8f
commit
79be62f338
12
.gitattributes
vendored
12
.gitattributes
vendored
@ -1777,6 +1777,18 @@ components/mouseandkeyinput/winmouseinput.pas svneol=native#text/pascal
|
|||||||
components/mouseandkeyinput/xkeyinput.pas svneol=native#text/pascal
|
components/mouseandkeyinput/xkeyinput.pas svneol=native#text/pascal
|
||||||
components/mouseandkeyinput/xmouseinput.pas svneol=native#text/pascal
|
components/mouseandkeyinput/xmouseinput.pas svneol=native#text/pascal
|
||||||
components/mpaslex/mpaslex.pp svneol=native#text/pascal
|
components/mpaslex/mpaslex.pp svneol=native#text/pascal
|
||||||
|
components/mrumenu/demo/frmmain.lfm svneol=native#text/plain
|
||||||
|
components/mrumenu/demo/frmmain.pp svneol=native#text/plain
|
||||||
|
components/mrumenu/demo/mrudemo.ico -text svneol=unset#image/ico
|
||||||
|
components/mrumenu/demo/mrudemo.lpi svneol=native#text/plain
|
||||||
|
components/mrumenu/demo/mrudemo.lpr svneol=native#text/plain
|
||||||
|
components/mrumenu/demo/mrudemo.res -text
|
||||||
|
components/mrumenu/lazmrumenu.lpk svneol=native#text/plain
|
||||||
|
components/mrumenu/lazmrumenu.pas svneol=native#text/plain
|
||||||
|
components/mrumenu/mrumanager.pp svneol=native#text/plain
|
||||||
|
components/mrumenu/reglazmru.pp svneol=native#text/plain
|
||||||
|
components/mrumenu/regmru.lrs svneol=native#text/plain
|
||||||
|
components/mrumenu/tmrumenumanager.png -text svneol=unset#image/png
|
||||||
components/opengl/example/imgui.lpi svneol=native#text/plain
|
components/opengl/example/imgui.lpi svneol=native#text/plain
|
||||||
components/opengl/example/imgui.pas svneol=native#text/pascal
|
components/opengl/example/imgui.pas svneol=native#text/pascal
|
||||||
components/opengl/example/imgui.res -text
|
components/opengl/example/imgui.res -text
|
||||||
|
78
components/mrumenu/demo/frmmain.lfm
Normal file
78
components/mrumenu/demo/frmmain.lfm
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
object Form1: TForm1
|
||||||
|
Left = 422
|
||||||
|
Height = 240
|
||||||
|
Top = 281
|
||||||
|
Width = 320
|
||||||
|
Caption = 'Form1'
|
||||||
|
ClientHeight = 218
|
||||||
|
ClientWidth = 320
|
||||||
|
Menu = MainMenu1
|
||||||
|
OnCreate = FormCreate
|
||||||
|
OnDestroy = FormDestroy
|
||||||
|
LCLVersion = '0.9.31'
|
||||||
|
object PCFiles: TPageControl
|
||||||
|
Left = 0
|
||||||
|
Height = 218
|
||||||
|
Top = 0
|
||||||
|
Width = 320
|
||||||
|
Align = alClient
|
||||||
|
TabOrder = 0
|
||||||
|
end
|
||||||
|
object MainMenu1: TMainMenu
|
||||||
|
left = 57
|
||||||
|
top = 37
|
||||||
|
object MFile: TMenuItem
|
||||||
|
Caption = '&File'
|
||||||
|
object MINew: TMenuItem
|
||||||
|
Caption = '&New'
|
||||||
|
ShortCut = 16462
|
||||||
|
OnClick = MINewClick
|
||||||
|
end
|
||||||
|
object MIOpen: TMenuItem
|
||||||
|
Caption = '&Open'
|
||||||
|
ShortCut = 16463
|
||||||
|
OnClick = MIOpenClick
|
||||||
|
end
|
||||||
|
object MISave: TMenuItem
|
||||||
|
Caption = '&Save'
|
||||||
|
ShortCut = 16467
|
||||||
|
OnClick = MISaveClick
|
||||||
|
end
|
||||||
|
object MISaveAs: TMenuItem
|
||||||
|
Caption = 'Save as'
|
||||||
|
end
|
||||||
|
object MIRecent: TMenuItem
|
||||||
|
Caption = 'Recent'
|
||||||
|
end
|
||||||
|
object MenuItem2: TMenuItem
|
||||||
|
Caption = '-'
|
||||||
|
end
|
||||||
|
object MIQuit: TMenuItem
|
||||||
|
Caption = '&Quit'
|
||||||
|
ShortCut = 16465
|
||||||
|
OnClick = MIQuitClick
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
object MRUMenuManager1: TMRUMenuManager
|
||||||
|
MaxRecent = 5
|
||||||
|
MenuItem = MIRecent
|
||||||
|
OnRecentFile = MRUMenuManager1RecentFile
|
||||||
|
left = 176
|
||||||
|
top = 40
|
||||||
|
end
|
||||||
|
object ODFile: TOpenDialog
|
||||||
|
DefaultExt = '.txt'
|
||||||
|
Filter = 'Text files|*.txt|All files|*.*'
|
||||||
|
Options = [ofFileMustExist, ofEnableSizing, ofViewDetail]
|
||||||
|
left = 40
|
||||||
|
top = 109
|
||||||
|
end
|
||||||
|
object SDFile: TSaveDialog
|
||||||
|
DefaultExt = '.txt'
|
||||||
|
Filter = 'Text files|*.txt|All files|*.*'
|
||||||
|
Options = [ofPathMustExist, ofEnableSizing, ofViewDetail]
|
||||||
|
left = 121
|
||||||
|
top = 115
|
||||||
|
end
|
||||||
|
end
|
158
components/mrumenu/demo/frmmain.pp
Normal file
158
components/mrumenu/demo/frmmain.pp
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
unit frmmain;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, Menus,
|
||||||
|
stdctrls, ComCtrls, mrumanager;
|
||||||
|
|
||||||
|
Type
|
||||||
|
TMyTabSheet = Class(TTabsheet)
|
||||||
|
Public
|
||||||
|
FileName : String;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{ TForm1 }
|
||||||
|
|
||||||
|
TForm1 = class(TForm)
|
||||||
|
MainMenu1: TMainMenu;
|
||||||
|
MIRecent: TMenuItem;
|
||||||
|
MenuItem2: TMenuItem;
|
||||||
|
MIQuit: TMenuItem;
|
||||||
|
MISaveAs: TMenuItem;
|
||||||
|
MISave: TMenuItem;
|
||||||
|
MIOpen: TMenuItem;
|
||||||
|
MINew: TMenuItem;
|
||||||
|
MFile: TMenuItem;
|
||||||
|
MRUMenuManager1: TMRUMenuManager;
|
||||||
|
ODFile: TOpenDialog;
|
||||||
|
PCFiles: TPageControl;
|
||||||
|
SDFile: TSaveDialog;
|
||||||
|
procedure FormCreate(Sender: TObject);
|
||||||
|
procedure FormDestroy(Sender: TObject);
|
||||||
|
procedure MINewClick(Sender: TObject);
|
||||||
|
procedure MIOpenClick(Sender: TObject);
|
||||||
|
procedure MIQuitClick(Sender: TObject);
|
||||||
|
procedure MISaveClick(Sender: TObject);
|
||||||
|
procedure MRUMenuManager1RecentFile(Sender: TObject; const AFileName: String
|
||||||
|
);
|
||||||
|
private
|
||||||
|
function CurrentFileName: string;
|
||||||
|
procedure OpenFile(AFileName: String);
|
||||||
|
procedure SaveFile(const AFileName: String);
|
||||||
|
{ private declarations }
|
||||||
|
public
|
||||||
|
{ public declarations }
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
Form1: TForm1;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
{$R *.lfm}
|
||||||
|
|
||||||
|
{ TForm1 }
|
||||||
|
|
||||||
|
procedure TForm1.MIQuitClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
Close;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.MISaveClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
If (CurrentFileName='') or (Sender=MISaveAs) then
|
||||||
|
begin
|
||||||
|
if SDFile.Execute then
|
||||||
|
SaveFile(SDFile.FileName);
|
||||||
|
end
|
||||||
|
else
|
||||||
|
SaveFile(CurrentFileName);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.MRUMenuManager1RecentFile(Sender: TObject;
|
||||||
|
const AFileName: String);
|
||||||
|
begin
|
||||||
|
OpenFile(AFileName);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.SaveFile(Const AFileName : String);
|
||||||
|
|
||||||
|
Var
|
||||||
|
T : TMyTabSheet;
|
||||||
|
M : TMemo;
|
||||||
|
|
||||||
|
begin
|
||||||
|
if (PCFiles.ActivePage is TMyTabSheet) then
|
||||||
|
begin
|
||||||
|
T:=PCFiles.ActivePage as TMyTabSheet;
|
||||||
|
if (T.ControlCount>0) and (T.Controls[0] is TMemo) then
|
||||||
|
begin
|
||||||
|
M:=T.Controls[0] as TMemo;
|
||||||
|
M.Lines.SaveToFile(AFileName);
|
||||||
|
MRUMenuManager1.AddTorecent(AFileName);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
Function TForm1.CurrentFileName : string;
|
||||||
|
|
||||||
|
begin
|
||||||
|
if (PCFiles.ActivePage is TMyTabSheet) then
|
||||||
|
Result:=(PCFiles.ActivePage as TMyTabSheet).FileName
|
||||||
|
else
|
||||||
|
Result:='';
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TForm1.MIOpenClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
If ODFIle.Execute then
|
||||||
|
OpenFile(ODFile.FileName);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.MINewClick(Sender: TObject);
|
||||||
|
begin
|
||||||
|
OpenFile('')
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.FormCreate(Sender: TObject);
|
||||||
|
begin
|
||||||
|
MRUMenuManager1.LoadRecentFilesFromIni;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TForm1.FormDestroy(Sender: TObject);
|
||||||
|
begin
|
||||||
|
MRUMenuManager1.SaveRecentFilesToIni;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
procedure TForm1.OpenFile(AFileName : String);
|
||||||
|
|
||||||
|
Var
|
||||||
|
TS : TMyTabSheet;
|
||||||
|
M : TMemo;
|
||||||
|
|
||||||
|
begin
|
||||||
|
TS:=TMyTabSheet.Create(Self);
|
||||||
|
TS.FileName:=AFileName;
|
||||||
|
TS.Parent:=PCFiles;
|
||||||
|
TS.PageControl:=PCFiles;
|
||||||
|
if (AFileName<>'') then
|
||||||
|
TS.Caption:=ExtractFileName(AFileName)
|
||||||
|
else
|
||||||
|
TS.Caption:='New file';
|
||||||
|
M:=TMemo.Create(Self);
|
||||||
|
M.Align:=AlClient;
|
||||||
|
M.Parent:=TS;
|
||||||
|
if (AFileName<>'') then
|
||||||
|
M.Lines.LoadFromFile(AFileName);
|
||||||
|
PCFIles.ActivePage:=TS;
|
||||||
|
if (AFileName<>'') then
|
||||||
|
MRUMenuManager1.AddToRecent(AFileName);
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
BIN
components/mrumenu/demo/mrudemo.ico
Normal file
BIN
components/mrumenu/demo/mrudemo.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 134 KiB |
208
components/mrumenu/demo/mrudemo.lpi
Normal file
208
components/mrumenu/demo/mrudemo.lpi
Normal file
@ -0,0 +1,208 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<CONFIG>
|
||||||
|
<ProjectOptions>
|
||||||
|
<Version Value="9"/>
|
||||||
|
<General>
|
||||||
|
<MainUnit Value="0"/>
|
||||||
|
<ResourceType Value="res"/>
|
||||||
|
<UseXPManifest Value="True"/>
|
||||||
|
<Icon Value="0"/>
|
||||||
|
<ActiveWindowIndexAtStart Value="0"/>
|
||||||
|
</General>
|
||||||
|
<i18n>
|
||||||
|
<EnableI18N LFM="False"/>
|
||||||
|
</i18n>
|
||||||
|
<VersionInfo>
|
||||||
|
<StringTable ProductVersion=""/>
|
||||||
|
</VersionInfo>
|
||||||
|
<BuildModes Count="1" Active="Default">
|
||||||
|
<Item1 Name="Default" Default="True"/>
|
||||||
|
</BuildModes>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||||
|
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
|
||||||
|
</PublishOptions>
|
||||||
|
<RunParams>
|
||||||
|
<local>
|
||||||
|
<FormatVersion Value="1"/>
|
||||||
|
<LaunchingApplication PathPlusParams="/usr/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
||||||
|
</local>
|
||||||
|
</RunParams>
|
||||||
|
<RequiredPackages Count="3">
|
||||||
|
<Item1>
|
||||||
|
<PackageName Value="lazmrumenu"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<PackageName Value="LCLBase"/>
|
||||||
|
<MinVersion Valid="True"/>
|
||||||
|
</Item2>
|
||||||
|
<Item3>
|
||||||
|
<PackageName Value="LCL"/>
|
||||||
|
</Item3>
|
||||||
|
</RequiredPackages>
|
||||||
|
<Units Count="7">
|
||||||
|
<Unit0>
|
||||||
|
<Filename Value="mrudemo.lpr"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="mrudemo"/>
|
||||||
|
<UsageCount Value="22"/>
|
||||||
|
</Unit0>
|
||||||
|
<Unit1>
|
||||||
|
<Filename Value="frmmain.pp"/>
|
||||||
|
<IsPartOfProject Value="True"/>
|
||||||
|
<ComponentName Value="Form1"/>
|
||||||
|
<ResourceBaseClass Value="Form"/>
|
||||||
|
<UnitName Value="frmmain"/>
|
||||||
|
<EditorIndex Value="0"/>
|
||||||
|
<WindowIndex Value="0"/>
|
||||||
|
<TopLine Value="124"/>
|
||||||
|
<CursorPos X="44" Y="138"/>
|
||||||
|
<UsageCount Value="22"/>
|
||||||
|
<Loaded Value="True"/>
|
||||||
|
<LoadedDesigner Value="True"/>
|
||||||
|
</Unit1>
|
||||||
|
<Unit2>
|
||||||
|
<Filename Value="../mrumanager.pp"/>
|
||||||
|
<UnitName Value="mrumanager"/>
|
||||||
|
<IsVisibleTab Value="True"/>
|
||||||
|
<EditorIndex Value="2"/>
|
||||||
|
<WindowIndex Value="0"/>
|
||||||
|
<TopLine Value="1"/>
|
||||||
|
<CursorPos X="1" Y="14"/>
|
||||||
|
<UsageCount Value="11"/>
|
||||||
|
<Loaded Value="True"/>
|
||||||
|
</Unit2>
|
||||||
|
<Unit3>
|
||||||
|
<Filename Value="../regmru.lrs"/>
|
||||||
|
<EditorIndex Value="4"/>
|
||||||
|
<WindowIndex Value="0"/>
|
||||||
|
<TopLine Value="1"/>
|
||||||
|
<CursorPos X="17" Y="1"/>
|
||||||
|
<UsageCount Value="11"/>
|
||||||
|
<Loaded Value="True"/>
|
||||||
|
</Unit3>
|
||||||
|
<Unit4>
|
||||||
|
<Filename Value="../reglazmru.pp"/>
|
||||||
|
<UnitName Value="reglazmru"/>
|
||||||
|
<EditorIndex Value="3"/>
|
||||||
|
<WindowIndex Value="0"/>
|
||||||
|
<TopLine Value="1"/>
|
||||||
|
<CursorPos X="44" Y="8"/>
|
||||||
|
<UsageCount Value="11"/>
|
||||||
|
<Loaded Value="True"/>
|
||||||
|
</Unit4>
|
||||||
|
<Unit5>
|
||||||
|
<Filename Value="/data/wisa/projects/fpcpackages/wisawebdb/menueditor/demo/frmmain.pp"/>
|
||||||
|
<UnitName Value="frmmain"/>
|
||||||
|
<WindowIndex Value="0"/>
|
||||||
|
<TopLine Value="124"/>
|
||||||
|
<CursorPos X="16" Y="136"/>
|
||||||
|
<UsageCount Value="10"/>
|
||||||
|
</Unit5>
|
||||||
|
<Unit6>
|
||||||
|
<Filename Value="/data/wisa/projects/fpcpackages/wisawebdb/menueditor/mrumanager.pp"/>
|
||||||
|
<UnitName Value="mrumanager"/>
|
||||||
|
<EditorIndex Value="1"/>
|
||||||
|
<WindowIndex Value="0"/>
|
||||||
|
<TopLine Value="85"/>
|
||||||
|
<CursorPos X="1" Y="113"/>
|
||||||
|
<UsageCount Value="11"/>
|
||||||
|
<Loaded Value="True"/>
|
||||||
|
</Unit6>
|
||||||
|
</Units>
|
||||||
|
<JumpHistory Count="16" HistoryIndex="15">
|
||||||
|
<Position1>
|
||||||
|
<Filename Value="frmmain.pp"/>
|
||||||
|
<Caret Line="84" Column="37" TopLine="68"/>
|
||||||
|
</Position1>
|
||||||
|
<Position2>
|
||||||
|
<Filename Value="frmmain.pp"/>
|
||||||
|
<Caret Line="94" Column="21" TopLine="76"/>
|
||||||
|
</Position2>
|
||||||
|
<Position3>
|
||||||
|
<Filename Value="frmmain.pp"/>
|
||||||
|
<Caret Line="103" Column="21" TopLine="86"/>
|
||||||
|
</Position3>
|
||||||
|
<Position4>
|
||||||
|
<Filename Value="frmmain.pp"/>
|
||||||
|
<Caret Line="93" Column="10" TopLine="85"/>
|
||||||
|
</Position4>
|
||||||
|
<Position5>
|
||||||
|
<Filename Value="frmmain.pp"/>
|
||||||
|
<Caret Line="115" Column="41" TopLine="111"/>
|
||||||
|
</Position5>
|
||||||
|
<Position6>
|
||||||
|
<Filename Value="frmmain.pp"/>
|
||||||
|
<Caret Line="128" Column="36" TopLine="122"/>
|
||||||
|
</Position6>
|
||||||
|
<Position7>
|
||||||
|
<Filename Value="frmmain.pp"/>
|
||||||
|
<Caret Line="148" Column="21" TopLine="124"/>
|
||||||
|
</Position7>
|
||||||
|
<Position8>
|
||||||
|
<Filename Value="/data/wisa/projects/fpcpackages/wisawebdb/menueditor/mrumanager.pp"/>
|
||||||
|
<Caret Line="101" Column="1" TopLine="84"/>
|
||||||
|
</Position8>
|
||||||
|
<Position9>
|
||||||
|
<Filename Value="/data/wisa/projects/fpcpackages/wisawebdb/menueditor/mrumanager.pp"/>
|
||||||
|
<Caret Line="102" Column="1" TopLine="84"/>
|
||||||
|
</Position9>
|
||||||
|
<Position10>
|
||||||
|
<Filename Value="/data/wisa/projects/fpcpackages/wisawebdb/menueditor/mrumanager.pp"/>
|
||||||
|
<Caret Line="103" Column="1" TopLine="84"/>
|
||||||
|
</Position10>
|
||||||
|
<Position11>
|
||||||
|
<Filename Value="/data/wisa/projects/fpcpackages/wisawebdb/menueditor/mrumanager.pp"/>
|
||||||
|
<Caret Line="105" Column="1" TopLine="84"/>
|
||||||
|
</Position11>
|
||||||
|
<Position12>
|
||||||
|
<Filename Value="/data/wisa/projects/fpcpackages/wisawebdb/menueditor/mrumanager.pp"/>
|
||||||
|
<Caret Line="106" Column="1" TopLine="84"/>
|
||||||
|
</Position12>
|
||||||
|
<Position13>
|
||||||
|
<Filename Value="../mrumanager.pp"/>
|
||||||
|
<Caret Line="69" Column="19" TopLine="54"/>
|
||||||
|
</Position13>
|
||||||
|
<Position14>
|
||||||
|
<Filename Value="../mrumanager.pp"/>
|
||||||
|
<Caret Line="283" Column="27" TopLine="279"/>
|
||||||
|
</Position14>
|
||||||
|
<Position15>
|
||||||
|
<Filename Value="../mrumanager.pp"/>
|
||||||
|
<Caret Line="72" Column="89" TopLine="65"/>
|
||||||
|
</Position15>
|
||||||
|
<Position16>
|
||||||
|
<Filename Value="frmmain.pp"/>
|
||||||
|
<Caret Line="138" Column="44" TopLine="124"/>
|
||||||
|
</Position16>
|
||||||
|
</JumpHistory>
|
||||||
|
</ProjectOptions>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="10"/>
|
||||||
|
<SearchPaths>
|
||||||
|
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||||
|
</SearchPaths>
|
||||||
|
<Parsing>
|
||||||
|
<SyntaxOptions>
|
||||||
|
<UseAnsiStrings Value="False"/>
|
||||||
|
</SyntaxOptions>
|
||||||
|
</Parsing>
|
||||||
|
<Other>
|
||||||
|
<CompilerPath Value="$(CompPath)"/>
|
||||||
|
</Other>
|
||||||
|
</CompilerOptions>
|
||||||
|
<Debugging>
|
||||||
|
<Exceptions Count="3">
|
||||||
|
<Item1>
|
||||||
|
<Name Value="EAbort"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<Name Value="ECodetoolError"/>
|
||||||
|
</Item2>
|
||||||
|
<Item3>
|
||||||
|
<Name Value="EFOpenError"/>
|
||||||
|
</Item3>
|
||||||
|
</Exceptions>
|
||||||
|
</Debugging>
|
||||||
|
</CONFIG>
|
21
components/mrumenu/demo/mrudemo.lpr
Normal file
21
components/mrumenu/demo/mrudemo.lpr
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
program mrudemo;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
uses
|
||||||
|
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||||
|
cthreads,
|
||||||
|
{$ENDIF}{$ENDIF}
|
||||||
|
Interfaces, // this includes the LCL widgetset
|
||||||
|
Forms, alllclunits, frmmain, lazmrumenu
|
||||||
|
{ you can add units after this };
|
||||||
|
|
||||||
|
{$R *.res}
|
||||||
|
|
||||||
|
begin
|
||||||
|
RequireDerivedFormResource := True;
|
||||||
|
Application.Initialize;
|
||||||
|
Application.CreateForm(TForm1, Form1);
|
||||||
|
Application.Run;
|
||||||
|
end.
|
||||||
|
|
BIN
components/mrumenu/demo/mrudemo.res
Normal file
BIN
components/mrumenu/demo/mrudemo.res
Normal file
Binary file not shown.
42
components/mrumenu/lazmrumenu.lpk
Normal file
42
components/mrumenu/lazmrumenu.lpk
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<CONFIG>
|
||||||
|
<Package Version="3">
|
||||||
|
<Name Value="lazmrumenu"/>
|
||||||
|
<CompilerOptions>
|
||||||
|
<Version Value="10"/>
|
||||||
|
<SearchPaths>
|
||||||
|
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)/"/>
|
||||||
|
</SearchPaths>
|
||||||
|
<Other>
|
||||||
|
<CompilerPath Value="$(CompPath)"/>
|
||||||
|
</Other>
|
||||||
|
</CompilerOptions>
|
||||||
|
<Files Count="2">
|
||||||
|
<Item1>
|
||||||
|
<Filename Value="reglazmru.pp"/>
|
||||||
|
<HasRegisterProc Value="True"/>
|
||||||
|
<UnitName Value="reglazmru"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<Filename Value="mrumanager.pp"/>
|
||||||
|
<UnitName Value="mrumanager"/>
|
||||||
|
</Item2>
|
||||||
|
</Files>
|
||||||
|
<Type Value="RunAndDesignTime"/>
|
||||||
|
<RequiredPkgs Count="2">
|
||||||
|
<Item1>
|
||||||
|
<PackageName Value="LCL"/>
|
||||||
|
</Item1>
|
||||||
|
<Item2>
|
||||||
|
<PackageName Value="FCL"/>
|
||||||
|
<MinVersion Valid="True"/>
|
||||||
|
</Item2>
|
||||||
|
</RequiredPkgs>
|
||||||
|
<UsageOptions>
|
||||||
|
<UnitPath Value="$(PkgOutDir)"/>
|
||||||
|
</UsageOptions>
|
||||||
|
<PublishOptions>
|
||||||
|
<Version Value="2"/>
|
||||||
|
</PublishOptions>
|
||||||
|
</Package>
|
||||||
|
</CONFIG>
|
21
components/mrumenu/lazmrumenu.pas
Normal file
21
components/mrumenu/lazmrumenu.pas
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
{ This file was automatically created by Lazarus. Do not edit!
|
||||||
|
This source is only used to compile and install the package.
|
||||||
|
}
|
||||||
|
|
||||||
|
unit lazmrumenu;
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
reglazmru, mrumanager, LazarusPackageIntf;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
procedure Register;
|
||||||
|
begin
|
||||||
|
RegisterUnit('reglazmru', @reglazmru.Register);
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
RegisterPackage('lazmrumenu', @Register);
|
||||||
|
end.
|
302
components/mrumenu/mrumanager.pp
Normal file
302
components/mrumenu/mrumanager.pp
Normal file
@ -0,0 +1,302 @@
|
|||||||
|
unit mrumanager;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, inifiles, menus;
|
||||||
|
|
||||||
|
Type
|
||||||
|
{ TRecentMenuItem }
|
||||||
|
|
||||||
|
TRecentMenuItem = Class(TMenuItem)
|
||||||
|
Private
|
||||||
|
FFileName : string;
|
||||||
|
Public
|
||||||
|
Property FileName : String Read FFileName;
|
||||||
|
end;
|
||||||
|
TRecentMenuItemClass = Class of TRecentMenuItem;
|
||||||
|
|
||||||
|
{ TMRUMenuManager }
|
||||||
|
|
||||||
|
TOnRecentFileEvent = Procedure(Sender : TObject; Const AFileName : String) of object;
|
||||||
|
|
||||||
|
TMRUMenuManager = Class(TComponent)
|
||||||
|
Private
|
||||||
|
FIniFileName: String;
|
||||||
|
FIniSection: String;
|
||||||
|
FOnRecent: TOnRecentFileEvent;
|
||||||
|
FRecent : TStrings;
|
||||||
|
FMaxRecent : Integer;
|
||||||
|
FMIRecent : TMenuItem;
|
||||||
|
procedure SetMIRecent(const AValue: TMenuItem);
|
||||||
|
procedure SetRecent(const AValue: TStrings);
|
||||||
|
protected
|
||||||
|
// Overrides.
|
||||||
|
procedure loaded; override;
|
||||||
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
||||||
|
// Return default name and section if either is empty.
|
||||||
|
procedure GetFileNameAndSection(Var AFileName,ASection : String); virtual;
|
||||||
|
// Override if you want to load additional values.
|
||||||
|
procedure LoadFromIni(Ini: TCustomIniFile; ASection: String); virtual;
|
||||||
|
// Override if you want to write additional values.
|
||||||
|
procedure SaveToIni(Ini: TCustomIniFile; ASection: String); virtual;
|
||||||
|
// Called when menu item is clicked.
|
||||||
|
procedure DoOnRecentClick(Sender: TObject); virtual;
|
||||||
|
// Override this if you want to create a custom class of menu itel.
|
||||||
|
function CreateMenuItem(AOwner: TComponent): TRecentMenuItem; virtual;
|
||||||
|
// Create a menu caption. Default is index followed by filename.
|
||||||
|
// Override if you want to customize.
|
||||||
|
Function CreateMenuCaption(AIndex : Integer; Const AFileName : String) : String; virtual;
|
||||||
|
Public
|
||||||
|
Constructor Create(AOwner : TComponent);override;
|
||||||
|
Destructor Destroy; override;
|
||||||
|
// Load files from ini file AFileName in section ASection. Calls ShowRecentFiles
|
||||||
|
procedure LoadRecentFilesFromIni(const AFileName: string=''; const ASection: String='');
|
||||||
|
// Saves files to ini file AFileName in section ASection.
|
||||||
|
procedure SaveRecentFilesToIni(const AFileName: string=''; const ASection: String='');
|
||||||
|
// Add a filename to the list of files.
|
||||||
|
// If an existing file is added, it is moved first in the list.
|
||||||
|
// If MaxRecent is attained, the last one is removed.
|
||||||
|
// Calls ShowRecentFiles.
|
||||||
|
procedure AddToRecent(AFileName: String);
|
||||||
|
// Re-populate the menu.
|
||||||
|
procedure ShowRecentFiles;
|
||||||
|
Published
|
||||||
|
// Max. items to be kept in the list.
|
||||||
|
Property MaxRecent : Integer Read FMaxRecent write FMaxRecent;
|
||||||
|
// Menu item to create a submenu under. Existing items will be removed.
|
||||||
|
Property MenuItem : TMenuItem Read FMIRecent Write SetMIRecent;
|
||||||
|
// Default ini filename.
|
||||||
|
Property IniFileName : String Read FIniFileName Write FIniFileName;
|
||||||
|
// Default ini section.
|
||||||
|
Property IniSection : String Read FIniSection Write FIniSection;
|
||||||
|
// Recent items. If adding manually to the list, ShowRecentFiles must be called manually.
|
||||||
|
Property Recent : TStrings Read FRecent Write SetRecent;
|
||||||
|
// Called when the user clicks an recent meu item.
|
||||||
|
Property OnRecentFile : TOnRecentFileEvent Read FOnRecent Write FOnRecent;
|
||||||
|
end;
|
||||||
|
EMRUManager = Class(Exception);
|
||||||
|
|
||||||
|
Const
|
||||||
|
DefaultIniFile = 'recent.ini';
|
||||||
|
DefaultSection = 'Global';
|
||||||
|
KeyMaxRecent = 'MaxRecent';
|
||||||
|
KeyCount = 'Count';
|
||||||
|
KeyFile = 'File%d';
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
Resourcestring
|
||||||
|
SErrFailedToCreateDir = 'Failed to create directory "%s"';
|
||||||
|
|
||||||
|
|
||||||
|
procedure TMRUMenuManager.AddToRecent(AFileName : String);
|
||||||
|
|
||||||
|
Var
|
||||||
|
I,J : Integer;
|
||||||
|
B : Boolean;
|
||||||
|
|
||||||
|
begin
|
||||||
|
AFileName:=ExpandFileName(AFileName);
|
||||||
|
With FRecent do
|
||||||
|
begin
|
||||||
|
J:=IndexOf(AFileName);
|
||||||
|
If (J<>-1) then
|
||||||
|
begin
|
||||||
|
if (J>0) then
|
||||||
|
Exchange(0,J)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
While (Count>=FMaxRecent) do
|
||||||
|
Delete(Count-1);
|
||||||
|
Insert(0,AFileName)
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
ShowRecentFiles;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TMRUMenuManager.CreateMenuItem(AOwner :TComponent) : TRecentMenuItem;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Result:=TRecentMenuItem.Create(AOwner);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TMRUMenuManager.CreateMenuCaption(AIndex: Integer;
|
||||||
|
const AFileName: String): String;
|
||||||
|
begin
|
||||||
|
Result:=Format('%d. %s',[AIndex+1,AFileName]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMRUMenuManager.ShowRecentFiles;
|
||||||
|
|
||||||
|
Var
|
||||||
|
I : Integer;
|
||||||
|
M : TRecentMenuItem;
|
||||||
|
|
||||||
|
begin
|
||||||
|
if Not Assigned(FMIRecent) then
|
||||||
|
Exit;
|
||||||
|
FMIRecent.clear;
|
||||||
|
For I:=0 to FRecent.Count-1 do
|
||||||
|
begin
|
||||||
|
M:=CreateMenuItem(Self.Owner);
|
||||||
|
M.Caption:=CreateMenuCaption(I,FRecent[i]);
|
||||||
|
M.FFileName:=FRecent[i];
|
||||||
|
M.OnClick:=@DoOnRecentClick;
|
||||||
|
FMIRecent.Add(M);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMRUMenuManager.LoadFromIni(Ini : TCustomIniFile; ASection : String);
|
||||||
|
|
||||||
|
Var
|
||||||
|
I,Count : Integer;
|
||||||
|
FN : String;
|
||||||
|
|
||||||
|
begin
|
||||||
|
FRecent.Clear;
|
||||||
|
FMaxRecent:=Ini.ReadInteger(ASection,KeyMaxRecent,10);
|
||||||
|
Count:=Ini.ReadInteger(ASection,KeyCount,0);
|
||||||
|
For I:=1 to Count do
|
||||||
|
begin
|
||||||
|
FN:=Ini.ReadString(ASection,Format(KeyFile,[i]),'');
|
||||||
|
If (FN<>'') then
|
||||||
|
FRecent.Add(FN);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMRUMenuManager.GetFileNameAndSection(var AFileName, ASection: String);
|
||||||
|
|
||||||
|
begin
|
||||||
|
if (AFileName='') then
|
||||||
|
begin
|
||||||
|
AFileName:=GetAppConfigDir(False);
|
||||||
|
AFileName:=IncludeTrailingPathDelimiter(AFileName)+DefaultIniFile;
|
||||||
|
end;
|
||||||
|
if (ASection='') then
|
||||||
|
ASection:=DefaultSection;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMRUMenuManager.LoadRecentFilesFromIni(Const AFileName : string = ''; Const ASection : String = '');
|
||||||
|
|
||||||
|
Var
|
||||||
|
DN,FN,Sec : String;
|
||||||
|
Ini : TIniFile;
|
||||||
|
|
||||||
|
begin
|
||||||
|
FN:=AFileName;
|
||||||
|
Sec:=ASection;
|
||||||
|
GetFileNameAndSection(FN,Sec);
|
||||||
|
DN:=ExtractFilePath(FN);
|
||||||
|
If ForceDirectories(DN) then
|
||||||
|
begin
|
||||||
|
If FileExists(FN) then
|
||||||
|
begin
|
||||||
|
Ini:=TIniFile.Create(FN);
|
||||||
|
try
|
||||||
|
LoadFromIni(Ini,Sec);
|
||||||
|
finally
|
||||||
|
Ini.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
ShowRecentFiles;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMRUMenuManager.SaveToIni(Ini : TCustomIniFile; ASection : String);
|
||||||
|
|
||||||
|
Var
|
||||||
|
I : Integer;
|
||||||
|
begin
|
||||||
|
Ini.EraseSection(ASection);
|
||||||
|
Ini.WriteInteger(ASection,KeyMaxRecent,FMaxRecent);
|
||||||
|
Ini.WriteInteger(ASection,KeyCount,FRecent.Count);
|
||||||
|
For I:=0 to FRecent.Count-1 do
|
||||||
|
Ini.WriteString(ASection,Format(KeyFile,[i+1]),FRecent[i]);
|
||||||
|
Ini.UpdateFile;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMRUMenuManager.SaveRecentFilesToIni(Const AFileName : string = ''; Const ASection : String = '');
|
||||||
|
|
||||||
|
Var
|
||||||
|
DN,FN,Sec : String;
|
||||||
|
Ini : TMemIniFile;
|
||||||
|
|
||||||
|
begin
|
||||||
|
FN:=AFileName;
|
||||||
|
Sec:=ASection;
|
||||||
|
GetFileNameAndSection(FN,Sec);
|
||||||
|
DN:=ExtractFilePath(FN);
|
||||||
|
If not ForceDirectories(DN) then
|
||||||
|
Raise EMRUManager.CreateFmt(SErrFailedToCreateDir,[DN]);
|
||||||
|
Ini:=TMemIniFile.Create(FN);
|
||||||
|
try
|
||||||
|
SaveToIni(Ini,Sec);
|
||||||
|
finally
|
||||||
|
Ini.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMRUMenuManager.SetMIRecent(const AValue: TMenuItem);
|
||||||
|
begin
|
||||||
|
if FMIRecent=AValue then exit;
|
||||||
|
If Assigned(FMIRecent) then
|
||||||
|
FMIRecent.RemoveFreeNotification(Self);
|
||||||
|
FMIRecent:=AValue;
|
||||||
|
If Assigned(FMIRecent) then
|
||||||
|
FMIRecent.FreeNotification(Self);
|
||||||
|
ShowRecentFiles;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMRUMenuManager.SetRecent(const AValue: TStrings);
|
||||||
|
begin
|
||||||
|
if FRecent=AValue then exit;
|
||||||
|
FRecent.Assign(AValue);
|
||||||
|
ShowRecentFiles;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMRUMenuManager.loaded;
|
||||||
|
begin
|
||||||
|
inherited loaded;
|
||||||
|
if (FRecent.Count>0) and assigned(FMIRecent) then
|
||||||
|
ShowRecentFiles;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
constructor TMRUMenuManager.Create(AOwner: TComponent);
|
||||||
|
begin
|
||||||
|
inherited Create(AOwner);
|
||||||
|
FRecent:=TStringList.Create;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor TMRUMenuManager.Destroy;
|
||||||
|
begin
|
||||||
|
FreeAndNil(FRecent);
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMRUMenuManager.Notification(AComponent: TComponent;
|
||||||
|
Operation: TOperation);
|
||||||
|
begin
|
||||||
|
inherited Notification(AComponent, Operation);
|
||||||
|
if (Operation=opRemove) and (AComponent=FMIrecent) then
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TMRUMenuManager.DoOnRecentClick(Sender: TObject);
|
||||||
|
|
||||||
|
Var
|
||||||
|
FN : String;
|
||||||
|
|
||||||
|
begin
|
||||||
|
With (Sender as TRecentMenuItem) do
|
||||||
|
FN:=FileName;
|
||||||
|
if (FN<>'') and (OnRecentFile<>Nil) then
|
||||||
|
OnRecentFile(Self,FN);
|
||||||
|
end;
|
||||||
|
|
||||||
|
end.
|
||||||
|
|
23
components/mrumenu/reglazmru.pp
Normal file
23
components/mrumenu/reglazmru.pp
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
unit reglazmru;
|
||||||
|
|
||||||
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
interface
|
||||||
|
|
||||||
|
uses
|
||||||
|
Classes, SysUtils, mrumanager, lresources;
|
||||||
|
|
||||||
|
procedure Register;
|
||||||
|
|
||||||
|
implementation
|
||||||
|
|
||||||
|
procedure Register;
|
||||||
|
|
||||||
|
begin
|
||||||
|
RegisterComponents('Misc',[TMRUMenuManager]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
initialization
|
||||||
|
{$i regmru.lrs}
|
||||||
|
end.
|
||||||
|
|
30
components/mrumenu/regmru.lrs
Normal file
30
components/mrumenu/regmru.lrs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
LazarusResources.Add('tmrumenumanager','PNG',[
|
||||||
|
#137'PNG'#13#10#26#10#0#0#0#13'IHDR'#0#0#0#24#0#0#0#24#8#6#0#0#0#224'w='#248#0
|
||||||
|
+#0#0#6'bKGD'#0#255#0#255#0#255#160#189#167#147#0#0#2'FIDATx'#218#237#149'1k'
|
||||||
|
+#219'P'#20#133'?'#217#181'[Z'#240#224#226#22'2'#185#191#161#245#210'n'#197'k'
|
||||||
|
+'!'#16#8'(['#134#196'&S'#16'ZBB'#192'd'#203'b'#26'2'#20'<'#246#7#216'd'#8#25
|
||||||
|
+'2g'#201#28#19#240#146#242#240#18#168'jE'#188'b'#17#219#183'C'#165'TIe'#201
|
||||||
|
+'i'#155#173#23#238#162#247#222'='#231#157'wt/'#252#143#148'0'#238#177#207#152
|
||||||
|
+'q'#191'Dr'#166#168#1'R.'#151#229#206#225'i'#185#14'<'#3#178#179'2'#23#219
|
||||||
|
+#182'Ek'#157#154#213'j5'#4'y'#21#128#24'i'#197's'#128'h'#173#165'V'#171#137
|
||||||
|
+#235#186#162#148#18#173#181'('#165#196#243'<QJ'#201#249#249#185',..'#202#209
|
||||||
|
+#209'Q'#8#240#26'x'#158't'#139'{'#201'R'#169'T'#164#219#237'J'#167#211#9#191
|
||||||
|
+#189#5'^'#0#217#204#20#230#159'l'#219#230#236#236#12#173'ubV'#171'UNOO'#25
|
||||||
|
+#143#199'q'#166' '#19'S'#252#17'@'#163#209#192#178',F'#163#17#142#227#0#224
|
||||||
|
+'8'#14#147#201#4#199'qPJ'#177#188#188#140'm'#219#0'x'#158#135#136#252';'#183
|
||||||
|
+#220#149#229#240#240'P'#218#237'v'#184#254#14'x'#25#149#232#175'e'#217#223
|
||||||
|
+#223''''#159#207'Oe'#159#249#19#183#156#156#156#220#176'>88'#136#218#244#230
|
||||||
|
+#145'C'#128'l'#8#160#148#146'z'#189'.'#158#231'I'#191#223#151#171#171'+QJI'
|
||||||
|
+#183#219#21#211'4'#147'd'#9#243'c'#212#166'q.bss'#19#203#178'('#20#10#184#174
|
||||||
|
+#203'p8dgg'#135#221#221#221'$Y>'#0#239#129#207#128#3#12#129'I,'#192#245#245
|
||||||
|
+'5sss'#172#174#174'R,'#22#217#222#222#166'T*'#161#181#190#229#150'z'#189'N'
|
||||||
|
+#179#217#12#143'i'#160#15'|'#1'.'#3#0#249'M'#162#139#139#11#217#216#216#16
|
||||||
|
+#165#148'('#165#196'4M'#233#245'z'#210#235#245'dee%I'#150'7@)'#248#251#141
|
||||||
|
+#232#227#222#138'V'#171#197#218#218#26#131#193#0#223#247#217#218#218#2#192
|
||||||
|
+#247'}'#22#22#22#146'd'#249#10'|'#7'FQ'#230'F'#228#6#163#165#165'%'#230#231
|
||||||
|
+#231'1'#140'_=JD'#200'd~'#242'0'#12#131'\.'#199#222#222#30#199#199#199#4#197
|
||||||
|
+#251#192#183#160#248#16#24'O'#179#233#250#140#237'8U'#150#184#129'c'#0'O'#3
|
||||||
|
+#239#22#129#199')'#173'V'#0'?p'#203'e'#192'^'#210'&Z'#22'x'#18'd6e'#226'I '
|
||||||
|
+#197'0I'#150#184#2#15':'#26#31'$~'#0#156#213#234#156'f'#131#154#16#0#0#0#0'I'
|
||||||
|
+'END'#174'B`'#130
|
||||||
|
]);
|
BIN
components/mrumenu/tmrumenumanager.png
Normal file
BIN
components/mrumenu/tmrumenumanager.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 657 B |
Loading…
Reference in New Issue
Block a user