Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
2015OmegaT/OmegaT/scripts/auto_open_last_project.groovy
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
50 lines (45 sloc)
1.37 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** :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 | |
} |