vscode extension onDidChangeCursorPosition - visual-studio-code

I am developing a vscode extention and I want provide something like the bracket match decoration. My problem is that I need to register onDidChangeCursorPosition and I don't know how to do that.
My purpose is to create a decorations that appears only when the cursor is on it.

There is no such event like onDidChangeCursorPosition. However you can use onDidChangeTextEditorSelection. The onDidChangeTextEditorSelection is actually a field on the vscode's window object and you can assign your own function to it which gets called when this event is sent. Look at my extension (or many others which do that) to learn how to handle the cursor change event.

Related

GUI: configure the racket:text% to read-only

I want to use an editor to display a log from a program, I just need a very basic text field:
With a vertical scrollbar
With a contextual menu for copy/paste
Prevent the user from changing the text
In order to activate the copy/paste menu, I use the class racket:text% from framework rather than the basic one.
How to prevent the user from changing the text?
I read the documentation, as far as I understand the closest thing I found is lock method:
https://docs.racket-lang.org/gui/editor___.html?q=lock#%28meth._%28%28%28lib._mred%2Fmain..rkt%29._editor~3c~25~3e%29._lock%29%29
But it is not convenient, as it also prevent my program to write the data.
I also find get-read-write? but cannot find set-read-write.
Use the lock method, and just unlock the editor around any modifications that you want to do. You may find it useful to write a call-with-unlock helper function or with-unlock macro.
If you do your updates from the eventspace's handler thread (and you probably should; use queue-callback if they originate from another thread), then as long as you re-lock the editor at the end of an update, the user will never be able to interact with the unlocked editor.

Multiple shortcuts for one action in GTK

What is the best way to bind multiple keyboard shortcuts to one action in GTK+ 3?
I have been searching for an answer to this for a few days and have come up with naught. The function gtk_accelerator_parse does not support comma-deliminated shortcuts. Putting multiple <accelerator> tags in a .ui file with the same action attribute and different key attributes also does not work.
I do not want to have to write a custom key press handler just so I can have two shortcuts for one action, but is that really the only way?
Since GTK version 3.12 (released on 2014-03-25) there is a new method called gtk_application_set_accels_for_action() that should help.
I have found a way, but it is truly terrible. Using gtk_accel_group_connect I can add additional accelerators for my own functions which can then trigger the action desired based off the key pressed and any modifiers. This however feels like a hack as I am basically creating my own accelerator-to-action map rather than using GTK's.
I would like to know a better way, if anyone knows of one.

Making a Macro available for any Visio document

I want to create a number of macros and be able to use them in any Visio document. I know the rudiments of creating a macro with the "Record Macro function", but it appears that the macro so recorded is only available to that Visio file. I've searched to see how this could be done but have not had success on how to do so. Any assistance would be appreciated.
I'm assuming you mean you want to write code in a Visio document that calls code written in another Visio document. There are two ways I know of to do this with VBA.
The first is to use the ExecuteLine method on a Document object. You just pass in a line of VBA you want to call in that document as a string argument, and the code gets called. This is really only good for calling macros that take no arguments, or if they do, just string/number arguments.
The second way is to save your document (usually a vss* stencil file, if you provide template shapes with your macros), and in any other document you just set a reference to your code file. This allows the VB Editor to have intellisense and see all the methods you can call in your macro file, and makes it possible to pass whatever type of arguments that your methods can take.
Now, if you are only interested in invoking/calling simple methods in a central file through UI actions, there are many different ways to do this. You can assign code to different shapes, ie whenever that shape moves, or when it'd double clicked. This can be assigned in the ShapeSheet window for a shape in the Events section.
You can also draw command buttons or any other VBA controls right on a Visio page and assign your macros to those buttons.
Or you can go to Tools->Macros->(your document name) and there will be more dropdowns for each module in your code file, where you can call any public subs that have no arguments.
Or you can build a toolbar (in the pre-Visio 2010) or ribbon interface with buttons that call your code. Building a toolbar for a VBA solution is kinda crappy though, from my experience. A toolbar button has to call code contained in the document you want to have your code act on. So let's say you have your code all written and saved in a VSS file that, any time a new document is opened, calls a method that adds a toolbar for the new document. When you assign the code to the buttons on that toolbar, the toolbar is assuming the code you've assigned resides in the new document you've opened, not your VSS file. So, to make your buttons call your VSS file, you have to have a method in your new document that uses ExecuteLine to call your actual code in your VSS file. This is a pain, because now your user has to use a VST template file you provide, rather than, theoretically, use your tool on any drawing they want to.
Sorry for the rant, but Visio is pretty flexible in terms of how to call code, so you can probably do just about anything you want.
My solution is to save my macros in a stencil. As long as you have the stencil open, the code is available to the active drawing. Now, if I just figure out how to put "buttons" in the stencil to activate a specific macro...

avoid chrome popup extension to close

Is there a function that allow me to select text when the extension
stays open. Normally when I Use the extension popup and I Click outside the
extension the extension close. Is there a wat to avoid this.
Thank you so much
Unfortunately there is currently no way to keep the popup open once you focus out of it. This is by design.
If you would like to always show something while interacting with the page, perhaps the experimental Info bars or even Desktop Notifications would work?
Hope that helped!
The only way to keep it open is to right click over the extension icon (button) and select "Inspect popup" the extension popup then show up and remain open but of course the debugger window show and this not a fix obviously still it will maybe inspire a hack... if someone is skilled enough and share the solution with all of us.
I encountered the same problem and I've thought of a possible solution (though not tested it):
Use your background.html to store the content of the popup action and upon loading the popup, you fetch the content via the default messaging for chrome extensions.
When doing all kinds of other stuff, like XHR's or something, I think you should do that in background.html too, so the requests won't abort if you close and you can do something with the result. Then when a user re-opens the popup, he'll see the result of his previous action instead of the default screen.
Anyone tried something like did already?
As far as I know you can't persist a pop up menu but my workaround has been using a content script to append a menu on page load. After the menu is appended you can toggle the menu via messaging between the background script and the content script.
If you want to encapsulate the menu from the page it's deployed on you could wrap your menu in an iframe. This could add complexity to your project since you would have to deal with cross origin issues and permissions.
There is an alternative hack for this. You can make use of chrome local storage to store the metadata as needed. Upon restart you can read that metadata and render the desired content. You will also probably clear that metadata after you have completed performing the operations based on that.

RichEdit control: Determine when text is changed?

I'm trying to count the number of times that text is changed in a given RichEdit control. I considered using events like key down, but that gets messy when you consider keys that don't change the text (like arrows, page up, etc). And how do you make sure you get all of those keys?
It seems it would be simpler to register a callback for a onTextChanged event, if one exists. Is there any way to do something like that?
Well you need to listen to the EN_CHANGE message if your using C++. Note that you also have to call SetEventMask with ENM_CHANGE to receive these notifications unlike a normal edit control will sends these messages by default.