From 134445c78df222adf80055f174bab0e8fb29ebe3 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Mon, 20 May 2019 01:00:37 +0300 Subject: [PATCH] [vcs-log] add a resume indexing button to the log toolbar GitOrigin-RevId: d3215c9b91929fbbd2bca100973cc59ffb5680b1 --- .../vcs-log/impl/src/META-INF/vcs-log.xml | 6 ++ .../data/index/VcsLogBigRepositoriesList.java | 4 +- .../log/data/index/VcsLogPersistentIndex.java | 37 +++++++----- .../vcs/log/ui/VcsLogActionPlaces.java | 2 +- .../log/ui/actions/ResumeIndexingAction.kt | 56 +++++++++++++++++++ .../intellij/vcs/log/ui/frame/MainFrame.java | 12 ++-- 6 files changed, 93 insertions(+), 24 deletions(-) create mode 100644 platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/ResumeIndexingAction.kt diff --git a/platform/vcs-log/impl/src/META-INF/vcs-log.xml b/platform/vcs-log/impl/src/META-INF/vcs-log.xml index fc367fcabd7d..85e305ac8e00 100644 --- a/platform/vcs-log/impl/src/META-INF/vcs-log.xml +++ b/platform/vcs-log/impl/src/META-INF/vcs-log.xml @@ -123,6 +123,8 @@ + @@ -160,6 +162,10 @@ + + + + diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogBigRepositoriesList.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogBigRepositoriesList.java index b634ee87e231..dd22ca316054 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogBigRepositoriesList.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/data/index/VcsLogBigRepositoriesList.java @@ -42,9 +42,9 @@ public class VcsLogBigRepositoriesList implements PersistentStateComponent(); - myRoots = new LinkedHashSet<>(); - for (Map.Entry entry : providers.entrySet()) { - VirtualFile root = entry.getKey(); - VcsLogProvider provider = entry.getValue(); - if (VcsLogProperties.get(provider, VcsLogProperties.SUPPORTS_INDEXING) && provider instanceof VcsIndexableLogProvider) { - myIndexers.put(root, ((VcsIndexableLogProvider)provider).getIndexer()); - myRoots.add(root); - } - } + myIndexers = getAvailableIndexers(providers); + myRoots = new LinkedHashSet<>(myIndexers.keySet()); VcsUserRegistry userRegistry = ServiceManager.getService(myProject, VcsUserRegistry.class); @@ -307,6 +299,24 @@ public class VcsLogPersistentIndex implements VcsLogModifiableIndex, Disposable public void dispose() { } + @NotNull + private static Map getAvailableIndexers(@NotNull Map providers) { + Map indexers = new LinkedHashMap<>(); + for (Map.Entry entry : providers.entrySet()) { + VirtualFile root = entry.getKey(); + VcsLogProvider provider = entry.getValue(); + if (VcsLogProperties.get(provider, VcsLogProperties.SUPPORTS_INDEXING) && provider instanceof VcsIndexableLogProvider) { + indexers.put(root, ((VcsIndexableLogProvider)provider).getIndexer()); + } + } + return indexers; + } + + @NotNull + public static Set getRootsForIndexing(@NotNull Map providers) { + return getAvailableIndexers(providers).keySet(); + } + static class IndexStorage implements Disposable { private static final String COMMITS = "commits"; private static final String MESSAGES = "messages"; @@ -662,11 +672,8 @@ public class VcsLogPersistentIndex implements VcsLogModifiableIndex, Disposable NotificationType.INFORMATION, null); notification.addAction(NotificationAction.createSimple("Resume", () -> { myIndexCollector.reportResumeClick(); - if (myBigRepositoriesList.isBig(myRoot)) { - LOG.info("Resuming indexing " + myRoot.getName()); - myBigRepositoriesList.removeRepository(myRoot); - scheduleIndex(false); - } + LOG.info("Resuming indexing for " + myRoot.getName()); + if (myBigRepositoriesList.removeRepository(myRoot)) scheduleIndex(false); notification.expire(); })); notification.setContextHelpAction(new DumbAwareAction("Why is it helpful?", diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogActionPlaces.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogActionPlaces.java index 5c3716bf6406..9a811aa4feac 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogActionPlaces.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/VcsLogActionPlaces.java @@ -19,6 +19,7 @@ public class VcsLogActionPlaces { // action groups public static final String POPUP_ACTION_GROUP = "Vcs.Log.ContextMenu"; public static final String TOOLBAR_ACTION_GROUP = "Vcs.Log.Toolbar.Internal"; + public static final String TOOLBAR_RIGHT_CORNER_ACTION_GROUP = "Vcs.Log.Toolbar.RightCorner"; public static final String PRESENTATION_SETTINGS_ACTION_GROUP = "Vcs.Log.PresentationSettings"; public static final String TEXT_FILTER_SETTINGS_ACTION_GROUP = "Vcs.Log.TextFilterSettings"; public static final String FILE_HISTORY_TOOLBAR_ACTION_GROUP = "Vcs.FileHistory.Toolbar"; @@ -37,5 +38,4 @@ public class VcsLogActionPlaces { public static final String VCS_LOG_FOCUS_TEXT_FILTER = "Vcs.Log.FocusTextFilter"; public static final String VCS_LOG_SHOW_DIFF_ACTION = "Diff.ShowDiff"; public static final String CHECKIN_PROJECT_ACTION = "CheckinProject"; - public static final String VCS_LOG_GO_TO_HASH_OR_REF_ACTION = "Vcs.Log.GoToRef"; } diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/ResumeIndexingAction.kt b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/ResumeIndexingAction.kt new file mode 100644 index 000000000000..5041cb700ed9 --- /dev/null +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/actions/ResumeIndexingAction.kt @@ -0,0 +1,56 @@ +// Copyright 2000-2019 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.vcs.log.ui.actions + +import com.intellij.openapi.actionSystem.AnActionEvent +import com.intellij.openapi.project.DumbAwareAction +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.vcs.log.data.VcsLogData +import com.intellij.vcs.log.data.index.VcsLogBigRepositoriesList +import com.intellij.vcs.log.data.index.VcsLogModifiableIndex +import com.intellij.vcs.log.data.index.VcsLogPersistentIndex +import com.intellij.vcs.log.impl.VcsLogSharedSettings +import com.intellij.vcs.log.statistics.VcsLogUsageTriggerCollector +import com.intellij.vcs.log.ui.VcsLogInternalDataKeys + +class ResumeIndexingAction : DumbAwareAction() { + override fun update(e: AnActionEvent) { + val data = e.getData(VcsLogInternalDataKeys.LOG_DATA) + val project = e.project + if (data == null || project == null || !VcsLogSharedSettings.isIndexSwitchedOn(project)) { + e.presentation.isEnabledAndVisible = false + return + } + + val bigRepositories = getBigRepositories(data) + e.presentation.isEnabledAndVisible = VcsLogPersistentIndex.getRootsForIndexing(data.logProviders).isNotEmpty() && + bigRepositories.isNotEmpty() + e.presentation.description = "Indexing ${getText(bigRepositories)} was paused as it took longer than expected. Resume." + } + + private fun getText(bigRepositories: List): String { + val repositoriesLimit = 3 + val result = bigRepositories.map { it.name }.sorted().take(repositoriesLimit).joinToString(", ") { "'$it'" } + if (bigRepositories.size > repositoriesLimit) { + return "$result, ..." + } + return result + } + + override fun actionPerformed(e: AnActionEvent) { + VcsLogUsageTriggerCollector.triggerUsage(e, this) + + val data = e.getRequiredData(VcsLogInternalDataKeys.LOG_DATA) + + var resumed = false + for (root in getBigRepositories(data)) { + resumed = resumed or VcsLogBigRepositoriesList.getInstance().removeRepository(root) + } + if (resumed) (data.index as? VcsLogModifiableIndex)?.scheduleIndex(false) + } + + private fun getBigRepositories(data: VcsLogData): List { + return VcsLogPersistentIndex.getRootsForIndexing(data.logProviders).filter { + VcsLogBigRepositoriesList.getInstance().isBig(it) + } + } +} \ No newline at end of file diff --git a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/MainFrame.java b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/MainFrame.java index 40fe8c8dcbbc..0628236f5366 100644 --- a/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/MainFrame.java +++ b/platform/vcs-log/impl/src/com/intellij/vcs/log/ui/frame/MainFrame.java @@ -199,16 +199,16 @@ public class MainFrame extends JPanel implements DataProvider, Disposable { textFilter.setVerticalSizeReferent(toolbar.getComponent()); textFilter.setBorder(JBUI.Borders.emptyLeft(5)); - ActionToolbar goToHashOrRefAction = - createActionsToolbar( - new DefaultActionGroup(ActionManager.getInstance().getAction(VcsLogActionPlaces.VCS_LOG_GO_TO_HASH_OR_REF_ACTION))); - goToHashOrRefAction.setReservePlaceAutoPopupIcon(false); - goToHashOrRefAction.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY); + DefaultActionGroup rightCornerGroup = + new DefaultActionGroup(ActionManager.getInstance().getAction(VcsLogActionPlaces.TOOLBAR_RIGHT_CORNER_ACTION_GROUP)); + ActionToolbar rightCornerToolbar = createActionsToolbar(rightCornerGroup); + rightCornerToolbar.setReservePlaceAutoPopupIcon(false); + rightCornerToolbar.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY); JPanel panel = new JPanel(new MigLayout("ins 0, fill", "[left]0[left, fill]push[right]", "center")); panel.add(textFilter); panel.add(toolbar.getComponent()); - panel.add(goToHashOrRefAction.getComponent()); + panel.add(rightCornerToolbar.getComponent()); return panel; }