- extend menuintf: allow set ResourceName for menu items (to assign menu glyph)
- uniteditor: assign some glyphs to editor popup menu 

git-svn-id: trunk@13070 -
This commit is contained in:
paul 2007-11-29 02:59:32 +00:00
parent deb3af7f84
commit 6301facd85
4 changed files with 58 additions and 29 deletions

View File

@ -2533,6 +2533,7 @@ begin
NewMenuCmd:=RegisterIDEMenuCommand(DesignerMenuSectionComponentEditor,
'ComponentEditorVerMenuItem'+IntToStr(i),
AComponentEditor.GetVerb(i),
'',
@OnComponentEditorVerbMenuItemClick);
if NewMenuCmd.MenuItem<>nil then
AComponentEditor.PrepareItem(i,NewMenuCmd.MenuItem);

View File

@ -886,6 +886,7 @@ begin
RegisterIDEMenuCommand(MsgQuickFixIDEMenuSection,
QuickFixItem.Name,
QuickFixItem.Caption,
'',
@OnQuickFixClick);
end;
end;

View File

@ -51,7 +51,7 @@ uses
SynEditKeyCmds, SynCompletion,
// IDE interface
MacroIntf, ProjectIntf, SrcEditorIntf, MenuIntf, LazIDEIntf, PackageIntf,
IDEWindowIntf,
IDEWindowIntf, IDEImagesIntf,
// IDE units
LazarusIDEStrConsts, LazConf, IDECommands, EditorOptions, KeyMapping, Project,
WordCompletion, FindReplaceDialog, FindInFilesDlg, IDEProcs, IDEOptionDefs,
@ -886,11 +886,11 @@ begin
SrcEditMenuProcedureJump:=RegisterIDEMenuCommand(AParent,'Procedure Jump',
uemProcedureJump);
SrcEditMenuFindNextWordOccurrence:=RegisterIDEMenuCommand(AParent,
'Find next word occurrence',srkmecFindNextWordOccurrence);
'Find next word occurrence', srkmecFindNextWordOccurrence, 'menu_search_find_next');
SrcEditMenuFindPrevWordOccurrence:=RegisterIDEMenuCommand(AParent,
'Find previous word occurrence',srkmecFindPrevWordOccurrence);
'Find previous word occurrence', srkmecFindPrevWordOccurrence, 'menu_search_find_previous');
SrcEditMenuFindInFiles:=RegisterIDEMenuCommand(AParent,
'Find in files',srkmecFindInFiles);
'Find in files', srkmecFindInFiles, 'menu_search_files');
AParent:=SrcEditMenuSectionFirstStatic;
SrcEditMenuOpenFileAtCursor:=RegisterIDEMenuCommand(AParent,
@ -902,9 +902,9 @@ begin
SrcEditMenuSectionClipboard:=RegisterIDEMenuSection(SourceEditorMenuRoot,
'Clipboard');
AParent:=SrcEditMenuSectionClipboard;
SrcEditMenuCut:=RegisterIDEMenuCommand(AParent,'Cut',uemCut);
SrcEditMenuCopy:=RegisterIDEMenuCommand(AParent,'Copy',uemCopy);
SrcEditMenuPaste:=RegisterIDEMenuCommand(AParent,'Paste',uemPaste);
SrcEditMenuCut:=RegisterIDEMenuCommand(AParent,'Cut',uemCut, 'menu_edit_cut');
SrcEditMenuCopy:=RegisterIDEMenuCommand(AParent,'Copy',uemCopy, 'menu_edit_copy');
SrcEditMenuPaste:=RegisterIDEMenuCommand(AParent,'Paste',uemPaste, 'menu_edit_paste');
SrcEditMenuCopyFilename:=RegisterIDEMenuCommand(AParent,'Copy filename',
uemCopyFilename);
@ -943,9 +943,9 @@ begin
SrcEditMenuAddWatchAtCursor:=RegisterIDEMenuCommand(AParent,
'Add Watch at Cursor',uemAddWatchAtCursor);
SrcEditMenuRunToCursor:=RegisterIDEMenuCommand(AParent,
'Run to cursor',uemRunToCursor);
'Run to cursor', uemRunToCursor, 'menu_run_cursor');
SrcEditMenuViewCallStack:=RegisterIDEMenuCommand(AParent,
'View Call Stack',uemViewCallStack);
'View Call Stack', uemViewCallStack, 'debugger_call_stack');
// register the File Specific dynamic section
AParent:=SourceEditorMenuRoot;
@ -995,7 +995,7 @@ begin
uemShowUnitInfo);
SrcEditMenuSectionHighlighter:=RegisterIDEMenuSection(AParent,'Highlighter');
SrcEditMenuEditorProperties:=RegisterIDEMenuCommand(AParent,
'EditorProperties',uemEditorProperties);
'EditorProperties',uemEditorProperties, 'menu_editor_options');
end;
@ -3964,9 +3964,11 @@ begin
//debugln('TSourceNotebook.BuildPopupMenu');
SrcPopupMenu := TPopupMenu.Create(Self);
with SrcPopupMenu do begin
with SrcPopupMenu do
begin
AutoPopup := True;
OnPopup :=@SrcPopupMenuPopup;
Images := IDEImages.Images_16;
end;
// assign the root TMenuItem to the registered menu root.
@ -4048,7 +4050,7 @@ begin
if SrcEditMenuSectionHighlighter.Count=i then begin
// add new item
IDEMenuItem:=RegisterIDEMenuCommand(SrcEditMenuSectionHighlighter,
CurName,CurCaption,@HighlighterClicked);
CurName,CurCaption,'',@HighlighterClicked);
end else begin
IDEMenuItem:=SrcEditMenuSectionHighlighter[i];
IDEMenuItem.Caption:=CurCaption;
@ -4070,7 +4072,7 @@ function TSourceNotebook.AddUserDefinedPopupMenuItem(const NewCaption: string;
const NewEnabled: boolean; const NewOnClick: TNotifyEvent): TIDEMenuItem;
begin
Result:=RegisterIDEMenuCommand(SrcEditMenuSectionFirstDynamic.GetPath,
'Dynamic',NewCaption,NewOnClick);
'Dynamic',NewCaption,'',NewOnClick);
Result.Enabled:=NewEnabled;
end;
@ -4086,7 +4088,7 @@ function TSourceNotebook.AddContextPopupMenuItem(const NewCaption: string;
const NewEnabled: boolean; const NewOnClick: TNotifyEvent): TIDEMenuItem;
begin
Result:=RegisterIDEMenuCommand(SrcEditMenuSectionFileDynamic.GetPath,
'FileDynamic',NewCaption,NewOnClick);
'FileDynamic',NewCaption,'',NewOnClick);
Result.Enabled:=NewEnabled;
end;

