Advertisement
KosIvantsov

open_project_save.groovy

May 25th, 2013
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.60 KB | None | 0 0
  1. /*
  2.  *  Open project_save.tmx in an editor
  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. /**
  13.  * Uncomment the next line if you want to set a default text editor
  14.  * that will open project_save.tmx
  15.  */
  16. // def textEditor = /path to your editor/
  17. // E.g., /TextMate/
  18. // /C:\Program Files (x86)\editor\editor.exe/
  19. // ['x-terminal-emulator', '-e', 'vi']
  20. // "x-terminal-emulator -e vi".split()
  21.  
  22. // abort if a project is not opened yet
  23. def prop = project.projectProperties
  24. if (!prop) {
  25.   final def title = 'open project_save.tmx'
  26.   final def msg   = 'Please try again after you open a project.'
  27.   showMessageDialog null, msg, title, INFORMATION_MESSAGE
  28.   return
  29. }
  30.  
  31. // get command GString list to open a file
  32. def file = "${prop.projectInternal}project_save.tmx"
  33. def command
  34. switch (osType) {
  35.   case [OsType.WIN64, OsType.WIN32]:
  36.     command = "cmd /c start \"\" \"$file\""  // default
  37.     try { command = textEditor instanceof List ? [*textEditor, file] : "\"$textEditor\" \"$file\"" } catch (ignore) {}
  38.     break
  39.   case [OsType.MAC64, OsType.MAC32]:
  40.     command = "open \"$file\""  // default
  41.     try { command = textEditor instanceof List ? [*textEditor, file] : "open -a \"$textEditor\" \"$file\"" } catch (ignore) {}
  42.     break
  43.   default:  // for Linux or others
  44.     command = ['xdg-open', file] // default
  45.     try { command = textEditor instanceof List ? [*textEditor, file] : [textEditor, file] } catch (ignore) {}
  46.     break
  47. }
  48.  
  49. // open it
  50. console.println "command: $command"
  51. command.execute()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement