mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-24 14:19:13 +02:00
EditorOption, mouse-settings: Changed the way they are saved. Advanced customization will always save complete, and not as diff to a (potential) random pre-set
git-svn-id: trunk@21247 -
This commit is contained in:
parent
3c8e6f9173
commit
60723c24b9
@ -700,6 +700,7 @@ type
|
|||||||
FTextDrag: Boolean;
|
FTextDrag: Boolean;
|
||||||
FTextRightMoveCaret: Boolean;
|
FTextRightMoveCaret: Boolean;
|
||||||
private
|
private
|
||||||
|
FCustomSavedActions: Boolean;
|
||||||
FOptions: TEditorOptions;
|
FOptions: TEditorOptions;
|
||||||
FMainActions, FSelActions: TSynEditMouseActions;
|
FMainActions, FSelActions: TSynEditMouseActions;
|
||||||
FGutterActions: TSynEditMouseActions;
|
FGutterActions: TSynEditMouseActions;
|
||||||
@ -708,12 +709,14 @@ type
|
|||||||
public
|
public
|
||||||
constructor Create(AOptions: TEditorOptions);
|
constructor Create(AOptions: TEditorOptions);
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
|
procedure Reset;
|
||||||
procedure Read;
|
procedure Read;
|
||||||
procedure WriteBack;
|
procedure WriteBack;
|
||||||
procedure ResetGutterToDefault;
|
procedure ResetGutterToDefault;
|
||||||
procedure ResetTextToDefault;
|
procedure ResetTextToDefault;
|
||||||
procedure Assign(Src: TEditorMouseOptions); reintroduce;
|
procedure Assign(Src: TEditorMouseOptions); reintroduce;
|
||||||
function IsEqualToMouseActions: Boolean;
|
function IsPresetEqualToMouseActions: Boolean;
|
||||||
|
function CalcCustomSavedActions: Boolean;
|
||||||
|
|
||||||
property MainActions: TSynEditMouseActions read FMainActions;
|
property MainActions: TSynEditMouseActions read FMainActions;
|
||||||
property SelActions: TSynEditMouseActions read FSelActions;
|
property SelActions: TSynEditMouseActions read FSelActions;
|
||||||
@ -730,6 +733,8 @@ type
|
|||||||
property TextRightMoveCaret: Boolean read FTextRightMoveCaret write FTextRightMoveCaret;
|
property TextRightMoveCaret: Boolean read FTextRightMoveCaret write FTextRightMoveCaret;
|
||||||
property TextMiddleClick: TMouseOptTextMiddleType read FTextMiddleClick write FTextMiddleClick;
|
property TextMiddleClick: TMouseOptTextMiddleType read FTextMiddleClick write FTextMiddleClick;
|
||||||
property TextCtrlLeftClick: TMouseOptTextCtrlLeft read FTextCtrlLeftClick write FTextCtrlLeftClick;
|
property TextCtrlLeftClick: TMouseOptTextCtrlLeft read FTextCtrlLeftClick write FTextCtrlLeftClick;
|
||||||
|
// the flag below is set by CalcCustomSavedActions
|
||||||
|
property CustomSavedActions: Boolean read FCustomSavedActions write FCustomSavedActions;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TRttiXMLConfig }
|
{ TRttiXMLConfig }
|
||||||
@ -2033,8 +2038,7 @@ end;
|
|||||||
constructor TEditorMouseOptions.Create(AOptions: TEditorOptions);
|
constructor TEditorMouseOptions.Create(AOptions: TEditorOptions);
|
||||||
begin
|
begin
|
||||||
inherited Create;
|
inherited Create;
|
||||||
FAltColumnMode := True;
|
Reset;
|
||||||
FTextDrag := True;
|
|
||||||
FOptions := AOptions;
|
FOptions := AOptions;
|
||||||
FMainActions := TSynEditMouseActions.Create(nil);
|
FMainActions := TSynEditMouseActions.Create(nil);
|
||||||
FSelActions := TSynEditMouseActions.Create(nil);
|
FSelActions := TSynEditMouseActions.Create(nil);
|
||||||
@ -2057,6 +2061,18 @@ begin
|
|||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TEditorMouseOptions.Reset;
|
||||||
|
begin
|
||||||
|
FCustomSavedActions := False;
|
||||||
|
FGutterLeft := moGLDownClick;
|
||||||
|
FTextMiddleClick := moTMPaste;
|
||||||
|
FTextCtrlLeftClick := moTCLJump;
|
||||||
|
FTextDoubleSelLine := False;
|
||||||
|
FTextRightMoveCaret := False;
|
||||||
|
FAltColumnMode := True;
|
||||||
|
FTextDrag := True;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TEditorMouseOptions.Read;
|
procedure TEditorMouseOptions.Read;
|
||||||
begin
|
begin
|
||||||
FMainActions.Assign(FOptions.MouseMap);
|
FMainActions.Assign(FOptions.MouseMap);
|
||||||
@ -2206,7 +2222,7 @@ begin
|
|||||||
FGutterActionsLines.Assign (Src.GutterActionsLines);
|
FGutterActionsLines.Assign (Src.GutterActionsLines);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TEditorMouseOptions.IsEqualToMouseActions: Boolean;
|
function TEditorMouseOptions.IsPresetEqualToMouseActions: Boolean;
|
||||||
var
|
var
|
||||||
Temp: TEditorMouseOptions;
|
Temp: TEditorMouseOptions;
|
||||||
begin
|
begin
|
||||||
@ -2225,6 +2241,18 @@ begin
|
|||||||
Temp.Free;
|
Temp.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TEditorMouseOptions.CalcCustomSavedActions: Boolean;
|
||||||
|
var
|
||||||
|
Temp: TEditorMouseOptions;
|
||||||
|
begin
|
||||||
|
Temp := TEditorMouseOptions.Create(FOptions);
|
||||||
|
Temp.Assign(self);
|
||||||
|
Temp.Read;
|
||||||
|
Result := not Temp.IsPresetEqualToMouseActions;
|
||||||
|
Temp.Free;
|
||||||
|
FCustomSavedActions := Result;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TEditorOptions }
|
{ TEditorOptions }
|
||||||
|
|
||||||
constructor TEditorOptions.Create;
|
constructor TEditorOptions.Create;
|
||||||
@ -2423,21 +2451,13 @@ var
|
|||||||
|
|
||||||
Procedure LoadMouseAct(Path: String; MActions: TSynEditMouseActions);
|
Procedure LoadMouseAct(Path: String; MActions: TSynEditMouseActions);
|
||||||
var
|
var
|
||||||
c, i, j: Integer;
|
c, i: Integer;
|
||||||
MAct: TSynEditMouseActionKeyCmdHelper;
|
MAct: TSynEditMouseActionKeyCmdHelper;
|
||||||
//ErrShown: Boolean;
|
//ErrShown: Boolean;
|
||||||
begin
|
begin
|
||||||
//ErrShown := False;
|
//ErrShown := False;
|
||||||
|
MActions.Clear;
|
||||||
// Deleted Defaults
|
|
||||||
MAct := TSynEditMouseActionKeyCmdHelper.Create(nil);
|
MAct := TSynEditMouseActionKeyCmdHelper.Create(nil);
|
||||||
c := XMLConfig.GetValue(Path + 'CountDel', 0);
|
|
||||||
for i := 0 to c - 1 do begin
|
|
||||||
Mact.Clear;
|
|
||||||
XMLConfig.ReadObject(Path + 'Del' + IntToStr(i) + '/', MAct);
|
|
||||||
j := MActions.IndexOf(MAct, True);
|
|
||||||
if j >= 0 then MActions.Delete(j);
|
|
||||||
end;
|
|
||||||
|
|
||||||
c := XMLConfig.GetValue(Path + 'Count', 0);
|
c := XMLConfig.GetValue(Path + 'Count', 0);
|
||||||
for i := 0 to c - 1 do begin
|
for i := 0 to c - 1 do begin
|
||||||
@ -2447,11 +2467,7 @@ var
|
|||||||
// If the object would ever be extended, old configs will not have all properties.
|
// If the object would ever be extended, old configs will not have all properties.
|
||||||
Mact.Clear;
|
Mact.Clear;
|
||||||
XMLConfig.ReadObject(Path + 'M' + IntToStr(i) + '/', MAct);
|
XMLConfig.ReadObject(Path + 'M' + IntToStr(i) + '/', MAct);
|
||||||
j := MActions.IndexOf(MAct, True);
|
MActions.Add.Assign(MAct);
|
||||||
if j >= 0 then
|
|
||||||
MActions[j].Assign(MAct)
|
|
||||||
else
|
|
||||||
MActions.Add.Assign(MAct);
|
|
||||||
finally
|
finally
|
||||||
MActions.DecAssertLock;
|
MActions.DecAssertLock;
|
||||||
end;
|
end;
|
||||||
@ -2463,7 +2479,6 @@ var
|
|||||||
//ErrShown := True;
|
//ErrShown := True;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
MAct.Free;
|
MAct.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2641,6 +2656,7 @@ begin
|
|||||||
XMLConfig.GetValue(
|
XMLConfig.GetValue(
|
||||||
'EditorOptions/CodeFolding/UseCodeFolding', True);
|
'EditorOptions/CodeFolding/UseCodeFolding', True);
|
||||||
|
|
||||||
|
FTempMouseSettings.Reset;
|
||||||
// Read deprecated value
|
// Read deprecated value
|
||||||
// It is on by default, so only if a user switched it off, actions is required
|
// It is on by default, so only if a user switched it off, actions is required
|
||||||
if not XMLConfig.GetValue('EditorOptions/General/Editor/DragDropEditing', True) then
|
if not XMLConfig.GetValue('EditorOptions/General/Editor/DragDropEditing', True) then
|
||||||
@ -2659,18 +2675,23 @@ begin
|
|||||||
FTempMouseSettings.TextDoubleSelLine := True;
|
FTempMouseSettings.TextDoubleSelLine := True;
|
||||||
XMLConfig.DeleteValue('EditorOptions/General/Editor/DoubleClickSelectsLine');
|
XMLConfig.DeleteValue('EditorOptions/General/Editor/DoubleClickSelectsLine');
|
||||||
|
|
||||||
|
FTempMouseSettings.CustomSavedActions := False;
|
||||||
XMLConfig.ReadObject('EditorOptions/Mouse/Default/', FTempMouseSettings);
|
XMLConfig.ReadObject('EditorOptions/Mouse/Default/', FTempMouseSettings);
|
||||||
FTempMouseSettings.ResetTextToDefault;
|
if FTempMouseSettings.CustomSavedActions then begin
|
||||||
FTempMouseSettings.ResetGutterToDefault;
|
// Load
|
||||||
FTempMouseSettings.WriteBack;
|
LoadMouseAct('EditorOptions/Mouse/Main/', MouseMap);
|
||||||
// Load the differences
|
LoadMouseAct('EditorOptions/Mouse/MainSelection/', MouseSelMap);
|
||||||
LoadMouseAct('EditorOptions/Mouse/Main/', MouseMap);
|
LoadMouseAct('EditorOptions/Mouse/Gutter/', MouseGutterActions);
|
||||||
LoadMouseAct('EditorOptions/Mouse/MainSelection/', MouseSelMap);
|
LoadMouseAct('EditorOptions/Mouse/GutterFold/', MouseGutterActionsFold);
|
||||||
LoadMouseAct('EditorOptions/Mouse/Gutter/', MouseGutterActions);
|
LoadMouseAct('EditorOptions/Mouse/GutterFoldExp/', MouseGutterActionsFoldExp);
|
||||||
LoadMouseAct('EditorOptions/Mouse/GutterFold/', MouseGutterActionsFold);
|
LoadMouseAct('EditorOptions/Mouse/GutterFoldCol/', MouseGutterActionsFoldCol);
|
||||||
LoadMouseAct('EditorOptions/Mouse/GutterFoldExp/', MouseGutterActionsFoldExp);
|
LoadMouseAct('EditorOptions/Mouse/GutterLineNum/', MouseGutterActionsLines);
|
||||||
LoadMouseAct('EditorOptions/Mouse/GutterFoldCol/', MouseGutterActionsFoldCol);
|
end
|
||||||
LoadMouseAct('EditorOptions/Mouse/GutterLineNum/', MouseGutterActionsLines);
|
else begin
|
||||||
|
FTempMouseSettings.ResetTextToDefault;
|
||||||
|
FTempMouseSettings.ResetGutterToDefault;
|
||||||
|
FTempMouseSettings.WriteBack;
|
||||||
|
end;
|
||||||
|
|
||||||
except
|
except
|
||||||
on E: Exception do
|
on E: Exception do
|
||||||
@ -2685,45 +2706,25 @@ var
|
|||||||
SynEditOptName: String;
|
SynEditOptName: String;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
SynEditOpt2: TSynEditorOption2;
|
SynEditOpt2: TSynEditorOption2;
|
||||||
|
DefMouseSettings: TEditorMouseOptions;
|
||||||
|
|
||||||
Procedure SaveMouseAct(Path: String; MActions, MADef: TSynEditMouseActions);
|
Procedure SaveMouseAct(Path: String; MActions: TSynEditMouseActions);
|
||||||
var
|
var
|
||||||
i, j, k, OldCnt: Integer;
|
i, OldCnt: Integer;
|
||||||
MAct: TSynEditMouseActionKeyCmdHelper;
|
MAct: TSynEditMouseActionKeyCmdHelper;
|
||||||
begin
|
begin
|
||||||
MAct := TSynEditMouseActionKeyCmdHelper.Create(nil);
|
MAct := TSynEditMouseActionKeyCmdHelper.Create(nil);
|
||||||
OldCnt := XMLConfig.GetValue(Path + 'Count', 0);
|
OldCnt := XMLConfig.GetValue(Path + 'Count', 0);
|
||||||
j := 0;
|
|
||||||
for i := 0 to MActions.Count - 1 do begin
|
for i := 0 to MActions.Count - 1 do begin
|
||||||
k := MADef.IndexOf(MActions[i], True);
|
if MActions[i].Command = emcSynEditCommand then begin
|
||||||
if (k < 0) or not(MActions[i].Equals(MADef[k])) then begin
|
MAct.Assign(MActions[i]);
|
||||||
if MActions[i].Command = emcSynEditCommand then begin
|
XMLConfig.WriteObject(Path + 'M' + IntToStr(i) + '/', MAct);
|
||||||
MAct.Assign(MActions[i]);
|
|
||||||
XMLConfig.WriteObject(Path + 'M' + IntToStr(j) + '/', MAct);
|
|
||||||
end else
|
|
||||||
XMLConfig.WriteObject(Path + 'M' + IntToStr(j) + '/', MActions[i]);
|
|
||||||
Inc(j);
|
|
||||||
end;
|
|
||||||
if k >= 0 then
|
|
||||||
MADef.Delete(k);
|
|
||||||
end;
|
|
||||||
XMLConfig.SetValue(Path + 'Count', j);
|
|
||||||
for i := j to OldCnt do
|
|
||||||
XMLConfig.DeletePath(Path + 'M' + IntToStr(i));
|
|
||||||
|
|
||||||
// Deleted Defaults
|
|
||||||
OldCnt := XMLConfig.GetValue(Path + 'CountDel', 0);
|
|
||||||
for i := 0 to MADef.Count - 1 do begin
|
|
||||||
if MADef[i].Command = emcSynEditCommand then begin
|
|
||||||
MAct.Assign(MADef[i]);
|
|
||||||
XMLConfig.WriteObject(Path + 'Del' + IntToStr(i) + '/', MAct);
|
|
||||||
end else
|
end else
|
||||||
XMLConfig.WriteObject(Path + 'Del' + IntToStr(i) + '/', MADef[i]);
|
XMLConfig.WriteObject(Path + 'M' + IntToStr(i) + '/', MActions[i]);
|
||||||
end;
|
end;
|
||||||
XMLConfig.SetValue(Path + 'CountDel', MADef.Count);
|
XMLConfig.SetValue(Path + 'Count', MActions.Count);
|
||||||
for i := MADef.Count to OldCnt do
|
for i := MActions.Count to OldCnt do
|
||||||
XMLConfig.DeletePath(Path + 'Del' + IntToStr(i));
|
XMLConfig.DeletePath(Path + 'M' + IntToStr(i));
|
||||||
|
|
||||||
MAct.Free;
|
MAct.Free;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -2875,20 +2876,29 @@ begin
|
|||||||
XMLConfig.SetDeleteValue('EditorOptions/CodeFolding/UseCodeFolding',
|
XMLConfig.SetDeleteValue('EditorOptions/CodeFolding/UseCodeFolding',
|
||||||
FUseCodeFolding, True);
|
FUseCodeFolding, True);
|
||||||
|
|
||||||
XMLConfig.WriteObject('EditorOptions/Mouse/Default/', FTempMouseSettings);
|
DefMouseSettings := TEditorMouseOptions.Create(self);
|
||||||
// Create defaults, but do not WriteBack
|
FTempMouseSettings.CalcCustomSavedActions;
|
||||||
FTempMouseSettings.ResetTextToDefault;
|
XMLConfig.WriteObject('EditorOptions/Mouse/Default/', FTempMouseSettings, DefMouseSettings);
|
||||||
FTempMouseSettings.ResetGutterToDefault;
|
DefMouseSettings.Free;
|
||||||
// Save differences
|
if FTempMouseSettings.CustomSavedActions then begin
|
||||||
SaveMouseAct('EditorOptions/Mouse/Main/', MouseMap, FTempMouseSettings.MainActions);
|
// Save full settings / based on empty
|
||||||
SaveMouseAct('EditorOptions/Mouse/MainSelection/', MouseSelMap, FTempMouseSettings.SelActions);
|
SaveMouseAct('EditorOptions/Mouse/Main/', MouseMap);
|
||||||
SaveMouseAct('EditorOptions/Mouse/Gutter/', MouseGutterActions, FTempMouseSettings.GutterActions);
|
SaveMouseAct('EditorOptions/Mouse/MainSelection/', MouseSelMap);
|
||||||
SaveMouseAct('EditorOptions/Mouse/GutterFold/', MouseGutterActionsFold, FTempMouseSettings.GutterActionsFold);
|
SaveMouseAct('EditorOptions/Mouse/Gutter/', MouseGutterActions);
|
||||||
SaveMouseAct('EditorOptions/Mouse/GutterFoldExp/', MouseGutterActionsFoldExp, FTempMouseSettings.GutterActionsFoldExp);
|
SaveMouseAct('EditorOptions/Mouse/GutterFold/', MouseGutterActionsFold);
|
||||||
SaveMouseAct('EditorOptions/Mouse/GutterFoldCol/', MouseGutterActionsFoldCol, FTempMouseSettings.GutterActionsFoldCol);
|
SaveMouseAct('EditorOptions/Mouse/GutterFoldExp/', MouseGutterActionsFoldExp);
|
||||||
SaveMouseAct('EditorOptions/Mouse/GutterLineNum/', MouseGutterActionsLines, FTempMouseSettings.GutterActionsLines);
|
SaveMouseAct('EditorOptions/Mouse/GutterFoldCol/', MouseGutterActionsFoldCol);
|
||||||
// Set back to user values (after create defaults above
|
SaveMouseAct('EditorOptions/Mouse/GutterLineNum/', MouseGutterActionsLines);
|
||||||
FTempMouseSettings.Read;
|
end else begin
|
||||||
|
// clear unused entries
|
||||||
|
XMLConfig.DeletePath('EditorOptions/Mouse/Main');
|
||||||
|
XMLConfig.DeletePath('EditorOptions/Mouse/MainSelection');
|
||||||
|
XMLConfig.DeletePath('EditorOptions/Mouse/Gutter');
|
||||||
|
XMLConfig.DeletePath('EditorOptions/Mouse/GutterFold');
|
||||||
|
XMLConfig.DeletePath('EditorOptions/Mouse/GutterFoldExp');
|
||||||
|
XMLConfig.DeletePath('EditorOptions/Mouse/GutterFoldCol');
|
||||||
|
XMLConfig.DeletePath('EditorOptions/Mouse/GutterLineNum');
|
||||||
|
end;
|
||||||
|
|
||||||
InvalidateFileStateCache;
|
InvalidateFileStateCache;
|
||||||
XMLConfig.Flush;
|
XMLConfig.Flush;
|
||||||
|
@ -97,7 +97,7 @@ procedure TEditorMouseOptionsFrame.CheckOrRadioChange(Sender: TObject);
|
|||||||
var
|
var
|
||||||
MouseDiff: Boolean;
|
MouseDiff: Boolean;
|
||||||
begin
|
begin
|
||||||
MouseDiff := not FTempMouseSettings.IsEqualToMouseActions;
|
MouseDiff := not FTempMouseSettings.IsPresetEqualToMouseActions;
|
||||||
ResetTextButton.Enabled := MouseDiff or IsTextSettingsChanged;
|
ResetTextButton.Enabled := MouseDiff or IsTextSettingsChanged;
|
||||||
ResetGutterButton.Enabled := MouseDiff or IsGutterSettingsChanged;
|
ResetGutterButton.Enabled := MouseDiff or IsGutterSettingsChanged;
|
||||||
ResetAllButton.Enabled := ResetTextButton.Enabled or ResetGutterButton.Enabled;
|
ResetAllButton.Enabled := ResetTextButton.Enabled or ResetGutterButton.Enabled;
|
||||||
|
Loading…
Reference in New Issue
Block a user