IDEA-147618 add actions to show Local Changes, Log, and Shelf.

This commit is contained in:
Kirill Likhodedov
2015-11-17 18:32:58 +03:00
parent 4152c28fd6
commit d65ba3dff9
7 changed files with 175 additions and 4 deletions
@@ -379,5 +379,11 @@
<add-to-group group-id="Diff.KeymapGroup"/>
</group>
<group id="Vcs.Show.Toolwindow.Tab">
<add-to-group group-id="VcsGeneral.KeymapGroup"/>
<action id="Vcs.Show.Local.Changes" class="com.intellij.vcs.VcsShowLocalChangesAction" text="Show Local Changes"/>
<action id="Vcs.Show.Shelf" class="com.intellij.vcs.VcsShowShelfAction" text="Show Shelf"/>
</group>
</actions>
</idea-plugin>
@@ -228,14 +228,20 @@ public class ChangesViewContentManager extends AbstractProjectComponent implemen
return null;
}
public boolean isContentSelected(final Content content) {
return Comparing.equal(content, myContentManager.getSelectedContent());
public boolean isContentSelected(@NotNull String contentName) {
Content selectedContent = myContentManager.getSelectedContent();
if (selectedContent == null) return false;
return Comparing.equal(contentName, selectedContent.getTabName());
}
public void selectContent(final String tabName) {
public void selectContent(@NotNull String tabName) {
selectContent(tabName, false);
}
public void selectContent(@NotNull String tabName, boolean requestFocus) {
for(Content content: myContentManager.getContents()) {
if (content.getDisplayName().equals(tabName)) {
myContentManager.setSelectedContent(content);
myContentManager.setSelectedContent(content, requestFocus);
break;
}
}
@@ -0,0 +1,27 @@
/*
* Copyright 2000-2015 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 com.intellij.vcs;
import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager;
import org.jetbrains.annotations.NotNull;
public class VcsShowLocalChangesAction extends VcsShowToolWindowTabAction {
@NotNull
@Override
protected String getTabName() {
return ChangesViewContentManager.LOCAL_CHANGES;
}
}
@@ -0,0 +1,28 @@
/*
* Copyright 2000-2015 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 com.intellij.vcs;
import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager;
import org.jetbrains.annotations.NotNull;
public class VcsShowShelfAction extends VcsShowToolWindowTabAction {
@NotNull
@Override
protected String getTabName() {
return ChangesViewContentManager.SHELF;
}
}
@@ -0,0 +1,72 @@
/*
* Copyright 2000-2015 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 com.intellij.vcs;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.changes.ui.ChangesViewContentManager;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowManager;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static com.intellij.util.ObjectUtils.assertNotNull;
public abstract class VcsShowToolWindowTabAction extends DumbAwareAction {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
ToolWindow toolWindow = assertNotNull(getToolWindow(project));
final ChangesViewContentManager changesViewContentManager = (ChangesViewContentManager)ChangesViewContentManager.getInstance(project);
final String tabName = getTabName();
if (toolWindow.isActive() && changesViewContentManager.isContentSelected(tabName)) {
toolWindow.hide(null);
}
else {
toolWindow.activate(new Runnable() {
@Override
public void run() {
IdeFocusManager.getInstance(project).doWhenFocusSettlesDown(new Runnable() {
@Override
public void run() {
changesViewContentManager.selectContent(tabName, true);
}
});
}
}, true, true);
}
}
@Nullable
private static ToolWindow getToolWindow(@Nullable Project project) {
if (project == null) return null;
return ToolWindowManager.getInstance(project).getToolWindow(ChangesViewContentManager.TOOLWINDOW_ID);
}
@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);
e.getPresentation().setEnabledAndVisible(getToolWindow(e.getProject()) != null);
}
@NotNull
protected abstract String getTabName();
}
@@ -28,6 +28,9 @@
<action class="com.intellij.vcs.log.ui.actions.VcsLogQuickSettingsActions" id="Vcs.Log.QuickSettings"
icon="AllIcons.General.Gear" text="Quick Settings" description="Quick Settings" />
<action class="com.intellij.vcs.log.ui.actions.IntelliSortChooserToggleAction" id="Vcs.Log.IntelliSortChooser"/>
<action class="com.intellij.vcs.log.ui.actions.VcsShowLogAction" id="Vcs.Show.Log" text="Show VCS Log">
<add-to-group group-id="Vcs.Show.Toolwindow.Tab"/>
</action>
<group id="Vcs.Log.Toolbar">
<reference id="Vcs.Log.GoToRef" />
@@ -0,0 +1,29 @@
/*
* Copyright 2000-2015 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 com.intellij.vcs.log.ui.actions;
import com.intellij.vcs.VcsShowToolWindowTabAction;
import com.intellij.vcs.log.impl.VcsLogContentProvider;
import org.jetbrains.annotations.NotNull;
public class VcsShowLogAction extends VcsShowToolWindowTabAction {
@NotNull
@Override
protected String getTabName() {
return VcsLogContentProvider.TAB_NAME;
}
}