@Nullable
  public LocalChangeList getSelectedList(Project project) {
    ChangeListManager manager = ChangeListManager.getInstance(project);
    if (myRbNew.isSelected()) {
      String newText = myNewListPanel.getChangeListName();
      if (manager.findChangeList(newText) != null) {
        Messages.showErrorDialog(
            project,
            VcsBundle.message("changes.newchangelist.warning.already.exists.text", newText),
            VcsBundle.message("changes.newchangelist.warning.already.exists.title"));
        return null;
      }
    }
    final boolean existingSelected = myRbExisting.isSelected();
    VcsConfiguration.getInstance(myProject).PRESELECT_EXISTING_CHANGELIST = existingSelected;

    if (existingSelected) {
      return (LocalChangeList) myExistingListsCombo.getSelectedItem();
    } else {
      LocalChangeList changeList =
          manager.addChangeList(
              myNewListPanel.getChangeListName(), myNewListPanel.getDescription());
      myNewListPanel.changelistCreatedOrChanged(changeList);
      if (myNewListPanel.getMakeActiveCheckBox().isSelected()) {
        manager.setDefaultChangeList(changeList);
      }
      VcsConfiguration.getInstance(project).MAKE_NEW_CHANGELIST_ACTIVE =
          myNewListPanel.getMakeActiveCheckBox().isSelected();

      return changeList;
    }
  }
 @Override
 public UpdateInfoTree showUpdateProjectInfo(
     UpdatedFiles updatedFiles,
     String displayActionName,
     ActionInfo actionInfo,
     boolean canceled) {
   if (!myProject.isOpen() || myProject.isDisposed()) return null;
   ContentManager contentManager = getContentManager();
   if (contentManager == null) {
     return null; // content manager is made null during dispose; flag is set later
   }
   final UpdateInfoTree updateInfoTree =
       new UpdateInfoTree(contentManager, myProject, updatedFiles, displayActionName, actionInfo);
   Content content =
       ContentFactory.SERVICE
           .getInstance()
           .createContent(
               updateInfoTree,
               canceled
                   ? VcsBundle.message(
                       "toolwindow.title.update.action.canceled.info", displayActionName)
                   : VcsBundle.message("toolwindow.title.update.action.info", displayActionName),
               true);
   Disposer.register(content, updateInfoTree);
   ContentsUtil.addContent(contentManager, content, true);
   ToolWindowManager.getInstance(myProject).getToolWindow(ToolWindowId.VCS).activate(null);
   updateInfoTree.expandRootChildren();
   return updateInfoTree;
 }
  @Nullable
  private RangeHighlighter createHighlighter(@NotNull Range range) {
    myApplication.assertIsDispatchThread();

    LOG.assertTrue(!myReleased, "Already released");

    if (myMode == Mode.SILENT) return null;

    int first =
        range.getLine1() >= getLineCount(myDocument)
            ? myDocument.getTextLength()
            : myDocument.getLineStartOffset(range.getLine1());

    int second =
        range.getLine2() >= getLineCount(myDocument)
            ? myDocument.getTextLength()
            : myDocument.getLineStartOffset(range.getLine2());

    final TextAttributes attr = LineStatusTrackerDrawing.getAttributesFor(range);
    final RangeHighlighter highlighter =
        DocumentMarkupModel.forDocument(myDocument, myProject, true)
            .addRangeHighlighter(
                first,
                second,
                HighlighterLayer.FIRST - 1,
                attr,
                HighlighterTargetArea.LINES_IN_RANGE);

    highlighter.setThinErrorStripeMark(true);
    highlighter.setGreedyToLeft(true);
    highlighter.setGreedyToRight(true);
    highlighter.setLineMarkerRenderer(LineStatusTrackerDrawing.createRenderer(range, this));
    highlighter.setEditorFilter(MarkupEditorFilterFactory.createIsNotDiffFilter());

    final String tooltip;
    if (range.getLine1() == range.getLine2()) {
      if (range.getVcsLine1() + 1 == range.getVcsLine2()) {
        tooltip = VcsBundle.message("tooltip.text.line.before.deleted", range.getLine1() + 1);
      } else {
        tooltip =
            VcsBundle.message(
                "tooltip.text.lines.before.deleted",
                range.getLine1() + 1,
                range.getVcsLine2() - range.getVcsLine1());
      }
    } else if (range.getLine1() + 1 == range.getLine2()) {
      tooltip = VcsBundle.message("tooltip.text.line.changed", range.getLine1() + 1);
    } else {
      tooltip =
          VcsBundle.message("tooltip.text.lines.changed", range.getLine1() + 1, range.getLine2());
    }

    highlighter.setErrorStripeTooltip(tooltip);
    return highlighter;
  }
 protected static void showApplyStatus(@NotNull Project project, final ApplyPatchStatus status) {
   if (status == ApplyPatchStatus.ALREADY_APPLIED) {
     showError(project, VcsBundle.message("patch.apply.already.applied"), false);
   } else if (status == ApplyPatchStatus.PARTIAL) {
     showError(project, VcsBundle.message("patch.apply.partially.applied"), false);
   } else if (ApplyPatchStatus.SUCCESS.equals(status)) {
     final String message = VcsBundle.message("patch.apply.success.applied.text");
     VcsBalloonProblemNotifier.NOTIFICATION_GROUP
         .createNotification(message, MessageType.INFO)
         .notify(project);
   }
 }
