Skip to content

Commit 70e1249

Browse files
author
mgricken
committed
Implemented feature request 2888809:
Interactions Working Directory Preference for Flat-File Mode There is a directory preference in the Preferences, Interactions category. It is only used in flat-file mode, not in project mode. If it is not set, then the source root of the document run is used. M src/edu/rice/cs/drjava/model/DefaultGlobalModel.java M src/edu/rice/cs/drjava/model/AbstractGlobalModel.java M src/edu/rice/cs/drjava/ui/config/ConfigFrame.java git-svn-id: file:///tmp/test-svn/trunk@5128 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 2d86cf0 commit 70e1249

3 files changed

Lines changed: 57 additions & 19 deletions

File tree

drjava/src/edu/rice/cs/drjava/model/AbstractGlobalModel.java

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -687,10 +687,23 @@ public File getProjectRoot() {
687687
public File getWorkingDirectory() {
688688
try {
689689
if (_workDir == null || _workDir == FileOps.NULL_FILE) {
690+
// if no project working directory is set, check preferences working directory
691+
File prefWorkDir = DrJava.getConfig().getSetting(FIXED_INTERACTIONS_DIRECTORY);
692+
if ((prefWorkDir != null) && (prefWorkDir != FileOps.NULL_FILE)) {
693+
try {
694+
// make sure it's a valid directory
695+
prefWorkDir = FileOps.getValidDirectory(prefWorkDir);
696+
}
697+
catch (RuntimeException e) { prefWorkDir = FileOps.NULL_FILE; }
698+
}
699+
if ((prefWorkDir != null) && (prefWorkDir != FileOps.NULL_FILE)) { return prefWorkDir; }
700+
701+
// if there is no fixed working directory in the preferences, use the directory
702+
// containing the project file
690703
File parentDir = _projectFile.getParentFile();
691704
if (parentDir != null) {
692705
return parentDir.getCanonicalFile(); // default is project root
693-
}
706+
} // or if all else fails, user.dir
694707
else return new File(System.getProperty("user.dir"));
695708
}
696709
return _workDir.getCanonicalFile();
@@ -919,11 +932,38 @@ class FlatFileGroupingState implements FileGroupingState {
919932
public File getBuildDirectory() { return FileOps.NULL_FILE; }
920933
public File getProjectRoot() { return getWorkingDirectory(); }
921934
public File getWorkingDirectory() {
935+
// if a fixed working directory has been set in the Preferences, use it
936+
File prefWorkDir = DrJava.getConfig().getSetting(FIXED_INTERACTIONS_DIRECTORY);
937+
if ((prefWorkDir != null) && (prefWorkDir != FileOps.NULL_FILE)) {
938+
try {
939+
// make sure it's a valid directory
940+
prefWorkDir = FileOps.getValidDirectory(prefWorkDir);
941+
}
942+
catch (RuntimeException e) { prefWorkDir = FileOps.NULL_FILE; }
943+
}
944+
if ((prefWorkDir != null) && (prefWorkDir != FileOps.NULL_FILE)) {
945+
// update the setting and return it
946+
DrJava.getConfig().setSetting(LAST_INTERACTIONS_DIRECTORY, prefWorkDir);
947+
return prefWorkDir;
948+
}
949+
950+
// otherwise determine the working directory based on the source root
951+
File file = FileOps.NULL_FILE;
952+
try {
953+
file = getActiveDocument().getSourceRoot(); // source root of the current document
954+
}
955+
catch(InvalidPackageException ipe) { file = FileOps.NULL_FILE; }
956+
if ((file != null) && (file != FileOps.NULL_FILE)) {
957+
// update the setting and return it
958+
DrJava.getConfig().setSetting(LAST_INTERACTIONS_DIRECTORY, file);
959+
return file;
960+
}
961+
962+
// if we can't get the source root of the current document, use the first document
922963
Iterable<File> roots = getSourceRootSet();
923964
if (!IterUtil.isEmpty(roots)) { return IterUtil.first(roots); }
924965
else {
925966
// use the last directory saved to the configuration
926-
File file = FileOps.NULL_FILE;
927967
if (DrJava.getConfig().getSetting(STICKY_INTERACTIONS_DIRECTORY)) {
928968
try {
929969
// restore the path from the configuration

drjava/src/edu/rice/cs/drjava/model/DefaultGlobalModel.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -540,17 +540,14 @@ public void run() {
540540
}
541541
};
542542

543+
File oldWorkDir = _interactionsModel.getWorkingDirectory();
543544
_interactionsModel.addListener(_runMain);
544545

545546
File workDir;
546-
if (isProjectActive()) workDir = getWorkingDirectory(); // use working directory for project
547-
else {
548-
// use source root of current document
549-
try { workDir = getSourceRoot(); }
550-
catch (InvalidPackageException e) { workDir = FileOps.NULL_FILE; }
551-
}
552-
// Reset interactions to the soure root for this document; class will be executed when new interpreter is ready
553-
resetInteractions(workDir);
547+
workDir = getWorkingDirectory();
548+
549+
// Reset interactions to the working directory
550+
resetInteractions(workDir, !workDir.equals(oldWorkDir));
554551
}
555552

556553
/** Runs the main method in this document in the interactions pane after resetting interactions with the source

drjava/src/edu/rice/cs/drjava/ui/config/ConfigFrame.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,15 +1443,16 @@ private void _setupInteractionsPanel(ConfigPanel panel) {
14431443
"(currently "+System.getProperty("user.home")+").");
14441444
addOptionComponent(panel, stickyComponent);
14451445

1446-
// OptionComponent.ChangeListener wdListener = new OptionComponent.ChangeListener() {
1447-
// public Object value(Object oc) {
1448-
// File f = wdComponent.getComponent().getFileFromField();
1449-
// boolean enabled = (f == null) || (f.equals(FileOps.NULL_FILE));
1450-
// stickyComponent.getComponent().setEnabled(enabled);
1451-
// return null;
1452-
// }
1453-
// };
1454-
// wdListener.value(wdComponent);
1446+
OptionComponent.ChangeListener wdListener = new OptionComponent.ChangeListener() {
1447+
public Object value(Object oc) {
1448+
File f = wdComponent.getComponent().getFileFromField();
1449+
boolean enabled = (f == null) || (f.equals(FileOps.NULL_FILE));
1450+
stickyComponent.getComponent().setEnabled(enabled);
1451+
return null;
1452+
}
1453+
};
1454+
wdComponent.addChangeListener(wdListener);
1455+
wdListener.value(wdComponent);
14551456

14561457
addOptionComponent(panel, new LabelComponent("<html>&nbsp;</html>", this, true));
14571458
addOptionComponent(panel, new LabelComponent("<html>&nbsp;</html>", this, true));

0 commit comments

Comments
 (0)