Java Code Examples for com.intellij.openapi.fileEditor.FileEditorManagerEvent

The following examples show how to use com.intellij.openapi.fileEditor.FileEditorManagerEvent. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: reasonml-idea-plugin   Source File: ORFileEditorListener.java    License: MIT License 6 votes vote down vote up
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
    VirtualFile newFile = event.getNewFile();
    if (newFile != null) {
        FileType fileType = newFile.getFileType();
        if (FileHelper.isReason(fileType) || FileHelper.isOCaml(fileType)) {
            // On tab change, we redo the background compilation
            Document document = FileDocumentManager.getInstance().getDocument(newFile);
            InsightUpdateQueue insightUpdateQueue = document == null ? null : document.getUserData(INSIGHT_QUEUE);
            if (insightUpdateQueue != null) {
                insightUpdateQueue.queue(m_project, document);
            }
            // and refresh inferred types
            InferredTypesService.queryForSelectedTextEditor(m_project);
        }
    }
}
 
Example 2
Source Project: editorconfig-jetbrains   Source File: LineEndingsManager.java    License: MIT License 6 votes vote down vote up
private void updateStatusBar() {
    ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
            IdeFrame frame = WindowManager.getInstance().getIdeFrame(project);
            StatusBar statusBar = frame.getStatusBar();
            StatusBarWidget widget = statusBar != null ? statusBar.getWidget("LineSeparator") : null;

            if (widget instanceof LineSeparatorPanel) {
                FileEditorManagerEvent event = new FileEditorManagerEvent(FileEditorManager.getInstance(project),
                                                                          null, null, null, null);
                ((LineSeparatorPanel)widget).selectionChanged(event);
            }
        }
    });
}
 
Example 3
Source Project: consulo   Source File: AutoScrollFromSourceHandler.java    License: Apache License 2.0 6 votes vote down vote up
public void install() {
  final MessageBusConnection connection = myProject.getMessageBus().connect(myProject);
  connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() {
    @Override
    public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
      final FileEditor editor = event.getNewEditor();
      if (editor != null && myComponent.isShowing() && isAutoScrollEnabled()) {
        myAlarm.cancelAllRequests();
        myAlarm.addRequest(new Runnable() {
          @Override
          public void run() {
            selectElementFromEditor(editor);
          }
        }, getAlarmDelay(), getModalityState());
      }
    }
  });
}
 
Example 4
Source Project: consulo   Source File: ToggleReadOnlyAttributePanel.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void install(@Nonnull StatusBar statusBar) {
  myStatusBar = statusBar;
  Project project = statusBar.getProject();
  if (project == null) {
    return;
  }

  project.getMessageBus().connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
    @Override
    public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
      if (myStatusBar != null) {
        myStatusBar.updateWidget(ID());
      }
    }
  });
}
 
Example 5
Source Project: consulo   Source File: EditorTracker.java    License: Apache License 2.0 6 votes vote down vote up
@Inject
public EditorTracker(@Nonnull Project project, @Nonnull Provider<WindowManager> windowManagerProvider) {
  myProject = project;

  project.getMessageBus().connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
    @Override
    public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
      JFrame frame = windowManagerProvider.get().getFrame(myProject);
      if (frame == null || frame.getFocusOwner() == null) {
        return;
      }

      setActiveWindow(TargetAWT.from(frame));
    }
  });
}
 
Example 6
Source Project: consulo   Source File: StatusBarUpdater.java    License: Apache License 2.0 6 votes vote down vote up
public StatusBarUpdater(Project project) {
  myProject = project;

  project.getMessageBus().connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerAdapter() {
    @Override
    public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
      updateLater();
    }
  });

  project.getMessageBus().connect(this).subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, new DaemonCodeAnalyzer.DaemonListenerAdapter() {
    @Override
    public void daemonFinished() {
      updateLater();
    }
  });
}
 
