mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-18 05:39:14 +02:00
IDEIntf: object inspector: changed TPropertyEditor.Verbs to the same mechanims as TComponentEditor
git-svn-id: trunk@39528 -
This commit is contained in:
parent
ffc03ddc8f
commit
15db32a35e
@ -36,7 +36,7 @@ uses
|
|||||||
// IMPORTANT: the object inspector is a tool and can be used in other programs
|
// IMPORTANT: the object inspector is a tool and can be used in other programs
|
||||||
// too. Don't put Lazarus IDE specific things here.
|
// too. Don't put Lazarus IDE specific things here.
|
||||||
// FCL
|
// FCL
|
||||||
SysUtils, Types, Classes, TypInfo,
|
SysUtils, Types, Classes, TypInfo, contnrs,
|
||||||
// LCL
|
// LCL
|
||||||
InterfaceBase, Forms, Buttons, Graphics, GraphType, LCLProc, StdCtrls,
|
InterfaceBase, Forms, Buttons, Graphics, GraphType, LCLProc, StdCtrls,
|
||||||
LCLType, LCLIntf, Controls, ComCtrls, ExtCtrls, LMessages, LResources,
|
LCLType, LCLIntf, Controls, ComCtrls, ExtCtrls, LMessages, LResources,
|
||||||
@ -47,7 +47,6 @@ uses
|
|||||||
|
|
||||||
const
|
const
|
||||||
OIOptionsFileVersion = 3;
|
OIOptionsFileVersion = 3;
|
||||||
EditorPopupMax = 2; // Number of popup menu items created for PropEditors
|
|
||||||
|
|
||||||
DefBackgroundColor = clBtnFace;
|
DefBackgroundColor = clBtnFace;
|
||||||
DefReferencesColor = clMaroon;
|
DefReferencesColor = clMaroon;
|
||||||
@ -564,8 +563,6 @@ type
|
|||||||
|
|
||||||
//============================================================================
|
//============================================================================
|
||||||
|
|
||||||
TPropEditPopupMenuItems = array[0..EditorPopupMax-1] of TMenuItem;
|
|
||||||
|
|
||||||
TOnAddAvailablePersistent = procedure(APersistent: TPersistent;
|
TOnAddAvailablePersistent = procedure(APersistent: TPersistent;
|
||||||
var Allowed: boolean) of object;
|
var Allowed: boolean) of object;
|
||||||
|
|
||||||
@ -671,7 +668,6 @@ type
|
|||||||
FUpdateLock: integer;
|
FUpdateLock: integer;
|
||||||
FUpdatingAvailComboBox: boolean;
|
FUpdatingAvailComboBox: boolean;
|
||||||
FComponentEditor: TBaseComponentEditor;
|
FComponentEditor: TBaseComponentEditor;
|
||||||
FPropEditPopupMenuItems: TPropEditPopupMenuItems; // Popup menu items for PropEdits
|
|
||||||
function GetGridControl(Page: TObjectInspectorPage): TOICustomPropertyGrid;
|
function GetGridControl(Page: TObjectInspectorPage): TOICustomPropertyGrid;
|
||||||
procedure SetComponentEditor(const AValue: TBaseComponentEditor);
|
procedure SetComponentEditor(const AValue: TBaseComponentEditor);
|
||||||
procedure SetFavorites(const AValue: TOIFavoriteProperties);
|
procedure SetFavorites(const AValue: TOIFavoriteProperties);
|
||||||
@ -3931,15 +3927,6 @@ begin
|
|||||||
FilterLabel.Caption := oisComponents;
|
FilterLabel.Caption := oisComponents;
|
||||||
MainPopupMenu.Images := IDEImages.Images_16;
|
MainPopupMenu.Images := IDEImages.Images_16;
|
||||||
|
|
||||||
// "EditorPopupMax" menu items are created for PropEditors already here.
|
|
||||||
// If more of them must be created, adjust EditorPopupMax accordingly.
|
|
||||||
for i := 0 to EditorPopupMax-1 do
|
|
||||||
begin
|
|
||||||
s := 'PropEditPopupMenuItem'+IntToStr(i);
|
|
||||||
AddPopupMenuItem(FPropEditPopupMenuItems[i],nil,s,s,'','',@OnPropEditPopupClick,false,true,true);
|
|
||||||
FPropEditPopupMenuItems[i].Tag := i;
|
|
||||||
DebugLn(['Created menu item "', s, '"']);
|
|
||||||
end;
|
|
||||||
AddPopupMenuItem(AddToFavoritesPopupMenuItem,nil,'AddToFavoritePopupMenuItem',
|
AddPopupMenuItem(AddToFavoritesPopupMenuItem,nil,'AddToFavoritePopupMenuItem',
|
||||||
oisAddtofavorites,'Add property to favorites properties', '',
|
oisAddtofavorites,'Add property to favorites properties', '',
|
||||||
@OnAddToFavoritesPopupmenuItemClick,false,true,true);
|
@OnAddToFavoritesPopupmenuItemClick,false,true,true);
|
||||||
@ -5068,15 +5055,53 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TObjectInspectorDlg.OnMainPopupMenuPopup(Sender: TObject);
|
procedure TObjectInspectorDlg.OnMainPopupMenuPopup(Sender: TObject);
|
||||||
|
const
|
||||||
|
PropertyEditorMIPrefix = 'PropertyEditorVerbMenuItem';
|
||||||
|
ComponentEditorMIPrefix = 'ComponentEditorVerbMenuItem';
|
||||||
var
|
var
|
||||||
EditorVerbSeparator: TMenuItem;
|
ComponentEditorVerbSeparator: TMenuItem;
|
||||||
|
PropertyEditorVerbSeparator: TMenuItem;
|
||||||
|
|
||||||
|
procedure RemovePropertyEditorMenuItems;
|
||||||
|
var
|
||||||
|
I: Integer;
|
||||||
|
begin
|
||||||
|
PropertyEditorVerbSeparator := nil;
|
||||||
|
for I := MainPopupMenu.Items.Count - 1 downto 0 do
|
||||||
|
if Pos(PropertyEditorMIPrefix, MainPopupMenu.Items[I].Name) = 1 then
|
||||||
|
MainPopupMenu.Items[I].Free;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure AddPropertyEditorMenuItems(Editor: TPropertyEditor);
|
||||||
|
var
|
||||||
|
I, VerbCount: Integer;
|
||||||
|
Item: TMenuItem;
|
||||||
|
begin
|
||||||
|
VerbCount := Editor.GetVerbCount;
|
||||||
|
for I := 0 to VerbCount - 1 do
|
||||||
|
begin
|
||||||
|
Item := NewItem(Editor.GetVerb(I), 0, False, True,
|
||||||
|
@OnPropEditPopupClick, 0, PropertyEditorMIPrefix + IntToStr(i));
|
||||||
|
Editor.PrepareItem(I, Item);
|
||||||
|
Item.Tag:=I;
|
||||||
|
MainPopupMenu.Items.Insert(I, Item);
|
||||||
|
end;
|
||||||
|
// insert the separator
|
||||||
|
if VerbCount > 0 then
|
||||||
|
begin
|
||||||
|
PropertyEditorVerbSeparator := Menus.NewLine;
|
||||||
|
PropertyEditorVerbSeparator.Name := PropertyEditorMIPrefix + IntToStr(VerbCount);
|
||||||
|
MainPopupMenu.Items.Insert(VerbCount, PropertyEditorVerbSeparator);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure RemoveComponentEditorMenuItems;
|
procedure RemoveComponentEditorMenuItems;
|
||||||
var
|
var
|
||||||
I: Integer;
|
I: Integer;
|
||||||
begin
|
begin
|
||||||
|
ComponentEditorVerbSeparator:=nil;
|
||||||
for I := MainPopupMenu.Items.Count - 1 downto 0 do
|
for I := MainPopupMenu.Items.Count - 1 downto 0 do
|
||||||
if Pos('ComponentEditorVerbMenuItem', MainPopupMenu.Items[I].Name) = 1 then
|
if Pos(ComponentEditorMIPrefix, MainPopupMenu.Items[I].Name) = 1 then
|
||||||
MainPopupMenu.Items[I].Free;
|
MainPopupMenu.Items[I].Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -5089,16 +5114,17 @@ var
|
|||||||
for I := 0 to VerbCount - 1 do
|
for I := 0 to VerbCount - 1 do
|
||||||
begin
|
begin
|
||||||
Item := NewItem(ComponentEditor.GetVerb(I), 0, False, True,
|
Item := NewItem(ComponentEditor.GetVerb(I), 0, False, True,
|
||||||
@DoComponentEditorVerbMenuItemClick, 0, 'ComponentEditorVerbMenuItem' + IntToStr(i));
|
@DoComponentEditorVerbMenuItemClick, 0, ComponentEditorMIPrefix + IntToStr(i));
|
||||||
ComponentEditor.PrepareItem(I, Item);
|
ComponentEditor.PrepareItem(I, Item);
|
||||||
|
Item.Tag:=I;
|
||||||
MainPopupMenu.Items.Insert(I, Item);
|
MainPopupMenu.Items.Insert(I, Item);
|
||||||
end;
|
end;
|
||||||
// insert the separator
|
// insert the separator
|
||||||
if VerbCount > 0 then
|
if VerbCount > 0 then
|
||||||
begin
|
begin
|
||||||
EditorVerbSeparator := NewLine;
|
ComponentEditorVerbSeparator := Menus.NewLine;
|
||||||
EditorVerbSeparator.Name := 'ComponentEditorVerbMenuItem' + IntToStr(VerbCount);
|
ComponentEditorVerbSeparator.Name := ComponentEditorMIPrefix + IntToStr(VerbCount);
|
||||||
MainPopupMenu.Items.Insert(VerbCount, EditorVerbSeparator);
|
MainPopupMenu.Items.Insert(VerbCount, ComponentEditorVerbSeparator);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -5107,18 +5133,18 @@ var
|
|||||||
Item: TMenuItem;
|
Item: TMenuItem;
|
||||||
begin
|
begin
|
||||||
Item := NewItem(oisAddCollectionItem, 0, False, True,
|
Item := NewItem(oisAddCollectionItem, 0, False, True,
|
||||||
@DoCollectionAddItem, 0, 'ComponentEditorVerbMenuItem0');
|
@DoCollectionAddItem, 0, ComponentEditorMIPrefix+'0');
|
||||||
MainPopupMenu.Items.Insert(0, Item);
|
MainPopupMenu.Items.Insert(0, Item);
|
||||||
EditorVerbSeparator := NewLine;
|
ComponentEditorVerbSeparator := NewLine;
|
||||||
EditorVerbSeparator.Name := 'ComponentEditorVerbMenuItem1';
|
ComponentEditorVerbSeparator.Name := ComponentEditorMIPrefix+'1';
|
||||||
MainPopupMenu.Items.Insert(1, EditorVerbSeparator);
|
MainPopupMenu.Items.Insert(1, ComponentEditorVerbSeparator);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure AddZOrderMenuItems;
|
procedure AddZOrderMenuItems;
|
||||||
var
|
var
|
||||||
ZItem, Item: TMenuItem;
|
ZItem, Item: TMenuItem;
|
||||||
begin
|
begin
|
||||||
ZItem := NewSubMenu(oisZOrder, 0, 'ComponentEditorVerbMenuItemZOrder', [], True);
|
ZItem := NewSubMenu(oisZOrder, 0, ComponentEditorMIPrefix+'ZOrder', [], True);
|
||||||
Item := NewItem(oisOrderMoveToFront, 0, False, True, @DoZOrderItemClick, 0, '');
|
Item := NewItem(oisOrderMoveToFront, 0, False, True, @DoZOrderItemClick, 0, '');
|
||||||
Item.ImageIndex := IDEImages.LoadImage(16, 'Order_move_front');
|
Item.ImageIndex := IDEImages.LoadImage(16, 'Order_move_front');
|
||||||
Item.Tag := 0;
|
Item.Tag := 0;
|
||||||
@ -5135,12 +5161,12 @@ var
|
|||||||
Item.ImageIndex := IDEImages.LoadImage(16, 'Order_back_one');
|
Item.ImageIndex := IDEImages.LoadImage(16, 'Order_back_one');
|
||||||
Item.Tag := 3;
|
Item.Tag := 3;
|
||||||
ZItem.Add(Item);
|
ZItem.Add(Item);
|
||||||
if EditorVerbSeparator <> nil then
|
if ComponentEditorVerbSeparator <> nil then
|
||||||
MainPopupMenu.Items.Insert(EditorVerbSeparator.MenuIndex + 1, ZItem)
|
MainPopupMenu.Items.Insert(ComponentEditorVerbSeparator.MenuIndex + 1, ZItem)
|
||||||
else
|
else
|
||||||
MainPopupMenu.Items.Insert(0, ZItem);
|
MainPopupMenu.Items.Insert(0, ZItem);
|
||||||
Item := NewLine;
|
Item := NewLine;
|
||||||
Item.Name := 'ComponentEditorVerbMenuItemZOrderSeparator';
|
Item.Name := ComponentEditorMIPrefix+'ZOrderSeparator';
|
||||||
MainPopupMenu.Items.Insert(ZItem.MenuIndex + 1, Item);
|
MainPopupMenu.Items.Insert(ZItem.MenuIndex + 1, Item);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -5151,13 +5177,13 @@ var
|
|||||||
CurRow: TOIPropertyGridRow;
|
CurRow: TOIPropertyGridRow;
|
||||||
Persistent: TPersistent;
|
Persistent: TPersistent;
|
||||||
begin
|
begin
|
||||||
|
RemovePropertyEditorMenuItems;
|
||||||
RemoveComponentEditorMenuItems;
|
RemoveComponentEditorMenuItems;
|
||||||
ShowHintsPopupMenuItem.Checked := PropertyGrid.ShowHint;
|
ShowHintsPopupMenuItem.Checked := PropertyGrid.ShowHint;
|
||||||
Persistent := GetSelectedPersistent;
|
Persistent := GetSelectedPersistent;
|
||||||
// show component editors only for component treeview
|
// show component editors only for component treeview
|
||||||
if MainPopupMenu.PopupComponent = ComponentTree then
|
if MainPopupMenu.PopupComponent = ComponentTree then
|
||||||
begin
|
begin
|
||||||
EditorVerbSeparator := nil;
|
|
||||||
ComponentEditor := GetComponentEditorForSelection;
|
ComponentEditor := GetComponentEditorForSelection;
|
||||||
if ComponentEditor <> nil then
|
if ComponentEditor <> nil then
|
||||||
AddComponentEditorMenuItems
|
AddComponentEditorMenuItems
|
||||||
@ -5194,19 +5220,9 @@ begin
|
|||||||
CurRow := GetActivePropertyRow;
|
CurRow := GetActivePropertyRow;
|
||||||
if (MainPopupMenu.PopupComponent is TOICustomPropertyGrid) then
|
if (MainPopupMenu.PopupComponent is TOICustomPropertyGrid) then
|
||||||
begin
|
begin
|
||||||
for i := 0 to EditorPopupMax-1 do
|
// popup menu of property grid
|
||||||
begin
|
if CurRow<>nil then
|
||||||
Capt := '';
|
AddPropertyEditorMenuItems(CurRow.Editor);
|
||||||
if Assigned(CurRow) and (i < CurRow.Editor.GetVerbCount) then
|
|
||||||
Capt := CurRow.Editor.GetVerb(i, sHint);
|
|
||||||
FPropEditPopupMenuItems[i].Visible := Capt<>'';
|
|
||||||
if FPropEditPopupMenuItems[i].Visible then
|
|
||||||
begin
|
|
||||||
FPropEditPopupMenuItems[i].Caption := Capt;
|
|
||||||
FPropEditPopupMenuItems[i].Hint := sHint;
|
|
||||||
FPropEditPopupMenuItems[i].Enabled := CurRow.Editor.GetVerbEnabled(i);
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
b := (Favorites <> nil) and ShowFavorites and (GetActivePropertyRow <> nil);
|
b := (Favorites <> nil) and ShowFavorites and (GetActivePropertyRow <> nil);
|
||||||
AddToFavoritesPopupMenuItem.Visible := b and
|
AddToFavoritesPopupMenuItem.Visible := b and
|
||||||
@ -5231,8 +5247,7 @@ begin
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
for i := 0 to EditorPopupMax-1 do
|
// default popup menu
|
||||||
FPropEditPopupMenuItems[i].Visible := False;
|
|
||||||
AddToFavoritesPopupMenuItem.Visible := False;
|
AddToFavoritesPopupMenuItem.Visible := False;
|
||||||
RemoveFromFavoritesPopupMenuItem.Visible := False;
|
RemoveFromFavoritesPopupMenuItem.Visible := False;
|
||||||
UndoPropertyPopupMenuItem.Visible := False;
|
UndoPropertyPopupMenuItem.Visible := False;
|
||||||
@ -5262,8 +5277,7 @@ begin
|
|||||||
AMenuItem := TMenuItem(Sender)
|
AMenuItem := TMenuItem(Sender)
|
||||||
else
|
else
|
||||||
Exit;
|
Exit;
|
||||||
// component menu items start from the start of menu
|
Verb := AMenuItem.Tag;
|
||||||
Verb := AMenuItem.MenuIndex;
|
|
||||||
ComponentEditor.ExecuteVerb(Verb);
|
ComponentEditor.ExecuteVerb(Verb);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -373,8 +373,8 @@ type
|
|||||||
function IsNotDefaultValue: boolean; virtual;
|
function IsNotDefaultValue: boolean; virtual;
|
||||||
// These are used for the popup menu in OI
|
// These are used for the popup menu in OI
|
||||||
function GetVerbCount: Integer; virtual;
|
function GetVerbCount: Integer; virtual;
|
||||||
function GetVerb(Index: Integer; out AHint: string): string; virtual;
|
function GetVerb(Index: Integer): string; virtual;
|
||||||
function GetVerbEnabled(Index: Integer): Boolean; virtual;
|
procedure PrepareItem(Index: Integer; const AnItem: TMenuItem); virtual;
|
||||||
procedure ExecuteVerb(Index: Integer); virtual;
|
procedure ExecuteVerb(Index: Integer); virtual;
|
||||||
public
|
public
|
||||||
property PropertyHook: TPropertyEditorHook read FPropertyHook;
|
property PropertyHook: TPropertyEditorHook read FPropertyHook;
|
||||||
@ -874,8 +874,8 @@ type
|
|||||||
public
|
public
|
||||||
// These are used for the popup menu in OI
|
// These are used for the popup menu in OI
|
||||||
function GetVerbCount: Integer; override;
|
function GetVerbCount: Integer; override;
|
||||||
function GetVerb(Index: Integer; out AHint: string): string; override;
|
function GetVerb(Index: Integer): string; override;
|
||||||
function GetVerbEnabled(Index: Integer): Boolean; override;
|
procedure PrepareItem(Index: Integer; const AnItem: TMenuItem); override;
|
||||||
procedure ExecuteVerb(Index: Integer); override;
|
procedure ExecuteVerb(Index: Integer); override;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2919,15 +2919,14 @@ begin
|
|||||||
Result := 0;
|
Result := 0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TPropertyEditor.GetVerb(Index: Integer; out AHint: string): string;
|
function TPropertyEditor.GetVerb(Index: Integer): string;
|
||||||
begin
|
begin
|
||||||
Result := Format(oisSetToDefault, [GetDefaultValue]);
|
Result := Format(oisSetToDefault, [GetDefaultValue]);
|
||||||
AHint := oisSetToDefaultHint;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TPropertyEditor.GetVerbEnabled(Index: Integer): Boolean;
|
procedure TPropertyEditor.PrepareItem(Index: Integer; const AnItem: TMenuItem);
|
||||||
begin
|
begin
|
||||||
Result := IsNotDefaultValue;
|
// overridden by descendants
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TPropertyEditor.ExecuteVerb(Index: Integer);
|
procedure TPropertyEditor.ExecuteVerb(Index: Integer);
|
||||||
@ -5131,35 +5130,40 @@ begin
|
|||||||
Result:=2;
|
Result:=2;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TConstraintsPropertyEditor.GetVerb(Index: Integer; out AHint: string): string;
|
function TConstraintsPropertyEditor.GetVerb(Index: Integer): string;
|
||||||
var
|
var
|
||||||
s: String;
|
s: String;
|
||||||
c: TControl;
|
c: TControl;
|
||||||
begin
|
begin
|
||||||
case Index of
|
case Index of
|
||||||
0: begin
|
0: s := oisSetMaxConstraints;
|
||||||
s := oisSetMaxConstraints;
|
1: s := oisSetMinConstraints;
|
||||||
AHint := oisSetMaxConstraintsHint;
|
|
||||||
end;
|
|
||||||
1: begin
|
|
||||||
s := oisSetMinConstraints;
|
|
||||||
AHint := oisSetMinConstraintsHint;
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
c := GetComponent(0) as TControl;
|
c := GetComponent(0) as TControl;
|
||||||
Result := Format(s, [c.Height, c.Width]);
|
Result := Format(s, [c.Height, c.Width]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TConstraintsPropertyEditor.GetVerbEnabled(Index: Integer): Boolean;
|
procedure TConstraintsPropertyEditor.PrepareItem(Index: Integer;
|
||||||
|
const AnItem: TMenuItem);
|
||||||
var
|
var
|
||||||
c: TControl;
|
c: TControl;
|
||||||
begin
|
begin
|
||||||
c := GetComponent(0) as TControl;
|
c := GetComponent(0) as TControl;
|
||||||
case Index of
|
case Index of
|
||||||
0: Result := (c.Constraints.MaxHeight<>c.Height)
|
0:
|
||||||
or (c.Constraints.MaxWidth<>c.Width);
|
begin
|
||||||
1: Result := (c.Constraints.MinHeight<>c.Height)
|
// set max constraints
|
||||||
or (c.Constraints.MinWidth<>c.Width);
|
AnItem.Enabled := (c.Constraints.MaxHeight<>c.Height)
|
||||||
|
or (c.Constraints.MaxWidth<>c.Width);
|
||||||
|
AnItem.Hint := oisSetMaxConstraintsHint;
|
||||||
|
end;
|
||||||
|
1:
|
||||||
|
begin
|
||||||
|
// set min constraints
|
||||||
|
AnItem.Enabled := (c.Constraints.MinHeight<>c.Height)
|
||||||
|
or (c.Constraints.MinWidth<>c.Width);
|
||||||
|
AnItem.Hint := oisSetMinConstraintsHint;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user