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

View File

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

View File

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