How to rename theia widgets via context-menu?

Right-clicking a theia widget gives us 4 options- Close, Close others, Close others to the right, Close All. I want to add another option in the context-menu for renaming the widget and persisting with the new name for that particular widget instance. Code snippets appreciated.

[original thread by rhendricks]

If you search Theia codebase for Close you will find this command definition: https://github.com/eclipse-theia/theia/blob/183ba3e5cee0e118a4cc80ef0f71242da13efba9/packages/core/src/browser/common-frontend-contribution.ts#L130

After that use code navigation in your IDE to learn how it is used to register in MenuContribution: https://github.com/eclipse-theia/theia/blob/183ba3e5cee0e118a4cc80ef0f71242da13efba9/packages/core/src/browser/common-frontend-contribution.ts#L411-L415

You can open a file in your browser by prefixing an URL with gitpod.io# to start searching: https://gitpod.io#https://github.com/eclipse-theia/theia/blob/183ba3e5cee0e118a4cc80ef0f71242da13efba9/packages/core/src/browser/common-frontend-contribution.ts#L130

[rhendricks]

Okay, will check this. But how to implement the rename functionality? How to rename the widget and replace the original name? I believe the widget label has to be modified, right? Is there any method similar to renaming a file that can be used to rename the widget itself(for eg: rename ‘output’ widget to ‘Multiple outputs’ or something from the UI) ?

if you want to change a title on creation when you should provide a custom factory which assigns a widget title