How can I tell if a Document relates to the build window or the Console?

Suppose I'm given a Document interface or DocumentImpl class. I can test whether it relates to a physical file or not by checking document's file with FileDocumentManager -- if it's null, it's not a physical document.

However, if file is null, this could relate to a document for either the event log (build events etc.) or the console output when the program is executed (or something else?).

My question: how can I programmatically tell which tool window this Document(Impl) relates to?

3 comments

You can try to get editors for that document using EditorFactory.getEditors method. If editor is currently visible you can probably check the ancestor of editor.getContentComponent(). editor.getEditorKind() might also provide some information.

0

Sadly editorKind returns "CONSOLE" for both the build window as well as the output console.

I also tried getting contentComponent, but I don't know how to differentiate! For example, but console and build window have editable=true (since when is build window editable?).

So given this, how can I differentiate between console and build window? My current implementation is a bit of a hack:

if (file == null)
{
  val editors = EditorFactory.getInstance().getEditors(document)
  for (i in editors.indices)
  {
    val kind = editors[i].editorKind
    if (kind.name != "CONSOLE")
      return null
    else {
      val component = editors[i].contentComponent
      var p = component.parent;
      while (p != null)
      {
        if (p.toString().contains("EventLog"))
          return null
        p = p.parent
      }
    }
  }
}

 

0

Checking whether ToolWindowManager.getToolWindow(id).getComponent() is an ancestor of editor.getContentComponent() might work (not sure about the case, when tool window is hidden though).

0

Please sign in to leave a comment.