Esempio n. 5
0
    private void doRun() {
      myIndicator = ProgressManager.getInstance().getProgressIndicator();

      final List<Change> changesToRefresh = new ArrayList<Change>();
      try {
        ChangesUtil.processChangesByVcs(
            myProject,
            myChanges,
            new ChangesUtil.PerVcsProcessor<Change>() {
              public void process(AbstractVcs vcs, List<Change> changes) {
                final RollbackEnvironment environment = vcs.getRollbackEnvironment();
                if (environment != null) {
                  changesToRefresh.addAll(changes);

                  if (myIndicator != null) {
                    myIndicator.setText(vcs.getDisplayName() + ": performing rollback...");
                    myIndicator.setIndeterminate(false);
                    myIndicator.checkCanceled();
                  }
                  environment.rollbackChanges(
                      changes,
                      myExceptions,
                      new RollbackProgressModifier(changes.size(), myIndicator));
                  if (myIndicator != null) {
                    myIndicator.setText2("");
                    myIndicator.checkCanceled();
                  }

                  if (myExceptions.isEmpty() && myDeleteLocallyAddedFiles) {
                    deleteAddedFilesLocally(changes);
                  }
                }
              }
            });
      } catch (ProcessCanceledException e) {
        // still do refresh
      }

      if (myIndicator != null) {
        myIndicator.startNonCancelableSection();
        myIndicator.setIndeterminate(true);
        myIndicator.setText2("");
        myIndicator.setText(VcsBundle.message("progress.text.synchronizing.files"));
      }

      doRefresh(myProject, changesToRefresh);

      AbstractVcsHelper.getInstance(myProject)
          .showErrors(myExceptions, VcsBundle.message("changes.action.rollback.text"));
    }
  private String getCheckinActionName(final VcsContext dataContext) {
    final Project project = dataContext.getProject();
    if (project == null) return VcsBundle.message("vcs.command.name.checkin");

    final AbstractVcs vcs = getCommonVcsFor(getRoots(dataContext), project);
    if (vcs == null) {
      return VcsBundle.message("vcs.command.name.checkin");
    } else {
      final CheckinEnvironment checkinEnvironment = vcs.getCheckinEnvironment();
      if (checkinEnvironment == null) {
        return VcsBundle.message("vcs.command.name.checkin");
      }
      return checkinEnvironment.getCheckinOperationName();
    }
  }
