use of org.jetbrains.android.uipreview.AndroidEditorSettings in project android by JetBrains.
the class NlPreviewManager method processFileEditorChange.
private void processFileEditorChange(@Nullable final TextEditor newEditor) {
if (myPendingShowComponent != null) {
myPendingShowComponent.removeHierarchyListener(myHierarchyListener);
myPendingShowComponent = null;
}
myToolWindowUpdateQueue.cancelAllUpdates();
myToolWindowUpdateQueue.queue(new Update("update") {
@Override
public void run() {
if (!myToolWindowReady || myToolWindowDisposed) {
return;
}
boolean renderImmediately = myRenderImmediately;
myRenderImmediately = false;
final Editor activeEditor = newEditor != null ? newEditor.getEditor() : null;
if (myToolWindow == null) {
if (activeEditor == null) {
return;
} else if (!activeEditor.getComponent().isShowing()) {
// per project frame.)
if (!mySeenEditor) {
myPendingShowComponent = activeEditor.getComponent();
if (myHierarchyListener == null) {
myHierarchyListener = new HierarchyListener() {
@Override
public void hierarchyChanged(HierarchyEvent hierarchyEvent) {
if ((hierarchyEvent.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0) {
if (hierarchyEvent.getComponent() == myPendingShowComponent && myPendingShowComponent.isShowing()) {
myPendingShowComponent.removeHierarchyListener(myHierarchyListener);
mySeenEditor = true;
myPendingShowComponent = null;
processFileEditorChange(getActiveLayoutXmlEditor());
}
}
}
};
}
myPendingShowComponent.addHierarchyListener(myHierarchyListener);
}
return;
}
mySeenEditor = true;
initToolWindow();
}
final AndroidEditorSettings settings = AndroidEditorSettings.getInstance();
final boolean hideForNonLayoutFiles = settings.getGlobalState().isHideForNonLayoutFiles();
if (activeEditor == null) {
myToolWindowForm.setFile(null);
myToolWindow.setAvailable(!hideForNonLayoutFiles, null);
return;
}
final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(activeEditor.getDocument());
myToolWindowForm.setFile(psiFile);
if (psiFile == null) {
myToolWindow.setAvailable(!hideForNonLayoutFiles, null);
return;
}
myToolWindow.setAvailable(true, null);
final boolean visible = AndroidEditorSettings.getInstance().getGlobalState().isVisible();
if (visible) {
// tool window is shown and the time the render has completed
if (!myToolWindow.isVisible()) {
RenderResult renderResult = myToolWindowForm.getRenderResult();
if (renderResult != null && renderResult.getFile() != psiFile) {
myToolWindowForm.setRenderResult(RenderResult.createBlank(psiFile));
}
}
myToolWindow.show(null);
}
}
});
}
Aggregations