001: /*
002: * :tabSize=8:indentSize=8:noTabs=false:
003: * :folding=explicit:collapseFolds=1:
004: *
005: * MacOSActions.java
006: * Copyright (C) 2002 Kris Kopicki
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package macos;
024:
025: //{{{ Imports
026: import java.io.*;
027: import javax.swing.*;
028: import com.apple.cocoa.application.*;
029: import com.apple.cocoa.foundation.*;
030: import org.gjt.sp.jedit.*;
031:
032: //}}}
033:
034: public class MacOSActions {
035: //{{{ showInFinder() method
036: public static void showInFinder(String path) {
037: if (new File(path).exists()) {
038: //Remember to make this an option later
039: //NSApplication.sharedApplication().hide(jEdit.getPlugin("MacOSPlugin"));
040: NSWorkspace.sharedWorkspace().selectFile(path, path);
041: }
042: } //}}}
043:
044: //{{{ runScript() method
045: public static void runScript(String path) {
046: new ScriptRunner(path).start();
047: //SwingUtilities.invokeLater(new ScriptRunner(path));
048: } //}}}
049:
050: //{{{ ScriptRunner class
051: static class ScriptRunner extends Thread {
052: private String path;
053:
054: public ScriptRunner(String path) {
055: this .path = path;
056: }
057:
058: public void run() {
059: File file = new File(path);
060:
061: if (file.exists()) {
062: try {
063: BufferedReader reader = new BufferedReader(
064: new FileReader(file));
065: StringBuffer code = new StringBuffer();
066: String line;
067:
068: while ((line = reader.readLine()) != null)
069: code.append(line + "\n");
070:
071: NSAppleScript script = new NSAppleScript(code
072: .toString());
073: NSMutableDictionary compileErrInfo = new NSMutableDictionary();
074: NSMutableDictionary execErrInfo = new NSMutableDictionary();
075: if (script.compile(compileErrInfo)) {
076: if (script.execute(execErrInfo) == null) {
077: JOptionPane
078: .showMessageDialog(
079: null,
080: execErrInfo
081: .objectForKey("NSAppleScriptErrorBriefMessage"),
082: jEdit
083: .getProperty("MacOSPlugin.dialog.script.title"),
084: JOptionPane.ERROR_MESSAGE);
085: }
086: } else {
087: JOptionPane
088: .showMessageDialog(
089: null,
090: compileErrInfo
091: .objectForKey("NSAppleScriptErrorBriefMessage"),
092: jEdit
093: .getProperty("MacOSPlugin.dialog.script.title"),
094: JOptionPane.ERROR_MESSAGE);
095: }
096: } catch (Exception ex) {
097: }
098: }
099: }
100: } //}}}
101: }
|