From 079bd524a7ecc0992a3f71af4b17015b118b8501 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Tue, 24 Apr 2018 21:48:43 +0300 Subject: [PATCH] [file-history] make RefreshFileHistoryAction context-based RefreshFileHistoryAction extracts FileHistoryRefresher from context and uses it to do refresh. In order to know whether refresh is already in progress, a method isInRefresh is added. --- .../src/idea/VcsActions.xml | 3 ++ .../vcs/history/FileHistoryPanelImpl.java | 35 ++----------------- .../vcs/history/FileHistoryRefresher.java | 7 ++++ .../vcs/history/FileHistoryRefresherI.java | 2 ++ .../actions/RefreshFileHistoryAction.java | 33 +++++++++++++++++ .../TreeConflictRefreshablePanel.java | 5 +++ 6 files changed, 53 insertions(+), 32 deletions(-) create mode 100644 platform/vcs-impl/src/com/intellij/openapi/vcs/history/actions/RefreshFileHistoryAction.java diff --git a/platform/platform-resources/src/idea/VcsActions.xml b/platform/platform-resources/src/idea/VcsActions.xml index a6a06bc59f04..28fa2424c288 100644 --- a/platform/platform-resources/src/idea/VcsActions.xml +++ b/platform/platform-resources/src/idea/VcsActions.xml @@ -24,6 +24,8 @@ text="Com_pare with Specified Revision..." popup="true"/> + + diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java index 011792ea31cb..fb5b31758850 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryPanelImpl.java @@ -18,7 +18,6 @@ package com.intellij.openapi.vcs.history; import com.intellij.CommonBundle; import com.intellij.icons.AllIcons; import com.intellij.ide.CopyProvider; -import com.intellij.ide.actions.RefreshAction; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.colors.EditorColorsListener; @@ -195,7 +194,7 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme lastTask = ourExecutor.submit(() -> { if (!updateAlarm.isDisposed() && myHistorySession.shouldBeRefreshed()) { - refreshUiAndScheduleDataRefresh(true); + ApplicationManager.getApplication().invokeAndWait(() -> myRefresherI.refresh(true)); } }); } @@ -402,15 +401,14 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme @NotNull private DefaultActionGroup fillActionGroup(boolean popup, DefaultActionGroup result) { - result.add(new RefreshFileHistoryAction()); - if (popup) { result.add(ActionManager.getInstance().getAction(IdeActions.ACTION_EDIT_SOURCE)); } AnAction actionGroup = ActionManager.getInstance().getAction(popup ? VCS_HISTORY_POPUP_ACTION_GROUP : VCS_HISTORY_TOOLBAR_ACTION_GROUP); result.add(actionGroup); - AnAction[] additionalActions = myProvider.getAdditionalActions(() -> refreshUiAndScheduleDataRefresh(true)); + AnAction[] additionalActions = + myProvider.getAdditionalActions(() -> ApplicationManager.getApplication().invokeAndWait(() -> myRefresherI.refresh(true))); if (additionalActions != null) { for (AnAction additionalAction : additionalActions) { if (popup || additionalAction.getTemplatePresentation().getIcon() != null) { @@ -429,12 +427,6 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme return result; } - private void refreshUiAndScheduleDataRefresh(boolean canUseCache) { - ApplicationManager.getApplication().invokeAndWait(() -> { - myRefresherI.refresh(canUseCache); - }); - } - public Object getData(String dataId) { if (CommonDataKeys.NAVIGATABLE.is(dataId)) { VcsFileRevision[] selectedRevisions = getSelectedRevisions(); @@ -996,27 +988,6 @@ public class FileHistoryPanelImpl extends PanelWithActionsAndCloseButton impleme } } - private class RefreshFileHistoryAction extends RefreshAction implements DumbAware { - public RefreshFileHistoryAction() { - super(VcsBundle.message("action.name.refresh"), VcsBundle.message("action.description.refresh"), AllIcons.Actions.Refresh); - registerShortcutOn(FileHistoryPanelImpl.this); - } - - public void actionPerformed(AnActionEvent e) { - refreshUiAndScheduleDataRefresh(false); - } - - @Override - public void update(AnActionEvent e) { - super.update(e); - e.getPresentation().setEnabled(!isInRefresh()); - } - - private boolean isInRefresh() { - return VcsCachingHistory.getHistoryLock(myVcs, VcsBackgroundableActions.CREATE_HISTORY_SESSION, myFilePath, myStartingRevision).isLocked(); - } - } - private class MyShowDetailsAction extends ToggleAction implements DumbAware { public MyShowDetailsAction() { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryRefresher.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryRefresher.java index eded6c69b9a2..2c51f552d40b 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryRefresher.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryRefresher.java @@ -17,6 +17,7 @@ package com.intellij.openapi.vcs.history; import com.intellij.openapi.vcs.AbstractVcs; import com.intellij.openapi.vcs.FilePath; +import com.intellij.openapi.vcs.impl.VcsBackgroundableActions; import com.intellij.vcs.history.VcsHistoryProviderEx; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -82,6 +83,12 @@ public class FileHistoryRefresher implements FileHistoryRefresherI { mySessionPartner.createOrSelectContent(); } + @Override + public boolean isInRefresh() { + return VcsCachingHistory.getHistoryLock(myVcs, VcsBackgroundableActions.CREATE_HISTORY_SESSION, myPath, myStartingRevisionNumber) + .isLocked(); + } + /** * @param canUseCache */ diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryRefresherI.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryRefresherI.java index 8a446363bfa4..ed37983a0007 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryRefresherI.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/FileHistoryRefresherI.java @@ -19,4 +19,6 @@ public interface FileHistoryRefresherI { void refresh(boolean canUseCache); void selectContent(); + + boolean isInRefresh(); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/actions/RefreshFileHistoryAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/actions/RefreshFileHistoryAction.java new file mode 100644 index 000000000000..0f4728d02078 --- /dev/null +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/actions/RefreshFileHistoryAction.java @@ -0,0 +1,33 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.openapi.vcs.history.actions; + +import com.intellij.icons.AllIcons; +import com.intellij.ide.actions.RefreshAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.project.DumbAware; +import com.intellij.openapi.vcs.VcsBundle; +import com.intellij.openapi.vcs.VcsDataKeys; +import com.intellij.openapi.vcs.history.FileHistoryPanelImpl; + +public class RefreshFileHistoryAction extends RefreshAction implements DumbAware { + public RefreshFileHistoryAction() { + super(VcsBundle.message("action.name.refresh"), VcsBundle.message("action.description.refresh"), AllIcons.Actions.Refresh); + } + + public void actionPerformed(AnActionEvent e) { + FileHistoryPanelImpl panel = (FileHistoryPanelImpl)e.getRequiredData(VcsDataKeys.FILE_HISTORY_PANEL); + panel.getRefresher().refresh(false); + } + + @Override + public void update(AnActionEvent e) { + super.update(e); + FileHistoryPanelImpl panel = (FileHistoryPanelImpl)e.getData(VcsDataKeys.FILE_HISTORY_PANEL); + if (panel == null) { + e.getPresentation().setEnabledAndVisible(false); + return; + } + e.getPresentation().setVisible(true); + e.getPresentation().setEnabled(!panel.getRefresher().isInRefresh()); + } +} diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/TreeConflictRefreshablePanel.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/TreeConflictRefreshablePanel.java index 395806aac8e6..1bd3762009b1 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/TreeConflictRefreshablePanel.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/treeConflict/TreeConflictRefreshablePanel.java @@ -528,6 +528,11 @@ public class TreeConflictRefreshablePanel implements Disposable { @Override public void selectContent() { } + + @Override + public boolean isInRefresh() { + return false; + } }, true); myFileHistoryPanel.setBottomRevisionForShowDiff(last); myFileHistoryPanel.setBorder(BorderFactory.createLineBorder(UIUtil.getBorderColor()));