Exemple #1
0
  public OpenNotebookAction(HexApplication application) {
    this.application = application;
    this.preferredDirectoryManager = application.getPreferredDirectoryManager();
    this.recentDocumentsModel = application.getRecentDocumentsModel();

    Resources.localiseAction(this, "Open");
  }
Exemple #2
0
  @Override
  protected void doAction(ActionEvent event) throws Exception {
    // For Mac OS X, when opening files, the file chooser is *not* parented by the current window.
    Window activeWindow = PLAFUtils.isAqua() ? null : HexFrame.findActiveFrame();

    FileSelection fileSelection = FileSelection.getInstance();

    File file =
        fileSelection.selectFile(
            activeWindow,
            FileSelection.Mode.LOAD,
            preferredDirectoryManager.getPreferredDirectory(PreferredDirectoryManager.NOTEBOOKS),
            new NotebookFileFilter());
    if (file != null) {
      if (!file.isFile()) {
        throw new ActionException(Resources.getMessage("Common.Errors.notFile"));
      }

      preferredDirectoryManager.setPreferredDirectory(
          PreferredDirectoryManager.NOTEBOOKS, file.getParentFile());
      recentDocumentsModel.addRecentDocument(file.toPath());

      application.openNotebook(new NotebookStorage().read(file.toURI().toURL()));
    }
  }