File: auto_open_last_project.groovy

package info (click to toggle)
omegat 3.6.0.10%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 63,728 kB
  • sloc: xml: 114,044; java: 74,758; sh: 174; javascript: 108; makefile: 22
file content (50 lines) | stat: -rw-r--r-- 1,404 bytes parent folder | download | duplicates (2)
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
}