VsCode extension. How to select a tree view item on right click - visual-studio-code

I am writitng a VsCode extension. When the user Right Clicks on an item in the tree view, he gets the popup command, whose actions apply to the previously selected item. In VsCode itself, this isn't the case. RightCliking on New File, for instance, adds a file to the currently highlighted folder (Not the selected one). How can I replicate this behavior in my extensions?

I found the solution.
When registering the command, which the right-click runs, add a parameter which is the Tree Node. When the command is invoked via the menu popup, this tree node will be the highlighted node, and not the selected node.
For example replace the code
commands.registerCommand('myExtension.myCommand', () => this.command());
and later on:
command() {
}
with
commands.registerCommand('myExtension.myCommand', command(), this);
and later on:
command(node: TreeNode) {
if (node) {
}
}
The if (node) is necessary, if the command may be invoked from a different context (like a button), in which case node would be undefined.

Related

ProseMirror / Tiptap: how to ScrollIntoView without focus?

I am working on a note-taking app that uses ProseMirror as the editor. I want to achieve the feature that when the user searches, the editor will automatically scroll to the most relevant position calculated by other functions. Meanwhile, the search bar should NOT lose the input focus so the user can modify the search content. Therefore, the straightforward way of
editor.chain().focus().setTextSelection().run()
would not work.
I have found a way to set the editor selection without focus. But the view is not scrolled. I need it to scroll to the new selection.
Here is an illustration of the scenario
I tried
editor.commands.scrollIntoView()
It does not work. But
editor.commands.setTextSelection()
does change the selection of editor.view.
You can use ProseMirror directly (instead of TipTap objects), or finding the DOM node worked for me too:
/**
* Scrolls to the current position/selection of the document. It does the same as scrollIntoView()
* but without requiring the focus on the editor, thus it can be called from the search box while
* typing or in shopping mode when the editor is disabled.
* #param {Editor} editor - A TipTap editor instance.
*/
function scrollToSelection(editor: Editor): void {
const { node } = editor.view.domAtPos(editor.state.selection.anchor);
if (node) {
(node as any).scrollIntoView?.(false);
}
}
Copied from SilentNotes

How to track down in which application is signal handler defined gtk/gtkmm for some button

The problem:
You wanna contribute to the some gnome/gtk/gtkmm project since you've noticed and know a way that things could be made better / you wanna fix some bug. Here are steps to get you started.
Example problem:
"Clean" button in Gnome Builder isn't doing anything to my project and since at this point I believe it is just empty function with placeholder button I wanna implement actual action.
Here are steps:
open application that you wanna modify in terminal where environment GTK_DEBUG=interactive environment variable is set. so run GTK_DEBUG=interactive gnome-builder
Gtk inspector should have opened and you should see bunch of Objects displayed. If you click on Object in inspector, that object should light up in your application
Gtk has clear hierarchy, so parent contains children, and your job is to detect in which parent is child that you want to modify
When you figure which parent you want click on arrow next to the name of that parent to reveal its children
Repeat steps 3. and 4. by applying 2. to get to the child that you want to modify
For example my path is IdePrimaryWorkspace -> GtkPopover -> GtkBox -> DzlPriorityBox -> GbpBuilduiOmniBarSection -> GtkBox -> GtkBox -> GtkButton
Double click last interactive entry (such as GtkButton
on the left, in drop-down switch to Properties view
find property that you want, mine is GtkActionable, and it's value is builder-manager.clean
open source folder in terminal of application that you are interested in (clone source of that application)
type in command tree | grep build-manager
if there are entries with that filename type in find . --name=filenameof.your.file
get file path, open that file in text editor/IDE, change stuff inside
submit patches

How to focus a custom view when writing a VS Code extension?

I need help with my VS Code extension. I've written a custom view which works just fine, however I'd like to activate / focus / bring into view that view by using a keyboard shortcut or a context menu command. I am unable to find how to use the VS code API to achieve that.
context.subscriptions.push(vscode.commands.registerCommand('extensionId.showView', () =>
{
// how to do that?
}));
I know this can be done, because one can display the file explorer by using this code snppet:
vscode.commands.executeCommand('workbench.view.search');
But how would you do that for a custom tree view?
You should be able to use the new focus option that was added to TreeView.reveal() in 1.25 for that. The method requires you to pass a tree item to be revealed, so it's more of a workaround for not being able to focus the view itself directly, but you could simply pass the first / root node.
treeView.reveal(item, {focus: true});
Note that focus in this case means keyboard focus. If you just want to bring it into view, calling reveal() without the focus option is good enough.
To obtain a TreeView instance, you need to call vscode.window.createTreeView() with your view ID and provider.
I think, it is also possible to use
vscode.commands.executeCommand("exampleView.focus")
using the exampleView declared in package.json:
...
"views": {
"exampleView": [
{
"id": "exampleView",
"name": "Example View"
}
]
},
...
as #Empiire said, focus command in the form of : vscode.commands.executeCommand
and adding the '.focus' at the end of the id of the view that was declared in the package.json works!
You can also provide an object as parameter such as { preserveFocus: true } to show without disturbing the current focus.
eamodio does it like that in gitlens : https://github.com/gitkraken/vscode-gitlens/blob/417587d0dfcda89e9e2d723f8b662d7cf9008c8f/src/webviews/webviewViewBase.ts#L85

Text Editor in eclipse plugin is not properly executed

I have created multipage HTML editor in which one tab has text editor. I have set the global action handler to the action bar for undo / redo actions in the source editor. Whenever I am adding something in the source editor then undo it, it is not returning the same code in the first attempt. It is completing in the second attempt. Can anyone help me to solve this issue.
In the main editor override the setFocus() method and in this method call the following method of source editor.
public void setUndoRedoActionHandlers() {
final IActionBars actionBars = getEditorSite().getActionBars();
actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(),
mUndoAction);
actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(),
mRedoAction);
actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(),
mDeleteAction);
actionBars.setGlobalActionHandler(
ITextEditorActionConstants.DELETE_LINE, mDeleteLineAction);
actionBars.updateActionBars();
}
Thanks
Are you sure that you set global actions by overriding setFocus()? Look at this : https://wiki.eclipse.org/FAQ_How_do_I_enable_global_actions_such_as_Cut,_Paste,_and_Print_in_my_editor%3F
It says they need to be set inside method setActiveEditor()
The reason I guess why you are seeing it working second time is - When the first time you click your editor gets focus and setFocus is called and only then the global actions are set. Then second time it will work because the actions are now set.

GWT : cell tree and initial keyboard selected node

I'm using a CellTree with the KeyboardSelectionPolicy.BOUND_TO_SELECTION.
I'd like to open the tree with a given path selected.
The code opening the child path and selecting the node is working fine when KeyboardSelectionPolicy is ENABLED/DISABLED but when BOUND_TO_SELECTION I can see that the keyboard-selected-node in the tree is never updated from : cellTree.selectionModel.setSelected( ... )
So I'm wondering if setSelected can work with BOUND_TO_SELECTION and how to do it.
See http://code.google.com/p/google-web-toolkit/issues/detail?id=6310
I suppose you could find a way to call setKeyboardSelectedRow in response to SelectionChangeEvents.