Search in sources :

Example 1 with EditorFactoryEvent

use of com.intellij.openapi.editor.event.EditorFactoryEvent in project ideavim by JetBrains.

the class VimPlugin method setupStatisticsReporter.

/**
   * Reports statistics about installed IdeaVim and enabled Vim emulation.
   *
   * See https://github.com/go-lang-plugin-org/go-lang-idea-plugin/commit/5182ab4a1d01ad37f6786268a2fe5e908575a217
   */
private void setupStatisticsReporter(@NotNull EventFacade eventFacade) {
    final Application application = ApplicationManager.getApplication();
    eventFacade.addEditorFactoryListener(new EditorFactoryAdapter() {

        @Override
        public void editorCreated(@NotNull EditorFactoryEvent event) {
            final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
            final long lastUpdate = propertiesComponent.getOrInitLong(IDEAVIM_STATISTICS_TIMESTAMP_KEY, 0);
            final boolean outOfDate = lastUpdate == 0 || System.currentTimeMillis() - lastUpdate > TimeUnit.DAYS.toMillis(1);
            if (outOfDate && isEnabled()) {
                application.executeOnPooledThread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            final String buildNumber = ApplicationInfo.getInstance().getBuild().asString();
                            final String pluginId = IDEAVIM_PLUGIN_ID;
                            final String version = URLEncoder.encode(getVersion(), CharsetToolkit.UTF8);
                            final String os = URLEncoder.encode(SystemInfo.OS_NAME + " " + SystemInfo.OS_VERSION, CharsetToolkit.UTF8);
                            final String uid = UpdateChecker.getInstallationUID(PropertiesComponent.getInstance());
                            final String url = "https://plugins.jetbrains.com/plugins/list" + "?pluginId=" + pluginId + "&build=" + buildNumber + "&pluginVersion=" + version + "&os=" + os + "&uuid=" + uid;
                            PropertiesComponent.getInstance().setValue(IDEAVIM_STATISTICS_TIMESTAMP_KEY, String.valueOf(System.currentTimeMillis()));
                            HttpRequests.request(url).connect(new HttpRequests.RequestProcessor<Object>() {

                                @Override
                                public Object process(@NotNull HttpRequests.Request request) throws IOException {
                                    LOG.info("Sending statistics: " + url);
                                    try {
                                        JDOMUtil.load(request.getInputStream());
                                    } catch (JDOMException e) {
                                        LOG.warn(e);
                                    }
                                    return null;
                                }
                            });
                        } catch (IOException e) {
                            LOG.warn(e);
                        }
                    }
                });
            }
        }
    }, application);
}
Also used : EditorFactoryAdapter(com.intellij.openapi.editor.event.EditorFactoryAdapter) EditorFactoryEvent(com.intellij.openapi.editor.event.EditorFactoryEvent) IOException(java.io.IOException) JDOMException(org.jdom.JDOMException) HttpRequests(com.intellij.util.io.HttpRequests) Application(com.intellij.openapi.application.Application) PropertiesComponent(com.intellij.ide.util.PropertiesComponent)

Example 2 with EditorFactoryEvent

use of com.intellij.openapi.editor.event.EditorFactoryEvent in project intellij-community by JetBrains.

the class EditorFactoryImpl method createEditor.

private Editor createEditor(@NotNull Document document, boolean isViewer, Project project) {
    Document hostDocument = document instanceof DocumentWindow ? ((DocumentWindow) document).getDelegate() : document;
    EditorImpl editor = new EditorImpl(hostDocument, isViewer, project);
    myEditors.add(editor);
    myEditorEventMulticaster.registerEditor(editor);
    myEditorFactoryEventDispatcher.getMulticaster().editorCreated(new EditorFactoryEvent(this, editor));
    if (LOG.isDebugEnabled()) {
        LOG.debug("number of Editors after create: " + myEditors.size());
    }
    return editor;
}
Also used : DocumentWindow(com.intellij.injected.editor.DocumentWindow) EditorFactoryEvent(com.intellij.openapi.editor.event.EditorFactoryEvent) Document(com.intellij.openapi.editor.Document)

Example 3 with EditorFactoryEvent

use of com.intellij.openapi.editor.event.EditorFactoryEvent in project intellij-community by JetBrains.

the class EditorUtil method disposeWithEditor.

public static void disposeWithEditor(@NotNull Editor editor, @NotNull Disposable disposable) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (Disposer.isDisposed(disposable))
        return;
    if (editor.isDisposed()) {
        Disposer.dispose(disposable);
        return;
    }
    // for injected editors disposal will happen only when host editor is disposed,
    // but this seems to be the best we can do (there are no notifications on disposal of injected editor)
    Editor hostEditor = editor instanceof EditorWindow ? ((EditorWindow) editor).getDelegate() : editor;
    EditorFactory.getInstance().addEditorFactoryListener(new EditorFactoryAdapter() {

        @Override
        public void editorReleased(@NotNull EditorFactoryEvent event) {
            if (event.getEditor() == hostEditor) {
                Disposer.dispose(disposable);
            }
        }
    }, disposable);
}
Also used : EditorFactoryAdapter(com.intellij.openapi.editor.event.EditorFactoryAdapter) EditorFactoryEvent(com.intellij.openapi.editor.event.EditorFactoryEvent) TextEditor(com.intellij.openapi.fileEditor.TextEditor) TextComponentEditor(com.intellij.openapi.editor.textarea.TextComponentEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) EditorWindow(com.intellij.injected.editor.EditorWindow)

Aggregations

EditorFactoryEvent (com.intellij.openapi.editor.event.EditorFactoryEvent)3 EditorFactoryAdapter (com.intellij.openapi.editor.event.EditorFactoryAdapter)2 PropertiesComponent (com.intellij.ide.util.PropertiesComponent)1 DocumentWindow (com.intellij.injected.editor.DocumentWindow)1 EditorWindow (com.intellij.injected.editor.EditorWindow)1 Application (com.intellij.openapi.application.Application)1 Document (com.intellij.openapi.editor.Document)1 TextComponentEditor (com.intellij.openapi.editor.textarea.TextComponentEditor)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 TextEditor (com.intellij.openapi.fileEditor.TextEditor)1 HttpRequests (com.intellij.util.io.HttpRequests)1 IOException (java.io.IOException)1 JDOMException (org.jdom.JDOMException)1