mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-08 02:19:57 +02:00
implemented replacing keys in editor options grab keys
git-svn-id: trunk@5827 -
This commit is contained in:
parent
1a019cd539
commit
c1484cc371
@ -26,10 +26,6 @@
|
||||
The editor options are stored in XML format in the
|
||||
~/.lazarus/editoroptions.xml file.
|
||||
Currently only for TSynEdit.
|
||||
|
||||
ToDo:
|
||||
- key mapping schemes
|
||||
- nicer TColorButton
|
||||
}
|
||||
unit EditorOptions;
|
||||
|
||||
@ -421,14 +417,14 @@ type
|
||||
// key mapping
|
||||
procedure KeyMappingChooseSchemeButtonClick(Sender: TObject);
|
||||
procedure KeyMappingTreeViewMouseUp(Sender:TObject;
|
||||
Button:TMouseButton; Shift:TShiftState; X,Y:integer);
|
||||
Button:TMouseButton; Shift:TShiftState; X,Y:integer);
|
||||
procedure KeyMappingConsistencyCheckButtonClick(Sender: TObject);
|
||||
|
||||
// color
|
||||
procedure ColorElementListBoxMouseUp(Sender:TObject;
|
||||
Button:TMouseButton; Shift:TShiftState; X,Y:integer);
|
||||
Button:TMouseButton; Shift:TShiftState; X,Y:integer);
|
||||
procedure ColorPreviewMouseUp(Sender:TObject;
|
||||
Button:TMouseButton; Shift:TShiftState; X,Y:integer);
|
||||
Button:TMouseButton; Shift:TShiftState; X,Y:integer);
|
||||
procedure OnSpecialLineColors(Sender: TObject; Line: integer;
|
||||
var Special: boolean; var FG, BG: TColor);
|
||||
procedure SetAttributeToDefaultButtonClick(Sender: TObject);
|
||||
@ -2777,7 +2773,7 @@ begin
|
||||
i:=EditingKeyMap.IndexOf(ARelation);
|
||||
if (i>=0)
|
||||
and (ShowKeyMappingEditForm(i,EditingKeyMap)=mrOk) then begin
|
||||
ANode.Text:=KeyMappingRelationToString(ARelation);
|
||||
FillKeyMappingTreeView;
|
||||
for i:=Low(PreviewEdits) to High(PreviewEdits) do
|
||||
if PreviewEdits[i]<>nil then
|
||||
EditingKeyMap.AssignTo(PreviewEdits[i].KeyStrokes,[caSourceEditor]);
|
||||
@ -3131,20 +3127,35 @@ var i, j: integer;
|
||||
begin
|
||||
with KeyMappingTreeView do begin
|
||||
BeginUpdate;
|
||||
Items.Clear;
|
||||
for i:=0 to EditingKeyMap.CategoryCount-1 do begin
|
||||
CurCategory:=EditingKeyMap.Categories[i];
|
||||
NewCategoryNode:=Items.AddObject(nil,CurCategory.Description,CurCategory);
|
||||
if Items.TopLvlCount>i then begin
|
||||
NewCategoryNode:=Items.TopLvlItems[i];
|
||||
NewCategoryNode.Text:=CurCategory.Description;
|
||||
NewCategoryNode.Data:=CurCategory;
|
||||
end else begin
|
||||
NewCategoryNode:=Items.AddObject(nil,CurCategory.Description,CurCategory);
|
||||
end;
|
||||
NewCategoryNode.ImageIndex:=0;
|
||||
NewCategoryNode.SelectedIndex:=NewCategoryNode.ImageIndex;
|
||||
for j:=0 to CurCategory.Count-1 do begin
|
||||
CurKeyRelation:=TKeyCommandRelation(CurCategory[j]);
|
||||
NewKeyNode:=Items.AddChildObject(NewCategoryNode,
|
||||
KeyMappingRelationToString(CurKeyRelation),CurKeyRelation);
|
||||
if NewCategoryNode.Count>j then begin
|
||||
NewKeyNode:=NewCategoryNode.Items[j];
|
||||
NewKeyNode.Text:=KeyMappingRelationToString(CurKeyRelation);
|
||||
NewKeyNode.Data:=CurKeyRelation;
|
||||
end else begin
|
||||
NewKeyNode:=Items.AddChildObject(NewCategoryNode,
|
||||
KeyMappingRelationToString(CurKeyRelation),CurKeyRelation);
|
||||
end;
|
||||
NewKeyNode.ImageIndex:=1;
|
||||
NewKeyNode.SelectedIndex:=NewKeyNode.ImageIndex;
|
||||
end;
|
||||
while NewCategoryNode.Count>EditingKeyMap.CategoryCount do
|
||||
NewCategoryNode[NewCategoryNode.Count-1].Delete;
|
||||
end;
|
||||
while Items.TopLvlCount>EditingKeyMap.CategoryCount do
|
||||
Items.TopLvlItems[Items.TopLvlCount-1].Delete;
|
||||
EndUpdate;
|
||||
end;
|
||||
end;
|
||||
|
@ -22,8 +22,9 @@
|
||||
}
|
||||
|
||||
const
|
||||
DefaultFPCSrcDirs: array[1..13] of string = (
|
||||
DefaultFPCSrcDirs: array[1..14] of string = (
|
||||
'/usr/share/fpcsrc',
|
||||
'/usr/local/share/fpcsrc',
|
||||
'/usr/fpcsrc',
|
||||
'/usr/share/fpc/src',
|
||||
'/usr/fpc/src',
|
||||
@ -34,9 +35,8 @@ const
|
||||
'/usr/local/lib/fpc/src',
|
||||
'/vol/fpc/src',
|
||||
'/vol/lib/fpc/src',
|
||||
// here some extra paths. These paths are also created by the fpc rpm
|
||||
// creation script and do not contain all sources. So, they are searched
|
||||
// last.
|
||||
// These paths are created by the fpc rpm creation script and do not
|
||||
// contain all sources. So, they are searched last.
|
||||
'/usr/src/fpc',
|
||||
'/vol/src/fpc'
|
||||
);
|
||||
|
@ -336,9 +336,11 @@ type
|
||||
GrabbingKey: integer; // 0=none, 1=Default key, 2=Alternative key
|
||||
procedure ActivateGrabbing(AGrabbingKey: integer);
|
||||
procedure DeactivateGrabbing;
|
||||
procedure SetComboBox(AComboBox: TComboBox; AValue: string);
|
||||
procedure SetComboBox(AComboBox: TComboBox; const AValue: string);
|
||||
function ResolveConflicts(AKey: Word; AShiftState: TShiftState;
|
||||
Areas: TCommandAreas): boolean;
|
||||
public
|
||||
constructor Create(TheOwner:TComponent); override;
|
||||
constructor Create(TheOwner: TComponent); override;
|
||||
KeyCommandRelationList:TKeyCommandRelationList;
|
||||
KeyIndex:integer;
|
||||
end;
|
||||
@ -1592,10 +1594,10 @@ begin
|
||||
end;
|
||||
|
||||
procedure TKeyMappingEditForm.OkButtonClick(Sender:TObject);
|
||||
var NewKey1,NewKey2:word;
|
||||
NewShiftState1,NewShiftState2:TShiftState;
|
||||
AText:AnsiString;
|
||||
DummyRelation, CurRelation:TKeyCommandRelation;
|
||||
var
|
||||
NewKey1, NewKey2: word;
|
||||
NewShiftState1, NewShiftState2: TShiftState;
|
||||
CurRelation: TKeyCommandRelation;
|
||||
begin
|
||||
// set defaults
|
||||
NewKey1:=VK_UNKNOWN;
|
||||
@ -1603,6 +1605,9 @@ begin
|
||||
NewKey2:=VK_UNKNOWN;
|
||||
NewShiftState2:=[];
|
||||
|
||||
// get old relation
|
||||
CurRelation:=KeyCommandRelationList.Relations[KeyIndex];
|
||||
|
||||
// get settings for key1
|
||||
NewKey1:=EditorKeyStringToVKCode(Key1KeyComboBox.Text);
|
||||
if NewKey1<>VK_UNKNOWN then
|
||||
@ -1612,22 +1617,10 @@ begin
|
||||
if Key1ShiftCheckBox.Checked then include(NewShiftState1,ssShift);
|
||||
end;
|
||||
|
||||
// get old relation
|
||||
CurRelation:=KeyCommandRelationList.Relations[KeyIndex];
|
||||
if not ResolveConflicts(NewKey1,NewShiftState1,CurRelation.Category.Areas)
|
||||
then exit;
|
||||
|
||||
// search for conflict
|
||||
DummyRelation:=KeyCommandRelationList.Find(NewKey1,NewShiftState1,
|
||||
CurRelation.Category.Areas);
|
||||
if (DummyRelation<>nil)
|
||||
and (DummyRelation<>KeyCommandRelationList.Relations[KeyIndex]) then
|
||||
begin
|
||||
AText:=Format(srkmAlreadyConnected,
|
||||
[KeyAndShiftStateToEditorKeyString(NewKey1,NewShiftState1),
|
||||
DummyRelation.Name]);
|
||||
MessageDlg(AText,mtError,[mbok],0);
|
||||
exit;
|
||||
end;
|
||||
|
||||
// get settings for key2
|
||||
NewKey2:=EditorKeyStringToVKCode(Key2KeyComboBox.Text);
|
||||
if (NewKey1=NewKey2) and (NewShiftState1=NewShiftState2) then
|
||||
NewKey2:=VK_UNKNOWN;
|
||||
@ -1637,18 +1630,9 @@ begin
|
||||
if Key2AltCheckBox.Checked then include(NewShiftState2,ssAlt);
|
||||
if Key2ShiftCheckBox.Checked then include(NewShiftState2,ssShift);
|
||||
end;
|
||||
DummyRelation:=KeyCommandRelationList.Find(NewKey2,NewShiftState2,
|
||||
CurRelation.Category.Areas);
|
||||
|
||||
if (DummyRelation<>nil)
|
||||
and (DummyRelation<>KeyCommandRelationList.Relations[KeyIndex]) then
|
||||
begin
|
||||
AText:=Format(srkmAlreadyConnected,
|
||||
[KeyAndShiftStateToEditorKeyString(NewKey2,NewShiftState2),
|
||||
DummyRelation.Name]);
|
||||
MessageDlg(AText,mterror,[mbok],0);
|
||||
exit;
|
||||
end;
|
||||
if not ResolveConflicts(NewKey2,NewShiftState2,CurRelation.Category.Areas)
|
||||
then exit;
|
||||
|
||||
if NewKey1=VK_UNKNOWN then
|
||||
begin
|
||||
@ -1696,7 +1680,8 @@ begin
|
||||
GrabbingKey:=0;
|
||||
end;
|
||||
|
||||
procedure TKeyMappingEditForm.SetComboBox(AComboBox: TComboBox; AValue: string);
|
||||
procedure TKeyMappingEditForm.SetComboBox(AComboBox: TComboBox;
|
||||
const AValue: string);
|
||||
var i: integer;
|
||||
begin
|
||||
i:=AComboBox.Items.IndexOf(AValue);
|
||||
@ -1709,6 +1694,46 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TKeyMappingEditForm.ResolveConflicts(AKey: Word;
|
||||
AShiftState: TShiftState; Areas: TCommandAreas): boolean;
|
||||
var
|
||||
ConflictRelation: TKeyCommandRelation;
|
||||
ConflictName: String;
|
||||
CurRelation: TKeyCommandRelation;
|
||||
CurName: String;
|
||||
begin
|
||||
// search for conflict
|
||||
CurRelation:=KeyCommandRelationList.Relations[KeyIndex];
|
||||
ConflictRelation:=KeyCommandRelationList.Find(AKey,AShiftState,Areas);
|
||||
if (ConflictRelation<>nil)
|
||||
and (ConflictRelation<>KeyCommandRelationList.Relations[KeyIndex]) then
|
||||
begin
|
||||
CurName:=CurRelation.GetCategoryAndName;
|
||||
ConflictName:=ConflictRelation.GetCategoryAndName;
|
||||
if MessageDlg('Conflict found',
|
||||
'The key '+KeyAndShiftStateToEditorKeyString(AKey,AShiftState)+#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 (ConflictRelation.KeyA.Key1=AKey)
|
||||
and (ConflictRelation.KeyA.Shift1=AShiftState) then begin
|
||||
ConflictRelation.ClearKeyA;
|
||||
end;
|
||||
if (ConflictRelation.KeyB.Key1=AKey)
|
||||
and (ConflictRelation.KeyB.Shift1=AShiftState) then begin
|
||||
ConflictRelation.ClearKeyB;
|
||||
end;
|
||||
end;
|
||||
Result:=true;
|
||||
end;
|
||||
|
||||
procedure TKeyMappingEditForm.ActivateGrabbing(AGrabbingKey: integer);
|
||||
var i: integer;
|
||||
begin
|
||||
|
@ -93,6 +93,9 @@ type
|
||||
KeyB: TIDEShortCut;
|
||||
DefaultKeyA: TIDEShortCut;
|
||||
DefaultKeyB: TIDEShortCut;
|
||||
procedure ClearKeyA;
|
||||
procedure ClearKeyB;
|
||||
function GetCategoryAndName: string;
|
||||
property Name: String read FName;
|
||||
property Command: word read FCommand; // see the ecXXX constants above
|
||||
property LocalizedName: string read GetLocalizedName write SetLocalizedName;
|
||||
@ -212,5 +215,22 @@ begin
|
||||
Category:=TheCategory;
|
||||
end;
|
||||
|
||||
procedure TIDECommandKeys.ClearKeyA;
|
||||
begin
|
||||
KeyA:=CleanIDEShortCut;
|
||||
end;
|
||||
|
||||
procedure TIDECommandKeys.ClearKeyB;
|
||||
begin
|
||||
KeyB:=CleanIDEShortCut;
|
||||
end;
|
||||
|
||||
function TIDECommandKeys.GetCategoryAndName: string;
|
||||
begin
|
||||
Result:='"'+GetLocalizedName+'"';
|
||||
if Category<>nil then
|
||||
Result:=Result+' in "'+Category.Description+'"';
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user