1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
/** :name=Auto Open Last Project :description=Allow to automatically open last used OmegaT project
*
* Allow to automatically open last used OmegaT project
*
* Usage: move this script to
* <your-scripts-folder>/application_startup/ sub-folder
* for event driven automatically execution.
*
* @author Yu Tang
* @date 2014-09-16
* @version 0.2
*/
import org.omegat.util.Log
import javax.swing.JMenu
import javax.swing.JMenuItem
openLastProject()
return
void openLastProject() {
final String SCRIPT_NAME = 'Auto Open Last Project'
JMenuItem item = lastProjectMenuItem
if (item == null) {
Log.log "$SCRIPT_NAME: No ProjectRecentMenuItems found."
} else if (!item.isEnabled()) {
Log.log "$SCRIPT_NAME: First ProjectRecentMenuItem is disabled."
} else if (org.omegat.Main.projectLocation) {
Log.log "$SCRIPT_NAME: Another project is specified via commandline arguments."
} else {
Log.log "$SCRIPT_NAME: Open '${item.text}'"
item.doClick()
}
}
JMenuItem getLastProjectMenuItem() {
JMenuItem item = null
try {
JMenu menu = (JMenu) mainWindow.mainMenu.projectRecentMenuItem
if (menu.itemCount > 0) {
item = menu.getItem(0)
}
//} catch (Exception ex) {
// java.lang.NoSuchMethodError not caught with Exception
} catch (Throwable ex) {
// ignore
}
item
}
|