mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[git] IDEA-116690 Fix "Select in Git Log" from File History
It used to navigate to the old log, therefore nothing happened with
new log implementation.
* Refer to new VcsLog from SelectRevisionInGitLogAction.
Ask VcsLogUi to get the VcsLog instance, because:
- VcsLog is not available in the DataContext of this action;
- VcsLogImpl can't be easily made a Service, because it depends on
non-components (this is to be changed later).
* VcsLogManager#getLogUi can be null if the log is not initialized
yet => fix annotation, add javadocs.
* Update the usages of these getters to be aware of pre-init condition
in SelectRevisionInGitLogAction & VcsLogQuickSettingsActions.
* Make the "Log" tab name public & move it to more appropriate place:
VcsLogContentProvider.
TODO:
If the log was not initialized yet when user invoked the action,
the tab will be open, and the log will be shown,
but the commit won't be selected.
This is a bug, but not fixing because this worked the same
way previously, and the fix is not trivial.
To be fixed later.
This commit is contained in:
@@ -30,6 +30,8 @@ import javax.swing.*;
|
||||
*/
|
||||
public class VcsLogContentProvider implements ChangesViewContentProvider, NotNullFunction<Project, Boolean> {
|
||||
|
||||
public static final String TAB_NAME = "Log";
|
||||
|
||||
@NotNull private final VcsLogManager myLogManager;
|
||||
|
||||
public VcsLogContentProvider(@NotNull VcsLogManager logManager) {
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.intellij.vcs.log.data.VcsLogUiProperties;
|
||||
import com.intellij.vcs.log.ui.VcsLogColorManagerImpl;
|
||||
import com.intellij.vcs.log.ui.VcsLogUI;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -114,11 +115,18 @@ public class VcsLogManager implements Disposable {
|
||||
return logProviders;
|
||||
}
|
||||
|
||||
/**
|
||||
* The instance of the {@link VcsLogDataHolder} or null if the log was not initialized yet.
|
||||
*/
|
||||
@Nullable
|
||||
public VcsLogDataHolder getDataHolder() {
|
||||
return myLogDataHolder;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
/**
|
||||
* The instance of the {@link VcsLogUI} or null if the log was not initialized yet.
|
||||
*/
|
||||
@Nullable
|
||||
public VcsLogUI getLogUi() {
|
||||
return myUi;
|
||||
}
|
||||
@@ -155,7 +163,6 @@ public class VcsLogManager implements Disposable {
|
||||
private static class PostponeableLogRefresher implements VcsLogRefresher, Disposable {
|
||||
|
||||
private static final String TOOLWINDOW_ID = ChangesViewContentManager.TOOLWINDOW_ID;
|
||||
private static final String TAB_NAME = "Log";
|
||||
|
||||
@NotNull private final VcsLogDataHolder myDataHolder;
|
||||
@NotNull private final ToolWindowManagerImpl myToolWindowManager;
|
||||
@@ -211,7 +218,7 @@ public class VcsLogManager implements Disposable {
|
||||
private boolean isOurContentPaneShowing() {
|
||||
if (myToolWindowManager.isToolWindowRegistered(TOOLWINDOW_ID) && myToolWindow.isVisible()) {
|
||||
Content content = myToolWindow.getContentManager().getSelectedContent();
|
||||
return content != null && content.getTabName().equals(TAB_NAME);
|
||||
return content != null && content.getTabName().equals(VcsLogContentProvider.TAB_NAME);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.intellij.vcs.log.impl;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.NotNullFunction;
|
||||
@@ -14,6 +15,8 @@ import java.util.List;
|
||||
*/
|
||||
public class VcsLogObjectsFactoryImpl implements VcsLogObjectsFactory {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(VcsLogObjectsFactoryImpl.class);
|
||||
|
||||
@NotNull private final VcsLogManager myLogManager;
|
||||
|
||||
public VcsLogObjectsFactoryImpl(@NotNull VcsLogManager logManager) {
|
||||
@@ -77,7 +80,12 @@ public class VcsLogObjectsFactoryImpl implements VcsLogObjectsFactory {
|
||||
@NotNull
|
||||
@Override
|
||||
public Integer fun(Hash hash) {
|
||||
return myLogManager.getDataHolder().putHash(hash);
|
||||
VcsLogDataHolder dataHolder = myLogManager.getDataHolder();
|
||||
if (dataHolder == null) {
|
||||
LOG.error("The log data holder should have been initialized at this point");
|
||||
return -1;
|
||||
}
|
||||
return dataHolder.putHash(hash);
|
||||
}
|
||||
}, commitHash, name, type, root);
|
||||
}
|
||||
|
||||
@@ -38,10 +38,10 @@ public class VcsLogQuickSettingsActions extends DumbAwareAction {
|
||||
}
|
||||
VcsLogSettings settings = ServiceManager.getService(project, VcsLogSettings.class);
|
||||
VcsLogManager logManager = ServiceManager.getService(project, VcsLogManager.class);
|
||||
if (settings == null || logManager == null) {
|
||||
VcsLogUI logUi = logManager.getLogUi();
|
||||
if (logUi == null) {
|
||||
return;
|
||||
}
|
||||
VcsLogUI logUi = logManager.getLogUi();
|
||||
|
||||
ActionGroup settingsGroup = new MySettingsActionGroup(settings, logUi);
|
||||
ActionPopupMenu popupMenu = ActionManager.getInstance().createActionPopupMenu(ToolWindowContentUi.POPUP_PLACE, settingsGroup);
|
||||
@@ -55,6 +55,18 @@ public class VcsLogQuickSettingsActions extends DumbAwareAction {
|
||||
popupMenu.getComponent().show(inputEvent.getComponent(), x, y);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
if (project == null) {
|
||||
e.getPresentation().setEnabledAndVisible(false);
|
||||
}
|
||||
else {
|
||||
VcsLogManager logManager = ServiceManager.getService(project, VcsLogManager.class);
|
||||
e.getPresentation().setEnabledAndVisible(logManager.getLogUi() != null);
|
||||
}
|
||||
}
|
||||
|
||||
private static class MySettingsActionGroup extends ActionGroup {
|
||||
|
||||
private final VcsLogSettings mySettings;
|
||||
|
||||
@@ -274,4 +274,9 @@ public class VcsLogUI {
|
||||
public Component getToolbar() {
|
||||
return myMainFrame.getToolbar();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public VcsLog getVcsLog() {
|
||||
return myLog;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package git4idea.history.wholeTree;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.VcsDataKeys;
|
||||
@@ -13,7 +14,9 @@ import com.intellij.openapi.wm.ToolWindow;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.ui.content.Content;
|
||||
import com.intellij.ui.content.ContentManager;
|
||||
import git4idea.history.browser.GitProjectLogManager;
|
||||
import com.intellij.vcs.log.impl.VcsLogContentProvider;
|
||||
import com.intellij.vcs.log.impl.VcsLogManager;
|
||||
import com.intellij.vcs.log.ui.VcsLogUI;
|
||||
import git4idea.i18n.GitBundle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -36,7 +39,7 @@ public class SelectRevisionInGitLogAction extends DumbAwareAction {
|
||||
return;
|
||||
}
|
||||
|
||||
final GitLog log = GitProjectLogManager.getInstance(project).getLog();
|
||||
final VcsLogManager log = ServiceManager.getService(project, VcsLogManager.class);
|
||||
if (log == null) {
|
||||
return;
|
||||
}
|
||||
@@ -45,7 +48,7 @@ public class SelectRevisionInGitLogAction extends DumbAwareAction {
|
||||
ContentManager cm = window.getContentManager();
|
||||
Content[] contents = cm.getContents();
|
||||
for (Content content : contents) {
|
||||
if (GitProjectLogManager.CONTENT_KEY.equals(content.getDisplayName())) {
|
||||
if (VcsLogContentProvider.TAB_NAME.equals(content.getDisplayName())) {
|
||||
cm.setSelectedContent(content);
|
||||
}
|
||||
}
|
||||
@@ -53,7 +56,11 @@ public class SelectRevisionInGitLogAction extends DumbAwareAction {
|
||||
Runnable selectCommit = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
log.selectCommit(revision.asString());
|
||||
VcsLogUI logUi = log.getLogUi();
|
||||
if (logUi == null) {
|
||||
return;
|
||||
}
|
||||
logUi.getVcsLog().jumpToReference(revision.asString());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user