Esempio n. 7
0
  /**
   * Collects all files which are located in the passed directory.
   *
   * @throws IllegalArgumentException if <code>dir</code> isn't a directory.
   */
  public static void collectFiles(
      final VirtualFile dir,
      final List<VirtualFile> files,
      final boolean recursive,
      final boolean addDirectories) {
    if (!dir.isDirectory()) {
      throw new IllegalArgumentException(
          VcsBundle.message("exception.text.file.should.be.directory", dir.getPresentableUrl()));
    }

    final FileTypeManager fileTypeManager = FileTypeManager.getInstance();
    VfsUtilCore.visitChildrenRecursively(
        dir,
        new VirtualFileVisitor() {
          @Override
          public boolean visitFile(@NotNull VirtualFile file) {
            if (file.isDirectory()) {
              if (addDirectories) {
                files.add(file);
              }
              if (!recursive && !Comparing.equal(file, dir)) {
                return false;
              }
            } else if (fileTypeManager == null || file.getFileType() != FileTypes.UNKNOWN) {
              files.add(file);
            }
            return true;
          }
        });
  }
 public static void showError(final Project project, final String message, final boolean error) {
   final Application application = ApplicationManager.getApplication();
   if (application.isUnitTestMode()) {
     return;
   }
   final String title = VcsBundle.message("patch.apply.dialog.title");
   final Runnable messageShower =
       new Runnable() {
         @Override
         public void run() {
           if (error) {
             Messages.showErrorDialog(project, message, title);
           } else {
             Messages.showInfoMessage(project, message, title);
           }
         }
       };
   WaitForProgressToShow.runOrInvokeLaterAboveProgress(
       new Runnable() {
         @Override
         public void run() {
           messageShower.run();
         }
       },
       null,
       project);
 }
  @CalledInAwt
  public static void refreshPassedFilesAndMoveToChangelist(
      @NotNull final Project project,
      final Collection<FilePath> directlyAffected,
      final Collection<VirtualFile> indirectlyAffected,
      final Consumer<Collection<FilePath>> targetChangelistMover) {
    final LocalFileSystem lfs = LocalFileSystem.getInstance();
    for (FilePath filePath : directlyAffected) {
      lfs.refreshAndFindFileByIoFile(filePath.getIOFile());
    }
    if (project.isDisposed()) return;

    final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
    if (!directlyAffected.isEmpty() && targetChangelistMover != null) {
      changeListManager.invokeAfterUpdate(
          new Runnable() {
            @Override
            public void run() {
              targetChangelistMover.consume(directlyAffected);
            }
          },
          InvokeAfterUpdateMode.SYNCHRONOUS_CANCELLABLE,
          VcsBundle.message("change.lists.manager.move.changes.to.list"),
          new Consumer<VcsDirtyScopeManager>() {
            @Override
            public void consume(final VcsDirtyScopeManager vcsDirtyScopeManager) {
              markDirty(vcsDirtyScopeManager, directlyAffected, indirectlyAffected);
            }
          },
          null);
    } else {
      markDirty(VcsDirtyScopeManager.getInstance(project), directlyAffected, indirectlyAffected);
    }
  }
  @Override
  @Nullable
  public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
    final JCheckBox reformatBox =
        new NonFocusableCheckBox(VcsBundle.message("checkbox.checkin.options.reformat.code"));
    CheckinHandlerUtil.disableWhenDumb(
        myProject, reformatBox, "Impossible until indices are up-to-date");
    return new RefreshableOnComponent() {
      @Override
      public JComponent getComponent() {
        final JPanel panel = new JPanel(new GridLayout(1, 0));
        panel.add(reformatBox);
        return panel;
      }

      @Override
      public void refresh() {}

      @Override
      public void saveState() {
        getSettings().REFORMAT_BEFORE_PROJECT_COMMIT = reformatBox.isSelected();
      }

      @Override
      public void restoreState() {
        reformatBox.setSelected(getSettings().REFORMAT_BEFORE_PROJECT_COMMIT);
      }
    };
  }
 @CalledInAwt
 @NotNull
 private ApplyPatchStatus getApplyPatchStatus(@NotNull final TriggerAdditionOrDeletion trigger) {
   final Ref<ApplyPatchStatus> refStatus = Ref.create(null);
   try {
     setConfirmationToDefault();
     CommandProcessor.getInstance()
         .executeCommand(
             myProject,
             new Runnable() {
               @Override
               public void run() {
                 // consider pre-check status only if not successful, otherwise we could not
                 // detect already applied status
                 if (createFiles() != ApplyPatchStatus.SUCCESS) {
                   refStatus.set(createFiles());
                 }
                 addSkippedItems(trigger);
                 trigger.prepare();
                 refStatus.set(ApplyPatchStatus.and(refStatus.get(), executeWritable()));
               }
             },
             VcsBundle.message("patch.apply.command"),
             null);
   } finally {
     returnConfirmationBack();
     VcsFileListenerContextHelper.getInstance(myProject).clearContext();
   }
   final ApplyPatchStatus status = refStatus.get();
   return status == null ? ApplyPatchStatus.ALREADY_APPLIED : status;
 }
  private Content getOrCreateConsoleContent(final ContentManager contentManager) {
    final String displayName = VcsBundle.message("vcs.console.toolwindow.display.name");
    Content content = contentManager.findContent(displayName);
    if (content == null) {
      releaseEditor();
      final EditorFactory editorFactory = EditorFactory.getInstance();
      final Editor editor = editorFactory.createViewer(editorFactory.createDocument(""), myProject);
      EditorSettings editorSettings = editor.getSettings();
      editorSettings.setLineMarkerAreaShown(false);
      editorSettings.setIndentGuidesShown(false);
      editorSettings.setLineNumbersShown(false);
      editorSettings.setFoldingOutlineShown(false);

      ((EditorEx) editor).getScrollPane().setBorder(null);
      myEditorAdapter = new EditorAdapter(editor, myProject, false);
      final JPanel panel = new JPanel(new BorderLayout());
      panel.add(editor.getComponent(), BorderLayout.CENTER);

      content = ContentFactory.SERVICE.getInstance().createContent(panel, displayName, true);
      contentManager.addContent(content);

      for (Pair<String, TextAttributes> pair : myPendingOutput) {
        myEditorAdapter.appendString(pair.first, pair.second);
      }
      myPendingOutput.clear();
    }
    return content;
  }
  public ReadOnlyStatusDialog(Project project, final FileInfo[] files) {
    super(project);
    myFiles = files;
    initFileList();

    ActionListener listener =
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            myChangelist.setEnabled(myUsingVcsRadioButton.isSelected());
          }
        };
    myUsingVcsRadioButton.addActionListener(listener);
    myUsingFileSystemRadioButton.addActionListener(listener);

    if (myUsingVcsRadioButton.isEnabled()) {
      myUsingVcsRadioButton.setSelected(true);
    } else {
      myUsingFileSystemRadioButton.setSelected(true);
    }
    myChangelist.setEnabled(myUsingVcsRadioButton.isSelected());
    myFileList.setCellRenderer(new FileListRenderer());
    setTitle(VcsBundle.message("dialog.title.clear.read.only.file.status"));

    init();
  }
 public void reportException(VcsException exception) {
   VcsBalloonProblemNotifier.showOverVersionControlView(
       myVcs.getProject(),
       VcsBundle.message("message.title.could.not.load.file.history")
           + ": "
           + exception.getMessage(),
       MessageType.ERROR);
 }
  @Override
  public void setUp() throws Exception {
    super.setUp();
    myDefaulListName = VcsBundle.message("changes.default.changlist.name");

    myScheme =
        new DuringChangeListManagerUpdateTestScheme(myProject, myTempDirFixture.getTempDirPath());
  }
 private String modifyCheckinActionName(final VcsContext dataContext, String checkinActionName) {
   final FilePath[] roots = getRoots(dataContext);
   if (roots == null || roots.length == 0) return checkinActionName;
   final FilePath first = roots[0];
   if (roots.length == 1) {
     if (first.isDirectory()) {
       return VcsBundle.message("action.name.checkin.directory", checkinActionName);
     } else {
       return VcsBundle.message("action.name.checkin.file", checkinActionName);
     }
   } else {
     if (first.isDirectory()) {
       return VcsBundle.message("action.name.checkin.directories", checkinActionName);
     } else {
       return VcsBundle.message("action.name.checkin.files", checkinActionName);
     }
   }
 }
