Sfoglia il codice sorgente

File dialog saves last directory

Arthur Yefimov 3 anni fa
parent
commit
7bd80ce9ff
2 ha cambiato i file con 27 aggiunte e 10 eliminazioni
  1. 6 4
      src/Editor.Mod
  2. 21 6
      src/FreeOberon.Mod

+ 6 - 4
src/Editor.Mod

@@ -219,7 +219,7 @@ BEGIN C := c(OV.ColumnList); w := C.parent(FileDialog);
   OV.EditSetCaption(w.edtFilename, s)
 END FileDialogListChange;
 
-PROCEDURE InitFileDialog*(c: FileDialog; type: INTEGER);
+PROCEDURE InitFileDialog*(c: FileDialog; type: INTEGER; IN dir: ARRAY OF CHAR);
 VAR L: INTEGER;
   s: FoStrings.String;
 BEGIN OV.InitWindow(c); c.do := fileDialogMethod; c.type := type;
@@ -257,7 +257,9 @@ BEGIN OV.InitWindow(c); c.do := fileDialogMethod; c.type := type;
     IF c.home[L] = '\' THEN c.home[L] := '/' END; INC(L)
   END; (* L = length of c.home; append / if it is not in the end *)
   IF c.home[L - 1] # '/' THEN c.home[L] := '/'; INC(L); c.home[L] := 0X END;
-  Strings.Append(Config.stdPath, c.home); c.path := c.home$;
+  Strings.Append(Config.stdPath, c.home);
+
+  IF dir[0] = 0X THEN c.path := c.home$ ELSE c.path := dir$ END; 
 
   (* ColumnList *)
   c.colFiles := OV.NewColumnList();
@@ -271,9 +273,9 @@ BEGIN OV.InitWindow(c); c.do := fileDialogMethod; c.type := type;
   OV.Add(c, c.colFiles)
 END InitFileDialog;
 
-PROCEDURE NewFileDialog*(type: INTEGER): FileDialog;
+PROCEDURE NewFileDialog*(type: INTEGER; IN dir: ARRAY OF CHAR): FileDialog;
 VAR c: FileDialog;
-BEGIN NEW(c); InitFileDialog(c, type) ;
+BEGIN NEW(c); InitFileDialog(c, type, dir) ;
 RETURN c END NewFileDialog;
 
 (* FileDialog Method *)

+ 21 - 6
src/FreeOberon.Mod

@@ -58,13 +58,14 @@ TYPE
   END;
 
 VAR
-  progBuf: ARRAY 16300 OF SHORTCHAR; (* For interacting with a launched program *)
-  inputBuf: ARRAY 16300 OF CHAR; (* Saves entered chars before Enter pressed *)
+  progBuf: ARRAY 16300 OF SHORTCHAR; (* For interaction with running program *)
+  inputBuf: ARRAY 16300 OF CHAR; (* Holds entered chars before Enter pressed *)
   inputBufLen: INTEGER;
   programFinished: BOOLEAN;
+  lastFileDialogDir: ARRAY 256 OF CHAR; (* Directory path for file dialog *)
   app: OV.App;
 
-  curX, curY: INTEGER; (* Cursor position *)
+  curX, curY: INTEGER; (* Text cursor position *)
   curFg, curBg: INTEGER; (* Current foreground and background of proc. Write *)
   terminalNeedRedraw: BOOLEAN; (* Used when a compiled program is running *)
   terminalMouseShown: BOOLEAN; (* Same *)
@@ -391,8 +392,21 @@ BEGIN dir := prg$; curX := 0; curY := 0; curFg := 7; curBg := 0;
   END
 END RunProgram;
 
+(** Puts in dir part of string s, before the last '/'.
+    If there is no '/', dir is ''. *)
+PROCEDURE DirName(IN s: ARRAY OF CHAR; OUT dir: ARRAY OF CHAR);
+VAR i: INTEGER;
+BEGIN
+  i := 0; WHILE s[i] # 0X DO INC(i) END;
+  WHILE (i >= 0) & (s[i] # '/') DO DEC(i) END;
+  dir[i + 1] := 0X;
+  WHILE i >= 0 DO dir[i] := s[i]; DEC(i) END
+END DirName;
+
 PROCEDURE OpenFileOkClick(c: OV.Control; fname: ARRAY OF CHAR);
-BEGIN DoOpenFile(fname)
+BEGIN
+  DirName(fname, lastFileDialogDir);
+  DoOpenFile(fname)
 END OpenFileOkClick;
 
 PROCEDURE DoSaveFile(c: OV.Control; fname: ARRAY OF CHAR);
@@ -411,7 +425,7 @@ END DoSaveFile;
 PROCEDURE FileOpen(c: OV.Control);
 VAR w: Editor.FileDialog;
 BEGIN
-  w := Editor.NewFileDialog(Editor.open);
+  w := Editor.NewFileDialog(Editor.open, lastFileDialogDir);
   w.onFileOk := OpenFileOkClick;
   OV.AddWindow(app, w)
 END FileOpen;
@@ -430,7 +444,7 @@ END FileReload;
 PROCEDURE FileSaveAs(c: OV.Control);
 VAR d: Editor.FileDialog;
   w: OV.Window; e: Editor.Editor;
-BEGIN d := Editor.NewFileDialog(Editor.save);
+BEGIN d := Editor.NewFileDialog(Editor.save, lastFileDialogDir);
   d.onFileOk := DoSaveFile;
   w := c.app.windows;
   IF (w # NIL) & (w IS Editor.Editor) THEN e := w(Editor.Editor);
@@ -938,6 +952,7 @@ VAR success, fs, sw: BOOLEAN;
   opt: SET;
 BEGIN
   success := FALSE;
+  lastFileDialogDir := '';
   ParseArgs(fs, sw, w, h, lang, fnames);
   opt := {T.resizable, T.center};
   IF fs THEN INCL(opt, T.fullscreen) ELSE INCL(opt, T.window) END;