Exemplo n.º 1
0
  public static void saveAndOpen(final String file) {
    ActionLock.lock();

    TuxGuitar.instance().getPlayer().reset();

    if (TuxGuitar.instance().getFileHistory().isUnsavedFile()) {
      ConfirmDialog confirm =
          new ConfirmDialog(TuxGuitar.getProperty("file.save-changes-question"));
      confirm.setDefaultStatus(ConfirmDialog.STATUS_CANCEL);
      int status =
          confirm.confirm(
              ConfirmDialog.BUTTON_YES | ConfirmDialog.BUTTON_NO | ConfirmDialog.BUTTON_CANCEL,
              ConfirmDialog.BUTTON_YES);
      if (status == ConfirmDialog.STATUS_CANCEL) {
        ActionLock.unlock();
        return;
      }
      if (status == ConfirmDialog.STATUS_YES) {
        final String fileName = FileActionUtils.getFileName();
        if (fileName == null) {
          ActionLock.unlock();
          return;
        }
        TuxGuitar.instance().loadCursor(SWT.CURSOR_WAIT);
        new Thread(
                new Runnable() {
                  public void run() {
                    if (!TuxGuitar.isDisposed()) {
                      FileActionUtils.save(fileName);
                      new SyncThread(
                              new Runnable() {
                                public void run() {
                                  if (!TuxGuitar.isDisposed()) {
                                    TuxGuitar.instance().loadCursor(SWT.CURSOR_ARROW);
                                    openFile(file);
                                  }
                                }
                              })
                          .start();
                    }
                  }
                })
            .start();
        return;
      }
    }
    openFile(file);
  }
Exemplo n.º 2
0
  protected int execute(TypedEvent e) {
    if (TuxGuitar.instance().getFileHistory().isUnsavedFile()) {
      ConfirmDialog confirm =
          new ConfirmDialog(TuxGuitar.getProperty("file.save-changes-question"));
      confirm.setDefaultStatus(ConfirmDialog.STATUS_CANCEL);
      int status =
          confirm.confirm(
              ConfirmDialog.BUTTON_YES | ConfirmDialog.BUTTON_NO | ConfirmDialog.BUTTON_CANCEL,
              ConfirmDialog.BUTTON_YES);
      if (status == ConfirmDialog.STATUS_CANCEL) {
        return AUTO_UNLOCK;
      }
      if (status == ConfirmDialog.STATUS_YES) {
        final String fileName = FileActionUtils.getFileName();
        if (fileName == null) {
          return AUTO_UNLOCK;
        }
        TuxGuitar.instance().loadCursor(SWT.CURSOR_WAIT);
        new Thread(
                new Runnable() {
                  public void run() {
                    if (!TuxGuitar.isDisposed()) {
                      FileActionUtils.save(fileName);
                      TuxGuitar.instance().loadCursor(SWT.CURSOR_ARROW);
                      new SyncThread(
                              new Runnable() {
                                public void run() {
                                  if (!TuxGuitar.isDisposed()) {
                                    newSong();
                                  }
                                }
                              })
                          .start();
                    }
                  }
                })
            .start();
        return 0;
      }
    }
    newSong();

    return 0;
  }