@@ -556,21 +556,28 @@ public void setBuildDirectory(File f) {
556556 /** Sets autofresh status of the project */
557557 public void setAutoRefreshStatus (boolean status ) { _state .setAutoRefreshStatus (status ); }
558558
559- /** @return the working directory for the Master JVM (editor and GUI). */
559+ /** @return the defrault working directory for the Master JVM (editor and GUI). If _activeDirectory is non-null,
560+ * it is probably a better choice for a guessed working directory. */
560561 public File getMasterWorkingDirectory () {
561- File file ;
562- try {
563- // restore the path from the configuration
564- file = FileOps .getValidDirectory (DrScala .getConfig ().getSetting (LAST_DIRECTORY ));
565- }
566- catch (RuntimeException e ) {
567- // something went wrong, clear the setting and use "user.home"
568- DrScala .getConfig ().setSetting (LAST_DIRECTORY , FileOps .NULL_FILE );
569- file = FileOps .getValidDirectory (new File (System .getProperty ("user.home" , "." )));
570- }
571- // update the setting and return it
572- DrScala .getConfig ().setSetting (LAST_DIRECTORY , file );
573- return file ;
562+ /* On startup, LAST_DIRECTORY is random! It may be left over from unit testing (including
563+ * a failing unit test) and no longer exist! It should NEVER be used in a fresh start of DrJava!
564+ */
565+ return FileOps .getValidDirectory (new File (System .getProperty ("user.home" , "." )));
566+
567+ // File file;
568+ // try {
569+ // // restore the path from the configuration
570+ // file = FileOps.getValidDirectory(DrScala.getConfig().getSetting(LAST_DIRECTORY));
571+ // }
572+ // catch (RuntimeException e) {
573+ // // something went wrong, clear the setting and use "user.home"
574+ // DrScala.getConfig().setSetting(LAST_DIRECTORY, FileOps.NULL_FILE);
575+ // file = ;
576+ // }
577+ // // update the setting and return it
578+ // DrScala.getConfig().setSetting(LAST_DIRECTORY, file);
579+ // return file;
580+ // }
574581 }
575582
576583 /** @return the working directory for the Slave (Interactions) JVM */
@@ -711,14 +718,14 @@ public File getWorkingDirectory() {
711718 // containing the project file
712719 File parentDir = _projectFile .getParentFile ();
713720 if (parentDir != null ) {
714- return parentDir .getCanonicalFile (); // default is project root
721+ return parentDir .getCanonicalFile (); // default is directory containing project file
715722 } // or if all else fails, user.dir
716723 else return new File (System .getProperty ("user.dir" ));
717724 }
718725 return _workDir .getCanonicalFile ();
719726 }
720727 catch (IOException e ) { /* fall through */ }
721- return _workDir .getAbsoluteFile ();
728+ return _workDir .getAbsoluteFile (); // Explain how getAbsoluteFile differs from getCanonicalFile
722729 }
723730
724731 /** Sets project file to specifed value; used in "Save Project As ..." command in MainFrame. */
@@ -1015,18 +1022,19 @@ public File getWorkingDirectory() {
10151022 Iterable <File > roots = getSourceRootSet ();
10161023 if (! IterUtil .isEmpty (roots )) { return IterUtil .first (roots ); }
10171024 else {
1018- // use the last directory saved to the configuration
1019- if (DrScala .getConfig ().getSetting (STICKY_INTERACTIONS_DIRECTORY )) {
1020- try {
1021- // restore the path from the configuration
1022- file = FileOps .getValidDirectory (DrScala .getConfig ().getSetting (LAST_INTERACTIONS_DIRECTORY ));
1023- }
1024- catch (RuntimeException e ) { file = FileOps .NULL_FILE ; }
1025- }
1026- if (file == FileOps .NULL_FILE ) {
1027- // something went wrong, clear the setting and use "user.home"
1028- file = FileOps .getValidDirectory (new File (System .getProperty ("user.home" , "." )));
1029- }
1025+ file = getMasterWorkingDirectory ();
1026+ // // use the last directory saved to the configuration
1027+ // if (DrScala.getConfig().getSetting(STICKY_INTERACTIONS_DIRECTORY)) {
1028+ // try {
1029+ // // restore the path from the configuration
1030+ // file = FileOps.getValidDirectory(DrScala.getConfig().getSetting(LAST_INTERACTIONS_DIRECTORY));
1031+ // }
1032+ // catch (RuntimeException e) { file = FileOps.NULL_FILE; }
1033+ // }
1034+ // if (file == FileOps.NULL_FILE) {
1035+ // // something went wrong, clear the setting and use "user.home"
1036+ // file = FileOps.getValidDirectory(new File(System.getProperty("user.home", ".")));
1037+ // }
10301038 // update the setting and return it
10311039 DrScala .getConfig ().setSetting (LAST_INTERACTIONS_DIRECTORY , file );
10321040 return file ;
@@ -1450,15 +1458,15 @@ private OpenDefinitionsDocument[] _openFiles(File[] files)
14501458 */
14511459 public void openFolder (File dir , boolean rec , String ext )
14521460 throws IOException , OperationCanceledException , AlreadyOpenException {
1453- debug .logStart ();
1461+ // debug.logStart();
14541462
14551463 final File [] sfiles = getFilesInFolder (dir , rec , ext );
14561464 if (sfiles == null ) return ;
14571465 openFiles (new FileOpenSelector () { public File [] getFiles () { return sfiles ; } });
14581466
14591467 if (sfiles .length > 0 && _state .inProjectPath (dir )) setProjectChanged (true );
14601468
1461- debug .logEnd ();
1469+ // debug.logEnd();
14621470 }
14631471
14641472 /** @return the file extension for the "Open Folder..." command for the currently selected compiler. */
@@ -2384,9 +2392,6 @@ void setDefinitionsIndent(int indent) {
23842392 /** A degenerate operation since this has no slave JVM and no interactions model. */
23852393 public void resetInteractions (File wd ) { /* do nothing */ }
23862394
2387- /** A degenerate operation since this has no slave JVM and no interactions model. */
2388- public void resetInteractions (File wd , boolean forceReset ) { /* do nothing */ }
2389-
23902395 /** Resets the console. Fires consoleReset() event. */
23912396 public void resetConsole () {
23922397 _consoleDoc .reset ("" );
@@ -4239,7 +4244,10 @@ private boolean _hasOneEmptyDocument() {
42394244
42404245 /** Creates a new document if there are currently no documents open. */
42414246 private void _ensureNotEmpty () {
4242- if (getDocumentCount () == 0 ) newFile (getMasterWorkingDirectory ());
4247+ if (getDocumentCount () == 0 ) {
4248+ File wd = _activeDirectory == null ? getMasterWorkingDirectory () : _activeDirectory ;
4249+ newFile (wd );
4250+ }
42434251 }
42444252
42454253 /** Makes sure that none of the documents in the list are active.
0 commit comments