mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-31 17:01:38 +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 = <
|
Columns = <
|
||||||
item
|
item
|
||||||
Title.Caption = 'Name'
|
Title.Caption = 'Name'
|
||||||
|
Title.PrefixOption = poNone
|
||||||
Width = 130
|
Width = 130
|
||||||
end
|
end
|
||||||
item
|
item
|
||||||
Title.Caption = 'File mask'
|
Title.Caption = 'File mask'
|
||||||
|
Title.PrefixOption = poNone
|
||||||
Width = 300
|
Width = 300
|
||||||
end>
|
end>
|
||||||
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goColSizing, goEditing, goThumbTracking, goSmoothScroll, goFixedRowNumbering]
|
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goColSizing, goEditing, goThumbTracking, goSmoothScroll, goFixedRowNumbering]
|
||||||
@ -31,9 +33,9 @@ inherited FileFiltersOptionsFrame: TFileFiltersOptionsFrame
|
|||||||
end
|
end
|
||||||
object lblTitle: TLabel[1]
|
object lblTitle: TLabel[1]
|
||||||
Left = 8
|
Left = 8
|
||||||
Height = 18
|
Height = 17
|
||||||
Top = 9
|
Top = 9
|
||||||
Width = 41
|
Width = 43
|
||||||
Caption = 'lblTitle'
|
Caption = 'lblTitle'
|
||||||
ParentColor = False
|
ParentColor = False
|
||||||
end
|
end
|
||||||
@ -52,5 +54,12 @@ inherited FileFiltersOptionsFrame: TFileFiltersOptionsFrame
|
|||||||
Caption = 'Insert row'
|
Caption = 'Insert row'
|
||||||
OnClick = pmiInsRowClick
|
OnClick = pmiInsRowClick
|
||||||
end
|
end
|
||||||
|
object MenuItem1: TMenuItem
|
||||||
|
Caption = '-'
|
||||||
|
end
|
||||||
|
object SetDefaultMenuItem: TMenuItem
|
||||||
|
Caption = 'Set defaults'
|
||||||
|
OnClick = SetDefaultMenuItemClick
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -18,6 +18,8 @@ type
|
|||||||
|
|
||||||
TFileFiltersOptionsFrame = class(TAbstractIDEOptionsEditor)
|
TFileFiltersOptionsFrame = class(TAbstractIDEOptionsEditor)
|
||||||
grdFileFilters: TStringGrid;
|
grdFileFilters: TStringGrid;
|
||||||
|
MenuItem1: TMenuItem;
|
||||||
|
SetDefaultMenuItem: TMenuItem;
|
||||||
pmGrid: TPopupMenu;
|
pmGrid: TPopupMenu;
|
||||||
pmiAddRow: TMenuItem;
|
pmiAddRow: TMenuItem;
|
||||||
pmiDelRow: TMenuItem;
|
pmiDelRow: TMenuItem;
|
||||||
@ -27,6 +29,7 @@ type
|
|||||||
procedure pmiAddRowClick(Sender: TObject);
|
procedure pmiAddRowClick(Sender: TObject);
|
||||||
procedure pmiDelRowClick(Sender: TObject);
|
procedure pmiDelRowClick(Sender: TObject);
|
||||||
procedure pmiInsRowClick(Sender: TObject);
|
procedure pmiInsRowClick(Sender: TObject);
|
||||||
|
procedure SetDefaultMenuItemClick(Sender: TObject);
|
||||||
private
|
private
|
||||||
FList: TStringList;
|
FList: TStringList;
|
||||||
fLoaded: boolean;
|
fLoaded: boolean;
|
||||||
@ -45,7 +48,9 @@ type
|
|||||||
procedure LoadFileDialogFilter;
|
procedure LoadFileDialogFilter;
|
||||||
procedure SaveFileDialogFilter;
|
procedure SaveFileDialogFilter;
|
||||||
function GetDefaultFileDialogFilter: string;
|
function GetDefaultFileDialogFilter: string;
|
||||||
|
function GetFileDialogFilterFromGrid(Grid: TStringGrid): string;
|
||||||
|
procedure LoadGridFromFileDialogFilter(Grid: TStringGrid; Filter: string;
|
||||||
|
AddEmptyRow: boolean);
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -152,6 +157,88 @@ begin
|
|||||||
+ '|' + lisLazarusOtherFile + ' (*.inc;*.lrs;*.lpl)|*.inc;*.lrs;*.lpl';
|
+ '|' + lisLazarusOtherFile + ' (*.inc;*.lrs;*.lpl)|*.inc;*.lrs;*.lpl';
|
||||||
end;
|
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 }
|
{ TFileFiltersOptionsFrame }
|
||||||
|
|
||||||
procedure TFileFiltersOptionsFrame.grdFileFiltersKeyDown(Sender: TObject; var Key: Word;
|
procedure TFileFiltersOptionsFrame.grdFileFiltersKeyDown(Sender: TObject; var Key: Word;
|
||||||
@ -176,6 +263,14 @@ begin
|
|||||||
grdFileFilters.InsertColRow(False, grdFileFilters.Row);
|
grdFileFilters.InsertColRow(False, grdFileFilters.Row);
|
||||||
end;
|
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);
|
constructor TFileFiltersOptionsFrame.Create(TheOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited Create(TheOwner);
|
inherited Create(TheOwner);
|
||||||
@ -208,86 +303,21 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFileFiltersOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
|
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
|
begin
|
||||||
if fLoaded then exit;
|
if fLoaded then exit;
|
||||||
fLoaded:=true;
|
fLoaded:=true;
|
||||||
|
|
||||||
Filter:=EnvironmentOptions.FileDialogFilter;
|
LoadGridFromFileDialogFilter(grdFileFilters,EnvironmentOptions.FileDialogFilter,false);
|
||||||
Cnt:=0;
|
|
||||||
ReadList(Filter,Cnt,true);
|
|
||||||
grdFileFilters.RowCount := Cnt+2; // +1 for header, +1 for a new item
|
|
||||||
ReadList(Filter,Cnt,false);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TFileFiltersOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
|
procedure TFileFiltersOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
|
||||||
var
|
var
|
||||||
Filter: String;
|
Filter: String;
|
||||||
i: Integer;
|
|
||||||
CurCaption: String;
|
|
||||||
CurMask: String;
|
|
||||||
begin
|
begin
|
||||||
if fSaved then exit;
|
if fSaved then exit;
|
||||||
fSaved:=true;
|
fSaved:=true;
|
||||||
|
|
||||||
Filter:='';
|
Filter:=GetFileDialogFilterFromGrid(grdFileFilters);
|
||||||
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;
|
|
||||||
|
|
||||||
if EnvironmentOptions.FileDialogFilter<>Filter then begin
|
if EnvironmentOptions.FileDialogFilter<>Filter then begin
|
||||||
//debugln(['TFileFiltersOptionsFrame.WriteSettings ']);
|
//debugln(['TFileFiltersOptionsFrame.WriteSettings ']);
|
||||||
|
@ -5360,6 +5360,8 @@ resourcestring
|
|||||||
// File Filters - Environment options
|
// File Filters - Environment options
|
||||||
lisFileFiltersTitle ='These are file filters that will appear in all File Open dialogs';
|
lisFileFiltersTitle ='These are file filters that will appear in all File Open dialogs';
|
||||||
lisFileFilters = 'File Filters';
|
lisFileFilters = 'File Filters';
|
||||||
|
lisConfirm = 'Confirm';
|
||||||
|
lisResetAllFileFiltersToDefaults = 'Reset all file filters to defaults?';
|
||||||
lisFileFiltersName = 'Name';
|
lisFileFiltersName = 'Name';
|
||||||
lisFileFiltersMask = 'File mask';
|
lisFileFiltersMask = 'File mask';
|
||||||
lisFileFiltersAddRow = 'Add Row';
|
lisFileFiltersAddRow = 'Add Row';
|
||||||
|
Loading…
Reference in New Issue
Block a user