[log] Add "New Branch", "New Tag" actions to the log + refactor

* Extract GitLogSingleCommitAction - the common class
  for all Git actions on the log, which operate on a single commit.
* Implement "New Branch" and "New Tag" actions. Use GitBrancher for
  the first, reuse the existing CreateNewTag for the latter.
* Regroup actions in plugin.xml so that they form a single group which
  is then added to the Vcs group.
  It lets add a separator, and also makes the code more clear.
This commit is contained in:
Kirill Likhodedov
2013-11-03 19:32:37 +04:00
parent aef03d9f2d
commit 32c3c35969
5 changed files with 135 additions and 11 deletions
+18 -5
View File
@@ -75,14 +75,27 @@
<separator/>
</group>
<action id="Git.CherryPick" class="git4idea.cherrypick.GitCherryPickAction" text="Cherry-Pick" icon="Git4ideaIcons.CherryPick" anchor="First">
<action id="Git.CherryPick" class="git4idea.cherrypick.GitCherryPickAction" text="Cherry-Pick" icon="Git4ideaIcons.CherryPick"/>
<action class="git4idea.actions.GitCheckoutRevisionAction" id="Git.CheckoutRevision" text="Checkout Revision"/>
<action class="git4idea.actions.GitCreateNewBranchAction" id="Git.CreateNewBranch" text="New Branch"
description="Create new branch starting from the selected commit"/>
<action class="git4idea.actions.GitCreateTagAction" id="Git.CreateNewTag" text="New Tag"
description="Create new tag pointing to this commit"/>
<group id="Git.Log.ContextMenu">
<separator/>
<reference id="Git.CherryPick" />
<reference id="Git.CheckoutRevision"/>
<reference id="Git.CreateNewBranch" />
<reference id="Git.CreateNewTag" />
<add-to-group group-id="Vcs.Log.ContextMenu" />
</group>
<group id="Git.Log.Toolbar">
<reference id="Git.CherryPick"/>
<add-to-group group-id="Vcs.Log.Toolbar" />
</action>
</group>
<action class="git4idea.branch.GitCheckoutRevisionAction" id="Git.CheckoutRevision" text="Checkout Revision">
<add-to-group group-id="Vcs.Log.ContextMenu" />
</action>
</actions>
@@ -0,0 +1,34 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package git4idea.actions;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.vcs.log.VcsFullCommitDetails;
import git4idea.branch.GitBrancher;
import git4idea.repo.GitRepository;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
public class GitCheckoutRevisionAction extends GitLogSingleCommitAction {
@Override
protected void actionPerformed(@NotNull GitRepository repository, @NotNull VcsFullCommitDetails commit) {
GitBrancher brancher = ServiceManager.getService(repository.getProject(), GitBrancher.class);
brancher.checkout(commit.getHash().asString(), Collections.singletonList(repository), null);
}
}
@@ -0,0 +1,41 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package git4idea.actions;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.project.Project;
import com.intellij.vcs.log.VcsFullCommitDetails;
import git4idea.branch.GitBranchUtil;
import git4idea.branch.GitBrancher;
import git4idea.repo.GitRepository;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
public class GitCreateNewBranchAction extends GitLogSingleCommitAction {
@Override
protected void actionPerformed(@NotNull GitRepository repository, @NotNull VcsFullCommitDetails commit) {
Project project = repository.getProject();
String reference = commit.getHash().asString();
final String name = GitBranchUtil.getNewBranchNameFromUser(project, Collections.singleton(repository),
"Checkout New Branch From " + reference);
if (name != null) {
GitBrancher brancher = ServiceManager.getService(project, GitBrancher.class);
brancher.checkoutNewBranchStartingFrom(name, reference, Collections.singletonList(repository), null);
}
}
}
@@ -0,0 +1,31 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package git4idea.actions;
import com.intellij.vcs.log.VcsFullCommitDetails;
import git4idea.history.wholeTree.GitCreateNewTag;
import git4idea.repo.GitRepository;
import org.jetbrains.annotations.NotNull;
public class GitCreateTagAction extends GitLogSingleCommitAction {
@Override
protected void actionPerformed(@NotNull GitRepository repository, @NotNull VcsFullCommitDetails commit) {
String reference = commit.getHash().asString();
new GitCreateNewTag(repository.getProject(), repository, reference, null).execute();
}
}
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package git4idea.branch;
package git4idea.actions;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
@@ -27,13 +27,18 @@ import com.intellij.vcs.log.VcsLogDataKeys;
import git4idea.GitUtil;
import git4idea.repo.GitRepository;
import git4idea.repo.GitRepositoryManager;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
public class GitCheckoutRevisionAction extends DumbAwareAction {
/**
* @author Kirill Likhodedov
*/
public abstract class GitLogSingleCommitAction extends DumbAwareAction {
private static final Logger LOG = Logger.getInstance(GitCheckoutRevisionAction.class);
private static final Logger LOG = Logger.getInstance(GitLogSingleCommitAction.class);
protected abstract void actionPerformed(@NotNull GitRepository repository, @NotNull VcsFullCommitDetails commit);
@Override
public void actionPerformed(AnActionEvent e) {
@@ -54,8 +59,8 @@ public class GitCheckoutRevisionAction extends DumbAwareAction {
GitUtil.noRepositoryForRoot(LOG, commit.getRoot(), data.project);
return;
}
GitBrancher brancher = ServiceManager.getService(data.project, GitBrancher.class);
brancher.checkout(commit.getHash().asString(), Collections.singletonList(repository), null);
actionPerformed(repository, commit);
}
@Override