implemented ide command scopes in keymapping, not functional yet

git-svn-id: trunk@7691 -
This commit is contained in:
mattias 2005-09-14 00:17:45 +00:00
parent defdd14239
commit c727146b87
3 changed files with 133 additions and 113 deletions

View File

@ -377,7 +377,7 @@ type
): boolean; ): boolean;
public public
constructor Create(TheOwner: TComponent); override; constructor Create(TheOwner: TComponent); override;
KeyCommandRelationList:TKeyCommandRelationList; KeyCommandRelationList: TKeyCommandRelationList;
KeyIndex:integer; KeyIndex:integer;
end; end;
@ -1778,7 +1778,7 @@ begin
AddAttributesAndKey; AddAttributesAndKey;
end; end;
function KeyAndShiftStateToEditorKeyString(Key: TIDEShortCut):AnsiString; function KeyAndShiftStateToEditorKeyString(Key: TIDEShortCut): String;
begin begin
Result := KeyAndShiftStateToEditorKeyString(Key.Key1, Key.Shift1); Result := KeyAndShiftStateToEditorKeyString(Key.Key1, Key.Shift1);
if (Key.Key2<>VK_UNKNOWN) then if (Key.Key2<>VK_UNKNOWN) then
@ -2058,13 +2058,15 @@ end;
function TKeyMappingEditForm.ResolveConflicts(Key: TIDEShortCut; function TKeyMappingEditForm.ResolveConflicts(Key: TIDEShortCut;
{$IFDEF UseIDEScopes}Scope: TIDECommandScope{$ELSE}Areas: TCommandAreas{$ENDIF} {$IFDEF UseIDEScopes}Scope: TIDECommandScope{$ELSE}Areas: TCommandAreas{$ENDIF}
): boolean; ): boolean;
type
TConflictType = (ctNone,ctConflictKeyA,ctConflictKeyB);
var var
ConflictRelation: TKeyCommandRelation; ConflictRelation: TKeyCommandRelation;
ConflictName: String; ConflictName: String;
CurRelation: TKeyCommandRelation; CurRelation: TKeyCommandRelation;
CurName: String; CurName: String;
j: integer; j: integer;
conflictType: integer; conflictType: TConflictType;
begin begin
// search for conflict // search for conflict
CurRelation:=KeyCommandRelationList.Relations[KeyIndex]; CurRelation:=KeyCommandRelationList.Relations[KeyIndex];
@ -2073,92 +2075,54 @@ begin
Result:=true; Result:=true;
exit; exit;
end; end;
//Try to find a relation that conflicts //Try to find an IDE command that conflicts
for j:=0 to KeyCommandRelationList.RelationCount-1 do for j:=0 to KeyCommandRelationList.RelationCount-1 do begin
with KeyCommandRelationList.Relations[j] do conflictType:=ctNone;
ConflictRelation:=KeyCommandRelationList.Relations[j];
with ConflictRelation do
begin begin
if (j=KeyIndex) or (Category.Areas*Areas=[]) then continue; if (j=KeyIndex) then continue;
{$IFDEF UseIDEScopes}
{$WARN TODO: TKeyMappingEditForm.ResolveConflicts}
{$ELSE}
if (Category.Areas*Areas=[]) then continue;
{$ENDIF}
if (Key.Key1=KeyA.Key1) and (Key.Shift1=KeyA.Shift1) then if ((Key.Key1=KeyA.Key1) and (Key.Shift1=KeyA.Shift1))
if (Key.Key2=KeyA.Key2) and (Key.Shift2=KeyA.Shift2) then and (((Key.Key2=KeyA.Key2) and (Key.Shift2=KeyA.Shift2))
begin or (Key.Key2=VK_UNKNOWN) or (KeyA.Key2=VK_UNKNOWN))
ConflictRelation:=KeyCommandRelationList.Relations[j]; then begin
conflictType:=1; // Key = KeyA of this relation conflictType:=ctConflictKeyA; // KeyA bites
break; end
end else if ((Key.Key1=KeyB.Key1) and (Key.Shift1=KeyB.Shift1))
else begin and (((Key.Key2=KeyB.Key2) and (Key.Shift2=KeyB.Shift2))
if (Key.Key2<>VK_UNKNOWN) and (KeyA.Key2=VK_UNKNOWN) then or (Key.Key2<>VK_UNKNOWN) or (KeyB.Key2=VK_UNKNOWN))
begin then begin
ConflictRelation:=KeyCommandRelationList.Relations[j]; conflictType:=ctConflictKeyB; // KeyB bites
conflictType:=3; // Key is two-key combo, while KeyA is not end;
break;
end;
if (Key.Key2=VK_UNKNOWN) and (KeyA.Key2<>VK_UNKNOWN) then
begin
ConflictRelation:=KeyCommandRelationList.Relations[j];
conflictType:=3; // KeyA is two-key combo, while Key is not
break;
end;
end
else if (Key.Key1=KeyB.Key1) and (Key.Shift1=KeyB.Shift1) then
if (Key.Key2=KeyB.Key2) and (Key.Shift2=KeyB.Shift2) then
begin
ConflictRelation:=KeyCommandRelationList.Relations[j];
conflictType:=2; // Key = KeyB of this relation
break;
end
else begin
if (Key.Key2<>VK_UNKNOWN) and (KeyB.Key2=VK_UNKNOWN) then
begin
ConflictRelation:=KeyCommandRelationList.Relations[j];
conflictType:=4; // Key is two-key combo, while KeyB is not
break;
end;
if (Key.Key2=VK_UNKNOWN) and (KeyB.Key2<>VK_UNKNOWN) then
begin
ConflictRelation:=KeyCommandRelationList.Relations[j];
conflictType:=4; // KeyB is two-key combo, while Key is not
break;
end;
end
else
conflictType:=0;
end; end;
if (conflictType<>0) then if (conflictType<>ctNone) then begin
begin CurName:=CurRelation.GetCategoryAndName;
CurName:=CurRelation.GetCategoryAndName; ConflictName:=ConflictRelation.GetCategoryAndName;
ConflictName:=ConflictRelation.GetCategoryAndName; if conflictType=ctConflictKeyA then
case conflictType of ConflictName:=ConflictName
1,2:begin +' ('+KeyAndShiftStateToEditorKeyString(ConflictRelation.KeyA)
if MessageDlg('Conflict found', else
'The key '+KeyAndShiftStateToEditorKeyString(Key)+#13+ ConflictName:=ConflictName
'is already assigned to '+ConflictName+'.'#13+#13+ +' ('+KeyAndShiftStateToEditorKeyString(ConflictRelation.KeyB);
'Remove the old assignment and assign the key to the new function'#13+ if MessageDlg('Conflict found',
CurName+'?', mtConfirmation,[mbOk,mbCancel],0) <> mrOk then 'The key '+KeyAndShiftStateToEditorKeyString(Key)+#13+
begin 'is already assigned to '+ConflictName+'.'#13+#13+
Result:=false; 'Remove the old assignment and assign the key to the new function'#13+
exit; CurName+'?', mtConfirmation,[mbOk,mbCancel],0) <> mrOk then
end; begin
Result:=false;
exit;
end; end;
3,4:begin if (conflictType=ctConflictKeyA) then
if (conflictType=1) then ConflictRelation.KeyA:=ConflictRelation.KeyB;
ConflictName:=ConflictName+' ('+KeyAndShiftStateToEditorKeyString(ConflictRelation.KeyA) ConflictRelation.ClearKeyB;
else end;
ConflictName:=ConflictName+' ('+KeyAndShiftStateToEditorKeyString(ConflictRelation.KeyB);
if MessageDlg('Conflict found',
'The key '+KeyAndShiftStateToEditorKeyString(Key)+#13+
'conflicts with '+ConflictName+')'+#13+
'Remove the old assignment and assign the key to the new function'#13+
CurName+'?', mtConfirmation,[mbOk,mbCancel],0) <> mrOk then
begin
Result:=false;
exit;
end;
end;
end; // case
if (conflictType=1) then
ConflictRelation.KeyA:=ConflictRelation.KeyB;
ConflictRelation.ClearKeyB;
end; end;
Result:=true; Result:=true;