Esempio n. 17
0
  public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    if (project == null) return;
    final ShelvedChangeList[] changeLists =
        e.getData(ShelvedChangesViewManager.SHELVED_CHANGELIST_KEY);
    List<ShelvedChange> changes = e.getData(ShelvedChangesViewManager.SHELVED_CHANGE_KEY);
    List<ShelvedBinaryFile> binaryFiles =
        e.getData(ShelvedChangesViewManager.SHELVED_BINARY_FILE_KEY);
    if (changes != null && binaryFiles != null && changes.size() == 0 && binaryFiles.size() == 0) {
      changes = null;
      binaryFiles = null;
    }
    LOG.assertTrue(changeLists != null);

    final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
    final List<LocalChangeList> allChangeLists = changeListManager.getChangeListsCopy();
    String defaultName = changeLists[0].DESCRIPTION;
    LocalChangeList list = null;
    if (changeLists.length == 1) {
      final LocalChangeList sameNamedList = changeListManager.findChangeList(defaultName);
      if (sameNamedList != null) {
        list = sameNamedList;
      }
    }
    if (list == null) {
      list = changeListManager.getDefaultChangeList();
    }
    final ChangeListChooser chooser =
        new ChangeListChooser(
            project,
            allChangeLists,
            list,
            VcsBundle.message("unshelve.changelist.chooser.title"),
            defaultName);
    chooser.show();
    if (!chooser.isOK()) {
      return;
    }

    FileDocumentManager.getInstance().saveAllDocuments();

    final List<ShelvedBinaryFile> finalBinaryFiles = binaryFiles;
    final List<ShelvedChange> finalChanges = changes;
    ProgressManager.getInstance()
        .run(
            new Task.Backgroundable(
                project, "Unshelve changes", true, BackgroundFromStartOption.getInstance()) {
              @Override
              public void run(@NotNull ProgressIndicator indicator) {
                for (ShelvedChangeList changeList : changeLists) {
                  ShelveChangesManager.getInstance(project)
                      .unshelveChangeList(
                          changeList, finalChanges, finalBinaryFiles, chooser.getSelectedList());
                }
              }
            });
  }
 public boolean processCheckedOutDirectory(Project project, File directory) {
   File[] files =
       directory.listFiles(
           (FilenameFilter) new GlobFilenameFilter("*" + ProjectFileType.DOT_DEFAULT_EXTENSION));
   if (files != null && files.length > 0) {
     int rc =
         Messages.showYesNoDialog(
             project,
             VcsBundle.message("checkout.open.project.prompt", files[0].getPath()),
             VcsBundle.message("checkout.title"),
             Messages.getQuestionIcon());
     if (rc == 0) {
       ProjectUtil.openProject(files[0].getPath(), project, false);
     }
     return true;
   }
   return false;
 }
 @NotNull
 private static String getTooltipText(@NotNull Range range) {
   if (range.getLine1() == range.getLine2()) {
     if (range.getVcsLine1() + 1 == range.getVcsLine2()) {
       return VcsBundle.message("tooltip.text.line.before.deleted", range.getLine1() + 1);
     } else {
       return VcsBundle.message(
           "tooltip.text.lines.before.deleted",
           range.getLine1() + 1,
           range.getVcsLine2() - range.getVcsLine1());
     }
   } else if (range.getLine1() + 1 == range.getLine2()) {
     return VcsBundle.message("tooltip.text.line.changed", range.getLine1() + 1);
   } else {
     return VcsBundle.message(
         "tooltip.text.lines.changed", range.getLine1() + 1, range.getLine2());
   }
 }
