Ejemplo n.º 1
0
 public void refreshAll() {
   List<Tab> tabs = tabPane.getTabs();
   for (Tab tab : tabs) {
     Resource resource = (Resource) tab.getUserData();
     if (tab.getContent() instanceof CodeEditor) {
       CodeEditor editor = (CodeEditor) tab.getContent();
       try {
         editor.setCode(new String(resource.getData(), "UTF-8"));
       } catch (IOException e) {
         logger.error("", e);
       }
     }
   }
 }
Ejemplo n.º 2
0
  private void saveUnsavedEditors() {
    for (Tab tab : tabPane.getTabs()) {
      EditorPane pane = (EditorPane) tab.getContent();

      pane.promptSave();
    }
  }
Ejemplo n.º 3
0
  private void saveEditorPaneConfig() {
    List<String> editorPanePaths = new ArrayList<>();

    for (Tab tab : tabPane.getTabs()) {
      EditorPane pane = (EditorPane) tab.getContent();

      if (pane != null && pane.getSourceFile() != null) {
        String editorPanePath = pane.getSourceFile().getAbsolutePath();
        editorPanePaths.add(editorPanePath);
      }
    }

    config.setLastEditorPaneList(editorPanePaths);
    config.saveConfig();
  }
Ejemplo n.º 4
0
  public void refreshImageViewer(Resource resourceToUpdate) {
    List<Tab> tabs = tabPane.getTabs();
    for (Tab tab : tabs) {
      Resource resource = (Resource) tab.getUserData();
      if (resourceToUpdate.equals(resource)) {
        ImageResource imageResource = (ImageResource) resourceToUpdate;
        logger.info("refreshing image resource");
        ImageViewerPane imageViewerPane = (ImageViewerPane) tab.getContent();
        ImageView imageView = imageViewerPane.getImageView();
        imageView.setImage(imageResource.asNativeFormat());
        imageView.setFitHeight(-1);
        imageView.setFitWidth(-1);

        Label imagePropertiesLabel = imageViewerPane.getImagePropertiesLabel();
        imagePropertiesLabel.setText(imageResource.getImageDescription());
      }
    }
  }
Ejemplo n.º 5
0
  @Override
  public void setModified(EditorPane pane, boolean isModified) {
    for (Tab tab : tabPane.getTabs()) {
      EditorPane currentPane = (EditorPane) tab.getContent();

      if (currentPane == pane) {
        String tabText = tab.getText();

        if (isModified) {
          if (!tabText.endsWith(S_ASTERISK)) {
            tab.setText(tabText + S_ASTERISK);
          }
        } else {
          if (tabText.endsWith(S_ASTERISK)) {
            tab.setText(tabText.substring(0, tabText.length() - 1));
          }
        }
      }
    }
  }
Ejemplo n.º 6
0
  private void runSandbox(File fileToRun) {
    try {
      Platform.runLater(
          new Runnable() {
            @Override
            public void run() {
              taLog.setText(S_EMPTY);
            }
          });

      String language = comboBoxVMLanguage.getValue();

      if (language != null) {
        List<File> compileList = new ArrayList<>();

        for (Tab tab : tabPane.getTabs()) {
          EditorPane pane = (EditorPane) tab.getContent();

          File sourceFile = pane.getSourceFile();

          if (sourceFile != null) {
            if (LanguageManager.isCompilable(language, sourceFile)) {
              compileList.add(sourceFile);
            }
          }
        }

        if (compileList.size() > 0) {
          sandbox.runSandbox(language, compileList, fileToRun);
        } else {
          log("Nothing to compile?");
        }
      }
    } catch (Exception e) {
      logger.error("Sandbox failure", e);
    }
  }
  public void setMdBox(MdTextController mdBox, Textual extract, Tab tab) throws IOException {
    this.mainApp = mdBox.getMainApp();
    this.config = mainApp.getConfig();
    this.mdBox = mdBox;
    this.tab = tab;
    this.extract = extract;

    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(MainApp.class.getResource("fxml/Editor.fxml"));
    loader.load();

    if (mainApp.getConfig().getEditorToolbarView().equals("no")) {
      BoxEditor.setTop(null);
      BoxRender.setTop(null);
    }

    SourceText.setFont(new Font(config.getEditorFont(), config.getEditorFontsize()));
    SourceText.setStyle("-fx-font-family: \"" + config.getEditorFont() + "\";");
    SourceText.replaceText(extract.getMarkdown());
    SourceText.textProperty()
        .addListener(
            (observableValue, s, s2) -> {
              tab.setText("! " + extract.getTitle());
              this.isSaved = false;
              SourceText.getUndoManager().mark();
              updateRender();
            });
    updateRender();
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(S, SHORTCUT_DOWN), () -> HandleSaveButtonAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(G, SHORTCUT_DOWN), () -> HandleBoldButtonAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(I, SHORTCUT_DOWN), () -> HandleItalicButtonAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(B, SHORTCUT_DOWN), () -> HandleBarredButtonAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(K, SHORTCUT_DOWN), () -> HandleTouchButtonAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(PLUS, SHORTCUT_DOWN), () -> HandleExpButtonAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(EQUALS, SHORTCUT_DOWN), () -> HandleIndButtonAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(E, SHORTCUT_DOWN), () -> HandleCenterButtonAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(
            new KeyCodeCombination(D, SHORTCUT_DOWN, SHIFT_DOWN),
            () -> HandleRightButtonAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(SPACE, SHORTCUT_DOWN), () -> HandleUnbreakableAction(null));
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(L, SHORTCUT_DOWN), this::HandleGoToLineAction);
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(F, SHORTCUT_DOWN), this::HandleFindReplaceDialog);
    tab.getContent()
        .getScene()
        .getAccelerators()
        .put(new KeyCodeCombination(A, SHORTCUT_DOWN), () -> SourceText.selectAll());

    SourceText.requestFocus();
  }