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);
}
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;
}
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);
}
Aggregations