Example 7
Source Project: consulo   Source File: CurrentFileTodosPanel.java    License: Apache License 2.0 6 votes vote down vote up
CurrentFileTodosPanel(Project project, TodoPanelSettings settings, Content content) {
  super(project, settings, true, content);

  VirtualFile[] files = FileEditorManager.getInstance(project).getSelectedFiles();
  setFile(files.length == 0 ? null : PsiManager.getInstance(myProject).findFile(files[0]), true);
  // It's important to remove this listener. It prevents invocation of setFile method after the tree builder is disposed
  project.getMessageBus().connect(this).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
    @Override
    public void selectionChanged(@Nonnull FileEditorManagerEvent e) {
      VirtualFile file = e.getNewFile();
      final PsiFile psiFile = file != null && file.isValid() ? PsiManager.getInstance(myProject).findFile(file) : null;
      // This invokeLater is required. The problem is setFile does a commit to PSI, but setFile is
      // invoked inside PSI change event. It causes an Exception like "Changes to PSI are not allowed inside event processing"
      DumbService.getInstance(myProject).smartInvokeLater(() -> setFile(psiFile, false));
    }
  });
}
 
Example 8
public WidgetPerfTipsPanel(Disposable parentDisposable, @NotNull FlutterApp app) {
  setLayout(new VerticalLayout(5));

  add(new JSeparator());

  perfManager = FlutterWidgetPerfManager.getInstance(app.getProject());
  perfTips = new JPanel();
  perfTips.setLayout(new VerticalLayout(0));

  linkListener = (source, tip) -> handleTipSelection(tip);
  final Project project = app.getProject();
  final MessageBusConnection bus = project.getMessageBus().connect(project);
  final FileEditorManagerListener listener = new FileEditorManagerListener() {
    @Override
    public void selectionChanged(@NotNull FileEditorManagerEvent event) {
      selectedEditorChanged();
    }
  };
  selectedEditorChanged();
  bus.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener);

  // Computing performance tips is somewhat expensive so we don't want to
  // compute them too frequently. Performance tips are only computed when
  // new performance stats are available but performance stats are updated
  // at 60fps so to be conservative we delay computing perf tips.
  final Timer perfTipComputeDelayTimer = new Timer(PERF_TIP_COMPUTE_DELAY, this::onComputePerfTips);
  perfTipComputeDelayTimer.start();
  Disposer.register(parentDisposable, perfTipComputeDelayTimer::stop);
}
 
Example 9
public WidgetPerfTipsPanel(Disposable parentDisposable, @NotNull FlutterApp app) {
  setLayout(new VerticalLayout(5));

  add(new JSeparator());

  perfManager = FlutterWidgetPerfManager.getInstance(app.getProject());
  perfTips = new JPanel();
  perfTips.setLayout(new VerticalLayout(0));

  linkListener = (source, tip) -> handleTipSelection(tip);
  final Project project = app.getProject();
  final MessageBusConnection bus = project.getMessageBus().connect(project);
  final FileEditorManagerListener listener = new FileEditorManagerListener() {
    @Override
    public void selectionChanged(@NotNull FileEditorManagerEvent event) {
      selectedEditorChanged();
    }
  };
  selectedEditorChanged();
  bus.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, listener);

  // Computing performance tips is somewhat expensive so we don't want to
  // compute them too frequently. Performance tips are only computed when
  // new performance stats are available but performance stats are updated
  // at 60fps so to be conservative we delay computing perf tips.
  final Timer perfTipComputeDelayTimer = new Timer(PERF_TIP_COMPUTE_DELAY, this::onComputePerfTips);
  perfTipComputeDelayTimer.start();
  Disposer.register(parentDisposable, perfTipComputeDelayTimer::stop);
}
 
Example 10
Source Project: GitToolBox   Source File: GitStatusWidget.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
  VirtualFile file = event.getNewFile();
  if (file != null) {
    runUpdate(myProject, file);
  } else {
    runUpdate(myProject);
  }
}
 
Example 11
Source Project: GitToolBox   Source File: BlameStatusWidget.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
  VirtualFile newFile = event.getNewFile();
  if (newFile != null) {
    log.debug("Selection changed: ", newFile);
    updateBlame(newFile);
  }
}
 