Esempio n. 20
0
 public Waiter(
     @NotNull Project project, @NotNull Runnable runnable, String title, boolean cancellable) {
   super(
       project,
       VcsBundle.message("change.list.manager.wait.lists.synchronization", title),
       cancellable);
   myRunnable = runnable;
   mySemaphore.down();
   setCancelText("Skip");
 }
  public ShelvedChangeList shelveChanges(
      final Collection<Change> changes, final String commitMessage, final boolean rollback)
      throws IOException, VcsException {
    final List<Change> textChanges = new ArrayList<Change>();
    final List<ShelvedBinaryFile> binaryFiles = new ArrayList<ShelvedBinaryFile>();
    for (Change change : changes) {
      if (ChangesUtil.getFilePath(change).isDirectory()) {
        continue;
      }
      if (change.getBeforeRevision() instanceof BinaryContentRevision
          || change.getAfterRevision() instanceof BinaryContentRevision) {
        binaryFiles.add(shelveBinaryFile(change));
      } else {
        textChanges.add(change);
      }
    }

    final ShelvedChangeList changeList;
    try {
      File patchPath = getPatchPath(commitMessage);
      ProgressManager.checkCanceled();
      final List<FilePatch> patches =
          IdeaTextPatchBuilder.buildPatch(
              myProject, textChanges, myProject.getBaseDir().getPresentableUrl(), false);
      ProgressManager.checkCanceled();

      CommitContext commitContext = new CommitContext();
      baseRevisionsOfDvcsIntoContext(textChanges, commitContext);
      myFileProcessor.savePathFile(
          new CompoundShelfFileProcessor.ContentProvider() {
            public void writeContentTo(final Writer writer, CommitContext commitContext)
                throws IOException {
              UnifiedDiffWriter.write(myProject, patches, writer, "\n", commitContext);
            }
          },
          patchPath,
          commitContext);

      changeList =
          new ShelvedChangeList(
              patchPath.toString(), commitMessage.replace('\n', ' '), binaryFiles);
      myShelvedChangeLists.add(changeList);
      ProgressManager.checkCanceled();

      if (rollback) {
        new RollbackWorker(myProject, false)
            .doRollback(changes, true, null, VcsBundle.message("shelve.changes.action"));
      }
    } finally {
      notifyStateChanged();
    }

    return changeList;
  }
