shortcuts, manage conflicts

This commit is contained in:
Basile Burg 2015-10-17 00:16:55 +02:00
parent 1e1fd2a97d
commit e2a763708b
3 changed files with 36 additions and 18 deletions

View File

@ -460,9 +460,10 @@ end;
procedure TCEEditorOptions.applyChangeToEditor(anEditor: TCESynMemo); procedure TCEEditorOptions.applyChangeToEditor(anEditor: TCESynMemo);
var var
i, j: Integer; i, j, k: Integer;
shc: TCEPersistentShortcut; shc: TCEPersistentShortcut;
kst: TSynEditKeyStroke; kst: TSynEditKeyStroke;
dup: boolean;
begin begin
anEditor.D2Highlighter.Assign(D2Syn); anEditor.D2Highlighter.Assign(D2Syn);
anEditor.TxtHighlighter.Assign(TxtSyn); anEditor.TxtHighlighter.Assign(TxtSyn);
@ -491,19 +492,21 @@ begin
kst := anEditor.Keystrokes.Items[i]; kst := anEditor.Keystrokes.Items[i];
for j := 0 to fShortCuts.Count-1 do for j := 0 to fShortCuts.Count-1 do
begin begin
dup := false;
shc := TCEPersistentShortcut(fShortCuts.Items[j]); shc := TCEPersistentShortcut(fShortCuts.Items[j]);
if shc.actionName = EditorCommandToCodeString(kst.Command) then if shc.actionName = EditorCommandToCodeString(kst.Command) then
begin begin
try try
// if anEditor.Keystrokes.FindShortcut(); for k := 0 to i-1 do
// try to find, if not match cur action, set to 0 if anEditor.Keystrokes.Items[k].shortCut = shc.shortcut then
kst.ShortCut := shc.shortcut; if shc.shortCut <> 0 then
dup := true;
if not dup then
kst.shortCut := shc.shortcut;
except except
kst.ShortCut := 0; kst.shortCut := 0;
shc.shortcut := 0; shc.shortcut := 0;
// TODO-cimprovement: manage shortcuts conflicts // in case of conflict synedit raises an exception.
// either here or in the shortcut editor.
// by default and if a conflict exists synedit will raise an exception here.
end; end;
break; break;
end; end;

View File

@ -20,7 +20,7 @@ object CEShortcutEditor: TCEShortcutEditor
TabOrder = 0 TabOrder = 0
object fltItems: TTreeFilterEdit object fltItems: TTreeFilterEdit
Left = 2 Left = 2
Height = 23 Height = 20
Top = 2 Top = 2
Width = 420 Width = 420
ButtonWidth = 28 ButtonWidth = 28
@ -33,14 +33,14 @@ object CEShortcutEditor: TCEShortcutEditor
end end
object tree: TTreeView object tree: TTreeView
Left = 2 Left = 2
Height = 404 Height = 407
Top = 29 Top = 26
Width = 420 Width = 420
Align = alClient Align = alClient
AutoExpand = True AutoExpand = True
BorderSpacing.Top = 2 BorderSpacing.Top = 2
BorderSpacing.Around = 2 BorderSpacing.Around = 2
DefaultItemHeight = 18 DefaultItemHeight = 16
HideSelection = False HideSelection = False
ReadOnly = True ReadOnly = True
ScrollBars = ssAutoBoth ScrollBars = ssAutoBoth

View File

@ -7,7 +7,8 @@ interface
uses uses
Classes, SysUtils, FileUtil, TreeFilterEdit, Forms, Controls, Menus, Graphics, Classes, SysUtils, FileUtil, TreeFilterEdit, Forms, Controls, Menus, Graphics,
ExtCtrls, LCLProc, ComCtrls, StdCtrls, Buttons, LCLType, ExtCtrls, LCLProc, ComCtrls, StdCtrls, Buttons, LCLType,
ce_sharedres, ce_observer, ce_interfaces, ce_common, ce_writableComponent; ce_sharedres, ce_observer, ce_interfaces, ce_common, ce_writableComponent,
ce_dialogs;
type type
@ -39,7 +40,7 @@ type
procedure assign(aValue: TPersistent); override; procedure assign(aValue: TPersistent); override;
// //
function findIdentifier(const identifier: string): boolean; function findIdentifier(const identifier: string): boolean;
function findShortcut(aShortcut: Word): boolean; function findShortcut(aShortcut: Word): TShortcutItem;
// //
property count: Integer read getCount; property count: Integer read getCount;
property item[index: Integer]: TShortcutItem read getItem; default; property item[index: Integer]: TShortcutItem read getItem; default;
@ -158,14 +159,14 @@ begin
exit(true); exit(true);
end; end;
function TShortCutCollection.findShortcut(aShortcut: Word): boolean; function TShortCutCollection.findShortcut(aShortcut: Word): TShortcutItem;
var var
i: Integer; i: Integer;
begin begin
result := false; result := nil;
for i := 0 to count-1 do for i := 0 to count-1 do
if item[i].data = aShortcut then if item[i].data = aShortcut then
exit(true); exit(item[i]);
end; end;
{$ENDREGION} {$ENDREGION}
@ -281,7 +282,12 @@ end;
procedure TCEShortcutEditor.LabeledEdit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); procedure TCEShortcutEditor.LabeledEdit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var var
i: integer;
sh: TShortCut; sh: TShortCut;
sht: string;
dup: TShortcutItem = nil;
const
msg = '"%s" is already assigned in the same category by "%s". The new shortcut will be ignored';
begin begin
if tree.Selected = nil then exit; if tree.Selected = nil then exit;
if tree.Selected.Level = 0 then exit; if tree.Selected.Level = 0 then exit;
@ -292,7 +298,16 @@ begin
else else
begin begin
sh := Shortcut(Key, Shift); sh := Shortcut(Key, Shift);
if TShortcutItem(tree.Selected.Data).data <> sh then sht := shortCutToText(sh);
if sht = '' then
exit;
for i:= 0 to tree.Selected.Parent.Count-1 do
if i <> tree.Selected.Index then
if TShortcutItem(tree.Selected.Parent.Items[i].Data).data = sh then
dup := TShortcutItem(tree.Selected.Parent.Items[i].Data);
if assigned(dup) then
dlgOkInfo(format(msg,[ShortCutToText(sh), dup.identifier]))
else if TShortcutItem(tree.Selected.Data).data <> sh then
begin begin
TShortcutItem(tree.Selected.Data).data := sh; TShortcutItem(tree.Selected.Data).data := sh;
fHasChanged := true; fHasChanged := true;