navbar update fix - 2

This commit is contained in:
Kirill Kalishev
2010-11-24 20:37:16 +03:00
parent 676dec984e
commit 20357257e8
2 changed files with 79 additions and 50 deletions
@@ -47,6 +47,7 @@ import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.PopupStep;
import com.intellij.openapi.ui.popup.util.BaseListPopupStep;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.vcs.FileStatus;
import com.intellij.openapi.vcs.FileStatusListener;
import com.intellij.openapi.vcs.FileStatusManager;
@@ -79,6 +80,8 @@ import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.Set;
@@ -115,13 +118,68 @@ public class NavBarPanel extends OpaquePanel.List implements DataProvider, Popup
private AtomicBoolean myModelUpdating = new AtomicBoolean(Boolean.FALSE);
private MyItemLabel myContextObject;
private PropertyChangeListener myFocusListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if ("focusOwner".equals(evt.getPropertyName()) || "permanentFocusOwner".equals(evt.getPropertyName())) {
myFocusChangedAlarm.cancelAllRequests();
myFocusChangedAlarm.addRequest(myFocusChangedRunnable, 250);
}
}
};
private Alarm myFocusChangedAlarm = new Alarm();
private Runnable myFocusChangedRunnable = new Runnable() {
@Override
public void run() {
processFocusChanged();
}
};
private void processFocusChanged() {
if (!isShowing()) {
return;
}
IdeFocusManager.getInstance(myProject).doWhenFocusSettlesDown(new Runnable() {
@Override
public void run() {
Window wnd = SwingUtilities.windowForComponent(NavBarPanel.this);
if (wnd == null) return;
Component focus = null;
if (!wnd.isActive()) {
IdeFrame frame = UIUtil.getParentOfType(IdeFrame.class, NavBarPanel.this);
if (frame != null) {
focus = IdeFocusManager.getInstance(myProject).getLastFocusedFor(frame);
}
} else {
final Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
if (window instanceof Dialog) {
final Dialog dialog = (Dialog)window;
if (dialog.isModal() && !SwingUtilities.isDescendingFrom(NavBarPanel.this, dialog)) {
return;
}
}
}
if (focus != null && focus.isShowing()) {
queueModelUpdate(DataManager.getInstance().getDataContext(focus));
} else if (wnd.isActive()) {
queueModelUpdateFromFocus();
}
}
});
}
public NavBarPanel(final Project project) {
super(new FlowLayout(FlowLayout.LEFT, 5, 0), UIUtil.isUnderGTKLookAndFeel() ? Color.WHITE : UIUtil.getListBackground());
myProject = project;
myModel = new NavBarModel(myProject);
myUpdateQueue = new MergingUpdateQueue("NavBar", 150, true, MergingUpdateQueue.ANY_COMPONENT, project, null);
myUpdateQueue = new MergingUpdateQueue("NavBar", Registry.intValue("navbar.updateMergeTime"), true, MergingUpdateQueue.ANY_COMPONENT, project, null);
PopupHandler.installPopupHandler(this, IdeActions.GROUP_PROJECT_VIEW_POPUP, ActionPlaces.NAVIGATION_BAR);
@@ -446,6 +504,17 @@ public class NavBarPanel extends OpaquePanel.List implements DataProvider, Popup
if (eachLabel.getObject() == null || !eachLabel.getObject().equals(eachElement)) {
return true;
}
SimpleTextAttributes modelAttributes1 = myModel.getTextAttributes(eachElement, true);
SimpleTextAttributes modelAttributes2 = myModel.getTextAttributes(eachElement, false);
SimpleTextAttributes labelAttributes = eachLabel.getAttributes();
if (!modelAttributes1.toTextAttributes().equals(labelAttributes.toTextAttributes())
&& !modelAttributes2.toTextAttributes().equals(labelAttributes.toTextAttributes())) {
return true;
}
index++;
}
@@ -896,15 +965,14 @@ public class NavBarPanel extends OpaquePanel.List implements DataProvider, Popup
final MyPsiTreeChangeAdapter psiListener = new MyPsiTreeChangeAdapter();
final MyProblemListener problemListener = new MyProblemListener();
final MyFileStatusListener fileStatusListener = new MyFileStatusListener();
final MyTimerListener timerListener = new MyTimerListener();
PsiManager.getInstance(myProject).addPsiTreeChangeListener(psiListener);
WolfTheProblemSolver.getInstance(myProject).addProblemListener(problemListener);
FileStatusManager.getInstance(myProject).addFileStatusListener(fileStatusListener);
final ActionManagerEx actionManager = ActionManagerEx.getInstanceEx();
actionManager.addTimerListener(10000, timerListener);
KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(myFocusListener);
final MessageBusConnection busConnection = myProject.getMessageBus().connect();
busConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new MyModuleRootListener());
@@ -924,7 +992,6 @@ public class NavBarPanel extends OpaquePanel.List implements DataProvider, Popup
myDetacher = new Runnable() {
public void run() {
ActionManagerEx.getInstanceEx().removeTimerListener(timerListener);
busConnection.disconnect();
WolfTheProblemSolver.getInstance(myProject).removeProblemListener(problemListener);
@@ -935,6 +1002,7 @@ public class NavBarPanel extends OpaquePanel.List implements DataProvider, Popup
}
public void uninstallListeners() {
KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener(myFocusListener);
myDetacher.run();
myDetacher = null;
}
@@ -1132,6 +1200,10 @@ public class NavBarPanel extends OpaquePanel.List implements DataProvider, Popup
return myObject;
}
public SimpleTextAttributes getAttributes() {
return myAttributes;
}
private void update() {
clear();
@@ -1161,50 +1233,6 @@ public class NavBarPanel extends OpaquePanel.List implements DataProvider, Popup
}
}
private final class MyTimerListener implements TimerListener {
public ModalityState getModalityState() {
return ModalityState.stateForComponent(NavBarPanel.this);
}
git a
public void run() {
if (!isShowing()) {
return;
}
IdeFocusManager.getInstance(myProject).doWhenFocusSettlesDown(new Runnable() {
@Override
public void run() {
Window wnd = SwingUtilities.windowForComponent(NavBarPanel.this);
if (wnd == null) return;
Component focus = null;
if (!wnd.isActive()) {
IdeFrame frame = UIUtil.getParentOfType(IdeFrame.class, NavBarPanel.this);
if (frame != null) {
focus = IdeFocusManager.getInstance(myProject).getLastFocusedFor(frame);
}
} else {
final Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
if (window instanceof Dialog) {
final Dialog dialog = (Dialog)window;
if (dialog.isModal() && !SwingUtilities.isDescendingFrom(NavBarPanel.this, dialog)) {
return;
}
}
}
if (focus != null && focus.isShowing()) {
queueModelUpdate(DataManager.getInstance().getDataContext(focus));
} else if (wnd.isActive()) {
queueModelUpdateFromFocus();
}
}
});
}
}
private final class MyIdeView implements IdeView {
public void selectElement(PsiElement element) {
@@ -106,4 +106,5 @@ jar.build=false
keymap.show.alias.actions=false
frameworks.download.libraries.server.url=http://pluginsrepo-test:8080
caches.indexerThreadsCount=-1
vcs.show.history.numbers=true
vcs.show.history.numbers=true
navbar.updateMergeTime=250