Esempio n. 22
0
  public void doRollback(
      final Collection<Change> changes,
      final boolean deleteLocallyAddedFiles,
      @Nullable final Runnable afterVcsRefreshInAwt,
      @Nullable final String localHistoryActionName) {
    final ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
    final Runnable notifier = changeListManager.prepareForChangeDeletion(changes);
    final Runnable afterRefresh =
        new Runnable() {
          public void run() {
            changeListManager.invokeAfterUpdate(
                new Runnable() {
                  public void run() {
                    notifier.run();
                    if (afterVcsRefreshInAwt != null) {
                      afterVcsRefreshInAwt.run();
                    }
                  }
                },
                InvokeAfterUpdateMode.SILENT,
                "Refresh change lists after update",
                ModalityState.current());
          }
        };

    final Runnable rollbackAction =
        new MyRollbackRunnable(
            changes, deleteLocallyAddedFiles, afterRefresh, localHistoryActionName);

    if (ApplicationManager.getApplication().isDispatchThread()) {
      ProgressManager.getInstance()
          .run(
              new Task.Backgroundable(
                  myProject,
                  VcsBundle.message("changes.action.rollback.text"),
                  true,
                  new PerformInBackgroundOption() {
                    public boolean shouldStartInBackground() {
                      return VcsConfiguration.getInstance(myProject).PERFORM_ROLLBACK_IN_BACKGROUND;
                    }

                    public void processSentToBackground() {
                      VcsConfiguration.getInstance(myProject).PERFORM_ROLLBACK_IN_BACKGROUND = true;
                    }
                  }) {
                public void run(@NotNull ProgressIndicator indicator) {
                  rollbackAction.run();
                }
              });
    } else {
      rollbackAction.run();
    }
    ((ChangeListManagerImpl) changeListManager).showLocalChangesInvalidated();
  }
 public void setCanGroupByChangeList(final boolean canGroupByChangeList) {
   myCanGroupByChangeList = canGroupByChangeList;
   if (myCanGroupByChangeList) {
     myLoadingChangeListsLabel = new JLabel(VcsBundle.message("update.info.loading.changelists"));
     add(myLoadingChangeListsLabel, BorderLayout.SOUTH);
     myGroupByChangeList = VcsConfiguration.getInstance(myProject).UPDATE_GROUP_BY_CHANGELIST;
     if (myGroupByChangeList) {
       final CardLayout cardLayout = (CardLayout) myCenterPanel.getLayout();
       cardLayout.show(myCenterPanel, CARD_CHANGES);
     }
   }
 }