View File

@ -61,30 +61,38 @@ const
type type
TIDECommandKeys = class; TIDECommandKeys = class;
TIDECommandCategory = class;
{ TIDECommandScope
A TIDECommandScope defines a set of IDE windows that will share the same
IDE commands. An IDE command can be valid in several scopes at the same
time. }
{ TIDECommandScope } { TIDECommandScope }
{ A TIDECommandScope defines a set of IDE windows that will share the same
IDE commands. }
TIDECommandScope = class(TPersistent) TIDECommandScope = class(TPersistent)
private private
FName: string; FName: string;
FIDEWindows: TFPList; FIDEWindows: TFPList;// list of TCustomForm
FCommands: TFPList; FIDEWindowClasses: TFPList;// list of TCustomFormClass
function GetCommands(Index: integer): TIDECommandKeys; FCategories: TFPList;
function GetCategories(Index: integer): TIDECommandCategory;
function GetIDEWindowClasses(Index: integer): TCustomFormClass;
function GetIDEWindows(Index: integer): TCustomForm; function GetIDEWindows(Index: integer): TCustomForm;
public public
constructor Create; constructor Create;
destructor Destroy; override; destructor Destroy; override;
procedure AddWindow(AnWindow: TCustomForm); procedure AddWindow(AWindow: TCustomForm);
procedure RemoveWindow(AWindow: TCustomForm);
function IDEWindowCount: integer; function IDEWindowCount: integer;
procedure AddCommand(ACommand: TIDECommandKeys); function IDEWindowClassCount: integer;
function CommandCount: integer; function CategoryCount: integer;
function HasIDEWindow(AnWindow: TCustomForm): boolean; function HasIDEWindow(AnWindow: TCustomForm): boolean;
public public
property Name: string read FName; property Name: string read FName;
property IDEWindows[Index: integer]: TCustomForm read GetIDEWindows; property IDEWindows[Index: integer]: TCustomForm read GetIDEWindows;
property Commands[Index: integer]: TIDECommandKeys read GetCommands; property IDEWindowClasses[Index: integer]: TCustomFormClass read GetIDEWindowClasses;
property Categories[Index: integer]: TIDECommandCategory read GetCategories;
end; end;
{ TIDECommandScopes } { TIDECommandScopes }
@ -117,26 +125,31 @@ type
Shift2: TShiftState; Shift2: TShiftState;
end; end;
{ TIDECommandCategory } { TIDECommandCategory
{ TIDECommandCategory is used to divide the commands in handy packets } TIDECommandCategory is used to divide the commands in handy packets }
TIDECommandCategory = class(TList) TIDECommandCategory = class(TList)
protected protected
{$IFDEF UseIDEScopes}
FScope: TIDECommandScope;
{$ELSE}
FAreas: TCommandAreas;
{$ENDIF}
FDescription: string; FDescription: string;
FName: string; FName: string;
FParent: TIDECommandCategory; FParent: TIDECommandCategory;
{$IFDEF UseIDEScopes}
FScope: TIDECommandScope;
procedure SetScope(const AValue: TIDECommandScope);
{$ELSE}
FAreas: TCommandAreas;
{$ENDIF}
public
{$IFDEF UseIDEScopes}
destructor Destroy; override;
{$ENDIF}
public public
property Name: string read FName; property Name: string read FName;
property Description: string read FDescription; property Description: string read FDescription;
property Parent: TIDECommandCategory read FParent; property Parent: TIDECommandCategory read FParent;
procedure Delete(Index: Integer); virtual; procedure Delete(Index: Integer); virtual;
{$IFDEF UseIDEScopes} {$IFDEF UseIDEScopes}
property Scope: TIDECommandScope read FScope write FScope; property Scope: TIDECommandScope read FScope write SetScope;
{$ELSE} {$ELSE}
property Areas: TCommandAreas read FAreas; property Areas: TCommandAreas read FAreas;
{$ENDIF} {$ENDIF}
@ -417,6 +430,24 @@ end;
{ TIDECommandCategory } { TIDECommandCategory }
{$IFDEF UseIDEScopes}
procedure TIDECommandCategory.SetScope(const AValue: TIDECommandScope);
begin
if FScope=AValue then exit;
if FScope<>nil then
FScope.FCategories.Remove(Self);
FScope:=AValue;
if FScope<>nil then
FScope.FCategories.Add(Self);
end;
destructor TIDECommandCategory.Destroy;
begin
Scope:=nil;
inherited Destroy;
end;
{$ENDIF}
procedure TIDECommandCategory.Delete(Index: Integer); procedure TIDECommandCategory.Delete(Index: Integer);
begin begin
inherited Delete(Index); inherited Delete(Index);
@ -429,27 +460,47 @@ begin
Result:=TCustomForm(FIDEWindows[Index]); Result:=TCustomForm(FIDEWindows[Index]);
end; end;
function TIDECommandScope.GetCommands(Index: integer): TIDECommandKeys; function TIDECommandScope.GetCategories(Index: integer): TIDECommandCategory;
begin begin
Result:=TIDECommandKeys(FCommands[Index]); Result:=TIDECommandCategory(FCategories[Index]);
end;
function TIDECommandScope.GetIDEWindowClasses(Index: integer): TCustomFormClass;
begin
Result:=TCustomFormClass(FIDEWindowClasses[Index]);
end; end;
constructor TIDECommandScope.Create; constructor TIDECommandScope.Create;
begin begin
FIDEWindows:=TFPList.Create; FIDEWindows:=TFPList.Create;
FCommands:=TFPList.Create; FIDEWindowClasses:=TFPList.Create;
FCategories:=TFPList.Create;
end; end;
destructor TIDECommandScope.Destroy; destructor TIDECommandScope.Destroy;
{$IFDEF UseIDEScopes}
var
i: Integer;
{$ENDIF}
begin begin
{$IFDEF UseIDEScopes}
for i:=FCategories.Count-1 downto 0 do
Categories[i].Scope:=nil;
{$ENDIF}
FreeAndNil(FIDEWindowClasses);
FreeAndNil(FIDEWindows); FreeAndNil(FIDEWindows);
FreeAndNil(FCommands); FreeAndNil(FCategories);
inherited Destroy; inherited Destroy;
end; end;
procedure TIDECommandScope.AddWindow(AnWindow: TCustomForm); procedure TIDECommandScope.AddWindow(AWindow: TCustomForm);
begin begin
FIDEWindows.Add(AnWindow); FIDEWindows.Add(AWindow);
end;
procedure TIDECommandScope.RemoveWindow(AWindow: TCustomForm);
begin
FIDEWindows.Remove(AWindow);
end; end;
function TIDECommandScope.IDEWindowCount: integer; function TIDECommandScope.IDEWindowCount: integer;
@ -457,14 +508,14 @@ begin
Result:=FIDEWindows.Count; Result:=FIDEWindows.Count;
end; end;
procedure TIDECommandScope.AddCommand(ACommand: TIDECommandKeys); function TIDECommandScope.IDEWindowClassCount: integer;
begin begin
FCommands.Add(ACommand); Result:=FIDEWindowClasses.Count;
end; end;
function TIDECommandScope.CommandCount: integer; function TIDECommandScope.CategoryCount: integer;
begin begin
Result:=FCommands.Count; Result:=FCategories.Count;
end; end;
function TIDECommandScope.HasIDEWindow(AnWindow: TCustomForm): boolean; function TIDECommandScope.HasIDEWindow(AnWindow: TCustomForm): boolean;
@ -472,7 +523,11 @@ var
i: Integer; i: Integer;
begin begin
for i:=0 to FIDEWindows.Count-1 do for i:=0 to FIDEWindows.Count-1 do
if TCustomForm(FIDEWindows[i])=AnWindow then exit(true); if TCustomForm(FIDEWindows[i])=AnWindow then
exit(true);
for i:=0 to FIDEWindowClasses.Count-1 do
if AnWindow.InheritsFrom(TCustomFormClass(FIDEWindowClasses[i])) then
exit(true);
Result:=false; Result:=false;
end; end;

View File

@ -551,6 +551,7 @@ type
default wsNormal; default wsNormal;
end; end;
TCustomFormClass = class of TCustomForm;
{ TForm } { TForm }