mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-22 01:19:29 +02:00
IDE: file dialog filters: menu item to set to defaults
git-svn-id: trunk@33765 -
This commit is contained in:
parent
40857d72fc
commit
a6966d1d21
@ -17,10 +17,12 @@ inherited FileFiltersOptionsFrame: TFileFiltersOptionsFrame
|
||||
Columns = <
|
||||
item
|
||||
Title.Caption = 'Name'
|
||||
Title.PrefixOption = poNone
|
||||
Width = 130
|
||||
end
|
||||
item
|
||||
Title.Caption = 'File mask'
|
||||
Title.PrefixOption = poNone
|
||||
Width = 300
|
||||
end>
|
||||
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goColSizing, goEditing, goThumbTracking, goSmoothScroll, goFixedRowNumbering]
|
||||
@ -31,9 +33,9 @@ inherited FileFiltersOptionsFrame: TFileFiltersOptionsFrame
|
||||
end
|
||||
object lblTitle: TLabel[1]
|
||||
Left = 8
|
||||
Height = 18
|
||||
Height = 17
|
||||
Top = 9
|
||||
Width = 41
|
||||
Width = 43
|
||||
Caption = 'lblTitle'
|
||||
ParentColor = False
|
||||
end
|
||||
@ -52,5 +54,12 @@ inherited FileFiltersOptionsFrame: TFileFiltersOptionsFrame
|
||||
Caption = 'Insert row'
|
||||
OnClick = pmiInsRowClick
|
||||
end
|
||||
object MenuItem1: TMenuItem
|
||||
Caption = '-'
|
||||
end
|
||||
object SetDefaultMenuItem: TMenuItem
|
||||
Caption = 'Set defaults'
|
||||
OnClick = SetDefaultMenuItemClick
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -18,6 +18,8 @@ type
|
||||
|
||||
TFileFiltersOptionsFrame = class(TAbstractIDEOptionsEditor)
|
||||
grdFileFilters: TStringGrid;
|
||||
MenuItem1: TMenuItem;
|
||||
SetDefaultMenuItem: TMenuItem;
|
||||
pmGrid: TPopupMenu;
|
||||
pmiAddRow: TMenuItem;
|
||||
pmiDelRow: TMenuItem;
|
||||
@ -27,6 +29,7 @@ type
|
||||
procedure pmiAddRowClick(Sender: TObject);
|
||||
procedure pmiDelRowClick(Sender: TObject);
|
||||
procedure pmiInsRowClick(Sender: TObject);
|
||||
procedure SetDefaultMenuItemClick(Sender: TObject);
|
||||
private
|
||||
FList: TStringList;
|
||||
fLoaded: boolean;
|
||||
@ -45,7 +48,9 @@ type
|
||||
procedure LoadFileDialogFilter;
|
||||
procedure SaveFileDialogFilter;
|
||||
function GetDefaultFileDialogFilter: string;
|
||||
|
||||
function GetFileDialogFilterFromGrid(Grid: TStringGrid): string;
|
||||
procedure LoadGridFromFileDialogFilter(Grid: TStringGrid; Filter: string;
|
||||
AddEmptyRow: boolean);
|
||||
|
||||
implementation
|
||||
|
||||
@ -152,6 +157,88 @@ begin
|
||||
+ '|' + lisLazarusOtherFile + ' (*.inc;*.lrs;*.lpl)|*.inc;*.lrs;*.lpl';
|
||||
end;
|
||||
|
||||
function GetFileDialogFilterFromGrid(Grid: TStringGrid): string;
|
||||
var
|
||||
i: Integer;
|
||||
CurCaption: String;
|
||||
CurMask: String;
|
||||
begin
|
||||
Result:='';
|
||||
for i := 1 to Grid.RowCount-1 do
|
||||
begin
|
||||
CurCaption:=Grid.Cells[1, i];
|
||||
CurMask:=Grid.Cells[2, i];
|
||||
CurCaption:=StringReplace(CurCaption,'|',',',[rfReplaceAll]);
|
||||
CurMask:=StringReplace(CurMask,'|',',',[rfReplaceAll]);
|
||||
if (CurCaption='') or (CurMask='') then continue;
|
||||
if Result<>'' then
|
||||
Result:=Result+'|';
|
||||
Result:=Result+CurCaption+'|'+CurMask;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure LoadGridFromFileDialogFilter(Grid: TStringGrid; Filter: string;
|
||||
AddEmptyRow: boolean);
|
||||
|
||||
procedure ReadList(var Cnt: integer; Scan: boolean);
|
||||
var
|
||||
p: PChar;
|
||||
CaptionStart: PChar;
|
||||
CurCaption: String;
|
||||
MaskStart: PChar;
|
||||
CurMask: String;
|
||||
begin
|
||||
Cnt:=0;
|
||||
if Filter<>'' then begin
|
||||
p:=PChar(Filter);
|
||||
while p^<>#0 do
|
||||
begin
|
||||
// caption
|
||||
CaptionStart:=p;
|
||||
while not (p^ in ['|',#0]) do inc(p);
|
||||
if p^=#0 then break;
|
||||
CurCaption:=copy(Filter,CaptionStart-PChar(Filter)+1,p-CaptionStart);
|
||||
// parse masks
|
||||
repeat
|
||||
inc(p);
|
||||
MaskStart:=p;
|
||||
while not (p^ in ['|',#0]) do inc(p);
|
||||
if p>MaskStart then begin
|
||||
CurMask:=copy(Filter,MaskStart-PChar(Filter)+1,p-MaskStart);
|
||||
inc(Cnt);
|
||||
if not Scan then begin
|
||||
Grid.Cells[1, Cnt] := CurCaption;
|
||||
Grid.Cells[2, Cnt] := CurMask;
|
||||
end;
|
||||
end;
|
||||
if p^='|' then break;
|
||||
until p^=#0;
|
||||
inc(p);
|
||||
end;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
var
|
||||
Cnt: Integer;
|
||||
begin
|
||||
Cnt:=0;
|
||||
ReadList(Cnt,true);
|
||||
Grid.BeginUpdate;
|
||||
try
|
||||
inc(Cnt,Grid.FixedRows);
|
||||
if AddEmptyRow then inc(Cnt);
|
||||
Grid.RowCount := Cnt;
|
||||
if AddEmptyRow then begin
|
||||
Grid.Cells[1, Cnt-1] := '';
|
||||
Grid.Cells[2, Cnt-1] := '';
|
||||
end;
|
||||
ReadList(Cnt,false);
|
||||
finally
|
||||
Grid.EndUpdate(true);
|
||||
end;
|
||||
end;
|
||||
|
||||
{ TFileFiltersOptionsFrame }
|
||||
|
||||
procedure TFileFiltersOptionsFrame.grdFileFiltersKeyDown(Sender: TObject; var Key: Word;
|
||||
@ -176,6 +263,14 @@ begin
|
||||
grdFileFilters.InsertColRow(False, grdFileFilters.Row);
|
||||
end;
|
||||
|
||||
procedure TFileFiltersOptionsFrame.SetDefaultMenuItemClick(Sender: TObject);
|
||||
begin
|
||||
if MessageDlg(lisConfirm,
|
||||
lisResetAllFileFiltersToDefaults, mtConfirmation, [mbCancel, mbOK], 0)<>mrOk
|
||||
then exit;
|
||||
LoadGridFromFileDialogFilter(grdFileFilters,GetDefaultFileDialogFilter,false);
|
||||
end;
|
||||
|
||||
constructor TFileFiltersOptionsFrame.Create(TheOwner: TComponent);
|
||||
begin
|
||||
inherited Create(TheOwner);
|
||||
@ -208,86 +303,21 @@ begin
|
||||
end;
|
||||
|
||||
procedure TFileFiltersOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
|
||||
|
||||
procedure AddRowItem(const ARow: integer; const AName, AMask: String);
|
||||
begin
|
||||
grdFileFilters.Cells[1, ARow] := AName;
|
||||
grdFileFilters.Cells[2, ARow] := AMask;
|
||||
end;
|
||||
|
||||
procedure ReadList(Filter: String; var Cnt: integer; Scan: boolean);
|
||||
var
|
||||
p: PChar;
|
||||
CaptionStart: PChar;
|
||||
CurCaption: String;
|
||||
MaskStart: PChar;
|
||||
CurMask: String;
|
||||
begin
|
||||
Cnt:=0;
|
||||
if Filter<>'' then begin
|
||||
p:=PChar(Filter);
|
||||
while p^<>#0 do
|
||||
begin
|
||||
// caption
|
||||
CaptionStart:=p;
|
||||
while not (p^ in ['|',#0]) do inc(p);
|
||||
if p^=#0 then break;
|
||||
CurCaption:=copy(Filter,CaptionStart-PChar(Filter)+1,p-CaptionStart);
|
||||
// parse masks
|
||||
repeat
|
||||
inc(p);
|
||||
MaskStart:=p;
|
||||
while not (p^ in ['|',#0]) do inc(p);
|
||||
if p>MaskStart then begin
|
||||
CurMask:=copy(Filter,MaskStart-PChar(Filter)+1,p-MaskStart);
|
||||
inc(Cnt);
|
||||
if not Scan then
|
||||
AddRowItem(Cnt,CurCaption,CurMask);
|
||||
end;
|
||||
if p^='|' then break;
|
||||
until p^=#0;
|
||||
inc(p);
|
||||
end;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
var
|
||||
Filter: String;
|
||||
Cnt: Integer;
|
||||
begin
|
||||
if fLoaded then exit;
|
||||
fLoaded:=true;
|
||||
|
||||
Filter:=EnvironmentOptions.FileDialogFilter;
|
||||
Cnt:=0;
|
||||
ReadList(Filter,Cnt,true);
|
||||
grdFileFilters.RowCount := Cnt+2; // +1 for header, +1 for a new item
|
||||
ReadList(Filter,Cnt,false);
|
||||
LoadGridFromFileDialogFilter(grdFileFilters,EnvironmentOptions.FileDialogFilter,false);
|
||||
end;
|
||||
|
||||
procedure TFileFiltersOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
|
||||
var
|
||||
Filter: String;
|
||||
i: Integer;
|
||||
CurCaption: String;
|
||||
CurMask: String;
|
||||
begin
|
||||
if fSaved then exit;
|
||||
fSaved:=true;
|
||||
|
||||
Filter:='';
|
||||
for i := 1 to grdFileFilters.RowCount-1 do
|
||||
begin
|
||||
CurCaption:=grdFileFilters.Cells[1, i];
|
||||
CurMask:=grdFileFilters.Cells[2, i];
|
||||
CurCaption:=StringReplace(CurCaption,'|',',',[rfReplaceAll]);
|
||||
CurMask:=StringReplace(CurMask,'|',',',[rfReplaceAll]);
|
||||
if (CurCaption='') or (CurMask='') then continue;
|
||||
if Filter<>'' then
|
||||
Filter:=Filter+'|';
|
||||
Filter:=Filter+CurCaption+'|'+CurMask;
|
||||
end;
|
||||
Filter:=GetFileDialogFilterFromGrid(grdFileFilters);
|
||||
|
||||
if EnvironmentOptions.FileDialogFilter<>Filter then begin
|
||||
//debugln(['TFileFiltersOptionsFrame.WriteSettings ']);
|
||||
|
@ -5360,6 +5360,8 @@ resourcestring
|
||||
// File Filters - Environment options
|
||||
lisFileFiltersTitle ='These are file filters that will appear in all File Open dialogs';
|
||||
lisFileFilters = 'File Filters';
|
||||
lisConfirm = 'Confirm';
|
||||
lisResetAllFileFiltersToDefaults = 'Reset all file filters to defaults?';
|
||||
lisFileFiltersName = 'Name';
|
||||
lisFileFiltersMask = 'File mask';
|
||||
lisFileFiltersAddRow = 'Add Row';
|
||||
|
Loading…
Reference in New Issue
Block a user