Skip to content

Commit 5e7a160

Browse files
author
mgricken
committed
Opening .drjava projects by double-clicking on Macs.
git-svn-id: file:///tmp/test-svn/trunk@4952 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 6db37f3 commit 5e7a160

8 files changed

Lines changed: 84 additions & 49 deletions

File tree

drjava/lib/platform.jar

704 Bytes
Binary file not shown.

drjava/packaging/mac/DrJava.app/Contents/Info.plist

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,18 @@
3636
<string>$APP_PACKAGE/Contents/Resources/DrJava.icns</string>
3737
</dict>
3838
</dict>
39+
<key>CFBundleDocumentTypes</key>
40+
<array>
41+
<dict>
42+
<key>CFBundleTypeExtensions</key>
43+
<array>
44+
<string>drjava</string>
45+
</array>
46+
<key>CFBundleTypeName</key>
47+
<string>DrJava Project File</string>
48+
<key>CFBundleTypeRole</key>
49+
<string>Editor</string>
50+
</dict>
51+
</array>
3952
</dict>
4053
</plist>

drjava/src/edu/rice/cs/drjava/DrJava.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@
6666
* @version $Id$
6767
*/
6868
public class DrJava {
69-
70-
private static volatile Log _log = new Log("DrJava.txt", false);
69+
public static volatile Log _log = new Log("DrJava.txt", false);
7170

7271
private static final String DEFAULT_MAX_HEAP_SIZE_ARG = "-Xmx128M";
7372

@@ -79,9 +78,6 @@ public class DrJava {
7978
/** true if a new instance of DrJava should be started instead of
8079
* connecting to an already running instance. */
8180
static volatile boolean _forceNewInstance = false;
82-
83-
/** true if the files that were specified on the command line contain project files */
84-
static volatile boolean _filesToOpenContainProjectFiles = false;
8581

8682
/** Time in millisecond before restarting DrJava to change the heap size, etc. is deemed a success. */
8783
private static final int WAIT_BEFORE_DECLARING_SUCCESS = 5000;
@@ -108,6 +104,16 @@ public class DrJava {
108104
/** @return an array of the files that were passed on the command line. */
109105
public static String[] getFilesToOpen() { return _filesToOpen.toArray(new String[0]); }
110106

107+
/** Add a file to the list of files to open. */
108+
public static void addFileToOpen(String s) {
109+
_filesToOpen.add(s);
110+
boolean isProjectFile =
111+
s.endsWith(OptionConstants.PROJECT_FILE_EXTENSION) ||
112+
s.endsWith(OptionConstants.PROJECT_FILE_EXTENSION2) ||
113+
s.endsWith(OptionConstants.OLD_PROJECT_FILE_EXTENSION);
114+
_forceNewInstance |= isProjectFile;
115+
}
116+
111117
/** @return true if the debug console should be enabled */
112118
public static boolean getShowDebugConsole() { return _showDebugConsole; }
113119

@@ -263,6 +269,8 @@ static boolean handleCommandLineArgs(String[] args) {
263269
// Loop through arguments looking for known options
264270
int argIndex = 0;
265271
int len = args.length;
272+
_log.log("handleCommandLineArgs. _filesToOpen: "+_filesToOpen);
273+
_log.log("\t_filesToOpen cleared");
266274
_filesToOpen.clear();
267275

268276
while(argIndex < len) {
@@ -299,19 +307,6 @@ else if (arg.equals("-help") || arg.equals("-?")) {
299307
else {
300308
// this is the first file to open, do not consume
301309
--argIndex;
302-
303-
// check if any of the files to open is a project file
304-
_filesToOpenContainProjectFiles = false;
305-
for (int tempIndex = argIndex; tempIndex < len; ++tempIndex) {
306-
String currFileName = args[tempIndex];
307-
boolean isProjectFile =
308-
currFileName.endsWith(OptionConstants.PROJECT_FILE_EXTENSION) ||
309-
currFileName.endsWith(OptionConstants.PROJECT_FILE_EXTENSION2) ||
310-
currFileName.endsWith(OptionConstants.OLD_PROJECT_FILE_EXTENSION);
311-
_filesToOpenContainProjectFiles |= isProjectFile;
312-
}
313-
// if a project file was specified, force a new instance
314-
if (_filesToOpenContainProjectFiles) _forceNewInstance = true;
315310
break;
316311
}
317312
}
@@ -341,7 +336,9 @@ else if (arg.equals("-help") || arg.equals("-?")) {
341336

342337
// Open the remaining args as filenames
343338

344-
for (int i = argIndex; i < len; i++) { _filesToOpen.add(args[i]); }
339+
for (int i = argIndex; i < len; i++) { addFileToOpen(args[i]); }
340+
_log.log("\t _filesToOpen now contains: "+_filesToOpen);
341+
345342
return true;
346343
}
347344

@@ -448,7 +445,9 @@ protected static void _saveConfig() {
448445

449446
/* Erase all non-final bindings created in this class. Only used in testing. */
450447
public static void cleanUp() {
448+
_log.log("cleanUp. _filesToOpen: "+_filesToOpen);
451449
_filesToOpen.clear();
450+
_log.log("\t_filesToOpen cleared");
452451
_jvmArgs.clear();
453452
// Do not set _config or _propertiesFile to null because THEY ARE static
454453
}

drjava/src/edu/rice/cs/drjava/DrJavaRoot.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,5 +348,20 @@ public static void installModalWindowAdapter(final Window w,
348348
public static void removeModalWindowAdapter(Window w) {
349349
_mainFrame.removeModalWindowAdapter(w);
350350
}
351+
352+
/** Handles an "open file" request, either from the remote control server or the operating system.
353+
* @param f file to open
354+
* @param lineNo line number to jump to, or -1 of not specified */
355+
public static void handleRemoteOpenFile(File f, int lineNo) {
356+
DrJava._log.log("DrJavaRoot.handleRemoteOpenFile, f="+f);
357+
if (_mainFrame != null) {
358+
DrJava._log.log("\tcalling _mainFrame");
359+
_mainFrame.handleRemoteOpenFile(f, lineNo);
360+
}
361+
else {
362+
DrJava._log.log("\tadded to _filesToOpen");
363+
DrJava.addFileToOpen(f.getAbsolutePath());
364+
}
365+
}
351366
}
352367

drjava/src/edu/rice/cs/drjava/RemoteControlServer.java

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -145,33 +145,7 @@ public void run() {
145145

146146
final File f = new File(request);
147147
if (f.exists()) {
148-
String currFileName = f.getName();
149-
if (currFileName.endsWith(OptionConstants.EXTPROCESS_FILE_EXTENSION)) {
150-
MainFrame.openExtProcessFile(f);
151-
}
152-
else {
153-
FileOpenSelector openSelector = new FileOpenSelector() {
154-
public File[] getFiles() throws OperationCanceledException {
155-
return new File[] { f };
156-
}
157-
};
158-
if (_frame != null) {
159-
if (currFileName.endsWith(OptionConstants.PROJECT_FILE_EXTENSION) ||
160-
currFileName.endsWith(OptionConstants.PROJECT_FILE_EXTENSION2) ||
161-
currFileName.endsWith(OptionConstants.OLD_PROJECT_FILE_EXTENSION)) {
162-
_frame.openProject(openSelector);
163-
}
164-
else {
165-
_frame.open(openSelector);
166-
if (lineNo>=0) {
167-
final int l = lineNo;
168-
edu.rice.cs.util.swing.Utilities.invokeLater(new Runnable() {
169-
public void run() { _frame._jumpToLine(l); }
170-
});
171-
}
172-
}
173-
}
174-
}
148+
DrJavaRoot.handleRemoteOpenFile(f, lineNo);
175149
}
176150
}
177151
else {

drjava/src/edu/rice/cs/drjava/model/cache/DocumentCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public class DocumentCache {
8383

8484
private static final int INIT_CACHE_SIZE = 32;
8585

86-
/** @invariant _residentQueue.size() <= CACHE_SIZE */
86+
/** invariant _residentQueue.size() <= CACHE_SIZE */
8787
private int CACHE_SIZE;
8888

8989
private LinkedHashSet<DocManager> _residentQueue;

drjava/src/edu/rice/cs/drjava/model/debug/jpda/JPDADebugger.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,8 +1489,8 @@ private ObjectReference _box(PrimitiveValue val, ThreadReference thread,
14891489

14901490

14911491
/** Create an unboxed primitive corresponding to the given object.
1492-
* @throw DebugException If the value is not of a type that can be unboxed, or if an error
1493-
* occurs in the unboxing method invocation.
1492+
* @throws DebugException If the value is not of a type that can be unboxed, or if an error
1493+
* occurs in the unboxing method invocation.
14941494
*/
14951495
private PrimitiveValue _unbox(ObjectReference val, ThreadReference thread) throws DebugException {
14961496
if (val == null) { throw new DebugException("Value can't be unboxed"); }

drjava/src/edu/rice/cs/drjava/ui/MainFrame.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4562,6 +4562,8 @@ boolean closeProject() {
45624562
* @return true if the project is closed, false if cancelled
45634563
*/
45644564
boolean _closeProject(boolean quitting) {
4565+
// TODO: in some cases, it is possible to see the documents being removed in the navigation pane
4566+
// this can cause errors. fix this.
45654567
_completeClassSet = new HashSet<GoToFileListEntry>(); // reset auto-completion list
45664568
_autoImportClassSet = new HashSet<JavaAPIListEntry>(); // reset auto-import list
45674569

@@ -9814,6 +9816,38 @@ private static List<File> textURIListToFileList(String data) {
98149816
return list;
98159817
}
98169818

9819+
/** Handles an "open file" request, either from the remote control server or the operating system.
9820+
* @param f file to open
9821+
* @param lineNo line number to jump to, or -1 of not specified
9822+
*/
9823+
public void handleRemoteOpenFile(final File f, final int lineNo) {
9824+
if (f.getName().endsWith(OptionConstants.EXTPROCESS_FILE_EXTENSION)) {
9825+
openExtProcessFile(f);
9826+
}
9827+
else {
9828+
FileOpenSelector openSelector = new FileOpenSelector() {
9829+
public File[] getFiles() throws OperationCanceledException {
9830+
return new File[] { f };
9831+
}
9832+
};
9833+
String currFileName = f.getName();
9834+
if (currFileName.endsWith(OptionConstants.PROJECT_FILE_EXTENSION) ||
9835+
currFileName.endsWith(OptionConstants.PROJECT_FILE_EXTENSION2) ||
9836+
currFileName.endsWith(OptionConstants.OLD_PROJECT_FILE_EXTENSION)) {
9837+
openProject(openSelector);
9838+
}
9839+
else {
9840+
open(openSelector);
9841+
if (lineNo>=0) {
9842+
final int l = lineNo;
9843+
Utilities.invokeLater(new Runnable() {
9844+
public void run() { _jumpToLine(l); }
9845+
});
9846+
}
9847+
}
9848+
}
9849+
}
9850+
98179851
/** Reset the position of the "Open Javadoc" dialog. */
98189852
public void resetAutoImportDialogPosition() {
98199853
_initAutoImportDialog();

0 commit comments

Comments
 (0)