MG: filedialogs now saves size and history

git-svn-id: trunk@1714 -
This commit is contained in:
lazarus 2002-05-30 14:18:47 +00:00
parent 9217c2841c
commit b312b70e90
6 changed files with 103 additions and 30 deletions

View File

@ -51,7 +51,7 @@ uses
{$else}
mwCustomEdit, mwPasSyn, mwHighlighter,
{$endif}
XMLCfg, CodeTemplateDialog, KeyMapping;
XMLCfg, CodeTemplateDialog, KeyMapping, InputHistory;
type
{$ifdef NEW_EDITOR_SYNEDIT}
@ -3010,11 +3010,14 @@ var OpenDialog:TOpenDialog;
begin
OpenDialog:=TOpenDialog.Create(Application);
try
InputHistories.ApplyFileDialogSettings(OpenDialog);
with OpenDialog do begin
Filter:='DCI file (*.dci)|*.dci';
Title:='Choose code template file (*.dci)';
Filter:='DCI file (*.dci)|*.dci|All files|*.*';
if Execute then
CodeTemplateFileNameComboBox.Text:=FileName;
end;
InputHistories.StoreFileDialogSettings(OpenDialog);
finally
OpenDialog.Free;
end;

View File

@ -39,7 +39,7 @@ uses
{$ENDIF}
Classes, SysUtils, Forms, Controls, Buttons, XMLCfg, ObjectInspector,
ExtCtrls, StdCtrls, EditorOptions, LResources, LazConf, Dialogs,
ExtToolDialog, IDEProcs, IDEOptionDefs;
ExtToolDialog, IDEProcs, IDEOptionDefs, InputHistory;
const
EnvOptsVersion: integer = 101;
@ -123,7 +123,6 @@ type
FMaxRecentOpenFiles: integer;
FRecentProjectFiles: TStringList;
FMaxRecentProjectFiles: integer;
FLastOpenDialogDir: string;
FOpenLastProjectAtStart: boolean;
// backup
@ -220,9 +219,7 @@ type
property MaxRecentProjectFiles: integer
read FMaxRecentProjectFiles write FMaxRecentProjectFiles;
procedure AddToRecentProjectFiles(const AFilename: string);
property LastOpenDialogDir: string
read FLastOpenDialogDir write FLastOpenDialogDir;
property LastSavedProjectFile: string
property LastSavedProjectFile: string
read FLastSavedProjectFile write FLastSavedProjectFile;
property OpenLastProjectAtStart: boolean
read FOpenLastProjectAtStart write FOpenLastProjectAtStart;
@ -487,7 +484,6 @@ begin
FMaxRecentOpenFiles:=10;
FRecentProjectFiles:=TStringList.Create;
FMaxRecentProjectFiles:=5;
FLastOpenDialogDir:='';
FOpenLastProjectAtStart:=true;
// backup
@ -705,9 +701,7 @@ begin
'EnvironmentOptions/Recent/ProjectFiles/Max',FMaxRecentProjectFiles);
LoadRecentList(XMLConfig,FRecentProjectFiles,
'EnvironmentOptions/Recent/ProjectFiles/');
FLastOpenDialogDir:=XMLConfig.GetValue(
'EnvironmentOptions/Recent/LastOpenDialogDir/Value',FLastOpenDialogDir);
// external tools
fExternalTools.Load(XMLConfig,'EnvironmentOptions/ExternalTools/');
@ -841,8 +835,6 @@ begin
'EnvironmentOptions/Recent/ProjectFiles/Max',FMaxRecentProjectFiles);
SaveRecentList(XMLConfig,FRecentProjectFiles,
'EnvironmentOptions/Recent/ProjectFiles/');
XMLConfig.SetValue('EnvironmentOptions/Recent/LastOpenDialogDir/Value'
,FLastOpenDialogDir);
// external tools
fExternalTools.Save(XMLConfig,'EnvironmentOptions/ExternalTools/');
@ -2394,6 +2386,7 @@ begin
SaveDialog:=TSaveDialog.Create(Application);
try
try
InputHistories.ApplyFileDialogSettings(SaveDialog);
SaveDialog.Filter:='Lazarus Desktop Settings (*.lds)|*.lds'
+'|XML files (*.xml)|*.xml'
+'|All files (*.*)|*.*';
@ -2409,6 +2402,7 @@ begin
AnEnvironmentOptions.Free;
end;
end;
InputHistories.StoreFileDialogSettings(SaveDialog);
except
// ToDo
writeln('ERROR: [TEnvironmentOptionsDialog.SaveDesktopSettingsToFileButtonClick]');
@ -2426,6 +2420,7 @@ begin
OpenDialog:=TOpenDialog.Create(Application);
try
try
InputHistories.ApplyFileDialogSettings(OpenDialog);
OpenDialog.Filter:='Lazarus Desktop Settings (*.lds)|*.lds'
+'|XML files (*.xml)|*.xml'
+'|All files (*.*)|*.*';
@ -2441,6 +2436,7 @@ begin
AnEnvironmentOptions.Free;
end;
end;
InputHistories.StoreFileDialogSettings(OpenDialog);
except
// ToDo
writeln('ERROR: [TEnvironmentOptionsDialog.SaveDesktopSettingsToFileButtonClick]');

View File

@ -29,7 +29,7 @@ interface
uses
Classes, SysUtils, Forms, Controls, Dialogs, Buttons, StdCtrls, IDEProcs,
LResources, TransferMacros;
LResources, TransferMacros, InputHistory;
type
TInputFileFlag = (iftDirectory, iftFilename, iftCmdLine,
@ -168,8 +168,10 @@ begin
if FileIndex<0 then exit;
if OpenDialog=nil then OpenDialog:=TOpenDialog.Create(Self);
with OpenDialog do begin
InputHistories.ApplyFileDialogSettings(OpenDialog);
Title:='Select '+GetGroupBox(FileIndex).Caption;
if (not Execute) then exit;
InputHistories.StoreFileDialogSettings(OpenDialog);
AFilename:=Filename;
if not FilenameIsValidForFileIndex(AFilename,FileIndex) then exit;
GetInputEdit(FileIndex).Text:=AFilename;

View File

@ -31,11 +31,20 @@ unit InputHistory;
interface
uses
Classes, SysUtils, IDEProcs, XMLCfg, LazConf;
Classes, SysUtils, IDEProcs, XMLCfg, LazConf, Dialogs;
type
TFileDialogSettings = record
InitialDir: string;
Width: integer;
Height: integer;
HistoryList: TStringList;
MaxHistory: integer;
end;
TInputHistories = class
private
FFileDialogSettings: TFileDialogSettings;
FFilename: string;
// Find- and replace-history
@ -68,6 +77,10 @@ type
function LastFPCUnitLinksValid: boolean;
function LastFPCUnitLinksNeedsUpdate(const SearchPath: string): boolean;
procedure SetLastFPCUnitLinks(const FPCPath, SearchPath, UnitLinks: string);
// filedialog
procedure ApplyFileDialogSettings(DestDialog: TFileDialog);
procedure StoreFileDialogSettings(SourceDialog: TFileDialog);
public
// Find- and replace-history
property FindHistory: TStringList read FFindHistory write FFindHistory;
@ -80,6 +93,10 @@ type
property LastFPCPath: string read FLastFPCPath write SetLastFPCPath;
property LastFPCSearchPath: string read FLastFPCSearchPath;
property LastFPCAge: longint read FLastFPCAge;
// filedialogs
property FileDialogSettings: TFileDialogSettings
read FFileDialogSettings write FFileDialogSettings;
end;
var InputHistories: TInputHistories;
@ -115,12 +132,16 @@ begin
FReplaceHistory:=TStringList.Create;
FMaxFindHistory:=20;
FFileDialogSettings.HistoryList:=TStringList.Create;
FFileDialogSettings.MaxHistory:=20;
FFilename:='';
Clear;
end;
destructor TInputHistories.Destroy;
begin
FFileDialogSettings.HistoryList.Free;
FFindHistory.Free;
FReplaceHistory.Free;
inherited Destroy;
@ -130,6 +151,12 @@ procedure TInputHistories.Clear;
begin
FFindHistory.Clear;
FReplaceHistory.Clear;
with FFileDialogSettings do begin
HistoryList.Clear;
Width:=0;
Height:=0;
InitialDir:='';
end;
FLastFPCPath:='';
end;
@ -144,6 +171,13 @@ begin
FLastFPCPath:=XMLConfig.GetValue(Path+'FPCUnitLinks/FPCPath','');
FLastFPCSearchPath:=XMLConfig.GetValue(Path+'FPCUnitLinks/FPCSearchPath','');
FLastFPCUnitLinks:=XMLConfig.GetValue(Path+'FPCUnitLinks/UnitLinks','');
with FFileDialogSettings do begin
Width:=XMLConfig.GetValue(Path+'FileDialog/Width',0);
Height:=XMLConfig.GetValue(Path+'FileDialog/Height',0);
InitialDir:=XMLConfig.GetValue(Path+'FileDialog/InitialDir','');
MaxHistory:=XMLConfig.GetValue(Path+'FileDialog/MaxHistory',20);
LoadRecentList(XMLConfig,HistoryList,Path+'FileDialog/HistoryList/');
end;
end;
procedure TInputHistories.SaveToXMLConfig(XMLConfig: TXMLConfig;
@ -157,6 +191,13 @@ begin
XMLConfig.SetValue(Path+'FPCUnitLinks/FPCPath',FLastFPCPath);
XMLConfig.SetValue(Path+'FPCUnitLinks/FPCSearchPath',FLastFPCSearchPath);
XMLConfig.SetValue(Path+'FPCUnitLinks/UnitLinks',FLastFPCUnitLinks);
with FFileDialogSettings do begin
XMLConfig.SetValue(Path+'FileDialog/Width',Width);
XMLConfig.SetValue(Path+'FileDialog/Height',Height);
XMLConfig.SetValue(Path+'FileDialog/InitialDir',InitialDir);
XMLConfig.SetValue(Path+'FileDialog/MaxHistory',MaxHistory);
SaveRecentList(XMLConfig,HistoryList,Path+'FileDialog/HistoryList/');
end;
end;
procedure TInputHistories.SetLazarusDefaultFilename;
@ -234,5 +275,26 @@ begin
FLastFPCAge:=FileAge(FPCPath);
end;
procedure TInputHistories.ApplyFileDialogSettings(DestDialog: TFileDialog);
begin
DestDialog.InitialDir:=FFileDialogSettings.InitialDir;
DestDialog.Width:=FFileDialogSettings.Width;
DestDialog.Height:=FFileDialogSettings.Height;
DestDialog.HistoryList:=FFileDialogSettings.HistoryList;
end;
procedure TInputHistories.StoreFileDialogSettings(SourceDialog: TFileDialog);
var s: string;
begin
FFileDialogSettings.InitialDir:=SourceDialog.InitialDir;
FFileDialogSettings.Width:=SourceDialog.Width;
FFileDialogSettings.Height:=SourceDialog.Height;
s:=ExtractFilePath(FFileDialogSettings.InitialDir);
if s<>'' then
AddToRecentList(s,FFileDialogSettings.HistoryList,
FFileDialogSettings.MaxHistory);
end;
end.

View File

@ -726,6 +726,7 @@ procedure TMainIDE.FormClose(Sender : TObject; var Action: TCloseAction);
begin
SaveEnvironment;
SaveIncludeLinks;
InputHistories.Save;
if TheControlSelection<>nil then TheControlSelection.Clear;
if SourceNoteBook<>nil then SourceNoteBook.ClearUnUsedEditorComponents(true);
end;
@ -1743,21 +1744,20 @@ begin
or (Sender is TSourceNoteBook) then begin
OpenDialog:=TOpenDialog.Create(Application);
try
InputHistories.ApplyFileDialogSettings(OpenDialog);
OpenDialog.Title:=lisOpenFile;
OpenDialog.InitialDir:=EnvironmentOptions.LastOpenDialogDir;
OpenDialog.Options:=[ofAllowMultiSelect];
OpenDialog.Options:=OpenDialog.Options+[ofAllowMultiSelect];
if OpenDialog.Execute and (OpenDialog.Files.Count>0) then begin
For I := 0 to OpenDialog.Files.Count-1 do
Begin
AFilename:=ExpandFilename(OpenDialog.Files.Strings[i]);
if i=0 then
EnvironmentOptions.LastOpenDialogDir:=ExtractFilePath(AFilename);
if DoOpenEditorFile(AFilename,[])=mrOk then begin
EnvironmentOptions.AddToRecentOpenFiles(AFilename);
EnvironmentOptions.AddToRecentOpenFiles(AFilename);
end;
end;
SaveEnvironment;
end;
InputHistories.StoreFileDialogSettings(OpenDialog);
finally
OpenDialog.Free;
end;
@ -2021,17 +2021,17 @@ begin
if Sender=itmProjectOpen then begin
OpenDialog:=TOpenDialog.Create(Application);
try
InputHistories.ApplyFileDialogSettings(OpenDialog);
OpenDialog.Title:=lisOpenProjectFile+' (*.lpi)';
OPenDialog.Filter := '*.lpi';
OpenDialog.InitialDir:=EnvironmentOptions.LastOpenDialogDir;
OpenDialog.Filter := 'Lazarus Project Info (*.lpi)|*.lpi|All Files|*.*';
if OpenDialog.Execute then begin
AFilename:=ExpandFilename(OpenDialog.Filename);
EnvironmentOptions.LastOpenDialogDir:=ExtractFilePath(AFilename);
if DoOpenProjectFile(AFilename)=mrOk then begin
EnvironmentOptions.AddToRecentProjectFiles(AFilename);
SaveEnvironment;
end;
end;
InputHistories.StoreFileDialogSettings(OpenDialog);
finally
OpenDialog.Free;
end;
@ -2527,9 +2527,9 @@ begin
SaveDialog:=TSaveDialog.Create(Application);
try
// show save dialog
InputHistories.ApplyFileDialogSettings(SaveDialog);
SaveDialog.Title:=lisSaveSpace+SaveAsFilename+' (*'+SaveAsFileExt+')';
SaveDialog.FileName:=SaveAsFilename+SaveAsFileExt;
SaveDialog.InitialDir:=EnvironmentOptions.LastOpenDialogDir;
if not SaveDialog.Execute then begin
// user cancels
Result:=mrCancel;
@ -2537,11 +2537,10 @@ begin
end;
NewFilename:=ExpandFilename(SaveDialog.Filename);
finally
InputHistories.StoreFileDialogSettings(SaveDialog);
SaveDialog.Free;
end;
EnvironmentOptions.LastOpenDialogDir:=ExtractFilePath(NewFilename);
// check unitname
if FilenameIsPascalUnit(NewFilename) then begin
NewUnitName:=ExtractFileNameOnly(NewFilename);
@ -3145,6 +3144,7 @@ begin
SaveDialog:=TSaveDialog.Create(Application);
try
InputHistories.ApplyFileDialogSettings(SaveDialog);
SaveDialog.Title:='Save Project '+Project1.Title+' (*.lpi)';
// build a nice project info filename suggestion
@ -3169,14 +3169,12 @@ begin
repeat
Result:=mrCancel;
SaveDialog.InitialDir:=EnvironmentOptions.LastOpenDialogDir;
if not SaveDialog.Execute then begin
// user cancels
Result:=mrCancel;
exit;
end;
NewFilename:=ExpandFilename(SaveDialog.Filename);
EnvironmentOptions.LastOpenDialogDir:=ExtractFilePath(NewFilename);
NewProgramName:=ExtractFileNameOnly(NewFilename);
// check filename
@ -3246,6 +3244,7 @@ begin
end;
until Result<>mrRetry;
finally
InputHistories.StoreFileDialogSettings(SaveDialog);
SaveDialog.Free;
end;
@ -3895,7 +3894,7 @@ begin
// search file in path (search especially for pascal files)
if FindFile(FName,SPath) then begin
result:=mrOk;
EnvironmentOptions.LastOpenDialogDir:=ExtractFilePath(FName);
InputHistories.FileDialogSettings.InitialDir:=ExtractFilePath(FName);
if DoOpenEditorFile(FName,[])=mrOk then begin
EnvironmentOptions.AddToRecentOpenFiles(FName);
SaveEnvironment;
@ -4584,6 +4583,9 @@ function TMainIDE.DoSaveAll: TModalResult;
begin
writeln('TMainIDE.DoSaveAll');
Result:=DoSaveProject([]);
SaveEnvironment;
SaveIncludeLinks;
InputHistories.Save;
// ToDo: save package, cvs settings, ...
end;
@ -6400,6 +6402,9 @@ end.
{ =============================================================================
$Log$
Revision 1.302 2002/05/30 14:18:46 lazarus
MG: filedialogs now saves size and history
Revision 1.301 2002/05/27 17:58:40 lazarus
MG: added command line help

View File

@ -48,7 +48,8 @@ uses
MemCheck,
{$ENDIF}
Classes, SysUtils, Controls, Forms, Buttons, StdCtrls, ComCtrls, Dialogs,
ExtCtrls, LResources, XMLCfg, DOS, IDEProcs, SysVarUserOverrideDlg;
ExtCtrls, LResources, XMLCfg, DOS, IDEProcs, SysVarUserOverrideDlg,
InputHistory;
{ The xml format version:
When the format changes (new values, changed formats) we can distinguish old
@ -717,6 +718,7 @@ var OpenDialog: TOpenDialog;
begin
OpenDialog:=TOpenDialog.Create(Self);
with OpenDialog do begin
InputHistories.ApplyFileDialogSettings(OpenDialog);
if HostApplicationEdit.Text<>'' then
OpenDialog.InitialDir:=ExtractFilePath(HostApplicationEdit.Text);
OpenDialog.Filename:=HostApplicationEdit.Text;
@ -729,6 +731,7 @@ begin
HostApplicationEdit.Text:=OpenDialog.Filename;
end;
end;
InputHistories.StoreFileDialogSettings(OpenDialog);
end;
end;
@ -778,6 +781,7 @@ var OpenDialog: TOpenDialog;
begin
OpenDialog:=TOpenDialog.Create(Self);
with OpenDialog do begin
InputHistories.ApplyFileDialogSettings(OpenDialog);
if WorkingDirectoryEdit.Text<>'' then
OpenDialog.InitialDir:=ExtractFilePath(WorkingDirectoryEdit.Text);
OpenDialog.Filename:=HostApplicationEdit.Text;
@ -790,6 +794,7 @@ begin
WorkingDirectoryEdit.Text:=OpenDialog.Filename;
end;
end;
InputHistories.StoreFileDialogSettings(OpenDialog);
end;
end;