use of com.intellij.openapi.editor.event.EditorFactoryAdapter 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.EditorFactoryAdapter 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