Custom view decorations in VSCode extension - visual-studio-code

I'm building a VS Code extension and it uses a TreeDataProvider to create a list of items. The list has nested children and I would like to show a count for these in the parent.
I've looked for examples and tried to understand how the git extension does it but no luck. Perhaps someone can provide an example of how to do this.

Support for custom decorations in views appears to be a work-in-progress. There has been an API for it in the "proposed state" for a while, see:
Make decoration provider API public (#54938)
relevant section in vscode.proposed.d.ts
Source Control and Problem decorations already shown in custom views if TreeView.resourceUri is set.
Source Control decorations are managed via the Source Control API - each SourceControlResourceState instance can have decorations attached to it. That would be how the Git extension you mentioned does it.
Problem decorations are derived from the "problems" (errors, warnings...) associated with a URI. These are also shown in the Problems panel. Problems can be created using the Diagnostics API or with a problem matcher.

As of VS code version 1.52, the FileDecorationProvider is available to use, which is a way to add a text badge to a TreeItem. Related GitHub issue here for more context.
If you are using TreeItem then you will need to specify a resourceUri property which you then use to identify where to apply the badge.
To be clear the badge is limited to text and does not include the option to put it in a circle badge, like in the first picture of the question.
Here is a simple code snippet on how to use it:
class CountDecorationProvider {
constructor() {
this.disposables = [];
this.disposables.push(vscode.window.registerFileDecorationProvider(this));
}
provideFileDecoration(uri) {
const showCountFor = "/aUserHere";
if (uri.path === showCountFor) {
return {
badge: "10",
tooltip: "User count"
};
}
}
dispose() {
this.disposables.forEach((d) => d.dispose());
}
}

Related

Mapbox Direction GL - show/hide driving instructions

I am hiding driving instructions by default:
var directions = new MapboxDirections({
accessToken: mapboxgl.accessToken,
controls: { instructions: false }
});
I want to have ability to display/hide it on button click and not sure how it needs to be done.
The mapbox-gl-directions plugin does not provide a setter method for the options.controls.instructions parameter. In other words, the boolean value specified at creation of the MapboxDirections instance cannot be toggled using a button. All instance members for MapboxDirections are documented in API.md.
You could experiment with implementing this custom functionality yourself by forking the plugin or opening a pull request to add a MapboxDirections#setControlsInstructions method, or something similar, to src/directions.js. This method could then be used with the button's click listener. This would require some careful state object management to ensure all visual interface elements are properly updated when the button is toggled (see src/reducers/index.js and src/controls/instructions.js).

Can I change "OK" button style in Select Dialog to emphasized?

anyone know if sapui5 provide solution/function to change button style in select dialog? I've checked the SAPUI5 sdk but there is none for this solution.
If you are OK with using "private" properties then you can use _oOkButton property of SelectDialog or else you can use _getOkButton function which also is kind of "private" and returns ok button instance.
Just use the instance of the Select Dialog and get all buttons using the following methods. Select Dialog is a dialog only, you can use the methods of sap.m.Dialog
Let say you have the instance of the dialog as oSlectDialog then
oSlectDialog.getButtons() - will return all the Buttons in the footer. You can use loop them and give custom class accordingly.
var oBtns = oSlectDialog.getButtons()
for(var b in oBtns) {
var oBtn = oBtns[b];//You can check for button instance, if you want to add custom class differently.
oBtn.addStyleClass("YourCustomClass");
}
You can also use the sap.m.Dialog methods like oSlectDialog.getBeginButton(), oSlectDialog.getEndButton().
Since UI5 1.62.0, the primary action OK (later renamed to Select) is automatically emphasized if the theme is sap_fiori_3.
https://openui5.hana.ondemand.com/#/entity/sap.m.SelectDialog/sample/sap.m.sample.SelectDialog
If it's not urgent, I'd suggest to avoid relying on private methods/ properties, but update to the latest UI5 version and themes.
Update: and since 1.70 (commit:1f421b0), the button is automatically emphasized in other supported themes too, such as sap_belize, sap_belize_plus
Related Github issue: https://github.com/SAP/openui5/issues/2254

How to use a FreeMarker template in a Magnolia App?

I'm using Magnolia 5.4 and have developed an app following the documentation:
https://documentation.magnolia-cms.com/display/DOCS54/Apps
The app is being rendered correctly in the magnolia shell.
Opening the app shows a «Hello World» message as described in the documentation:
https://documentation.magnolia-cms.com/display/DOCS54/Programming+an+app#Programminganapp-MainSubApp
I've removed the unnecessary code and ended up with this:
public class HelloWorldMainSubAppViewImpl implements HelloWorldMainSubAppView {
private VerticalLayout layout = new VerticalLayout();
private Listener listener;
public HelloWorldMainSubAppViewImpl() {
layout.setMargin(true);
layout.setSpacing(true);
layout.addComponent(new Label("Hello World!"));
}
#Override
public Component asVaadinComponent() {
return layout;
}
}
Instead of using the Label component I would like to use a FreeMarker template where I define a custom view.
Having read through the documentation I haven't figured out yet how to do this.
Here is the solution to my problem, based on the previous work.
This is the «EmbeddedPageSubApp» approach as described under «Custom App»
Create a regular page somewhere in your navigation.
Open the Configuration app, go to /modules/<APP_NAME>/apps/<APP_NAME>/subApps/main and add a url property to the mainSubApp with an absolute path to the previously created page.
Change value of the class property /modules/<APP_NAME>/apps/<APP_NAME>/subApps/main to info.magnolia.ui.framework.app.embedded.EmbeddedPageSubAppDescriptor
Change the value of the subAppClass property to info.magnolia.ui.framework.app.embedded.EmbeddedPageSubApp
If you don't want that page to be visible restrict its access within 'superuser' group / role so that only administrators can use it.
This binds that with an iframe. You should choose a blank template since the navigation elements of the embedded page are visible within the app.
I might be wrong here but to my knowledge Freemarker is only used to create templates and unfortunately limited to it. https://documentation.magnolia-cms.com/display/DOCS60/Template+scripts
On the other hand, What you want to do is to develop your custom app and here is an example of how to do that.
https://documentation.magnolia-cms.com/display/DOCS54/My+first+content+app
Also, if you are motivated to move to latest Magnolia version, you can define your custom app pretty easily using Content Types.
Hope that helps,
Cheers,

adding icons to custom Eclipse editor hovers

I've created my own extension to DefaultTextHover within my custom Eclipse editor, and wanted to add icons to the hover -- similar to what the JDT does when I hover over a program element.
Currently, my implementation of getHoverInfo returns the appropriate String for the hover itself. But I would like the hover to also contain an icon -- similar to what I'm already using in my editor's outline.
How can I do this?
You need to make your extension to DefaultTextHover implement ITextHoverExtension which adds the new method getHoverControlCreator. This method returns a IInformationControlCreator which is used to create the IInformationControl which is used to display the hover information.
IInformationControl creates the hover and can interpret the hover text any way it wishes (as HTML for example).
There is a DefaultInformationControl implementation of IInformationControl available which does a lot of the work for you. This requires you to provide a class implementing DefaultInformationControl.IInformationPresenter and DefaultInformationControl.IInformationPresenterExtension.
There is an internal JFace class HTMLTextPresenter which can be used as an example for implementing the information presenter (since this is internal you should not use it directly).

Eclipse RCP get elements by ID

I don't know RCP very well yet, but I've been reading a lot of the docs. I don't know if my question makes sense; I apologize if not and beg that you try to work out what I mean and come up with some kind of answer.
I have a tree view element, which has a double click listener on it. In another part of the window there is a layout folder which contains views that are supposed to be inspectors for the items double-clicked on.
The only way I know to make another inspector appear is:
getActivePage().showView(Inspector.ID).
showView() doesn't give any opportunity to pass extra information to the view, so can it know which element to inspect?
Pointers in different directions appreciated. The Vogel tutorial doesn't seem to cover this, or I don't understand it.
You could check if the article "Link to Editor" can help you here.
That is, instead of trying to access the right view, define a Listener for the Editors:
private IPartListener2 partListener2 = new IPartListener2() {
public void partActivated(IWorkbenchPartReference ref) {
if (ref.getPart(true) instanceof IEditorPart)
editorActivated(getViewSite().getPage().getActiveEditor());
}
That way, you can get back the right Editor, and ask that Editor all you need for your View to update accordingly.
You can use the SelectionService. The Inspector view should register as a SelectionListener. And the other view with the tree should register a SelectionProvider. This view should listen for the double click in the tree and then update the selection