IDEA-228866 Add theme switch delay and restoration of original theme on Escape

GitOrigin-RevId: 4498e1a376c921d0b20785a996c1418a4e7a5608
This commit is contained in:
Kirill Kirichenko
2020-01-14 09:08:13 +00:00
committed by intellij-monorepo-bot
parent 66f0b4a5b2
commit 1893964afa
2 changed files with 24 additions and 5 deletions
@@ -10,11 +10,14 @@ import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.JBPopupListener;
import com.intellij.openapi.ui.popup.LightweightWindowEvent;
import com.intellij.openapi.ui.popup.ListPopup;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.util.Alarm;
import com.intellij.util.ui.StartupUiUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -25,32 +28,46 @@ import javax.swing.*;
* @author max
*/
public class QuickChangeLookAndFeel extends QuickSwitchSchemeAction {
private UIManager.LookAndFeelInfo initialLaf;
private final Alarm switchAlarm = new Alarm();
@Override
protected void fillActions(Project project, @NotNull DefaultActionGroup group, @NotNull DataContext dataContext) {
LafManager lafMan = LafManager.getInstance();
UIManager.LookAndFeelInfo[] lfs = lafMan.getInstalledLookAndFeels();
UIManager.LookAndFeelInfo currentLaf = lafMan.getCurrentLookAndFeel();
initialLaf = lafMan.getCurrentLookAndFeel();
for (UIManager.LookAndFeelInfo lf : lfs) {
group.add(new LafChangeAction(lf, currentLaf == lf));
group.add(new LafChangeAction(lf, initialLaf == lf));
}
}
@Override
protected void showPopup(AnActionEvent e, ListPopup popup) {
switchAlarm.cancelAllRequests();
if (Registry.is("ide.instant.theme.switch")) {
LafManager lafMan = LafManager.getInstance();
popup.addListSelectionListener(event -> {
JList list = (JList)event.getSource();
Object item = list.getSelectedValue();
if (item instanceof AnActionHolder) {
LafChangeAction action = (LafChangeAction)((AnActionHolder)item).getAction();
switchLafAndUpdateUI(lafMan, action.myLookAndFeelInfo, false);
switchAlarm.cancelAllRequests();
switchAlarm.addRequest(() -> {
LafChangeAction action = (LafChangeAction)((AnActionHolder)item).getAction();
switchLafAndUpdateUI(LafManager.getInstance(), action.myLookAndFeelInfo, false);
}, Registry.get("ide.instant.theme.switch.delay").asInteger());
}
});
}
popup.addListener(new JBPopupListener() {
@Override
public void onClosed(@NotNull LightweightWindowEvent event) {
if (Registry.is("ide.instant.theme.switch") && !event.isOk()) {
switchLafAndUpdateUI(LafManager.getInstance(), initialLaf, false);
}
}
});
super.showPopup(e, popup);
}
@@ -1169,6 +1169,8 @@ ide.find.in.file.highlight.usages=false
ide.find.in.file.highlight.usages.description=Delegate FindUsagesInFile action to HighlightUsagesInFile
ide.instant.theme.switch=true
ide.instant.theme.switch.description=Switch theme in the quick switcher instantly, upon selection
ide.instant.theme.switch.delay=500
ide.instant.theme.switch.delay.description=Instant theme switch delay in milliseconds
git.execute.with.mediator=true
git.execute.with.mediator.description=Use wrapper executable on Windows to support soft Git process cancellation.