Advertisement
KosIvantsov

open_current_file.groovy

May 25th, 2013
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 0.94 KB | None | 0 0
  1. /*
  2.  *  Open current file
  3.  *
  4.  * @author  Yu Tang
  5.  * @date    2013-05-23
  6.  * @version 0.2
  7.  */
  8.  
  9. import static javax.swing.JOptionPane.*
  10. import static org.omegat.util.Platform.*
  11.  
  12. // abort if a project is not opened yet
  13. def prop = project.projectProperties
  14. if (!prop) {
  15.   final def title = 'open current file'
  16.   final def msg   = 'Please try again after you open a project.'
  17.   showMessageDialog null, msg, title, INFORMATION_MESSAGE
  18.   return
  19. }
  20.  
  21. // get command GString to open a file
  22. def file = prop.sourceRoot + editor.currentFile
  23. def command
  24. switch (osType) {
  25.   case [OsType.WIN64, OsType.WIN32]:
  26.     command = "cmd /c start \"\" \"$file\"" // for WinNT
  27.     // command = "command /c start \"\" \"$file\"" // for Win9x or WinME
  28.     break
  29.   case [OsType.MAC64, OsType.MAC32]:
  30.     command = "open \"$file\""
  31.     break
  32.   default:  // for Linux or others
  33.     command = ['xdg-open', file]
  34.     break
  35. }
  36.  
  37. // open it
  38. command.execute()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement