コード例 #1
0
  /**
   * A constructor
   *
   * @param project the project
   * @param roots the list of the roots
   * @param defaultRoot the default root to select
   */
  public GitUnstashDialog(
      final Project project, final List<VirtualFile> roots, final VirtualFile defaultRoot) {
    super(project, true);
    setModal(false);
    myProject = project;
    myVcs = GitVcs.getInstance(project);
    setTitle(GitBundle.getString("unstash.title"));
    setOKButtonText(GitBundle.getString("unstash.button.apply"));
    GitUIUtil.setupRootChooser(project, roots, defaultRoot, myGitRootComboBox, myCurrentBranch);
    myStashList.setModel(new DefaultListModel());
    refreshStashList();
    myGitRootComboBox.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent e) {
            refreshStashList();
            updateDialogState();
          }
        });
    myStashList.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(final ListSelectionEvent e) {
            updateDialogState();
          }
        });
    myBranchTextField
        .getDocument()
        .addDocumentListener(
            new DocumentAdapter() {
              protected void textChanged(final DocumentEvent e) {
                updateDialogState();
              }
            });
    myPopStashCheckBox.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            updateDialogState();
          }
        });
    myClearButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent e) {
            if (Messages.YES
                == Messages.showYesNoDialog(
                    GitUnstashDialog.this.getContentPane(),
                    GitBundle.message("git.unstash.clear.confirmation.message"),
                    GitBundle.message("git.unstash.clear.confirmation.title"),
                    Messages.getWarningIcon())) {
              GitLineHandler h = new GitLineHandler(myProject, getGitRoot(), GitCommand.STASH);
              h.setNoSSH(true);
              h.addParameters("clear");
              GitHandlerUtil.doSynchronously(
                  h, GitBundle.getString("unstash.clearing.stashes"), h.printableCommandLine());
              refreshStashList();
              updateDialogState();
            }
          }
        });
    myDropButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent e) {
            final StashInfo stash = getSelectedStash();
            if (Messages.YES
                == Messages.showYesNoDialog(
                    GitUnstashDialog.this.getContentPane(),
                    GitBundle.message(
                        "git.unstash.drop.confirmation.message",
                        stash.getStash(),
                        stash.getMessage()),
                    GitBundle.message("git.unstash.drop.confirmation.title", stash.getStash()),
                    Messages.getQuestionIcon())) {
              final ModalityState current = ModalityState.current();
              ProgressManager.getInstance()
                  .run(
                      new Task.Modal(myProject, "Removing stash " + stash.getStash(), false) {
                        @Override
                        public void run(@NotNull ProgressIndicator indicator) {
                          final GitSimpleHandler h = dropHandler(stash.getStash());
                          try {
                            h.run();
                            h.unsilence();
                          } catch (final VcsException ex) {
                            ApplicationManager.getApplication()
                                .invokeLater(
                                    new Runnable() {
                                      @Override
                                      public void run() {
                                        GitUIUtil.showOperationError(
                                            myProject, ex, h.printableCommandLine());
                                      }
                                    },
                                    current);
                          }
                        }
                      });
              refreshStashList();
              updateDialogState();
            }
          }

          private GitSimpleHandler dropHandler(String stash) {
            GitSimpleHandler h = new GitSimpleHandler(myProject, getGitRoot(), GitCommand.STASH);
            h.setNoSSH(true);
            h.addParameters("drop");
            addStashParameter(h, stash);
            return h;
          }
        });
    myViewButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(final ActionEvent e) {
            final VirtualFile root = getGitRoot();
            String resolvedStash;
            String selectedStash = getSelectedStash().getStash();
            try {
              GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.REV_LIST);
              h.setNoSSH(true);
              h.setSilent(true);
              h.addParameters("--timestamp", "--max-count=1");
              addStashParameter(h, selectedStash);
              h.endOptions();
              final String output = h.run();
              resolvedStash =
                  GitRevisionNumber.parseRevlistOutputAsRevisionNumber(h, output).asString();
            } catch (VcsException ex) {
              GitUIUtil.showOperationError(myProject, ex, "resolving revision");
              return;
            }
            GitShowAllSubmittedFilesAction.showSubmittedFiles(
                myProject, resolvedStash, root, true, false);
          }
        });
    init();
    updateDialogState();
  }
コード例 #2
0
 /** @return the selected git root */
 private VirtualFile getGitRoot() {
   return (VirtualFile) myGitRootComboBox.getSelectedItem();
 }