public void projectAccessTMMenuItemActionPerformed() {
   if (!Core.getProject().isProjectLoaded()) {
     return;
   }
   String path = Core.getProject().getProjectProperties().getTMRoot();
   openFile(new File(path));
 }
  /** Displays the filters setup dialog to allow customizing file filters in detail. */
  public void optionsSetupFileFiltersMenuItemActionPerformed() {
    FiltersCustomizer dlg =
        new FiltersCustomizer(
            mainWindow,
            false,
            FilterMaster.createDefaultFiltersConfig(),
            FilterMaster.loadConfig(StaticUtils.getConfigDir()),
            null);
    dlg.setVisible(true);
    if (dlg.getReturnStatus() == FiltersCustomizer.RET_OK) {
      // saving config
      FilterMaster.saveConfig(dlg.result, StaticUtils.getConfigDir());

      if (Core.getProject().isProjectLoaded()) {
        if (FilterMaster.loadConfig(Core.getProject().getProjectProperties().getProjectInternal())
            != null) {
          // project specific filters are in place. No need to reload project when
          // non-project-specific filters are changed
          return;
        }
        // asking to reload a project
        int res =
            JOptionPane.showConfirmDialog(
                mainWindow,
                OStrings.getString("MW_REOPEN_QUESTION"),
                OStrings.getString("MW_REOPEN_TITLE"),
                JOptionPane.YES_NO_OPTION);
        if (res == JOptionPane.YES_OPTION) ProjectUICommands.projectReload();
      }
    }
  }
  public static void projectSave() {
    UIThreadsUtil.mustBeSwingThread();

    if (!Core.getProject().isProjectLoaded()) {
      return;
    }

    // commit the current entry first
    Core.getEditor().commitAndLeave();

    new SwingWorker<Object, Void>() {
      protected Object doInBackground() throws Exception {
        IMainWindow mainWindow = Core.getMainWindow();
        Cursor hourglassCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
        Cursor oldCursor = mainWindow.getCursor();
        mainWindow.setCursor(hourglassCursor);

        mainWindow.showStatusMessageRB("MW_STATUS_SAVING");

        Core.executeExclusively(true, () -> Core.getProject().saveProject(true));

        mainWindow.showStatusMessageRB("MW_STATUS_SAVED");
        mainWindow.setCursor(oldCursor);
        return null;
      }

      protected void done() {
        try {
          get();
        } catch (Exception ex) {
          processSwingWorkerException(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
        }
      }
    }.execute();
  }
  public static void projectCompile() {
    UIThreadsUtil.mustBeSwingThread();

    if (!Core.getProject().isProjectLoaded()) {
      return;
    }

    // commit the current entry first
    Core.getEditor().commitAndLeave();

    new SwingWorker<Object, Void>() {
      protected Object doInBackground() throws Exception {
        Core.executeExclusively(
            true,
            () -> {
              Core.getProject().saveProject(true);
              try {
                Core.getProject().compileProject(".*");
              } catch (Exception ex) {
                throw new RuntimeException(ex);
              }
            });
        return null;
      }

      protected void done() {
        try {
          get();
        } catch (Exception ex) {
          processSwingWorkerException(ex, "TF_COMPILE_ERROR");
        }
      }
    }.execute();
  }
Beispiel #5
0
  public static Object executeScriptFileHeadless(
      ScriptItem scriptItem, boolean forceFromFile, Map<String, Object> additionalBindings) {
    ScriptEngineManager manager = new ScriptEngineManager(ScriptingWindow.class.getClassLoader());
    ScriptEngine scriptEngine =
        manager.getEngineByExtension(getFileExtension(scriptItem.getName()));

    if (scriptEngine == null) {
      scriptEngine = manager.getEngineByName(DEFAULT_SCRIPT);
    }

    SimpleBindings bindings = new SimpleBindings();
    bindings.put(VAR_PROJECT, Core.getProject());
    bindings.put(VAR_EDITOR, Core.getEditor());
    bindings.put(VAR_GLOSSARY, Core.getGlossary());
    bindings.put(VAR_MAINWINDOW, Core.getMainWindow());
    bindings.put(VAR_RESOURCES, scriptItem.getResourceBundle());

    if (additionalBindings != null) {
      bindings.putAll(additionalBindings);
    }

    Object eval = null;
    try {
      eval = scriptEngine.eval(scriptItem.getText(), bindings);
      if (eval != null) {
        Log.logRB("SCW_SCRIPT_RESULT");
        Log.log(eval.toString());
      }
    } catch (Throwable e) {
      Log.logErrorRB(e, "SCW_SCRIPT_ERROR");
    }

    return eval;
  }
 public void editOverwriteMachineTranslationMenuItemActionPerformed() {
   String tr = Core.getMachineTranslatePane().getDisplayedTranslation();
   if (tr == null) {
     Core.getMachineTranslatePane().forceLoad();
   } else if (!StringUtil.isEmpty(tr)) {
     Core.getEditor().replaceEditText(tr);
   }
 }
  /** Quits OmegaT */
  public void projectExitMenuItemActionPerformed() {
    boolean projectModified = false;
    if (Core.getProject().isProjectLoaded())
      projectModified = Core.getProject().isProjectModified();

    // RFE 1302358
    // Add Yes/No Warning before OmegaT quits
    if (projectModified || Preferences.isPreference(Preferences.ALWAYS_CONFIRM_QUIT)) {
      if (JOptionPane.YES_OPTION
          != JOptionPane.showConfirmDialog(
              mainWindow,
              OStrings.getString("MW_QUIT_CONFIRM"),
              OStrings.getString("CONFIRM_DIALOG_TITLE"),
              JOptionPane.YES_NO_OPTION)) {
        return;
      }
    }

    flushExportedSegments();

    new SwingWorker<Object, Void>() {
      @Override
      protected Object doInBackground() throws Exception {
        if (Core.getProject().isProjectLoaded()) {
          // Save the list of learned and ignore words
          ISpellChecker sc = Core.getSpellChecker();
          sc.saveWordLists();
          try {
            Core.getProject().saveProject();
          } catch (KnownException ex) {
            // hide exception on shutdown
          }
        }

        CoreEvents.fireApplicationShutdown();

        PluginUtils.unloadPlugins();

        return null;
      }

      @Override
      protected void done() {
        try {
          get();

          MainWindowUI.saveScreenLayout(mainWindow);

          Preferences.save();

          System.exit(0);
        } catch (Exception ex) {
          Log.logErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
          Core.getMainWindow().displayErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
        }
      }
    }.execute();
  }
  /** inserts the source text of a segment at cursor position */
  public void editInsertSourceMenuItemActionPerformed() {
    if (!Core.getProject().isProjectLoaded()) return;

    String toInsert = Core.getEditor().getCurrentEntry().getSrcText();
    if (Preferences.isPreference(Preferences.GLOSSARY_REPLACE_ON_INSERT)) {
      toInsert = EditorUtils.replaceGlossaryEntries(toInsert);
    }
    Core.getEditor().insertText(toInsert);
  }
 public void toolsSingleValidateTagsMenuItemActionPerformed() {
   String midName = Core.getEditor().getCurrentFile();
   List<ErrorReport> stes = null;
   if (!StringUtil.isEmpty(midName)) {
     String sourcePattern = StaticUtils.escapeNonRegex(midName);
     stes = Core.getTagValidation().listInvalidTags(sourcePattern);
   }
   Core.getTagValidation().displayTagValidationErrors(stes, null);
 }
 /**
  * Displays the font dialog to allow selecting the font for source, target text (in main window)
  * and for match and glossary windows.
  */
 public void optionsFontSelectionMenuItemActionPerformed() {
   FontSelectionDialog dlg =
       new FontSelectionDialog(
           Core.getMainWindow().getApplicationFrame(), Core.getMainWindow().getApplicationFont());
   dlg.setVisible(true);
   if (dlg.getReturnStatus() == FontSelectionDialog.RET_OK_CHANGED) {
     mainWindow.setApplicationFont(dlg.getSelectedFont());
   }
 }
  public static void projectClose() {
    UIThreadsUtil.mustBeSwingThread();

    if (!Core.getProject().isProjectLoaded()) {
      return;
    }

    // commit the current entry first
    Core.getEditor().commitAndLeave();

    new SwingWorker<Object, Void>() {
      protected Object doInBackground() throws Exception {
        Core.getMainWindow().showStatusMessageRB("MW_STATUS_SAVING");

        IMainWindow mainWindow = Core.getMainWindow();
        Cursor hourglassCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
        Cursor oldCursor = mainWindow.getCursor();
        mainWindow.setCursor(hourglassCursor);

        Preferences.save();

        Core.executeExclusively(
            true,
            () -> {
              Core.getProject().saveProject(true);
              ProjectFactory.closeProject();
            });

        Core.getMainWindow().showStatusMessageRB("MW_STATUS_SAVED");
        mainWindow.setCursor(oldCursor);

        // fix - reset progress bar to defaults
        Core.getMainWindow().showLengthMessage(OStrings.getString("MW_SEGMENT_LENGTH_DEFAULT"));
        Core.getMainWindow()
            .showProgressMessage(
                Preferences.getPreferenceEnumDefault(
                            Preferences.SB_PROGRESS_MODE, MainWindowUI.STATUS_BAR_MODE.DEFAULT)
                        == MainWindowUI.STATUS_BAR_MODE.DEFAULT
                    ? OStrings.getString("MW_PROGRESS_DEFAULT")
                    : OStrings.getProgressBarDefaultPrecentageText());

        return null;
      }

      protected void done() {
        try {
          get();
        } catch (Exception ex) {
          processSwingWorkerException(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
        }
        // Restore global prefs in case project had project-specific ones
        Core.setFilterMaster(new FilterMaster(Preferences.getFilters()));
        Core.setSegmenter(new Segmenter(Preferences.getSRX()));
      }
    }.execute();
  }
  public static void projectOpenMED() {
    UIThreadsUtil.mustBeSwingThread();

    if (Core.getProject().isProjectLoaded()) {
      return;
    }

    // ask for MED file
    ChooseMedProject ndm = new ChooseMedProject();
    int ndmResult = ndm.showOpenDialog(Core.getMainWindow().getApplicationFrame());
    if (ndmResult != OmegaTFileChooser.APPROVE_OPTION) {
      // user press 'Cancel' in project creation dialog
      return;
    }
    final File med = ndm.getSelectedFile();

    // ask for new project dir
    NewProjectFileChooser ndc = new NewProjectFileChooser();
    int ndcResult = ndc.showSaveDialog(Core.getMainWindow().getApplicationFrame());
    if (ndcResult != OmegaTFileChooser.APPROVE_OPTION) {
      // user press 'Cancel' in project creation dialog
      return;
    }
    final File dir = ndc.getSelectedFile();

    new SwingWorker<Object, Void>() {
      protected Object doInBackground() throws Exception {
        dir.mkdirs();

        final ProjectProperties newProps = new ProjectProperties(dir);
        ProjectMedProcessing.extractFromMed(med, newProps);
        // create project
        try {
          ProjectFactory.createProject(newProps);
        } catch (Exception ex) {
          Log.logErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
          Core.getMainWindow().displayErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
        }

        RecentProjects.add(dir.getAbsolutePath());

        return null;
      }

      protected void done() {
        try {
          get();
          SwingUtilities.invokeLater(Core.getEditor()::requestFocus);
        } catch (Exception ex) {
          Log.logErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
          Core.getMainWindow().displayErrorRB(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
        }
      }
    }.execute();
  }
  /**
   * Identify all the placeholders in the source text and automatically inserts them into the target
   * text.
   */
  public void editTagPainterMenuItemActionPerformed() {
    SourceTextEntry ste = Core.getEditor().getCurrentEntry();

    // insert tags
    String tr = Core.getEditor().getCurrentTranslation();
    for (ProtectedPart pp : ste.getProtectedParts()) {
      if (!tr.contains(pp.getTextInSourceSegment())) {
        Core.getEditor().insertText(pp.getTextInSourceSegment());
      }
    }
  }
  /** Displays the view options dialog to allow customizing the view options. */
  public void optionsViewOptionsMenuItemActionPerformed() {

    ViewOptionsDialog viewOptions = new ViewOptionsDialog(mainWindow);
    viewOptions.setVisible(true);

    if (viewOptions.getReturnStatus() == ViewOptionsDialog.RET_OK
        && Core.getProject().isProjectLoaded()) {
      // Redisplay according to new view settings
      Core.getEditor().getSettings().updateViewPreferences();
    }
  }
  /** Imports the file/files/folder into project's source files. */
  public static void doPromptImportSourceFiles() {
    OmegaTFileChooser chooser = new OmegaTFileChooser();
    chooser.setMultiSelectionEnabled(true);
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    chooser.setDialogTitle(OStrings.getString("TF_FILE_IMPORT_TITLE"));

    int result = chooser.showOpenDialog(Core.getMainWindow().getApplicationFrame());
    if (result == OmegaTFileChooser.APPROVE_OPTION) {
      File[] selFiles = chooser.getSelectedFiles();
      projectImportFiles(Core.getProject().getProjectProperties().getSourceRoot(), selFiles);
    }
  }
  /** Create translated documents. */
  public void projectCompileMenuItemActionPerformed() {
    if (Preferences.isPreference(Preferences.TAGS_VALID_REQUIRED)) {
      List<ErrorReport> stes = Core.getTagValidation().listInvalidTags();
      if (stes != null) {
        Core.getTagValidation()
            .displayTagValidationErrors(stes, OStrings.getString("TF_MESSAGE_COMPILE"));
        return;
      }
    }

    ProjectUICommands.projectCompile();
  }
Beispiel #17
0
  public void executeScriptFile(
      ScriptItem scriptItem, boolean forceFromFile, Map<String, Object> additionalBindings) {
    ScriptLogger scriptLogger = new ScriptLogger(m_txtResult);

    ScriptEngine scriptEngine =
        manager.getEngineByExtension(getFileExtension(scriptItem.getName()));

    if (scriptEngine == null) {
      scriptEngine = manager.getEngineByName(DEFAULT_SCRIPT);
    }

    // logResult(StaticUtils.format(OStrings.getString("SCW_SELECTED_LANGUAGE"),
    // scriptEngine.getFactory().getEngineName()));
    SimpleBindings bindings = new SimpleBindings();
    bindings.put(VAR_PROJECT, Core.getProject());
    bindings.put(VAR_EDITOR, Core.getEditor());
    bindings.put(VAR_GLOSSARY, Core.getGlossary());
    bindings.put(VAR_MAINWINDOW, Core.getMainWindow());
    bindings.put(VAR_CONSOLE, scriptLogger);
    bindings.put(VAR_RESOURCES, scriptItem.getResourceBundle());

    if (additionalBindings != null) {
      bindings.putAll(additionalBindings);
    }

    // evaluate JavaScript code from String
    try {
      String scriptString;
      if (forceFromFile) {
        scriptString = scriptItem.getText();
      } else if ("".equals(m_txtScriptEditor.getText().trim())) {
        scriptString = scriptItem.getText();
        m_txtScriptEditor.setText(scriptString);
      } else {
        scriptString = m_txtScriptEditor.getText();
      }

      if (!scriptString.endsWith("\n")) {
        scriptString += "\n";
      }

      Object eval = scriptEngine.eval(scriptString, bindings);
      if (eval != null) {
        logResult(OStrings.getString("SCW_SCRIPT_RESULT"));
        logResult(eval.toString());
      }
    } catch (Throwable e) {
      logResult(OStrings.getString("SCW_SCRIPT_ERROR"));
      logResult(e.getMessage());
      // e.printStackTrace();
    }
  }
Beispiel #18
0
  private void addExternalGlossaryEntries(List<GlossaryEntry> result, String src) {

    Language source = Core.getProject().getProjectProperties().getSourceLanguage();
    Language target = Core.getProject().getProjectProperties().getTargetLanguage();

    for (IGlossary gl : externalGlossaries) {
      try {
        result.addAll(gl.search(source, target, src));
      } catch (Exception ex) {
        Log.log(ex);
      }
    }
  }
 private static void processSwingWorkerException(Exception ex, String errorCode) {
   if (ex instanceof ExecutionException) {
     Log.logErrorRB(ex.getCause(), errorCode);
     if (ex.getCause() instanceof KnownException) {
       KnownException e = (KnownException) ex.getCause();
       Core.getMainWindow().displayErrorRB(e.getCause(), e.getMessage(), e.getParams());
     } else {
       Core.getMainWindow().displayErrorRB(ex.getCause(), errorCode);
     }
   } else {
     Log.logErrorRB(ex, errorCode);
     Core.getMainWindow().displayErrorRB(ex, errorCode);
   }
 }
 public void projectAccessWriteableGlossaryMenuItemActionPerformed(int modifier) {
   if (!Core.getProject().isProjectLoaded()) {
     return;
   }
   String path = Core.getProject().getProjectProperties().getWriteableGlossary();
   if (StringUtil.isEmpty(path)) {
     return;
   }
   File toOpen = new File(path);
   if ((modifier & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0) {
     toOpen = toOpen.getParentFile();
   }
   openFile(toOpen);
 }
 public void projectAccessCurrentTargetDocumentMenuItemActionPerformed(int modifier) {
   if (!Core.getProject().isProjectLoaded()) {
     return;
   }
   String root = Core.getProject().getProjectProperties().getTargetRoot();
   String path = Core.getEditor().getCurrentTargetFile();
   if (StringUtil.isEmpty(path)) {
     return;
   }
   File toOpen = new File(root, path);
   if ((modifier & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0) {
     toOpen = toOpen.getParentFile();
   }
   openFile(toOpen);
 }
 /** Prompt the user to reload the current project */
 public static void promptReload() {
   if (!Core.getProject().isProjectLoaded()) {
     return;
   }
   // asking to reload a project
   int res =
       JOptionPane.showConfirmDialog(
           Core.getMainWindow().getApplicationFrame(),
           OStrings.getString("MW_REOPEN_QUESTION"),
           OStrings.getString("MW_REOPEN_TITLE"),
           JOptionPane.YES_NO_OPTION);
   if (res == JOptionPane.YES_OPTION) {
     projectReload();
   }
 }
  public static void projectReload() {
    UIThreadsUtil.mustBeSwingThread();

    if (!Core.getProject().isProjectLoaded()) {
      return;
    }

    // commit the current entry first
    Core.getEditor().commitAndLeave();

    final ProjectProperties props = Core.getProject().getProjectProperties();

    new SwingWorker<Object, Void>() {
      int previousCurEntryNum = Core.getEditor().getCurrentEntryNumber();

      protected Object doInBackground() throws Exception {
        IMainWindow mainWindow = Core.getMainWindow();
        Cursor hourglassCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
        Cursor oldCursor = mainWindow.getCursor();
        mainWindow.setCursor(hourglassCursor);

        Core.executeExclusively(
            true,
            () -> {
              Core.getProject().saveProject(true);
              ProjectFactory.closeProject();

              ProjectFactory.loadProject(props, true);
            });
        mainWindow.setCursor(oldCursor);
        return null;
      }

      protected void done() {
        try {
          get();
          SwingUtilities.invokeLater(
              () -> {
                // activate entry later - after project will be loaded
                Core.getEditor().gotoEntry(previousCurEntryNum);
                Core.getEditor().requestFocus();
              });
        } catch (Exception ex) {
          processSwingWorkerException(ex, "PP_ERROR_UNABLE_TO_READ_PROJECT_FILE");
        }
      }
    }.execute();
  }
 public void optionsDictionaryFuzzyMatchingCheckBoxMenuItemActionPerformed() {
   Preferences.setPreference(
       Preferences.DICTIONARY_FUZZY_MATCHING,
       mainWindow.menu.optionsDictionaryFuzzyMatchingCheckBoxMenuItem.isSelected());
   Preferences.save();
   Core.getDictionaries().refresh();
 }
Beispiel #25
0
  private void addScriptCommandToOmegaT() {
    JMenu toolsMenu = Core.getMainWindow().getMainMenu().getToolsMenu();
    toolsMenu.add(new JSeparator());

    JMenuItem scriptMenu = new JMenuItem();
    Mnemonics.setLocalizedText(scriptMenu, OStrings.getString("TF_MENU_TOOLS_SCRIPTING"));
    scriptMenu.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            ScriptingWindow.this.setVisible(true);
          }
        });

    toolsMenu.add(scriptMenu);

    for (int i = 0; i < NUMBERS_OF_QUICK_SCRIPTS; i++) {
      JMenuItem menuItem = new JMenuItem();
      m_quickMenus[i] = menuItem;

      String scriptName = Preferences.getPreferenceDefault("scripts_quick_" + scriptKey(i), null);

      if (scriptName != null || "".equals(scriptName)) {
        setQuickScriptMenu(new ScriptItem(new File(m_scriptsDirectory, scriptName)), i);
      } else {
        unsetQuickScriptMenu(i);
      }

      // Since the script is run while editing a segment, the shortcut should not interfere
      // with the segment content, so we set it to a Function key.
      m_quickMenus[i].setAccelerator(KeyStroke.getKeyStroke("shift ctrl F" + (i + 1)));

      toolsMenu.add(menuItem);
    }
  }
  public void editExportSelectionMenuItemActionPerformed() {
    if (!Core.getProject().isProjectLoaded()) return;

    String selection = Core.getEditor().getSelectedText();
    if (selection == null) {
      SourceTextEntry ste = Core.getEditor().getCurrentEntry();
      TMXEntry te = Core.getProject().getTranslationInfo(ste);
      if (te.isTranslated()) {
        selection = te.translation;
      } else {
        selection = ste.getSrcText();
      }
    }

    FileUtil.writeScriptFile(selection, OConsts.SELECTION_EXPORT);
  }
Beispiel #27
0
  @Override
  public List<Mark> getMarksForEntry(
      SourceTextEntry ste, String sourceText, String translationText, boolean isActive)
      throws Exception {

    if (!isEnabled()) {
      return null;
    }

    int srcGlyphMissing;
    if (isActive
        || Core.getEditor().getSettings().isDisplaySegmentSources()
        || translationText == null) {
      srcGlyphMissing = editorFont.canDisplayUpTo(sourceText);
    } else {
      srcGlyphMissing = -1;
    }

    int trgGlyphMissing = translationText == null ? -1 : editorFont.canDisplayUpTo(translationText);

    if (srcGlyphMissing == -1 && trgGlyphMissing == -1) {
      return null;
    }
    List<Mark> marks = new ArrayList<Mark>();
    if (srcGlyphMissing != -1) {
      createMarks(marks, Mark.ENTRY_PART.SOURCE, sourceText, srcGlyphMissing);
    }

    if (trgGlyphMissing != -1) {
      createMarks(marks, Mark.ENTRY_PART.TRANSLATION, translationText, trgGlyphMissing);
    }

    return marks;
  }
 public void optionsGlossaryExactMatchCheckBoxMenuItemActionPerformed() {
   Preferences.setPreference(
       Preferences.GLOSSARY_NOT_EXACT_MATCH,
       mainWindow.menu.optionsGlossaryExactMatchCheckBoxMenuItem.isSelected());
   Preferences.save();
   Core.getGlossaryManager().forceUpdateGlossary();
 }
 public void optionsGlossaryStemmingCheckBoxMenuItemActionPerformed() {
   Preferences.setPreference(
       Preferences.GLOSSARY_STEMMING,
       mainWindow.menu.optionsGlossaryStemmingCheckBoxMenuItem.isSelected());
   Preferences.save();
   Core.getGlossaryManager().forceUpdateGlossary();
 }
Beispiel #30
0
 public BaseTranslate() {
   menuItem = new JCheckBoxMenuItem();
   Mnemonics.setLocalizedText(menuItem, getName());
   menuItem.addActionListener(this);
   enabled = Preferences.isPreference(getPreferenceName());
   menuItem.setState(enabled);
   Core.getMainWindow().getMainMenu().getMachineTranslationMenu().add(menuItem);
 }