PageRenderTime 139ms CodeModel.GetById 130ms app.highlight 6ms RepoModel.GetById 0ms app.codeStats 1ms

/jEdit/tags/jedit-4-2-pre4/jars/MacOS/macos/MacOSActions.java

#
Java | 120 lines | 45 code | 10 blank | 65 comment | 4 complexity | 5bc6e3c57e702ab36b484af9195b702b MD5 | raw file
  1/* 
  2 * :tabSize=8:indentSize=8:noTabs=false:
  3 * :folding=explicit:collapseFolds=1:
  4 *
  5 * MacOSActions.java
  6 * Copyright (C) 2002 Kris Kopicki
  7 *
  8 * This program is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU General Public License
 10 * as published by the Free Software Foundation; either version 2
 11 * of the License, or any later version.
 12 *
 13 * This program is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 16 * GNU General Public License for more details.
 17 *
 18 * You should have received a copy of the GNU General Public License
 19 * along with this program; if not, write to the Free Software
 20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 21 */
 22
 23package macos;
 24
 25//{{{ Imports
 26import java.io.*;
 27import javax.swing.*;
 28import com.apple.cocoa.application.*;
 29import com.apple.cocoa.foundation.*;
 30import org.gjt.sp.jedit.*;
 31//}}}
 32
 33public class MacOSActions
 34{
 35	//{{{ showInFinder() method
 36	public static void showInFinder(String path)
 37	{
 38		if (new File(path).exists())
 39		{
 40			//Remember to make this an option later
 41			//NSApplication.sharedApplication().hide(jEdit.getPlugin("MacOSPlugin"));
 42			NSWorkspace.sharedWorkspace().selectFile(path,path);
 43		}
 44	} //}}}
 45	
 46	//{{{ runScript() method
 47	public static void runScript(String path)
 48	{
 49		/*File file = new File(path);
 50			
 51		if (file.exists())
 52		{
 53			try {
 54				BufferedReader reader = new BufferedReader(new FileReader(file));
 55				StringBuffer code = new StringBuffer();
 56				String line;
 57				
 58				while ((line = reader.readLine()) != null)
 59					code.append(line);
 60				
 61				NSAppleScript script = new NSAppleScript(code.toString());
 62				script.compile(new NSMutableDictionary());
 63				script.execute(new NSMutableDictionary());
 64				
 65				/*
 66				String[] args = {"osascript",path};
 67				Process proc = Runtime.getRuntime().exec(args);
 68				BufferedReader r = new BufferedReader(
 69					new InputStreamReader(proc.getErrorStream()));
 70				//proc.waitFor();
 71				
 72				String mesg = new String();
 73				String line;
 74				while ((line = r.readLine()) != null)
 75				{
 76					if (!line.startsWith("##"))
 77						mesg += line;
 78				}
 79				r.close();
 80				
 81				if (proc.exitValue() != 0)
 82					JOptionPane.showMessageDialog(null,mesg,
 83						"Script Error",JOptionPane.ERROR_MESSAGE);
 84			} catch (Exception ex) {}
 85		}*/
 86		new ScriptRunner(path).start();
 87		//SwingUtilities.invokeLater(new ScriptRunner(path));
 88	} //}}}
 89	
 90	static class ScriptRunner extends Thread
 91	{
 92		private String path;
 93		
 94		public ScriptRunner(String path)
 95		{
 96			this.path = path;
 97		}
 98		
 99		public void run()
100		{
101			File file = new File(path);
102			
103			if (file.exists())
104			{
105				try {
106					BufferedReader reader = new BufferedReader(new FileReader(file));
107					StringBuffer code = new StringBuffer();
108					String line;
109					
110					while ((line = reader.readLine()) != null)
111						code.append(line);
112					
113					NSAppleScript script = new NSAppleScript(code.toString());
114					script.compile(new NSMutableDictionary());
115					script.execute(new NSMutableDictionary());
116				} catch (Exception ex) {}
117			}
118		}
119	}
120}