Example 12
Source Project: buck   Source File: BuildifierAutoFormatter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void initComponent() {
  mMessageBusConnection = ApplicationManager.getApplication().getMessageBus().connect(this);
  mMessageBusConnection.subscribe(
      FileEditorManagerListener.FILE_EDITOR_MANAGER,
      new FileEditorManagerListener() {
        @Override
        public void selectionChanged(@NotNull FileEditorManagerEvent event) {
          Project project = event.getManager().getProject();
          if (!BuckProjectSettingsProvider.getInstance(project).isAutoFormatOnBlur()) {
            return;
          }
          FileEditor newFileEditor = event.getNewEditor();
          FileEditor oldFileEditor = event.getOldEditor();
          if (oldFileEditor == null || oldFileEditor.equals(newFileEditor)) {
            return; // still editing same file
          }
          VirtualFile virtualFile = oldFileEditor.getFile();
          Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
          if (document == null) {
            return; // couldn't find document
          }
          PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
          if (!BuckFileType.INSTANCE.equals(psiFile.getFileType())) {
            return; // file type isn't a Buck file
          }
          Runnable runnable = () -> BuildifierUtil.doReformat(project, virtualFile);
          LOGGER.info("Autoformatting " + virtualFile.getPath());
          CommandProcessor.getInstance()
              .executeCommand(
                  project,
                  runnable,
                  null,
                  null,
                  UndoConfirmationPolicy.DO_NOT_REQUEST_CONFIRMATION,
                  document);
        }
      });
}
 
Example 13
Source Project: consulo   Source File: DesktopEditorComposite.java    License: Apache License 2.0 5 votes vote down vote up
private void fireSelectedEditorChanged(final FileEditor oldSelectedEditor, final FileEditor newSelectedEditor) {
  if ((!EventQueue.isDispatchThread() || !myFileEditorManager.isInsideChange()) && !Comparing.equal(oldSelectedEditor, newSelectedEditor)) {
    myFileEditorManager.notifyPublisher(() -> {
      final FileEditorManagerEvent event = new FileEditorManagerEvent(myFileEditorManager, myFile, oldSelectedEditor, myFile, newSelectedEditor);
      final FileEditorManagerListener publisher = myFileEditorManager.getProject().getMessageBus().syncPublisher(FileEditorManagerListener.FILE_EDITOR_MANAGER);
      publisher.selectionChanged(event);
    });
    final JComponent component = newSelectedEditor.getComponent();
    final EditorWindowHolder holder = UIUtil.getParentOfType(EditorWindowHolder.class, component);
    if (holder != null) {
      ((FileEditorManagerImpl)myFileEditorManager).addSelectionRecord(myFile, holder.getEditorWindow());
    }
  }
}
 
Example 14
Source Project: consulo   Source File: AnnotationsPreloader.java    License: Apache License 2.0 5 votes vote down vote up
public AnnotationsPreloader(final Project project) {
  myProject = project;
  myUpdateQueue = new MergingUpdateQueue("Annotations preloader queue", 1000, true, null, project, null, false);

  project.getMessageBus().connect(project).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
    @Override
    public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
      if (!isEnabled()) return;
      VirtualFile file = event.getNewFile();
      if (file != null) {
        schedulePreloading(file);
      }
    }
  });
}
 
Example 15
Source Project: gtm-jetbrains-plugin   Source File: GTMStatusWidget.java    License: MIT License 4 votes vote down vote up
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
    runUpdate();
}
 
Example 16
Source Project: intellij   Source File: AutoSyncHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(FileEditorManagerEvent event) {
  processEvent(event.getOldFile());
}
 
Example 17
Source Project: idea-php-symfony2-plugin   Source File: SymfonyProfilerWidget.java    License: MIT License 4 votes vote down vote up
@Override
public void selectionChanged(@NotNull FileEditorManagerEvent event) {
    update(event.getManager().getProject());
}
 
Example 18
Source Project: SVNToolBox   Source File: SvnBranchWidget.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(FileEditorManagerEvent event) {
    runUpdate();
}
 
Example 19
Source Project: consulo   Source File: HintManagerImpl.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
  hideHints(0, false, true);
}
 
Example 20
Source Project: consulo   Source File: ColumnSelectionModePanel.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
  updateStatus();
}
 
Example 21
Source Project: consulo   Source File: PositionPanel.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
  updatePosition(getEditor());
}
 
