Advertisement
KosIvantsov

open_glossary.groovy

May 25th, 2013
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.69 KB | None | 0 0
  1. /*
  2.  *  Open the writeable glossary 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 glossary file
  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.  
  21. // make a Closure to show message dialog
  22. def showMessage = { msg -> showMessageDialog null, msg, 'Open glossary', INFORMATION_MESSAGE }
  23.  
  24. // abort if a project is not opened yet
  25. def prop = project.projectProperties
  26. if (!prop) {
  27.   showMessage 'Please try again after you open a project.'
  28.   return
  29. }
  30.  
  31. // exit if file not found
  32. def file = prop.writeableGlossary
  33. if (! new File(file).exists()) {
  34.   showMessage 'Glossary file not found.'
  35.   return
  36. }
  37.  
  38. // get command GString list to open a file
  39. def command
  40. switch (osType) {
  41.   case [OsType.WIN64, OsType.WIN32]:
  42.     command = "cmd /c start \"\" \"$file\""  // default
  43.     try { command = textEditor instanceof List ? [*textEditor, file] : "\"$textEditor\" \"$file\"" } catch (ignore) {}
  44.     break
  45.   case [OsType.MAC64, OsType.MAC32]:
  46.     command = "open \"$file\""  // default
  47.     try { command = textEditor instanceof List ? [*textEditor, file] : "open -a \"$textEditor\" \"$file\"" } catch (ignore) {}
  48.     break
  49.   default:  // for Linux or others
  50.     command = ['xdg-open', file] // default
  51.     try { command = textEditor instanceof List ? [*textEditor, file] : [textEditor, file] } catch (ignore) {}
  52.     break
  53. }
  54.  
  55. // open it
  56. console.println "command: $command"
  57. command.execute()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement