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

View File

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

View File

@ -7,7 +7,8 @@ interface
uses
Classes, SysUtils, FileUtil, TreeFilterEdit, Forms, Controls, Menus, Graphics,
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
@ -39,7 +40,7 @@ type
procedure assign(aValue: TPersistent); override;
//
function findIdentifier(const identifier: string): boolean;
function findShortcut(aShortcut: Word): boolean;
function findShortcut(aShortcut: Word): TShortcutItem;
//
property count: Integer read getCount;
property item[index: Integer]: TShortcutItem read getItem; default;
@ -158,14 +159,14 @@ begin
exit(true);
end;
function TShortCutCollection.findShortcut(aShortcut: Word): boolean;
function TShortCutCollection.findShortcut(aShortcut: Word): TShortcutItem;
var
i: Integer;
begin
result := false;
result := nil;
for i := 0 to count-1 do
if item[i].data = aShortcut then
exit(true);
exit(item[i]);
end;
{$ENDREGION}
@ -281,7 +282,12 @@ end;
procedure TCEShortcutEditor.LabeledEdit1KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var
i: integer;
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
if tree.Selected = nil then exit;
if tree.Selected.Level = 0 then exit;
@ -292,7 +298,16 @@ begin
else
begin
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
TShortcutItem(tree.Selected.Data).data := sh;
fHasChanged := true;