Commit cee38e2b authored by ondrej's avatar ondrej
Browse files

IDE: Find/Replace: save options depending on selection availability. Issue #32619

git-svn-id: trunk@56325 -
parent 92c78dc8
......@@ -375,7 +375,7 @@ begin
AssignToComboBox(FileMaskComboBox, InputHistories.FindInFilesMaskHistory);
Options := InputHistories.FindInFilesSearchOptions;
//share basic options with FindReplaceDlg
SynSearchOptions := InputHistoriesSO.FindOptions * SharedOptions;
SynSearchOptions := InputHistoriesSO.FindOptions[False] * SharedOptions;
end;
procedure TLazFindInFilesDialog.SaveHistory;
......@@ -391,7 +391,7 @@ begin
InputHistories.AddToFindInFilesMaskHistory(FileMaskComboBox.Text);
InputHistories.FindInFilesSearchOptions:=Options;
//share basic options with FindReplaceDlg
InputHistoriesSO.FindOptions := InputHistoriesSO.FindOptions - SharedOptions
InputHistoriesSO.FindOptions[False] := InputHistoriesSO.FindOptions[False] - SharedOptions
+ (SynSearchOptions*SharedOptions);
InputHistories.Save;
end;
......
......@@ -39,7 +39,7 @@ uses
// RTL + LCL
Classes, SysUtils, Laz_AVL_Tree,
// LCL
Dialogs,
Dialogs, SynEditTypes,
// LazUtils
LazFileCache, LazFileUtils, LazUTF8, AvgLvlTree, Laz2_XMLCfg,
// Codetools
......@@ -275,7 +275,7 @@ type
end;
const
LazFindSearchOptionsDefault = [];
LazFindSearchOptionsDefault: array[Boolean] of TSynSearchOptions = ([], [ssoEntireScope, ssoSelectedOnly]);
LazFindInFileSearchOptionsDefault = [fifSearchOpen, fifIncludeSubDirs];
LazFindInFileSearchOptionNames: array[TLazFindInFileSearchOption] of string =(
'MatchCase',
......
......@@ -41,15 +41,27 @@ type
{ TInputHistoriesWithSearchOpt }
TInputHistoriesWithSearchOpt = class(TInputHistories)
private const
PathToOptions0: array[Boolean] of string = ('Options', 'Options'); // old config file
PathToOptions1: array[Boolean] of string = ('Options', 'SelOptions'); // new config file
XMLConfigVersion = 1;
public const
SaveOptionsGeneral = [ssoMatchCase, ssoWholeWord, ssoRegExpr, ssoRegExprMultiLine,
ssoPrompt, ssoBackwards];
SaveOptionsSelSpecific = [ssoEntireScope, ssoSelectedOnly];
SaveOptions = SaveOptionsGeneral + SaveOptionsSelSpecific;
private
FFindOptions: TSynSearchOptions;
FFindOptions: array[Boolean] of TSynSearchOptions; // array[SelAvail] - selection available
function GetFindOptions(const ASelAvail: Boolean): TSynSearchOptions;
procedure SetFindOptions(const ASelAvail: Boolean;
const AFindOptions: TSynSearchOptions);
protected
procedure LoadSearchOptions(XMLConfig: TXMLConfig; const Path: string); override;
procedure SaveSearchOptions(XMLConfig: TXMLConfig; const Path: string); override;
public
constructor Create;
destructor Destroy; override;
property FindOptions: TSynSearchOptions read FFindOptions write FFindOptions;
property FindOptions[const ASelAvail: Boolean]: TSynSearchOptions read GetFindOptions write SetFindOptions;
end;
const
......@@ -86,31 +98,62 @@ begin
inherited Destroy;
end;
function TInputHistoriesWithSearchOpt.GetFindOptions(
const ASelAvail: Boolean): TSynSearchOptions;
begin
Result := FFindOptions[ASelAvail]*SaveOptions;
end;
procedure TInputHistoriesWithSearchOpt.LoadSearchOptions(XMLConfig: TXMLConfig; const Path: string);
var
FindOption: TSynSearchOption;
PathToOptions: array[Boolean] of string;
I: Boolean;
begin
FFindOptions:=[];
for FindOption:=Low(FFindOptions) to High(FFindOptions) do
if XMLConfig.GetValue(Path+'Find/Version/Value',0)<=0 then
PathToOptions := PathToOptions0
else
PathToOptions := PathToOptions1;
for I := Low(FFindOptions) to High(FFindOptions) do
begin
if XMLConfig.GetValue(Path+'Find/Options/'+LazFindSearchOptionNames[FindOption],
FindOption in LazFindSearchOptionsDefault)
then
Include(FFindOptions,FindOption);
FFindOptions[I]:=[];
for FindOption:=Low(FFindOptions[I]) to High(FFindOptions[I]) do
begin
if XMLConfig.GetValue(Path+'Find/'+PathToOptions[I]+'/'+LazFindSearchOptionNames[FindOption],
FindOption in LazFindSearchOptionsDefault[I])
then
Include(FFindOptions[I],FindOption);
end;
end;
end;
procedure TInputHistoriesWithSearchOpt.SaveSearchOptions(XMLConfig: TXMLConfig; const Path: string);
var
FindOption: TSynSearchOption;
I: Boolean;
begin
for FindOption:=Low(FFindOptions) to High(FFindOptions) do begin
XMLConfig.SetDeleteValue(
Path+'Find/Options/'+LazFindSearchOptionNames[FindOption],
FindOption in FindOptions,
FindOption in LazFindSearchOptionsDefault);
for I := Low(FFindOptions) to High(FFindOptions) do
begin
XMLConfig.SetValue(Path+'Find/Version/Value', XMLConfigVersion);
for FindOption:=Low(FFindOptions[I]) to High(FFindOptions[I]) do
begin
XMLConfig.SetDeleteValue(
Path+'Find/'+PathToOptions1[I]+'/'+LazFindSearchOptionNames[FindOption],
FindOption in FindOptions[I],
FindOption in LazFindSearchOptionsDefault[I]);
end;
end;
end;
procedure TInputHistoriesWithSearchOpt.SetFindOptions(const ASelAvail: Boolean;
const AFindOptions: TSynSearchOptions);
begin
FFindOptions[ASelAvail] := AFindOptions*SaveOptions;
FFindOptions[not ASelAvail] := AFindOptions*SaveOptionsGeneral // change only general options
+ FFindOptions[not ASelAvail]*SaveOptionsSelSpecific;
end;
end.
......@@ -3328,9 +3328,6 @@ end;
{------------------------------S T A R T F I N D-----------------------------}
procedure TSourceEditor.StartFindAndReplace(Replace:boolean);
const
SaveOptions = [ssoMatchCase, ssoWholeWord, ssoRegExpr, ssoRegExprMultiLine,
ssoPrompt, ssoEntireScope, ssoBackwards];
var
NewOptions: TSynSearchOptions;
ALeft,ATop:integer;
......@@ -3346,16 +3343,14 @@ begin
NewOptions := NewOptions + [ssoReplace, ssoReplaceAll]
else
NewOptions := NewOptions - [ssoReplace, ssoReplaceAll];
NewOptions:=NewOptions-SaveOptions+InputHistoriesSO.FindOptions*SaveOptions
-[ssoSelectedOnly];
NewOptions:=NewOptions-InputHistoriesSO.SaveOptions
+InputHistoriesSO.FindOptions[EditorComponent.SelAvail];
// Fill in history items
LazFindReplaceDialog.TextToFindComboBox.Items.Assign(InputHistoriesSO.FindHistory);
LazFindReplaceDialog.ReplaceTextComboBox.Items.Assign(InputHistoriesSO.ReplaceHistory);
with EditorComponent do begin
if SelAvail then
NewOptions := NewOptions + [ssoSelectedOnly, ssoEntireScope];
if EditorOpts.FindTextAtCursor then begin
if SelAvail and (BlockBegin.Y = BlockEnd.Y) and
( ((ComparePoints(BlockBegin, LogicalCaretXY) <= 0) and
......@@ -3386,7 +3381,7 @@ begin
LazFindReplaceDialog.Options := NewOptions;
DlgResult:=LazFindReplaceDialog.ShowModal;
InputHistoriesSO.FindOptions:=LazFindReplaceDialog.Options*SaveOptions;
InputHistoriesSO.FindOptions[EditorComponent.SelAvail]:=LazFindReplaceDialog.Options;
InputHistoriesSO.FindAutoComplete:=LazFindReplaceDialog.EnableAutoComplete;
if DlgResult = mrCancel then
begin
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment