Save and return to last directory in next Textmode IDE session

This commit is contained in:
Margers 2024-11-11 08:22:17 +00:00 committed by Michael Van Canneyt
parent 97b79b3d4e
commit 530f08d9d3
5 changed files with 75 additions and 4 deletions

View File

@ -450,6 +450,9 @@ BEGIN
InitDesktopFile;
LoadDesktop;
{Adjust to current directory, might be changed by LoadDesktop.}
IDEapp.CurDirChanged;
{Menubar might be changed because of loading INI file.}
IDEapp.reload_menubar;

View File

@ -126,6 +126,7 @@ const
dfSymbolInformation = $00000020;
dfCodeCompleteWords = $00000040;
dfCodeTemplates = $00000080;
dfReturnToLastDir = $00000100;
{ Auto Save flag constants }
asEditorFiles = $00000001; { Editor files }

View File

@ -33,6 +33,7 @@ const
ResSymbols = 'SYMBOLS';
ResCodeComplete = 'CODECOMPLETE';
ResCodeTemplates = 'CODETEMPLATES';
ResLastDirectory = 'LASTDIRECTORY';
ResKeys = 'KEYS';
procedure InitDesktopFile;
@ -91,6 +92,8 @@ const
msg_storingcodecompletewordlist = 'Writing CodeComplete wordlist...';
msg_readingcodetemplates = 'Reading CodeTemplates...';
msg_storingcodetemplates = 'Writing CodeTemplates...';
msg_readingreturntolastdir = 'Reading Last directory to return...';
msg_storingreturntolastdir = 'Writing Last directory to return...';
msg_readingsymbolinformation = 'Reading symbol information...';
msg_storingsymbolinformation = 'Storing symbol information...';
msg_failedtoreplacedesktopfile = 'Failed to replace desktop file.';
@ -110,6 +113,8 @@ const
msg_errorstoringvideomode = 'Error storing video mode';
msg_errorloadingcodetemplates = 'Error loading CodeTemplates';
msg_errorstoringcodetemplates = 'Error writing CodeTemplates';
msg_errorloadingreturntolastdir = 'Error loading Last directory to return';
msg_errorstoringreturntolastdir = 'Error writing Last directory to return';
msg_errorloadingsymbolinformation = 'Error loading symbol information';
msg_errorstoringsymbolinformation = 'Error storing symbol information';
msg_errorloadingcodecompletewordlist = 'Error loading CodeComplete wordlist';
@ -845,6 +850,61 @@ begin
WriteCodeTemplates:=OK;
end;
function ReadReturnToLastDir(F: PResourceFile): boolean;
var S: PMemoryStream;
OK: boolean;
Dir:AnsiString;
Size:sw_integer;
begin
PushStatus(msg_readingreturntolastdir);
New(S, Init(1024,4096));
OK:=F^.ReadResourceEntryToStream(ResLastDirectory,langDefault,S^);
S^.Seek(0);
if OK then
begin
S^.Read(Size, sizeof(Size)); { Read directory size }
if Size>0 then
begin
Setlength(Dir,Size);
S^.Read(Dir[1], Size); { Read the directory }
{$i-}ChDir(Dir);{$i+}
IOResult; {eat io result so it does not affect leater operations}
GetDir(0,StartUpDir);
end;
end;
Dispose(S, Done);
if OK=false then
ErrorBox(msg_errorloadingreturntolastdir,nil);
PopStatus;
ReadReturnToLastDir:=OK;
end;
function WriteReturnToLastDir(F: PResourceFile): boolean;
var OK: boolean;
S: PMemoryStream;
Dir:AnsiString;
Size:sw_integer;
begin
PushStatus(msg_storingreturntolastdir);
New(S, Init(1024,4096));
OK:=true;
{$i-}GetDir(0,Dir);{$i+}
if IOResult=0 then
begin
Size:=length(Dir);
S^.Write(Size, sizeof(Size));
if Size>0 then S^.Write(Dir[1],Size);
S^.Seek(0);
F^.CreateResource(ResLastDirectory,rcBinary,0);
OK:=F^.AddResourceEntryFromStream(ResLastDirectory,langDefault,0,S^,S^.GetSize);
end;
Dispose(S, Done);
if OK=false then
ErrorBox(msg_errorstoringreturntolastdir,nil);
PopStatus;
WriteReturnToLastDir:=OK;
end;
function ReadFlags(F: PResourceFile): boolean;
var
OK: boolean;
@ -967,6 +1027,8 @@ begin
OK:=ReadCodeComplete(F) and OK;
if ((DesktopFileFlags and dfCodeTemplates)<>0) then
OK:=ReadCodeTemplates(F) and OK;
if ((DesktopFileFlags and dfReturnToLastDir)<>0) then
OK:=WriteReturnToLastDir(F) and OK;
{$ifdef Unix}
OK:=ReadKeys(F) and OK;
{$endif Unix}
@ -1012,6 +1074,8 @@ begin
OK:=OK and WriteCodeComplete(F);
if ((DesktopFileFlags and dfCodeTemplates)<>0) then
OK:=OK and WriteCodeTemplates(F);
if ((DesktopFileFlags and dfReturnToLastDir)<>0) then
OK:=WriteReturnToLastDir(F) and OK;
{$ifdef Unix}
OK:=OK and WriteKeys(F);
{$endif Unix}

View File

@ -153,7 +153,9 @@ type
procedure AddRecentFile(AFileName: string; CurX, CurY: sw_integer);
function SearchRecentFile(AFileName: string): integer;
procedure RemoveRecentFile(Index: integer);
public
procedure CurDirChanged;
private
procedure UpdatePrimaryFile;
procedure UpdateINIFile;
procedure UpdateRecentFileList;
@ -664,6 +666,7 @@ resourcestring menu_local_gotosource = '~G~oto source';
label_desktop_symbolinfo = '~S~ymbol information';
label_desktop_codecompletewords = 'Co~d~eComplete wordlist';
label_desktop_codetemplates = 'Code~T~emplates';
label_desktop_returntolastdir = '~R~eturn to last directory';
label_desktop_preservedacrosssessions = '~P~reserved across sessions';
{Mouse options dialog.}
@ -862,7 +865,6 @@ begin
CompilerMessageWindow^.Hide;
Desktop^.Insert(CompilerMessageWindow);
Message(@Self,evBroadcast,cmUpdate,nil);
CurDirChanged;
{ heap viewer }
GetExtent(R); Dec(R.B.X); R.A.X:=R.B.X-9; R.A.Y:=R.B.Y-1;
New(HeapView, InitKb(R));

View File

@ -1422,12 +1422,12 @@ var R: TRect;
D: PCenterDialog;
CB: PCheckBoxes;
begin
R.Assign(0,0,40,12);
R.Assign(0,0,40,13);
New(D, Init(R, dialog_desktoppreferences));
with D^ do
begin
HelpCtx:=hcDesktopOptions;
GetExtent(R); R.Grow(-2,-2); Inc(R.A.Y); R.B.Y:=R.A.Y+8;
GetExtent(R); R.Grow(-2,-2); Inc(R.A.Y); R.B.Y:=R.A.Y+9;
New(CB, Init(R,
NewSItem(label_desktop_historylists,
NewSItem(label_desktop_clipboard,
@ -1437,7 +1437,8 @@ begin
NewSItem(label_desktop_symbolinfo,
NewSItem(label_desktop_codecompletewords,
NewSItem(label_desktop_codetemplates,
nil))))))))));
NewSItem(label_desktop_returntolastdir,
nil)))))))))));
CB^.Value:=DesktopFileFlags;
Insert(CB);
R.Move(0,-1); R.B.Y:=R.A.Y+1;