PageRenderTime 37ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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. package macos;
  23. //{{{ Imports
  24. import java.io.*;
  25. import javax.swing.*;
  26. import com.apple.cocoa.application.*;
  27. import com.apple.cocoa.foundation.*;
  28. import org.gjt.sp.jedit.*;
  29. //}}}
  30. public class MacOSActions
  31. {
  32. //{{{ showInFinder() method
  33. public static void showInFinder(String path)
  34. {
  35. if (new File(path).exists())
  36. {
  37. //Remember to make this an option later
  38. //NSApplication.sharedApplication().hide(jEdit.getPlugin("MacOSPlugin"));
  39. NSWorkspace.sharedWorkspace().selectFile(path,path);
  40. }
  41. } //}}}
  42. //{{{ runScript() method
  43. public static void runScript(String path)
  44. {
  45. /*File file = new File(path);
  46. if (file.exists())
  47. {
  48. try {
  49. BufferedReader reader = new BufferedReader(new FileReader(file));
  50. StringBuffer code = new StringBuffer();
  51. String line;
  52. while ((line = reader.readLine()) != null)
  53. code.append(line);
  54. NSAppleScript script = new NSAppleScript(code.toString());
  55. script.compile(new NSMutableDictionary());
  56. script.execute(new NSMutableDictionary());
  57. /*
  58. String[] args = {"osascript",path};
  59. Process proc = Runtime.getRuntime().exec(args);
  60. BufferedReader r = new BufferedReader(
  61. new InputStreamReader(proc.getErrorStream()));
  62. //proc.waitFor();
  63. String mesg = new String();
  64. String line;
  65. while ((line = r.readLine()) != null)
  66. {
  67. if (!line.startsWith("##"))
  68. mesg += line;
  69. }
  70. r.close();
  71. if (proc.exitValue() != 0)
  72. JOptionPane.showMessageDialog(null,mesg,
  73. "Script Error",JOptionPane.ERROR_MESSAGE);
  74. } catch (Exception ex) {}
  75. }*/
  76. new ScriptRunner(path).start();
  77. //SwingUtilities.invokeLater(new ScriptRunner(path));
  78. } //}}}
  79. static class ScriptRunner extends Thread
  80. {
  81. private String path;
  82. public ScriptRunner(String path)
  83. {
  84. this.path = path;
  85. }
  86. public void run()
  87. {
  88. File file = new File(path);
  89. if (file.exists())
  90. {
  91. try {
  92. BufferedReader reader = new BufferedReader(new FileReader(file));
  93. StringBuffer code = new StringBuffer();
  94. String line;
  95. while ((line = reader.readLine()) != null)
  96. code.append(line);
  97. NSAppleScript script = new NSAppleScript(code.toString());
  98. script.compile(new NSMutableDictionary());
  99. script.execute(new NSMutableDictionary());
  100. } catch (Exception ex) {}
  101. }
  102. }
  103. }
  104. }