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
private ShortcutSet myShortcut;
private AnAction myAction = null;
private JComponent myContextComponent;
+ private Set<AnActionButtonUpdater> myUpdaters;
public AnActionButton(String text) {
super(text);
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);
updateButton(e);
}
}
+
+ public final void addCustomUpdater(@NotNull AnActionButtonUpdater updater) {
+ if (myUpdaters == null) {
+ myUpdaters = new HashSet<AnActionButtonUpdater>();
+ }
+ myUpdaters.add(updater);
+ }
public void updateButton(AnActionEvent e) {
}
--- /dev/null
+/*
+ * 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);
+}