mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
action button updater
This commit is contained in:
@@ -18,10 +18,13 @@ package com.intellij.ui;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
@@ -32,6 +35,7 @@ public abstract class AnActionButton extends AnAction implements ShortcutProvide
|
||||
private ShortcutSet myShortcut;
|
||||
private AnAction myAction = null;
|
||||
private JComponent myContextComponent;
|
||||
private Set<AnActionButtonUpdater> myUpdaters;
|
||||
|
||||
public AnActionButton(String text) {
|
||||
super(text);
|
||||
@@ -92,12 +96,20 @@ public abstract class AnActionButton extends AnAction implements ShortcutProvide
|
||||
public final void update(AnActionEvent e) {
|
||||
boolean myActionVisible = true;
|
||||
boolean myActionEnabled = true;
|
||||
if (myAction != null) {
|
||||
if (myAction != null) {
|
||||
myAction.update(e);
|
||||
myActionEnabled = myAction.getTemplatePresentation().isEnabled();
|
||||
myActionVisible = myAction.getTemplatePresentation().isVisible();
|
||||
myActionEnabled = e.getPresentation().isEnabled();
|
||||
myActionVisible = e.getPresentation().isVisible();
|
||||
}
|
||||
boolean enabled = isEnabled() && isContextComponentOk() && myActionEnabled;
|
||||
if (enabled) {
|
||||
for (AnActionButtonUpdater updater : myUpdaters) {
|
||||
if (!updater.isEnabled(e)) {
|
||||
enabled = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
final boolean enabled = isEnabled() && isContextComponentOk() && myActionEnabled;
|
||||
e.getPresentation().setEnabled(enabled);
|
||||
e.getPresentation().setVisible(isVisible() && myActionVisible);
|
||||
|
||||
@@ -105,6 +117,13 @@ public abstract class AnActionButton extends AnAction implements ShortcutProvide
|
||||
updateButton(e);
|
||||
}
|
||||
}
|
||||
|
||||
public final void addCustomUpdater(@NotNull AnActionButtonUpdater updater) {
|
||||
if (myUpdaters == null) {
|
||||
myUpdaters = new HashSet<AnActionButtonUpdater>();
|
||||
}
|
||||
myUpdaters.add(updater);
|
||||
}
|
||||
|
||||
public void updateButton(AnActionEvent e) {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ui;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public interface AnActionButtonUpdater {
|
||||
boolean isEnabled(AnActionEvent e);
|
||||
}
|
||||
Reference in New Issue
Block a user