Esempio n. 24
0
  public void run(@NotNull ProgressIndicator indicator) {
    indicator.setIndeterminate(true);
    indicator.setText2(VcsBundle.message("commit.wait.util.synched.text"));

    if (!myStarted.compareAndSet(false, true)) {
      LOG.error("Waiter running under progress being started again.");
    } else {
      while (!mySemaphore.waitFor(500)) {
        indicator.checkCanceled();
      }
    }
  }
 @Override
 public void render(
     final ChangesBrowserNodeRenderer renderer,
     final boolean selected,
     final boolean expanded,
     final boolean hasFocus) {
   if (userObject instanceof LocalChangeList) {
     final LocalChangeList list = ((LocalChangeList) userObject);
     renderer.appendTextWithIssueLinks(
         list.getName(),
         list.isDefault()
             ? SimpleTextAttributes.REGULAR_BOLD_ATTRIBUTES
             : SimpleTextAttributes.REGULAR_ATTRIBUTES);
     appendCount(renderer);
     for (ChangeListDecorator decorator : myDecorators) {
       decorator.decorateChangeList(list, renderer, selected, expanded, hasFocus);
     }
     final String freezed = myClManager.isFreezed();
     if (freezed != null) {
       renderer.append(" " + freezed, SimpleTextAttributes.GRAYED_ATTRIBUTES);
     } else if (myClManager.isInUpdate()) {
       renderer.append(
           " " + VcsBundle.message("changes.nodetitle.updating"),
           SimpleTextAttributes.GRAYED_ATTRIBUTES);
     }
     if (!myChangeListRemoteState.getState()) {
       renderer.append(" ");
       renderer.append(
           VcsBundle.message("changes.nodetitle.have.outdated.files"),
           SimpleTextAttributes.ERROR_ATTRIBUTES);
     }
   } else {
     renderer.append(getUserObject().getName(), SimpleTextAttributes.SIMPLE_CELL_ATTRIBUTES);
     appendCount(renderer);
   }
 }
  public void actionPerformed(AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    VirtualFile vFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
    assert vFile != null;
    AbstractVcs vcs = ProjectLevelVcsManager.getInstance(project).getVcsFor(vFile);
    assert vcs != null;
    final CommittedChangesProvider provider = vcs.getCommittedChangesProvider();
    assert provider != null;
    ChangeBrowserSettings settings = provider.createDefaultSettings();
    CommittedChangesFilterDialog dlg =
        new CommittedChangesFilterDialog(project, provider.createFilterUI(true), settings);
    dlg.show();
    if (!dlg.isOK()) return;

    int maxCount = 0;
    if (!settings.isAnyFilterSpecified()) {
      int rc =
          Messages.showYesNoCancelDialog(
              project,
              VcsBundle.message("browse.changes.no.filter.prompt"),
              VcsBundle.message("browse.changes.title"),
              VcsBundle.message("browse.changes.show.recent.button"),
              VcsBundle.message("browse.changes.show.all.button"),
              CommonBundle.getCancelButtonText(),
              Messages.getQuestionIcon());
      if (rc == Messages.CANCEL) {
        return;
      }
      if (rc == Messages.YES) {
        maxCount = 50;
      }
    }

    AbstractVcsHelper.getInstance(project)
        .openCommittedChangesTab(vcs, vFile, settings, maxCount, null);
  }
 private static boolean checkNotifyBinaryDiff(final Change selectedChange) {
   final ContentRevision beforeRevision = selectedChange.getBeforeRevision();
   final ContentRevision afterRevision = selectedChange.getAfterRevision();
   if (beforeRevision instanceof BinaryContentRevision
       && afterRevision instanceof BinaryContentRevision) {
     try {
       byte[] beforeContent = ((BinaryContentRevision) beforeRevision).getBinaryContent();
       byte[] afterContent = ((BinaryContentRevision) afterRevision).getBinaryContent();
       if (Arrays.equals(beforeContent, afterContent)) {
         Messages.showInfoMessage(
             VcsBundle.message("message.text.binary.versions.are.identical"),
             VcsBundle.message("message.title.diff"));
       } else {
         Messages.showInfoMessage(
             VcsBundle.message("message.text.binary.versions.are.different"),
             VcsBundle.message("message.title.diff"));
       }
     } catch (VcsException e) {
       Messages.showInfoMessage(e.getMessage(), VcsBundle.message("message.title.diff"));
     }
     return true;
   }
   return false;
 }
 protected void doOKAction() {
   for (Configurable configurable : myEnvToConfMap.values()) {
     try {
       configurable.apply();
     } catch (CancelledConfigurationException e) {
       return;
     } catch (ConfigurationException e) {
       Messages.showErrorDialog(
           myProject,
           VcsBundle.message("messge.text.cannot.save.settings", e.getLocalizedMessage()),
           getRealTitle());
       return;
     }
   }
   super.doOKAction();
 }