View File

@ -23,7 +23,7 @@ interface
uses
Classes, SysUtils, LCLProc, Menus, ImgList, Graphics, LazHelpIntf,
IDECommands;
IDECommands, IDEImagesIntf;
type
TIDEMenuItem = class;
@ -217,6 +217,7 @@ type
FDefault: Boolean;
FGroupIndex: Byte;
FRadioItem: Boolean;
FResourceName: String;
FRightJustify: boolean;
FShowAlwaysCheckable: boolean;
protected
@ -230,6 +231,7 @@ type
procedure SetShowAlwaysCheckable(const AValue: boolean); virtual;
procedure SetCommand(const AValue: TIDECommand); virtual;
procedure SetMenuItem(const AValue: TMenuItem); override;
procedure SetResourceName(const AValue: String);
procedure CommandChanged(Sender: TObject);
public
property Command: TIDECommand read FCommand write SetCommand;
@ -241,6 +243,7 @@ type
property RightJustify: boolean read FRightJustify write SetRightJustify;
property ShowAlwaysCheckable: boolean read FShowAlwaysCheckable
write SetShowAlwaysCheckable;
property ResourceName: String read FResourceName write SetResourceName;
end;
TIDEMenuCommandClass = class of TIDEMenuCommand;
@ -417,11 +420,13 @@ function RegisterIDESubMenu(const Path, Name, Caption: string;
): TIDEMenuSection; overload;
function RegisterIDEMenuCommand(Parent: TIDEMenuSection;
const Name, Caption: string;
const ResourceName: String = '';
const OnClickMethod: TNotifyEvent = nil;
const OnClickProc: TNotifyProcedure = nil;
const Command: TIDECommand = nil
): TIDEMenuCommand; overload;
function RegisterIDEMenuCommand(const Path, Name, Caption: string;
const ResourceName: String = '';
const OnClickMethod: TNotifyEvent = nil;
const OnClickProc: TNotifyProcedure = nil;
const Command: TIDECommand = nil
@ -478,29 +483,36 @@ begin
Result:=RegisterIDESubMenu(Parent,Name,Caption,OnClickMethod,OnClickProc);
end;
function RegisterIDEMenuCommand(Parent: TIDEMenuSection; const Name,
Caption: string; const OnClickMethod: TNotifyEvent;
const OnClickProc: TNotifyProcedure; const Command: TIDECommand
): TIDEMenuCommand;
function RegisterIDEMenuCommand(Parent: TIDEMenuSection;
const Name, Caption: string;
const ResourceName: String = '';
const OnClickMethod: TNotifyEvent = nil;
const OnClickProc: TNotifyProcedure = nil;
const Command: TIDECommand = nil
): TIDEMenuCommand;
begin
Result:=TIDEMenuCommand.Create(Name);
Result.Caption:=Caption;
Result.OnClick:=OnClickMethod;
Result.OnClickProc:=OnClickProc;
Result.Command:=Command;
Result := TIDEMenuCommand.Create(Name);
Result.Caption := Caption;
Result.OnClick := OnClickMethod;
Result.OnClickProc := OnClickProc;
Result.Command := Command;
Result.ResourceName := ResourceName;
Parent.AddLast(Result);
end;
function RegisterIDEMenuCommand(const Path, Name, Caption: string;
const OnClickMethod: TNotifyEvent; const OnClickProc: TNotifyProcedure;
const Command: TIDECommand): TIDEMenuCommand;
const ResourceName: String = '';
const OnClickMethod: TNotifyEvent = nil;
const OnClickProc: TNotifyProcedure = nil;
const Command: TIDECommand = nil
): TIDEMenuCommand;
var
Parent: TIDEMenuSection;
begin
//debugln('RegisterIDEMenuCommand Path="',Path,'" Name="',Name,'"');
Parent:=IDEMenuRoots.FindByPath(Path,true) as TIDEMenuSection;
Result:=RegisterIDEMenuCommand(Parent,Name,Caption,OnClickMethod,OnClickProc,
Command);
Parent := IDEMenuRoots.FindByPath(Path,true) as TIDEMenuSection;
Result := RegisterIDEMenuCommand(Parent, Name, Caption, ResourceName,
OnClickMethod, OnClickProc, Command);
end;
{ TIDEMenuItem }
@ -1465,6 +1477,17 @@ begin
MenuItem.ShortCut:=0;
end;
procedure TIDEMenuCommand.SetResourceName(const AValue: String);
begin
if FResourceName=AValue then exit;
FResourceName:=AValue;
if MenuItem<>nil then
if AValue <> '' then
MenuItem.ImageIndex := IDEImages.LoadImage(16, FResourceName)
else
MenuItem.ImageIndex := -1;
end;
procedure TIDEMenuCommand.MenuItemClick(Sender: TObject);
begin
inherited MenuItemClick(Sender);
@ -1555,6 +1578,8 @@ begin
else
MenuItem.ShortCut:=ShortCut(0,[]);
MenuItem.GroupIndex:=GroupIndex;
if ResourceName <> '' then
MenuItem.ImageIndex := IDEImages.LoadImage(16, ResourceName);
end;
end;