Interacting / sharing data between components

First of all, thank you to everyone here, you have all been very welcoming and kind in answering my questions.

Goal: is to have a button that executes a command on an open Python editor window, this will capture the contents of that editor (or filepath) and will run it in a shell, take the output and show it in a different component of the UI (my extension). And vice-versa, from my extension component, I’d like to get the filepath and contents of the current open (and on focus) editor window.

Could someone please point me in the right direction for discovering how to interact between components like this. Thank you very much, any help is much appreciated.

[original thread by Eiso Kant]

You should use EditorManager.activeEditor if you want to access currently focused editor, i.e. the focused HTML element belong to the editor widget. Or EditorManager.currentEditor to get the last focused editor. Usually one needs the latter.

For your widget i would create some kind of service, i.e. MyWidgetService or MyWidgetManager, and it will has open method which receives options to open.

So you can create a command which grabs the content of the current editor, uses a task to run it, gets output and when use your widget service to open with a result.

a command wil be available in the command pallete if you define a label for it, you can also bind it to the editor context menu or into the editor toolbar, via MenuContribution or TabBarContribution

[Eiso Kant]

Thank you @anton-kosyakov I really appreciate the detailed help here. This will save me a lot of time.

you are welcome!