VS Code Extension: Is it possible to access View items using JS? - visual-studio-code

Your package.json creates a View in the Explorer, say "Test"...
"views": {
"explorer": [
{
"id": "Test",
"name": "Test"
}
]
}
... is it possible in the extension's JS to access that View?
Something like this...
ThisView=vscode.window.getViewById("Test");

Related

Add custom command to own VS Code extention in "view/title"

I'm trying to add my own command in a Visual Studio Code extension in the upper "view/title" row. For example, like the built-in "Extension"-View:
I couldn't figure out from the menu-contributions API how this works. I specified a custom ViewContainer in the package.json, which in turn contains multiple views:
{
"viewsContainers": {
"activitybar": [
{
"id": "my-view",
"title": "My View",
"icon": "media/logo.png"
}
]
},
"views": {
"my-view": [
{
"id": "profiles",
"name": "Profiles"
},
{
"id": "templates",
"name": "Templates"
}
]
}
}
Since I have a command that goes across all views, I would like to have the button at the height of the ViewsContainer (as in the image). Is that possible?

How to create a new panel section in Visual Studio Code using extension

How can I create a panel section like the one that Gitlens has (see the screenshot below)? I've looked over the documentation and the Github examples presented here and I could not find anything on how to create this.
I want to have a button there next to TERMINAL and when I press on it to present a webview.
I have managed to do this by creating a viewContainer in the contributes object.
"viewsContainers": {
"panel": [
{
"id": "myPanel",
"title": "Colors",
"icon": "images/views/history.svg"
}
]
},
and then I create a view that uses the viewContainer.
"contributes": {
"views": {
"myPanel": [
{
"type": "webview",
"id": "calicoColors.colorsView",
"name": "Calico Colors"
}
]
},

How to access and modify custom settings in vscode extension?

I am creating a vscode extension which has some custom settings. I have defined the settings in package.json like so:
{
"contributes": {
"configuration":[
{
"title": "Extension",
"properties": {
"Codegenx."A Float": {
"type": "number",
"default": 1.0,
"description": "A sample decimal number"
}
}
}
]
}
}
How can I access these setings in my main extension? And also make sure that I get the updated value if the user changes the settings through the settings.json file or through the VsCode UI?

Writing a vscode plugin for adding snippets but only for file composer.json

Did you know if it's possible to write a vscode plugin to match only a given file?
My plugin already works but add snippets for all .json files. I wish to be able to add these snippets only if the current file is composer.json.
My current package.json (partial) is:
{
"contributes": {
"snippets": [
{
"language": "json",
"path": "./snippets/snippets.code-snippets"
}
]
}
}
The idea is to be able to having something like:
{
"contributes": {
"snippets": [
{
"filename": "composer.json", <-- JUST FOR ILLUSTRATION PURPOSE
"path": "./snippets/snippets.code-snippets"
}
]
}
}
Thanks.

SAPUI5 - create a JSONModel from Ajax response

I'm trying to build a SAPUI5 application using JSON model.
I want to add 2 dropdown select menus, so that the second one fills in depending on the current selection of the first one.
I tried to get it done, but stucked at the very beginning.
This is what I get from Ajax (the object itself is passed from the server):
var data = {
"firm1":["firm1project1","firm1project2","firm1project3"],
"firm2":["firm2project1","firm2project2","firm2project3"],
"firm3":["firm3project1","firm3project2","firm3project3"],
"firm4":["firm4project1","firm4project2","firm4project3"]
};
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(data);
sap.ui.getCore().setModel(oModel);
The first menu should be the list of firms and the second one - is the selected firm's projects. And now I have no idea how to bind the data to the controls the right way.
Thank you.
EDIT:
According to what I've read in the developer's guide, the data that should appear in different controls is contained under fixed keys (as shown in "Aggregation Data Binding in a Simple Application" part of the page that I linked above), so it would be possible to just write something like:
var oListItemTemplate = new sap.ui.commons.ListItem("ListItemTemplate", {
text : "{firm}",
});
and for the projects:
var oListItemTemplate = new sap.ui.commons.ListItem("ListItemTemplate", {
text : "{firm/project}",
});
But in my case there is no firm key. My ListItems for the firm selection menu are keys, not values. And ListItems for the project selection menu are in an array, not just separate values under fixed keys.
So, is there a way or to bind somehow the data I have in its current form to controls, or how the data should look like to be useful for binding?
your data looks better like the following, the data binding JSON objects are with keys. And there are two data models needed for two dropdown boxes, multi data model binding should be used. I did a example at JSBin which fulfills your requirements, you can have a look and get some thoughts.
{
"firms": [
{
"name": "firm1",
"projects": [
{
"name": "firm1project1"
},
{
"name": "firm1project2"
},
{
"name": "firm1project3"
}
]
},
{
"name": "firm2",
"projects": [
{
"name": "firm2project1"
},
{
"name": "firm2project2"
},
{
"name": "firm2project3"
}
]
},
{
"name": "firm3",
"projects": [
{
"name": "firm3project1"
},
{
"name": "firm3project2"
},
{
"name": "firm3project3"
}
]
},
{
"name": "firm4",
"projects": [
{
"name": "firm4project1"
},
{
"name": "firm4project2"
},
{
"name": "firm4project3"
}
]
}
]
}