Skip to content

Instantly share code, notes, and snippets.

@yu-tang
Last active December 27, 2015 02:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save yu-tang/38d54daf58a34d7b9f8c to your computer and use it in GitHub Desktop.
Execute External Command and Reload
/* :name=Execute External Command and Reload :description=Execute External Command and Reload Current Project
* @author Yu Tang
* @date 2015-12-27
* @version 0.2
*/
def command = /C:\Program Files (x86)\microsoft office\OFFICE11\WINWORD.EXE/
import javax.swing.SwingUtilities
import static javax.swing.JOptionPane.*
import org.omegat.core.CoreEvents
import org.omegat.core.events.IProjectEventListener
import static org.omegat.core.events.IProjectEventListener.PROJECT_CHANGE_TYPE
import static org.omegat.gui.main.ProjectUICommands.projectClose
import static org.omegat.util.Platform.*
// abort if a project is not opened yet
def prop = project.projectProperties
if (!prop) {
final def title = 'Execute External Command and Reload'
final def msg = 'Please try again after you open a project.'
showMessageDialog null, msg, title, INFORMATION_MESSAGE
return
}
// In order to avoid any changes by following external command will be lost, close the project in first
def doRun
doRun = { PROJECT_CHANGE_TYPE eventType ->
if (eventType == PROJECT_CHANGE_TYPE.CLOSE) {
def p = command.execute()
p.waitFor()
console.println "exitValue: " + p.exitValue()
SwingUtilities.invokeLater {
mainWindow.mainMenu.projectRecentMenuItem.getItem(0).doClick()
} as Runnable
CoreEvents.unregisterProjectChangeListener(doRun)
}
} as IProjectEventListener
CoreEvents.registerProjectChangeListener(doRun)
projectClose()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment