Search in sources :

Example 1 with CachesInvalidator

use of com.intellij.ide.caches.CachesInvalidator in project intellij-community by JetBrains.

the class InvalidateCachesAction method actionPerformed.

public void actionPerformed(@NotNull AnActionEvent e) {
    final ApplicationEx app = (ApplicationEx) ApplicationManager.getApplication();
    final boolean mac = Messages.canShowMacSheetPanel();
    boolean canRestart = app.isRestartCapable();
    String[] options = new String[canRestart ? 4 : 3];
    options[0] = canRestart ? "Invalidate and &Restart" : "Invalidate and &Exit";
    options[1] = mac ? "Cancel" : "&Invalidate";
    options[2] = mac ? "&Invalidate" : "Cancel";
    if (canRestart) {
        options[3] = "&Just Restart";
    }
    List<String> descriptions = new SmartList<>();
    descriptions.add("Local History");
    for (CachesInvalidator invalidater : CachesInvalidator.EP_NAME.getExtensions()) {
        ContainerUtil.addIfNotNull(descriptions, invalidater.getDescription());
    }
    Collections.sort(descriptions);
    String warnings = "WARNING: ";
    if (descriptions.size() == 1) {
        warnings += descriptions.get(0) + " will be also cleared.";
    } else {
        warnings += "The following items will also be cleared:\n" + StringUtil.join(descriptions, s -> "  " + s, "\n");
    }
    String message = "The caches will be invalidated and rebuilt on the next startup.\n\n" + warnings + "\n\n" + "Would you like to continue?\n";
    int result = Messages.showDialog(e.getData(CommonDataKeys.PROJECT), message, "Invalidate Caches", options, 0, Messages.getWarningIcon());
    if (result == -1 || result == (mac ? 1 : 2)) {
        return;
    }
    if (result == 3) {
        app.restart(true);
        return;
    }
    UsageTrigger.trigger(ApplicationManagerEx.getApplicationEx().getName() + ".caches.invalidated");
    FSRecords.invalidateCaches();
    for (CachesInvalidator invalidater : CachesInvalidator.EP_NAME.getExtensions()) {
        invalidater.invalidateCaches();
    }
    if (result == 0)
        app.restart(true);
}
Also used : CachesInvalidator(com.intellij.ide.caches.CachesInvalidator) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) SmartList(com.intellij.util.SmartList)

Aggregations

CachesInvalidator (com.intellij.ide.caches.CachesInvalidator)1 ApplicationEx (com.intellij.openapi.application.ex.ApplicationEx)1 SmartList (com.intellij.util.SmartList)1