Example 22
Source Project: consulo   Source File: DesktopEditorComposite.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @param file    {@code file} for which composite is being constructed
 * @param editors {@code edittors} that should be placed into the composite
 * @throws IllegalArgumentException if {@code editors}
 *                                  is {@code null} or {@code providers} is {@code null} or {@code myEditor} arrays is empty
 */
DesktopEditorComposite(@Nonnull final VirtualFile file, @Nonnull final FileEditor[] editors, @Nonnull final FileEditorManagerEx fileEditorManager) {
  myFile = file;
  myEditors = editors;
  if (NullUtils.hasNull(editors)) throw new IllegalArgumentException("Must not pass null editors in " + Arrays.asList(editors));
  myFileEditorManager = fileEditorManager;
  myInitialFileTimeStamp = myFile.getTimeStamp();

  Disposer.register(fileEditorManager.getProject(), this);

  if (editors.length > 1) {
    myTabbedPaneWrapper = createTabbedPaneWrapper(editors);
    JComponent component = myTabbedPaneWrapper.getComponent();
    myComponent = new MyComponent(component, component);
  }
  else if (editors.length == 1) {
    myTabbedPaneWrapper = null;
    FileEditor editor = editors[0];
    myComponent = new MyComponent(createEditorComponent(editor), editor.getPreferredFocusedComponent());
  }
  else {
    throw new IllegalArgumentException("editors array cannot be empty");
  }

  mySelectedEditor = editors[0];
  myFocusWatcher = new FocusWatcher();
  myFocusWatcher.install(myComponent);

  myFileEditorManager.addFileEditorManagerListener(new FileEditorManagerListener() {
    @Override
    public void selectionChanged(@Nonnull final FileEditorManagerEvent event) {
      final VirtualFile oldFile = event.getOldFile();
      final VirtualFile newFile = event.getNewFile();
      if (Comparing.equal(oldFile, newFile) && Comparing.equal(getFile(), newFile)) {
        Runnable runnable = () -> {
          final FileEditor oldEditor = event.getOldEditor();
          if (oldEditor != null) oldEditor.deselectNotify();
          final FileEditor newEditor = event.getNewEditor();
          if (newEditor != null) newEditor.selectNotify();
          ((FileEditorProviderManagerImpl)FileEditorProviderManager.getInstance()).providerSelected(DesktopEditorComposite.this);
          ((IdeDocumentHistoryImpl)IdeDocumentHistory.getInstance(myFileEditorManager.getProject())).onSelectionChanged();
        };
        if (ApplicationManager.getApplication().isDispatchThread()) {
          CommandProcessor.getInstance().executeCommand(myFileEditorManager.getProject(), runnable, "Switch Active Editor", null);
        }
        else {
          runnable.run(); // not invoked by user
        }
      }
    }
  }, this);
}
 
Example 23
Source Project: consulo   Source File: LightToolWindowManager.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
  bindToDesigner(getDesigner(event.getNewEditor()));
}
 
Example 24
Source Project: consulo   Source File: DvcsStatusWidget.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
  LOG.debug("selection changed");
  update();
}
 
Example 25
Source Project: consulo   Source File: CtrlMouseHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
  disposeHighlighter();
  cancelPreviousTooltip();
}
 
Example 26
Source Project: consulo   Source File: TogglePopupHintsPanel.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(@Nonnull FileEditorManagerEvent event) {
  updateStatus();
}
 
Example 27
Source Project: consulo   Source File: NavBarListener.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void selectionChanged(@Nonnull FileEditorManagerEvent event) {}
 
Example 28
/**
 * Calls {@link LocalEditorHandler#activateEditor(VirtualFile)}.
 *
 * <p>Does nothing if the opened editor is not a text editor.
 *
 * @param event the event to react to
 * @see FileEditorManagerListener#selectionChanged(FileEditorManagerEvent)
 */
private void generateEditorActivatedActivity(@NotNull FileEditorManagerEvent event) {
  FileEditor newEditor = event.getNewEditor();

  if (newEditor == null || newEditor instanceof TextEditor) {
    localEditorHandler.activateEditor(event.getNewFile());
  }
}
 
Example 29
@Override
public void selectionChanged(FileEditorManagerEvent event) {

}