![]() |
Frage zu Actionlist als/im Menü
Hi,
da mein Mainmenü sehr groß ist, wollte ich dem Benutzer die Möglichkeit geben, sich die für Ihn wichtigsten Items in einem ToolButtonDropdownMenü selber zusammenzustellen. Wie gehe ich da am Besten vor? Ist die Actionlist überhaupt das richtige Werkzeug? (Habe damit noch nie etwas gemacht). Viele Grüße ... |
AW: Frage zu Actionlist als/im Menü
Schieb :stupid:
|
AW: Frage zu Actionlist als/im Menü
Mit der ActionList liegst du schon richtig.
Sagen wir du hast eine Ini-Datei, die so aussieht:
Code:
Du könntest dir dann eine Klasse schreiben, die diese Ini-Datei auswertet und für jeden Eintrag dynamisch ein Menuitem erzeugt und mit der angegebenen Action verbindet.
[TForm1.MenuItemX]
0 = ActOpenFile 1 = ActSave 2 = ActPrint 3 = "-" 4 = ActExit Ich habe mir mal so eine Klasse programmiert; allerdings für Toolbars und nicht für Menues:
Delphi-Quellcode:
// Klasse zum Laden und Speichern von Konfigurationen in einer Ini-Datei
TActionListConfig = class(TObject) private FIni : TCustomIniFile; class function GetIniSectionname(AToolBar: TToolBar):string; public constructor Create(ini:TCustomIniFile); procedure SaveConfiguration(AToolBar: TToolBar; AActionList: TActionList; const AIniSection: string); procedure LoadConfiguration(AToolBar: TToolBar; AActionList: TActionList; const AIniSection: string); end; ... constructor TActionListConfig.Create(ini: TCustomIniFile); begin inherited Create; FIni := ini; end; class function TActionListConfig.GetIniSectionname(AToolBar: TToolBar): string; begin Result := AToolBar.Owner.ClassName + '_' + AToolBar.Name; end; procedure TActionListConfig.LoadConfiguration(AToolBar: TToolBar; AActionList: TActionList; const AIniSection: string); var i: Integer; s, section : string; a: TBasicAction; ActionName,ActionHotKey: string; sc: TShortCut; begin Assert(Assigned(AToolBar) and Assigned(AActionList) and (AToolBar.Images = AActionList.Images)); if AIniSection <> '' then section := AIniSection else section := GetIniSectionname(AToolBar); if not FIni.SectionExists(section) then Exit; Toolbar_DeleteAllButtons(AToolBar); for i := AActionList.ActionCount downto 0 do begin s := FIni.ReadString(section,IntToStr(i),''); if s = '' then Continue; ActionHotKey := s; ActionName := StrToken(ActionHotKey,','); a := ActionList_FindActionByName(AActionList,ActionName); if Assigned(a) and (a is TCustomAction) and (Pos(',',s) > 0) then begin if ActionHotKey = '' then sc := 0 else sc := TextToShortCut(StrRemoveChars(ActionHotKey,[' '] )); TCustomAction(a).ShortCut := sc; end; Toolbar_AddButton(AToolBar,a); end; end; procedure TActionListConfig.SaveConfiguration(AToolBar: TToolBar; AActionList: TActionList; const AIniSection: string); var i: Integer; s, section : string; tb : TToolButton; begin Assert(Assigned(AToolBar) and Assigned(AActionList) and (AToolBar.Images = AActionList.Images)); if AIniSection <> '' then section := AIniSection else section := GetIniSectionname(AToolBar); FIni.EraseSection(section); for i := 0 to AToolBar.ButtonCount-1 do begin tb := AToolBar.Buttons[i]; if tb.Style = tbsSeparator then s := CAPTION_SEPARATOR else begin s := tb.Action.Name; if tb.Action is TCustomAction then begin with TCustomAction(tb.Action) do begin if ShortCut <> 0 then begin s := s + ',' + ShortCutToText(ShortCut); end; end; end; end; FIni.WriteString(section,IntToStr(i),s); end; end; |
AW: Frage zu Actionlist als/im Menü
Hi,
danke für deine ausführliche Antwort. Das ist ne supi Grundlage für mich! :thumb: Viele Grüße ... |
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:08 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz