How to open editor in another window

I have 3 open files, and I drag 1 file (using the editor tab) to another screen display. It now lives in its own window.

Screen Shot 2015-06-19 at 12.30.42.png

My plugin navigates open files, but when I want to navigate to this other file, its window does not receive focus.
So my question is, how do I achieve this?

Currently I have this code:

final VirtualFile file = getListManager().getSelectedFile();
if (file != null && file
.isValid()) {
   //new OpenFileDescriptor(mProject, file, 1, 0).navigateInEditor(mProject, false);
   
FileEditorManager.getInstance(mProject).openFile(file, true, true);
}


So, how to also give the proper window focus, when I open a file editor?

3 comments
Comment actions Permalink

If you're passing true to focusEditor and the editor window isn't focused, then it's a bug. I don't think there's much that you can do as a plugin developer, other than sending us a pull request with a fix.

0
Comment actions Permalink

I've looked at (and copied) code for the original Switcher.java in the method navigate(boolean).

My current code looks like this:

getInstance(mProject).doWhenFocusSettlesDown(new Runnable() {
      @Override
      public void run()
{
         final FileEditorManagerImpl editorManager = (FileEditorManagerImpl) FileEditorManager
               .getInstance(mProject);
         final
VirtualFile file = getListManager().getSelectedFile();
         if (file != null && file
.isValid()) {

            // figure out the window
            FileInfo pair = new FileInfo(null, null, mProject);
            for (Pair<
VirtualFile, EditorWindow> looppair : editorManager.getSelectionHistory()) {
               if (looppair.first.equals(file)) {
                  pair.first = looppair.first;
                  pair
.second = looppair.second;
                  EditorWindow window = findAppropriateWindow(pair); // copied from Switcher.java
                  if (window != null)
{
                     editorManager.addSelectionRecord(file, window);
                     editorManager
.openFileImpl2(window, file, true);
                     break;
                  
}
               }
            }
         }
      }
   });
}




It works.. sometimes...

Should I take this to youtrack then?

0
Comment actions Permalink

It seems to work, now that I close the popup window before I call the.

doWhenFocusSettlesDown()



So that's good :)

0

Please sign in to leave a comment.