[vcs-log] add a resume indexing button to the log toolbar

GitOrigin-RevId: d3215c9b91929fbbd2bca100973cc59ffb5680b1
This commit is contained in:
Julia Beliaeva
2019-05-27 04:06:29 +03:00
committed by intellij-monorepo-bot
parent f7fa6cf609
commit 134445c78d
6 changed files with 93 additions and 24 deletions
@@ -123,6 +123,8 @@
<action class="com.intellij.vcs.log.ui.actions.CompareRevisionsFromLogAction" id="Vcs.Log.CompareRevisions"
text="Compare Versions" description="Compare selected versions"
icon="AllIcons.Actions.Diff"/>
<action class="com.intellij.vcs.log.ui.actions.ResumeIndexingAction" id="Vcs.Log.ResumeIndexing" icon="AllIcons.Process.ProgressResumeSmall"
text="Resume Indexing" description="Indexing was paused as it took longer than expected. Resume."/>
<group id="Vcs.Log.PresentationSettings" class="com.intellij.vcs.log.ui.actions.VcsLogToolbarPopupActionGroup"
icon="AllIcons.Actions.Show" text="Presentation Settings" description="Presentation Settings" popup="true">
@@ -160,6 +162,10 @@
<reference id="Vcs.Log.GoToParent"/>
<separator/>
</group>
<group id="Vcs.Log.Toolbar.RightCorner">
<reference id="Vcs.Log.ResumeIndexing"/>
<reference id="Vcs.Log.GoToRef"/>
</group>
<group id="Vcs.Log.LayoutConfiguration" class="com.intellij.vcs.log.ui.actions.VcsLogToolbarPopupActionGroup"
icon="AllIcons.Debugger.RestoreLayout" text="Configure Layout" description="Configure Layout" popup="true">
<reference id="Vcs.Log.ShowDetailsAction"/>
@@ -42,9 +42,9 @@ public class VcsLogBigRepositoriesList implements PersistentStateComponent<VcsLo
}
}
public void removeRepository(@NotNull VirtualFile root) {
public boolean removeRepository(@NotNull VirtualFile root) {
synchronized (myLock) {
myState.REPOSITORIES.remove(root.getPath());
return myState.REPOSITORIES.remove(root.getPath());
}
}
@@ -98,16 +98,8 @@ public class VcsLogPersistentIndex implements VcsLogModifiableIndex, Disposable
myBigRepositoriesList = VcsLogBigRepositoriesList.getInstance();
myIndexCollector = VcsLogIndexCollector.getInstance(myProject);
myIndexers = new HashMap<>();
myRoots = new LinkedHashSet<>();
for (Map.Entry<VirtualFile, VcsLogProvider> 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<VirtualFile, VcsLogIndexer> getAvailableIndexers(@NotNull Map<VirtualFile, VcsLogProvider> providers) {
Map<VirtualFile, VcsLogIndexer> indexers = new LinkedHashMap<>();
for (Map.Entry<VirtualFile, VcsLogProvider> 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<VirtualFile> getRootsForIndexing(@NotNull Map<VirtualFile, VcsLogProvider> 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?",
@@ -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";
}
@@ -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<VirtualFile>): 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<VirtualFile> {
return VcsLogPersistentIndex.getRootsForIndexing(data.logProviders).filter {
VcsLogBigRepositoriesList.getInstance().isBig(it)
}
}
}
@@ -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;
}