-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathsyneditpopup.pas
148 lines (126 loc) · 3.42 KB
/
syneditpopup.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
unit SynEditPopup;
{$mode objfpc}{$H+}
interface
uses
ActnList,
Menus,
Classes,
SynEdit;
type
TSynEdit = class(SynEdit.TSynEdit)
private
FActnList: TActionList;
FPopupMenu : TPopupMenu;
procedure CreateActns;
procedure FillPopupMenu(APopupMenu : TPopupMenu);
procedure CopyExecute(Sender: TObject);
procedure CopyUpdate(Sender: TObject);
procedure SelectAllExecute(Sender: TObject);
procedure SelectAllUpdate(Sender: TObject);
procedure SelectCopyAllExecute(Sender: TObject);
procedure SelectCopyAllUpdate(Sender: TObject);
procedure SetPopupMenu_(const Value: TPopupMenu);
function GetPopupMenu_: TPopupMenu;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property PopupMenu: TPopupMenu read GetPopupMenu_ write SetPopupMenu_;
end;
implementation
uses
SysUtils;
const
MenuName='uSynEditPopupMenu';
procedure TSynEdit.CopyExecute(Sender: TObject);
begin
Self.CopyToClipboard;
end;
procedure TSynEdit.CopyUpdate(Sender: TObject);
begin
TAction(Sender).Enabled :=Self.SelAvail;
end;
procedure TSynEdit.SelectAllExecute(Sender: TObject);
begin
Self.SelectAll;
end;
procedure TSynEdit.SelectAllUpdate(Sender: TObject);
begin
TAction(Sender).Enabled :=Self.Lines.Text<>'';
end;
procedure TSynEdit.SelectCopyAllExecute(Sender: TObject);
begin
Self.SelectAll;
Self.CopyToClipboard;
end;
procedure TSynEdit.SelectCopyAllUpdate(Sender: TObject);
begin
TAction(Sender).Enabled :=Self.Lines.Text<>'';
end;
constructor TSynEdit.Create(AOwner: TComponent);
begin
inherited;
FActnList:=TActionList.Create(Self);
FPopupMenu:=TPopupMenu.Create(Self);
FPopupMenu.Name:=MenuName;
CreateActns;
FillPopupMenu(FPopupMenu);
PopupMenu:=FPopupMenu;
end;
procedure TSynEdit.CreateActns;
procedure AddActItem(const AText:string;AShortCut : TShortCut;AEnabled:Boolean;OnExecute,OnUpdate:TNotifyEvent);
Var
ActionItem : TAction;
begin
ActionItem:=TAction.Create(FActnList);
ActionItem.ActionList:=FActnList;
ActionItem.Caption:=AText;
ActionItem.ShortCut:=AShortCut;
ActionItem.Enabled:=AEnabled;
ActionItem.OnExecute:=OnExecute;
ActionItem.OnUpdate:=OnUpdate;
end;
begin
AddActItem('&Copy',Menus.ShortCut(Word('C'), [ssCtrl]),False, @CopyExecute, @CopyUpdate);
AddActItem('-',0,False,nil,nil);
AddActItem('&Select All',Menus.ShortCut(Word('S'), [ssCtrl]),False, @SelectAllExecute, @SelectAllUpdate);
AddActItem('-',0,False,nil,nil);
AddActItem('Select and Copy &All',Menus.ShortCut(Word('A'), [ssCtrl]),False, @SelectCopyAllExecute, @SelectCopyAllUpdate);
end;
procedure TSynEdit.SetPopupMenu_(const Value: TPopupMenu);
Var
MenuItem : TMenuItem;
begin
SynEdit.TSynEdit(Self).PopupMenu:=Value;
if CompareText(MenuName,Value.Name)<>0 then
begin
MenuItem:=TMenuItem.Create(Value);
MenuItem.Caption:='-';
Value.Items.Add(MenuItem);
FillPopupMenu(Value);
end;
end;
function TSynEdit.GetPopupMenu_: TPopupMenu;
begin
Result:=SynEdit.TSynEdit(Self).PopupMenu;
end;
destructor TSynEdit.Destroy;
begin
FPopupMenu.Free;
FActnList.Free;
inherited;
end;
procedure TSynEdit.FillPopupMenu(APopupMenu : TPopupMenu);
var
i : integer;
MenuItem : TMenuItem;
begin
if Assigned(FActnList) then
for i := 0 to FActnList.ActionCount-1 do
begin
MenuItem:=TMenuItem.Create(APopupMenu);
MenuItem.Action :=FActnList.Actions[i];
APopupMenu.Items.Add(MenuItem);
end;
end;
end.