2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * Created by IntelliJ IDEA.
23 package com
.intellij
.openapi
.vcs
.changes
.actions
;
25 import com
.intellij
.openapi
.actionSystem
.AnAction
;
26 import com
.intellij
.openapi
.actionSystem
.AnActionEvent
;
27 import com
.intellij
.openapi
.actionSystem
.PlatformDataKeys
;
28 import com
.intellij
.openapi
.project
.Project
;
29 import com
.intellij
.openapi
.vcs
.*;
30 import com
.intellij
.openapi
.vcs
.changes
.ChangesUtil
;
31 import com
.intellij
.openapi
.vcs
.changes
.VcsDirtyScopeManager
;
32 import com
.intellij
.openapi
.vfs
.VfsUtil
;
33 import com
.intellij
.openapi
.vfs
.VirtualFile
;
35 import java
.util
.ArrayList
;
36 import java
.util
.List
;
38 public class EditAction
extends AnAction
{
39 public void actionPerformed(AnActionEvent e
) {
40 final Project project
= e
.getData(PlatformDataKeys
.PROJECT
);
41 List
<VirtualFile
> files
= e
.getData(VcsDataKeys
.MODIFIED_WITHOUT_EDITING_DATA_KEY
);
42 editFilesAndShowErrors(project
, files
);
45 public static void editFilesAndShowErrors(Project project
, List
<VirtualFile
> files
) {
46 final List
<VcsException
> exceptions
= new ArrayList
<VcsException
>();
47 editFiles(project
, files
, exceptions
);
48 if (!exceptions
.isEmpty()) {
49 AbstractVcsHelper
.getInstance(project
).showErrors(exceptions
, VcsBundle
.message("edit.errors"));
53 public static void editFiles(final Project project
, final List
<VirtualFile
> files
, final List
<VcsException
> exceptions
) {
54 ChangesUtil
.processVirtualFilesByVcs(project
, files
, new ChangesUtil
.PerVcsProcessor
<VirtualFile
>() {
55 public void process(final AbstractVcs vcs
, final List
<VirtualFile
> items
) {
56 final EditFileProvider provider
= vcs
.getEditFileProvider();
57 if (provider
!= null) {
59 provider
.editFiles(VfsUtil
.toVirtualFileArray(items
));
61 catch (VcsException e1
) {
64 for(VirtualFile file
: items
) {
65 VcsDirtyScopeManager
.getInstance(project
).fileDirty(file
);
66 FileStatusManager
.getInstance(project
).fileStatusChanged(file
);
73 public void update(final AnActionEvent e
) {
74 List
<VirtualFile
> files
= e
.getData(VcsDataKeys
.MODIFIED_WITHOUT_EDITING_DATA_KEY
);
75 boolean enabled
= files
!= null && !files
.isEmpty();
76 e
.getPresentation().setEnabled(enabled
);
77 e
.getPresentation().setVisible(enabled
);