Esempio n. 29
0
    private void doRefresh(final Project project, final List<Change> changesToRefresh) {
      final String actionName = VcsBundle.message("changes.action.rollback.text");
      final LocalHistoryAction action = LocalHistory.getInstance().startAction(actionName);

      final Runnable forAwtThread =
          new Runnable() {
            public void run() {
              action.finish();
              LocalHistory.getInstance()
                  .putSystemLabel(
                      myProject,
                      (myLocalHistoryActionName == null) ? actionName : myLocalHistoryActionName,
                      -1);
              final VcsDirtyScopeManager manager =
                  PeriodicalTasksCloser.getInstance()
                      .safeGetComponent(project, VcsDirtyScopeManager.class);
              for (Change change : changesToRefresh) {
                final ContentRevision beforeRevision = change.getBeforeRevision();
                final ContentRevision afterRevision = change.getAfterRevision();
                if ((!change.isIsReplaced())
                    && beforeRevision != null
                    && Comparing.equal(beforeRevision, afterRevision)) {
                  manager.fileDirty(beforeRevision.getFile());
                } else {
                  if (beforeRevision != null) {
                    final FilePath parent = beforeRevision.getFile().getParentPath();
                    if (parent != null) {
                      manager.dirDirtyRecursively(parent);
                    }
                  }
                  if (afterRevision != null) {
                    final FilePath parent = afterRevision.getFile().getParentPath();
                    if (parent != null) {
                      manager.dirDirtyRecursively(parent);
                    }
                  }
                }
              }

              myAfterRefresh.run();
            }
          };

      RefreshVFsSynchronously.updateChangesForRollback(changesToRefresh);

      WaitForProgressToShow.runOrInvokeLaterAboveProgress(forAwtThread, null, project);
    }
    public static Image createImage(final JTree tree) {
      final TreeSelectionModel model = tree.getSelectionModel();
      final TreePath[] paths = model.getSelectionPaths();

      int count = 0;
      final List<ChangesBrowserNode> nodes = new ArrayList<ChangesBrowserNode>();
      for (final TreePath path : paths) {
        final ChangesBrowserNode node = (ChangesBrowserNode) path.getLastPathComponent();
        if (!node.isLeaf()) {
          nodes.add(node);
          count += node.getCount();
        }
      }

      for (TreePath path : paths) {
        final ChangesBrowserNode element = (ChangesBrowserNode) path.getLastPathComponent();
        boolean child = false;
        for (final ChangesBrowserNode node : nodes) {
          if (node.isNodeChild(element)) {
            child = true;
            break;
          }
        }

        if (!child) {
          if (element.isLeaf()) count++;
        } else if (!element.isLeaf()) {
          count -= element.getCount();
        }
      }

      final JLabel label = new JLabel(VcsBundle.message("changes.view.dnd.label", count));
      label.setOpaque(true);
      label.setForeground(tree.getForeground());
      label.setBackground(tree.getBackground());
      label.setFont(tree.getFont());
      label.setSize(label.getPreferredSize());
      final BufferedImage image =
          new BufferedImage(label.getWidth(), label.getHeight(), BufferedImage.TYPE_INT_ARGB);

      Graphics2D g2 = (Graphics2D) image.getGraphics();
      g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f));
      label.paint(g2);
      g2.dispose();

      return image;
    }