| 1 |
unit PopupMenuSetting; |
| 2 |
|
| 3 |
interface |
| 4 |
|
| 5 |
uses |
| 6 |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
| 7 |
Dialogs, StdCtrls, ExtCtrls, ActnList, Menus, ComCtrls; |
| 8 |
|
| 9 |
type |
| 10 |
TPopupMenuSettingDialog = class(TForm) |
| 11 |
TopPanel: TPanel; |
| 12 |
PopupMenuComboLabel: TLabel; |
| 13 |
PopupMenuComboBox: TComboBox; |
| 14 |
MainPanel: TPanel; |
| 15 |
ActionListBox: TListBox; |
| 16 |
LabelButton: TButton; |
| 17 |
AddMainButton: TButton; |
| 18 |
AddSubButton: TButton; |
| 19 |
AddSepButton: TButton; |
| 20 |
RemoveButton: TButton; |
| 21 |
UpButton: TButton; |
| 22 |
DownButton: TButton; |
| 23 |
MenuTreeView: TTreeView; |
| 24 |
Panel1: TPanel; |
| 25 |
Panel2: TPanel; |
| 26 |
Panel4: TPanel; |
| 27 |
Splitter1: TSplitter; |
| 28 |
ApplyButton: TButton; |
| 29 |
procedure PopupMenuComboBoxChange(Sender: TObject); |
| 30 |
procedure FormCreate(Sender: TObject); |
| 31 |
procedure FormDestroy(Sender: TObject); |
| 32 |
procedure UpButtonClick(Sender: TObject); |
| 33 |
procedure DownButtonClick(Sender: TObject); |
| 34 |
procedure RemoveButtonClick(Sender: TObject); |
| 35 |
procedure AddSepButtonClick(Sender: TObject); |
| 36 |
procedure MenuTreeViewDblClick(Sender: TObject); |
| 37 |
procedure MenuTreeViewEdited(Sender: TObject; Node: TTreeNode; |
| 38 |
var S: String); |
| 39 |
procedure MenuTreeViewEditing(Sender: TObject; Node: TTreeNode; |
| 40 |
var AllowEdit: Boolean); |
| 41 |
procedure AddMainButtonClick(Sender: TObject); |
| 42 |
procedure AddSubButtonClick(Sender: TObject); |
| 43 |
procedure LabelButtonClick(Sender: TObject); |
| 44 |
procedure MenuTreeViewChange(Sender: TObject; Node: TTreeNode); |
| 45 |
procedure ApplyButtonClick(Sender: TObject); |
| 46 |
private |
| 47 |
{ Private 鐃緒申鐃緒申 } |
| 48 |
FActionList: TActionList; |
| 49 |
FSpecialActionLists: array[0..0] of TStringList; |
| 50 |
function GetMenuAction(var Item:TMenuItem; Idx:Integer): TBasicAction; |
| 51 |
procedure AddMainMenu(const Caption: String; Action: TBasicAction); |
| 52 |
procedure DeleteUsedActionList(Action: TBasicAction); |
| 53 |
function GetIniString(Node: TTreeNode; Parent: String; Idx: Integer): String; |
| 54 |
function GetIniValueString(Node: TTreeNode): String; |
| 55 |
public |
| 56 |
{ Public 鐃緒申鐃緒申 } |
| 57 |
constructor Create(AOwner: TComponent; ActionList: TActionList); reintroduce; overload; virtual; |
| 58 |
end; |
| 59 |
|
| 60 |
var |
| 61 |
PopupMenuSettingDialog: TPopupMenuSettingDialog; |
| 62 |
|
| 63 |
implementation |
| 64 |
|
| 65 |
uses |
| 66 |
PopupMenuUtil, IniFiles, GikoSystem, ToolBarUtil; |
| 67 |
{$R *.dfm} |
| 68 |
//! 鐃?鐃緒申鐃?鐃?鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃? |
| 69 |
constructor TPopupMenuSettingDialog.Create(AOwner: TComponent; ActionList: TActionList); |
| 70 |
const |
| 71 |
// 鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申 |
| 72 |
// 鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申 |
| 73 |
ROUNDITEM = 'RoundItem'; |
| 74 |
// 鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃?鐃?鐃緒申鐃緒申鐃? |
| 75 |
SAMPETHREAD='BoardThreadItem'; |
| 76 |
var |
| 77 |
act : TCustomAction; |
| 78 |
begin |
| 79 |
inherited Create(AOwner); |
| 80 |
FActionList := ActionList; |
| 81 |
FSpecialActionLists[0] := TStringList.Create(); |
| 82 |
// 鐃?鐃?鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 83 |
act := TCustomAction.Create(Self); |
| 84 |
act.Name := ROUNDITEM; |
| 85 |
act.Caption := '鐃?鐃緒申鐃?鐃?鐃緒申鐃緒申鐃?鐃緒申'; |
| 86 |
FSpecialActionLists[0].AddObject(act.Caption, act); |
| 87 |
act := TCustomAction.Create(Self); |
| 88 |
act.Name := SAMPETHREAD; |
| 89 |
act.Caption := '鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃?鐃?'; |
| 90 |
FSpecialActionLists[0].AddObject(act.Caption, act); |
| 91 |
|
| 92 |
end; |
| 93 |
//! 鐃?鐃?鐃?鐃?鐃?鐃?鐃緒申鐃?鐃緒申鐃?鐃?鐃緒申鐃?鐃?鐃?鐃?鐃?鐃緒申鐃?鐃?鐃?鐃緒申鐃? |
| 94 |
procedure TPopupMenuSettingDialog.PopupMenuComboBoxChange(Sender: TObject); |
| 95 |
var |
| 96 |
act : TCustomAction; |
| 97 |
bact: TBasicAction; |
| 98 |
ini : TMemIniFile; |
| 99 |
mkeys, skeys : TStringList; |
| 100 |
i, j, idx: Integer; |
| 101 |
value, subValue : String; |
| 102 |
item, subItem : TMenuItem; |
| 103 |
node : TTreeNode; |
| 104 |
begin |
| 105 |
ActionListBox.Items.Clear; |
| 106 |
MenuTreeView.Items.Clear; |
| 107 |
AddSubButton.Enabled := False; |
| 108 |
case PopupMenuComboBox.ItemIndex of |
| 109 |
0 : begin |
| 110 |
for idx := 0 to Length(PopupMenuUtil.ACK_BROWSER) -1 do begin |
| 111 |
act := PopupMenuUtil.GetActionItem(FActionList, PopupMenuUtil.ACK_BROWSER[idx]); |
| 112 |
if (act <> nil) then begin |
| 113 |
ActionListBox.AddItem(act.Caption, act); |
| 114 |
end; |
| 115 |
end; |
| 116 |
end |
| 117 |
else |
| 118 |
; |
| 119 |
end; |
| 120 |
for idx := 0 to FSpecialActionLists[PopupMenuComboBox.ItemIndex].Count - 1 do begin |
| 121 |
// 鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 122 |
act := TCustomAction(FSpecialActionLists[PopupMenuComboBox.ItemIndex].Objects[idx]); |
| 123 |
if (act <> nil) then begin |
| 124 |
ActionListBox.AddItem(act.Caption, act); |
| 125 |
end; |
| 126 |
end; |
| 127 |
|
| 128 |
//ini鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 129 |
if (FileExists(GikoSys.Setting.GetConfigDir + PopupMenuUtil.INI_FILENAME)) Then begin |
| 130 |
ini := TMemIniFile.Create(GikoSys.Setting.GetConfigDir + PopupMenuUtil.INI_FILENAME); |
| 131 |
mkeys := TStringList.Create; |
| 132 |
mkeys.Sorted := true; |
| 133 |
skeys := TStringList.Create; |
| 134 |
skeys.Sorted := true; |
| 135 |
try |
| 136 |
node := nil; |
| 137 |
idx := PopupMenuComboBox.ItemIndex; |
| 138 |
ini.ReadSection(PopupMenuUtil.SECTIONS[idx], mkeys); |
| 139 |
// main鐃緒申鐃緒申鐃?鐃? sub鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申 |
| 140 |
for i := mkeys.Count - 1 downto 0 do begin |
| 141 |
if (Pos('sub', mkeys[i]) = 1) then begin |
| 142 |
skeys.Add(mkeys[i]); |
| 143 |
mkeys.Delete(i); |
| 144 |
end; |
| 145 |
end; |
| 146 |
// 鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申 |
| 147 |
for i := 0 to mkeys.Count - 1 do begin |
| 148 |
value := ini.ReadString(PopupMenuUtil.SECTIONS[idx], mkeys[i], '-'); |
| 149 |
item := PopupMenuUtil.GetMenuItem( |
| 150 |
PopupMenuUtil.SECTIONS[idx], nil, FActionList, value); |
| 151 |
if (item <> nil) then begin |
| 152 |
bact := GetMenuAction(item, PopupMenuComboBox.ItemIndex); |
| 153 |
node := MenuTreeView.Items.AddObject(node, item.Caption, bact); |
| 154 |
DeleteUsedActionList(bact); |
| 155 |
// 鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 156 |
if (item.Action = nil) then begin |
| 157 |
// 鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申(鐃緒申鐃緒申鐃緒申) |
| 158 |
for j := 0 to skeys.Count - 1 do begin |
| 159 |
if (Pos('sub.' + mkeys[i], skeys[j]) = 1) then begin |
| 160 |
subValue := ini.ReadString(PopupMenuUtil.SECTIONS[idx], skeys[j], '-'); |
| 161 |
subItem := GetMenuItem(PopupMenuUtil.SECTIONS[idx], nil, FActionList, subValue); |
| 162 |
if (subItem <> nil) then begin |
| 163 |
bact := GetMenuAction(item, PopupMenuComboBox.ItemIndex); |
| 164 |
MenuTreeView.Items.AddChildObject( |
| 165 |
node, subItem.Caption, bact); |
| 166 |
DeleteUsedActionList(bact); |
| 167 |
subItem.Clear; |
| 168 |
end; |
| 169 |
end; |
| 170 |
end; |
| 171 |
end; |
| 172 |
item.Clear; |
| 173 |
end; |
| 174 |
end; |
| 175 |
finally |
| 176 |
skeys.Free; |
| 177 |
mkeys.Free; |
| 178 |
ini.free; |
| 179 |
end; |
| 180 |
end; |
| 181 |
|
| 182 |
end; |
| 183 |
//! 鐃緒申鐃?鐃緒申鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申 |
| 184 |
function TPopupMenuSettingDialog.GetMenuAction(var Item:TMenuItem; Idx:Integer): TBasicAction; |
| 185 |
var |
| 186 |
i : Integer; |
| 187 |
begin |
| 188 |
Result := nil; |
| 189 |
if (Item.Action <> nil) then begin |
| 190 |
Result := Item.Action; |
| 191 |
end else if (Item.Caption = '-') then begin |
| 192 |
Item.Caption := ToolBarUtil.SEPARATOR_TEXT; |
| 193 |
end else begin |
| 194 |
for i := 0 to FSpecialActionLists[Idx].Count - 1 do begin |
| 195 |
if Item.Name = TCustomAction(FSpecialActionLists[Idx].Objects[i]).Name then begin |
| 196 |
Result := TBasicAction(FSpecialActionLists[Idx].Objects[i]); |
| 197 |
break; |
| 198 |
end; |
| 199 |
end; |
| 200 |
end; |
| 201 |
end; |
| 202 |
//! 鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申 |
| 203 |
procedure TPopupMenuSettingDialog.FormCreate(Sender: TObject); |
| 204 |
begin |
| 205 |
PopupMenuComboBox.OnChange(nil); |
| 206 |
end; |
| 207 |
//! 鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申 |
| 208 |
procedure TPopupMenuSettingDialog.FormDestroy(Sender: TObject); |
| 209 |
var |
| 210 |
idx, i : Integer; |
| 211 |
begin |
| 212 |
ActionListBox.Items.Clear; |
| 213 |
// 鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 214 |
for i := 0 to Length(FSpecialActionLists) - 1 do begin |
| 215 |
if (FSpecialActionLists[i] <> nil) then begin |
| 216 |
for idx := FSpecialActionLists[i].Count - 1 downto 0 do begin |
| 217 |
TComponent(FSpecialActionLists[i].Objects[idx]).Free; |
| 218 |
end; |
| 219 |
FSpecialActionLists[i].Free; |
| 220 |
end; |
| 221 |
end; |
| 222 |
end; |
| 223 |
//! Up鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 224 |
procedure TPopupMenuSettingDialog.UpButtonClick(Sender: TObject); |
| 225 |
begin |
| 226 |
if (MenuTreeView.Selected <> nil) then begin |
| 227 |
if (MenuTreeView.Selected.GetPrevSibling <> nil) then begin |
| 228 |
MenuTreeView.Selected.MoveTo( |
| 229 |
MenuTreeView.Selected.GetPrevSibling, |
| 230 |
naInsert ); |
| 231 |
end; |
| 232 |
end; |
| 233 |
end; |
| 234 |
//! Down鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 235 |
procedure TPopupMenuSettingDialog.DownButtonClick(Sender: TObject); |
| 236 |
begin |
| 237 |
if (MenuTreeView.Selected <> nil) then begin |
| 238 |
if (MenuTreeView.Selected.GetNextSibling <> nil) then begin |
| 239 |
MenuTreeView.Selected.GetNextSibling |
| 240 |
.MoveTo( |
| 241 |
MenuTreeView.Selected, |
| 242 |
naInsert ); |
| 243 |
end; |
| 244 |
end; |
| 245 |
end; |
| 246 |
//! 鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 247 |
procedure TPopupMenuSettingDialog.RemoveButtonClick(Sender: TObject); |
| 248 |
var |
| 249 |
act : TCustomAction; |
| 250 |
idx : Integer; |
| 251 |
begin |
| 252 |
if (MenuTreeView.Selected <> nil) then begin |
| 253 |
if (TObject(MenuTreeView.Selected.Data) is TCustomAction) then begin |
| 254 |
act := TCustomAction(MenuTreeView.Selected.Data); |
| 255 |
// 鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?Action鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 256 |
for idx := 0 to FSpecialActionLists[PopupMenuComboBox.ItemIndex].Count - 1 do begin |
| 257 |
if ( act = TCustomAction(FSpecialActionLists[PopupMenuComboBox.ItemIndex].Objects[idx]) ) |
| 258 |
then begin |
| 259 |
ActionListBox.AddItem(act.Caption, act); |
| 260 |
break; |
| 261 |
end; |
| 262 |
end; |
| 263 |
end; |
| 264 |
MenuTreeView.Items.Delete(MenuTreeView.Selected); |
| 265 |
end; |
| 266 |
end; |
| 267 |
|
| 268 |
//! 鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃?鐃?鐃緒申鐃? |
| 269 |
procedure TPopupMenuSettingDialog.AddSepButtonClick(Sender: TObject); |
| 270 |
var |
| 271 |
item : TMenuItem; |
| 272 |
begin |
| 273 |
item := TMenuItem.Create(nil); |
| 274 |
item.Caption := '-'; |
| 275 |
AddMainMenu( item.Caption, |
| 276 |
GetMenuAction(item, PopupMenuComboBox.ItemIndex)); |
| 277 |
item.Free; |
| 278 |
end; |
| 279 |
//! 鐃緒申鐃?鐃緒申鐃?鐃?鐃緒申鐃?鐃?鐃?鐃緒申鐃?鐃緒申鐃?鐃?鐃緒申鐃?鐃?鐃緒申鐃? |
| 280 |
procedure TPopupMenuSettingDialog.MenuTreeViewDblClick(Sender: TObject); |
| 281 |
begin |
| 282 |
if (MenuTreeView.Selected <> nil) then begin |
| 283 |
// 鐃緒申鐃?鐃緒申鐃?鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?Action鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 284 |
if not (TObject(MenuTreeView.Selected.Data) is TBasicAction) then begin |
| 285 |
MenuTreeView.ReadOnly := False; |
| 286 |
MenuTreeView.Selected.EditText; |
| 287 |
end; |
| 288 |
end; |
| 289 |
end; |
| 290 |
//! 鐃緒申鐃?鐃緒申鐃?鐃?鐃緒申鐃?鐃緒申鐃?鐃緒申鐃緒申鐃?鐃?鐃緒申鐃? |
| 291 |
procedure TPopupMenuSettingDialog.MenuTreeViewEdited(Sender: TObject; |
| 292 |
Node: TTreeNode; var S: String); |
| 293 |
begin |
| 294 |
// 鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃? |
| 295 |
MenuTreeView.ReadOnly := True; |
| 296 |
end; |
| 297 |
//! 鐃緒申鐃?鐃緒申鐃?鐃?鐃緒申鐃?鐃緒申鐃?鐃?鐃?鐃緒申鐃? |
| 298 |
procedure TPopupMenuSettingDialog.MenuTreeViewEditing(Sender: TObject; |
| 299 |
Node: TTreeNode; var AllowEdit: Boolean); |
| 300 |
begin |
| 301 |
if (Node <> nil) then begin |
| 302 |
AllowEdit := not (TObject(Node.Data) is TBasicAction); |
| 303 |
end; |
| 304 |
end; |
| 305 |
//! 鐃緒申鐃?鐃緒申鐃?鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 306 |
procedure TPopupMenuSettingDialog.AddMainButtonClick(Sender: TObject); |
| 307 |
var |
| 308 |
idx, idx2 : Integer; |
| 309 |
act : TCustomAction; |
| 310 |
begin |
| 311 |
|
| 312 |
act := nil; |
| 313 |
for idx := 0 to ActionListBox.Count - 1 do begin |
| 314 |
if ( ActionListBox.Selected[idx] ) then begin |
| 315 |
act := TCustomAction(ActionListBox.Items.Objects[idx]); |
| 316 |
// 鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?Action鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 317 |
for idx2 := 0 to FSpecialActionLists[PopupMenuComboBox.ItemIndex].Count - 1 do begin |
| 318 |
if ( act = TCustomAction(FSpecialActionLists[PopupMenuComboBox.ItemIndex].Objects[idx2]) ) |
| 319 |
then begin |
| 320 |
ActionListBox.Items.Delete(idx); |
| 321 |
break; |
| 322 |
end; |
| 323 |
end; |
| 324 |
break; |
| 325 |
end; |
| 326 |
|
| 327 |
end; |
| 328 |
|
| 329 |
if ( act <> nil ) then begin |
| 330 |
AddMainMenu( act.Caption, TBasicAction(act) ); |
| 331 |
end; |
| 332 |
end; |
| 333 |
//! 鐃?鐃?鐃緒申鐃?鐃緒申鐃?鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 334 |
procedure TPopupMenuSettingDialog.AddSubButtonClick(Sender: TObject); |
| 335 |
var |
| 336 |
idx, idx2 : Integer; |
| 337 |
act : TCustomAction; |
| 338 |
node : TTreeNode; |
| 339 |
begin |
| 340 |
|
| 341 |
node := MenuTreeView.Selected; |
| 342 |
|
| 343 |
if (node <> nil) then begin |
| 344 |
if not (TObject(node.Data) is TBasicAction) then begin |
| 345 |
act := nil; |
| 346 |
for idx := 0 to ActionListBox.Count - 1 do begin |
| 347 |
if ( ActionListBox.Selected[idx] ) then begin |
| 348 |
act := TCustomAction(ActionListBox.Items.Objects[idx]); |
| 349 |
// 鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?Action鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 350 |
for idx2 := 0 to FSpecialActionLists[PopupMenuComboBox.ItemIndex].Count - 1 do begin |
| 351 |
if ( act = TCustomAction(FSpecialActionLists[PopupMenuComboBox.ItemIndex].Objects[idx2]) ) |
| 352 |
then begin |
| 353 |
ActionListBox.Items.Delete(idx); |
| 354 |
break; |
| 355 |
end; |
| 356 |
end; |
| 357 |
break; |
| 358 |
end; |
| 359 |
end; |
| 360 |
if ( act <> nil ) then begin |
| 361 |
MenuTreeView.Items.AddChildObject( |
| 362 |
node, act.Caption, act); |
| 363 |
end; |
| 364 |
end; |
| 365 |
end; |
| 366 |
end; |
| 367 |
//! 鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 368 |
procedure TPopupMenuSettingDialog.LabelButtonClick(Sender: TObject); |
| 369 |
begin |
| 370 |
if (MenuTreeView.Selected <> nil) then begin |
| 371 |
// 鐃?鐃?鐃緒申鐃?鐃緒申鐃?鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 372 |
if ( MenuTreeView.Selected.Parent <> nil) then begin |
| 373 |
Exit; |
| 374 |
end; |
| 375 |
end; |
| 376 |
AddMainMenu('鐃?鐃?鐃緒申鐃?鐃緒申', TBasicAction(nil)); |
| 377 |
end; |
| 378 |
//! 鐃緒申鐃?鐃緒申鐃?鐃?鐃緒申鐃?鐃緒申鐃?鐃緒申鐃緒申鐃?鐃緒申鐃?鐃緒申鐃緒申 |
| 379 |
procedure TPopupMenuSettingDialog.AddMainMenu(const Caption: String; Action: TBasicAction); |
| 380 |
var |
| 381 |
node : TTreeNode; |
| 382 |
begin |
| 383 |
node := nil; |
| 384 |
|
| 385 |
if (MenuTreeView.Selected <> nil) then begin |
| 386 |
// 鐃?鐃?鐃緒申鐃?鐃緒申鐃? |
| 387 |
if ( MenuTreeView.Selected.Parent <> nil) then begin |
| 388 |
// 鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申 |
| 389 |
if (MenuTreeView.Selected.getNextSibling <> nil) then begin |
| 390 |
node := MenuTreeView.Selected.getNextSibling; |
| 391 |
end else begin |
| 392 |
node := MenuTreeView.Selected; |
| 393 |
end; |
| 394 |
end else begin |
| 395 |
node := MenuTreeView.Selected.getNextSibling; |
| 396 |
end; |
| 397 |
end; |
| 398 |
// node 鐃緒申nil 鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 399 |
if ( node <> nil ) then begin |
| 400 |
MenuTreeView.Items.InsertObject(node, |
| 401 |
Caption, Action); |
| 402 |
end else begin |
| 403 |
MenuTreeView.Items.AddObject(node, |
| 404 |
Caption, Action); |
| 405 |
end; |
| 406 |
end; |
| 407 |
//! 鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 408 |
procedure TPopupMenuSettingDialog.DeleteUsedActionList(Action: TBasicAction); |
| 409 |
var |
| 410 |
idx, idx2 : Integer; |
| 411 |
act : TCustomAction; |
| 412 |
begin |
| 413 |
if (Action is TCustomAction) then begin |
| 414 |
act := TCustomAction(Action); |
| 415 |
// 鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?Action鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 416 |
for idx2 := 0 to FSpecialActionLists[PopupMenuComboBox.ItemIndex].Count - 1 do begin |
| 417 |
if ( act = TCustomAction(FSpecialActionLists[PopupMenuComboBox.ItemIndex].Objects[idx2]) ) |
| 418 |
then begin |
| 419 |
for idx := 0 to ActionListBox.Count - 1 do begin |
| 420 |
if ( act = TCustomAction(ActionListBox.Items.Objects[idx]) ) |
| 421 |
then begin |
| 422 |
ActionListBox.Items.Delete(idx); |
| 423 |
break; |
| 424 |
end; |
| 425 |
end; |
| 426 |
break; |
| 427 |
end; |
| 428 |
end; |
| 429 |
end; |
| 430 |
end; |
| 431 |
|
| 432 |
procedure TPopupMenuSettingDialog.MenuTreeViewChange(Sender: TObject; |
| 433 |
Node: TTreeNode); |
| 434 |
begin |
| 435 |
if (Node <> nil) then begin |
| 436 |
if (Node.Data = nil) and (Node.Text <> ToolBarUtil.SEPARATOR_TEXT) then begin |
| 437 |
AddSubButton.Enabled := True; |
| 438 |
end else begin |
| 439 |
AddSubButton.Enabled := False; |
| 440 |
end; |
| 441 |
end else begin |
| 442 |
AddSubButton.Enabled := False; |
| 443 |
|
| 444 |
end; |
| 445 |
end; |
| 446 |
function TPopupMenuSettingDialog.GetIniString(Node: TTreeNode; Parent: String; Idx: Integer): String; |
| 447 |
begin |
| 448 |
Result := ''; |
| 449 |
if ( Node.Parent <> nil ) then begin |
| 450 |
Result := Format('sub.%s.%2.2d', [Parent, idx + 1]); |
| 451 |
end else begin |
| 452 |
Result := Format('main.%2.2d', [idx + 1]); |
| 453 |
end; |
| 454 |
end; |
| 455 |
function TPopupMenuSettingDialog.GetIniValueString(Node: TTreeNode): String; |
| 456 |
begin |
| 457 |
Result := ''; |
| 458 |
if (Node.Data = nil) then begin |
| 459 |
if (Node.Text <> ToolBarUtil.SEPARATOR_TEXT) then begin |
| 460 |
Result := '"' + Node.Text; |
| 461 |
end else begin |
| 462 |
Result := '-'; |
| 463 |
end; |
| 464 |
end else begin |
| 465 |
Result := TBasicAction(Node.Data).Name; |
| 466 |
end; |
| 467 |
end; |
| 468 |
//! 鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 469 |
procedure TPopupMenuSettingDialog.ApplyButtonClick(Sender: TObject); |
| 470 |
var |
| 471 |
ini : TMemIniFile; |
| 472 |
sec, key, subkey : String; |
| 473 |
node : TTreeNode; |
| 474 |
idx, mainIdx, subIdx : Integer; |
| 475 |
begin |
| 476 |
ini := TMemIniFile.Create(GikoSys.Setting.GetConfigDir + PopupMenuUtil.INI_FILENAME); |
| 477 |
try |
| 478 |
sec := PopupMenuUtil.SECTIONS[PopupMenuComboBox.ItemIndex]; |
| 479 |
// 鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 480 |
ini.EraseSection(sec); |
| 481 |
mainIdx := 0; |
| 482 |
subIdx := 0; |
| 483 |
|
| 484 |
node := MenuTreeView.Items.GetFirstNode; |
| 485 |
while node <> nil do begin |
| 486 |
if (node.Parent = nil) then begin |
| 487 |
subIdx := 0; |
| 488 |
key := GetIniString(node, key, mainIdx); |
| 489 |
ini.WriteString(sec, key, GetIniValueString(node)); |
| 490 |
Inc(mainIdx); |
| 491 |
end else begin |
| 492 |
subkey := GetIniString(node, key, subIdx); |
| 493 |
ini.WriteString(sec, subkey, GetIniValueString(node)); |
| 494 |
Inc(subIdx); |
| 495 |
end; |
| 496 |
node := node.GetNext; |
| 497 |
end; |
| 498 |
ini.UpdateFile; |
| 499 |
finally |
| 500 |
ini.Free; |
| 501 |
end; |
| 502 |
end; |
| 503 |
end. |