AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Frage zu Actionlist als/im Menü

Ein Thema von fillibuster · begonnen am 29. Jun 2011 · letzter Beitrag vom 4. Jul 2011
Antwort Antwort
fillibuster

Registriert seit: 3. Nov 2010
Ort: Coesfeld
245 Beiträge
 
Delphi 2010 Professional
 
#1

Frage zu Actionlist als/im Menü

  Alt 29. Jun 2011, 11:53
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 ...
  Mit Zitat antworten Zitat
fillibuster

Registriert seit: 3. Nov 2010
Ort: Coesfeld
245 Beiträge
 
Delphi 2010 Professional
 
#2

AW: Frage zu Actionlist als/im Menü

  Alt 4. Jul 2011, 14:33
Schieb
  Mit Zitat antworten Zitat
shmia

Registriert seit: 2. Mär 2004
5.508 Beiträge
 
Delphi 5 Professional
 
#3

AW: Frage zu Actionlist als/im Menü

  Alt 4. Jul 2011, 15:45
Mit der ActionList liegst du schon richtig.
Sagen wir du hast eine Ini-Datei, die so aussieht:
Code:
[TForm1.MenuItemX]
0 = ActOpenFile
1 = ActSave
2 = ActPrint
3 = "-"
4 = ActExit
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.

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;
Andreas
  Mit Zitat antworten Zitat
fillibuster

Registriert seit: 3. Nov 2010
Ort: Coesfeld
245 Beiträge
 
Delphi 2010 Professional
 
#4

AW: Frage zu Actionlist als/im Menü

  Alt 4. Jul 2011, 19:42
Hi,

danke für deine ausführliche Antwort. Das ist ne supi Grundlage für mich!

Viele Grüße ...
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 10:05 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz