Search in sources :

Example 31 with ChangeListManager

use of com.intellij.openapi.vcs.changes.ChangeListManager in project intellij-community by JetBrains.

the class EditChangelistDialog method doOKAction.

protected void doOKAction() {
    String oldName = myList.getName();
    String oldComment = myList.getComment();
    if (!Comparing.equal(oldName, myPanel.getChangeListName()) && ChangeListManager.getInstance(myProject).findChangeList(myPanel.getChangeListName()) != null) {
        Messages.showErrorDialog(myPanel.getContent(), VcsBundle.message("changes.dialog.editchangelist.error.already.exists", myPanel.getChangeListName()), VcsBundle.message("changes.dialog.editchangelist.title"));
        return;
    }
    if (!Comparing.equal(oldName, myPanel.getChangeListName(), true) || !Comparing.equal(oldComment, myPanel.getDescription(), true)) {
        final ChangeListManager clManager = ChangeListManager.getInstance(myProject);
        final String newName = myPanel.getChangeListName();
        if (!myList.getName().equals(newName)) {
            clManager.editName(myList.getName(), newName);
        }
        final String newDescription = myPanel.getDescription();
        if (!myList.getComment().equals(newDescription)) {
            clManager.editComment(myList.getName(), newDescription);
        }
    }
    if (!myList.isDefault() && myPanel.getMakeActiveCheckBox().isSelected()) {
        ChangeListManager.getInstance(myProject).setDefaultChangeList(myList);
    }
    myPanel.changelistCreatedOrChanged(myList);
    super.doOKAction();
}
Also used : ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager)

Example 32 with ChangeListManager

use of com.intellij.openapi.vcs.changes.ChangeListManager in project intellij-community by JetBrains.

the class VcsStructureChooser method createCenterPanel.

@Override
protected JComponent createCenterPanel() {
    myTree = new Tree();
    myTree.setBorder(BORDER);
    myTree.setShowsRootHandles(true);
    myTree.setRootVisible(false);
    myTree.setExpandableItemsEnabled(false);
    FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, true, true, false, true) {

        @Override
        public boolean isFileVisible(VirtualFile file, boolean showHiddenFiles) {
            if (!super.isFileVisible(file, showHiddenFiles))
                return false;
            if (myRoots.contains(file))
                return false;
            ChangeListManager changeListManager = ChangeListManager.getInstance(myProject);
            return !changeListManager.isIgnoredFile(file) && !changeListManager.isUnversioned(file);
        }
    };
    descriptor.withRoots(new ArrayList<>(myRoots)).withShowHiddenFiles(true).withHideIgnored(true);
    final MyCheckboxTreeCellRenderer cellRenderer = new MyCheckboxTreeCellRenderer(mySelectionManager, myModulesSet, myProject, myTree, myRoots);
    FileSystemTreeImpl fileSystemTree = new FileSystemTreeImpl(myProject, descriptor, myTree, cellRenderer, null, o -> {
        DefaultMutableTreeNode lastPathComponent = ((DefaultMutableTreeNode) o.getLastPathComponent());
        Object uo = lastPathComponent.getUserObject();
        if (uo instanceof FileNodeDescriptor) {
            VirtualFile file = ((FileNodeDescriptor) uo).getElement().getFile();
            String module = myModulesSet.get(file);
            if (module != null)
                return module;
            return file == null ? "" : file.getName();
        }
        return o.toString();
    });
    fileSystemTree.getTreeBuilder().getUi().setNodeDescriptorComparator((o1, o2) -> {
        if (o1 instanceof FileNodeDescriptor && o2 instanceof FileNodeDescriptor) {
            VirtualFile f1 = ((FileNodeDescriptor) o1).getElement().getFile();
            VirtualFile f2 = ((FileNodeDescriptor) o2).getElement().getFile();
            boolean isDir1 = f1.isDirectory();
            boolean isDir2 = f2.isDirectory();
            if (isDir1 != isDir2)
                return isDir1 ? -1 : 1;
            return f1.getPath().compareToIgnoreCase(f2.getPath());
        }
        return o1.getIndex() - o2.getIndex();
    });
    new ClickListener() {

        @Override
        public boolean onClick(@NotNull MouseEvent e, int clickCount) {
            int row = myTree.getRowForLocation(e.getX(), e.getY());
            if (row < 0)
                return false;
            Object o = myTree.getPathForRow(row).getLastPathComponent();
            if (getTreeRoot() == o || getFile(o) == null)
                return false;
            Rectangle rowBounds = myTree.getRowBounds(row);
            cellRenderer.setBounds(rowBounds);
            Rectangle checkBounds = cellRenderer.myCheckbox.getBounds();
            checkBounds.setLocation(rowBounds.getLocation());
            if (checkBounds.height == 0)
                checkBounds.height = rowBounds.height;
            if (checkBounds.contains(e.getPoint())) {
                mySelectionManager.toggleSelection((DefaultMutableTreeNode) o);
                myTree.revalidate();
                myTree.repaint();
            }
            return true;
        }
    }.installOn(myTree);
    myTree.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_SPACE) {
                TreePath[] paths = myTree.getSelectionPaths();
                if (paths == null)
                    return;
                for (TreePath path : paths) {
                    if (path == null)
                        continue;
                    Object o = path.getLastPathComponent();
                    if (getTreeRoot() == o || getFile(o) == null)
                        return;
                    mySelectionManager.toggleSelection((DefaultMutableTreeNode) o);
                }
                myTree.revalidate();
                myTree.repaint();
                e.consume();
            }
        }
    });
    JBPanel panel = new JBPanel(new BorderLayout());
    panel.add(new JBScrollPane(fileSystemTree.getTree()), BorderLayout.CENTER);
    final JLabel selectedLabel = new JLabel("");
    selectedLabel.setBorder(JBUI.Borders.empty(2, 0));
    panel.add(selectedLabel, BorderLayout.SOUTH);
    mySelectionManager.setSelectionChangeListener(new PlusMinus<VirtualFile>() {

        @Override
        public void plus(VirtualFile virtualFile) {
            mySelectedFiles.add(virtualFile);
            recalculateErrorText();
        }

        private void recalculateErrorText() {
            checkEmpty();
            if (mySelectionManager.canAddSelection()) {
                selectedLabel.setText("");
            } else {
                selectedLabel.setText(CAN_NOT_ADD_TEXT);
            }
            selectedLabel.revalidate();
        }

        @Override
        public void minus(VirtualFile virtualFile) {
            mySelectedFiles.remove(virtualFile);
            recalculateErrorText();
        }
    });
    panel.setPreferredSize(JBUI.size(400, 300));
    return panel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) KeyAdapter(java.awt.event.KeyAdapter) KeyEvent(java.awt.event.KeyEvent) Tree(com.intellij.ui.treeStructure.Tree) MouseEvent(java.awt.event.MouseEvent) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) FileSystemTreeImpl(com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl) FileNodeDescriptor(com.intellij.openapi.fileChooser.ex.FileNodeDescriptor) JBPanel(com.intellij.ui.components.JBPanel) TreePath(javax.swing.tree.TreePath) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 33 with ChangeListManager

use of com.intellij.openapi.vcs.changes.ChangeListManager in project intellij-community by JetBrains.

the class GitStash method perform.

/**
   * {@inheritDoc}
   */
protected void perform(@NotNull final Project project, @NotNull final List<VirtualFile> gitRoots, @NotNull final VirtualFile defaultRoot) {
    final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
    if (changeListManager.isFreezedWithNotification("Can not stash changes now"))
        return;
    GitStashDialog d = new GitStashDialog(project, gitRoots, defaultRoot);
    if (!d.showAndGet()) {
        return;
    }
    VirtualFile root = d.getGitRoot();
    final GitLineHandler h = d.handler();
    AccessToken token = DvcsUtil.workingTreeChangeStarted(project);
    try {
        GitHandlerUtil.doSynchronously(h, GitBundle.getString("stashing.title"), h.printableCommandLine());
    } finally {
        token.finish();
    }
    VfsUtil.markDirtyAndRefresh(false, true, false, root);
    if (!h.errors().isEmpty()) {
        showErrors(project, getActionName(), h.errors());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) GitLineHandler(git4idea.commands.GitLineHandler) GitStashDialog(git4idea.ui.GitStashDialog) AccessToken(com.intellij.openapi.application.AccessToken) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager)

Example 34 with ChangeListManager

use of com.intellij.openapi.vcs.changes.ChangeListManager in project intellij-community by JetBrains.

the class GithubOpenInBrowserAction method getDataFromVirtualFile.

@Nullable
private static CommitData getDataFromVirtualFile(AnActionEvent e) {
    Project project = e.getData(CommonDataKeys.PROJECT);
    VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
    if (project == null || virtualFile == null)
        return null;
    GitRepository gitRepository = GitUtil.getRepositoryManager(project).getRepositoryForFile(virtualFile);
    if (gitRepository == null || !GithubUtil.isRepositoryOnGitHub(gitRepository))
        return null;
    ChangeListManager changeListManager = ChangeListManager.getInstance(project);
    if (changeListManager.isUnversioned(virtualFile))
        return new CommitData(project, gitRepository);
    Change change = changeListManager.getChange(virtualFile);
    if (change != null && change.getType() == Change.Type.NEW)
        return new CommitData(project, gitRepository);
    return new CommitData(project, gitRepository, virtualFile);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GitRepository(git4idea.repo.GitRepository) Change(com.intellij.openapi.vcs.changes.Change) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) Nullable(org.jetbrains.annotations.Nullable)

Example 35 with ChangeListManager

use of com.intellij.openapi.vcs.changes.ChangeListManager in project intellij-community by JetBrains.

the class GithubShareAction method filterOutIgnored.

@NotNull
private static Collection<VirtualFile> filterOutIgnored(@NotNull Project project, @NotNull Collection<VirtualFile> files) {
    final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
    final ProjectLevelVcsManager vcsManager = ProjectLevelVcsManager.getInstance(project);
    return ContainerUtil.filter(files, file -> !changeListManager.isIgnoredFile(file) && !vcsManager.isIgnored(file));
}
Also used : ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager) ChangeListManager(com.intellij.openapi.vcs.changes.ChangeListManager) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ChangeListManager (com.intellij.openapi.vcs.changes.ChangeListManager)77 VirtualFile (com.intellij.openapi.vfs.VirtualFile)65 Test (org.junit.Test)57 Change (com.intellij.openapi.vcs.changes.Change)42 File (java.io.File)28 LocalChangeList (com.intellij.openapi.vcs.changes.LocalChangeList)24 ConflictVersion (org.jetbrains.idea.svn.conflict.ConflictVersion)23 TreeConflictDescription (org.jetbrains.idea.svn.conflict.TreeConflictDescription)23 ArrayList (java.util.ArrayList)11 VcsException (com.intellij.openapi.vcs.VcsException)6 NotNull (org.jetbrains.annotations.NotNull)4 ContentRevision (com.intellij.openapi.vcs.changes.ContentRevision)3 ProcessOutput (com.intellij.execution.process.ProcessOutput)2 ChangeList (com.intellij.openapi.vcs.changes.ChangeList)2 Nullable (org.jetbrains.annotations.Nullable)2 AccessToken (com.intellij.openapi.application.AccessToken)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 FileNodeDescriptor (com.intellij.openapi.fileChooser.ex.FileNodeDescriptor)1 FileSystemTreeImpl (com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl)1 Project (com.intellij.openapi.project.Project)1