How to navigate in DocumentViewwhen developing an extension for VS 2022? - visual-studio-extensions

I have to develop a rather simple extension for VS 2022. To do so, I need to insert some text into a certain position of the document worked with (for simplicity, right into the beginning). I followed a few video tutorials by Mads Kristensen on YouTube and GitHub, e.g. his InsertGuid example (https://github.com/MadsKristensen/InsertGuid), which I found enlightening, but I failed to find guidance to how to navigate within the document's text, more specifically, how to insert text right into its beginning or end.
My question is how one can do it or where can I find some detailed tutorial or documentation.

After trying to find out myself (unsuccessfully) I asked on GitHub and got the following solution (https://github.com/VsixCommunity/Community.VisualStudio.Toolkit/discussions/355):
DocumentView docView = await VS.Documents.GetActiveDocumentViewAsync();
docView.TextBuffer.Insert(0, "I'm at the start.");
// Insert at the end of the document.
int end = docView.TextBuffer.CurrentSnapshot.Length;
docView.TextBuffer.Insert(end, "I'm at the end.");
// Inserting at the start of the second line.
ITextSnapshotLine secondLine = docView.TextBuffer.CurrentSnapshot.GetLineFromLineNumber(1);
docView.TextBuffer.Insert(secondLine.Start, "Now I am the second line\n.");
Tested, and it works.

Related

How do you flip whole Docs horizontally 180* with the CSS command rotateY(180deg)?

I can get basic html text to flip 180*, but I'd like to know how to get a whole Doc in my Drive file to flip using a standalone script (so I can do it repeatedly). I'm aware I can get a doc, open the scripts editor and then use my flippin' project to flip the doc I called, but I don't know what the syntax looks like. My first flippin' success was pasting text into the .html file as simply as possible and using:
function doGet() {
return HtmlService.createHtmlOutputFromFile('Page');
getContent()
}
I just test ran it from the dialog box as a web app. But I'm interested in building this one command feature out into several different domains to get experience with the variety of possibilities available in GAS. Anyone care to tutor me? Please?!...

How to simulate paste(CTRL + V) using AUTO IT in Word Document

Objectives -
Open the target app using AutoIy
Take a printscreen (ALT + PRTSCREEN) of the opened app(step 1)
Open a new word document
Paste the screenshot on word document
Issue:
I am able to complete the first two step, however I am not able to paste the screenshot in Word document.
Root Cause
I am able to take the print screen using SEND ("!{PRINTSCREEN}") and open word document using UDF _WORD_DOCADD, but I am not able to paste from clipboard. The issue is, when I am using WinWaitActive to activate the document, the document is still not active and hence SEND ("^V") is not working.
You are using Send incorrectly to send the Ctrl+V. With a capitol V, it will be interpreted by AutoIt as Ctrl+Shift+V (see helpfile for details). Instead what you want to use is Send("^v").
WinWaitActive does not activate the document, it simply waits for it to become active, use WinActivate to activate word.
The correct way to paste though is to use the word com object, something like: $oWord.Activedocument.Range.paste. That will work without word being active or visible.
Also, there are better ways to screenshot than sending Alt+Printscreen.
All these steps are very well documented, and have been done many times before.
I found a way to solve my problem. Steps followed are -
Simulate ALT + PRNTSCRN
Open Clipboard
GetData from Clipboard as BITMAP
Save the data as JPG using GDIPLUS_IMAGE_SAVETOFILE
Use DOCADD to open new document and _Word_DocPictureAdd to save the image to word document.

find all _stringbetween occurrences within a webpage

I am working on an AutoIT script to find select messages withing a chatroom type webpage, I have no problem with placing the sent text between two special characters to make them easier to find, also to filter out all of the unwanted stuff. the problem that I am having is once the _stringbetween finds what it is looking for it doesn't continue looking. For testing I have the values returning in a GUI box. If there is a way to return all text between "^","^" it would solve my problem. Here is what i have so far
$html = _StringBetween(_INetGetSource('https://dtss.campfirenow.com/room/595835'), '^','^')
MsgBox(0, "title", $html[0])
also if anyone knows of a better way to pull select messages from campfire that would also solve my problem, maybe using the star feature... If you would like to look at the source code and api's of campfire they are available on GitHub
The _stringbetween return all occurences it will find.
You can make this simple test.
#include <array.au3>
$source="^test1^blabla^test2^blabla^test3^blabla^test4^blabla^test5^blabla"
$aRes=_StringBetween($Source,"^","^")
_ArrayDisplay($aRes)
For your source I don't now what's happening but test like this :
#include <array.au3>
$Source = BinaryToString(InetRead("https://dtss.campfirenow.com/room/595835"))
$aRes=_StringBetween($Source,"^","^")
_ArrayDisplay($aRes)
If the problem persist make a paste of your source code's page and post the link.

How do I fetch text blurbs using open refine 2.6?

I am running a very simple exercise where I have a list of people's names that have been already reconciled via freebase, from within Open Refine.
The Github repository for Open Refine clearly indicates that fetching Properties against a reconciled Freebase Type is still a "To Do" project, but apparently, fetching text blurbs is possible..
Starting from your reconciled column, use "Add column from Freebase"
and use the "Add a property" field at the top to add
/common/topic/article. - using the new column, select "Add a column by
fetching a URL" and construct the URL as follows:
"http://api.freebase.com/api/trans/raw"+value - You'll end up with
another new column containing the text of all the blurbs
I don't have an option "Add column from Freebase".
Am I missing something? Thank you very much for your help.
That's presumably OpenRefine 2.6 beta since the production release isn't out yet [emphasis added].
If Add from Freebase is missing, something is wrong (ie it's a bug). Please file a bug report on GitHub with information on what operating system you're using. The documentation that you quoted is also out of date. Please also file a bug report for it with the location you found it.
Sorry about the problem! We'll have a look as soon as we've got the information from the bug report(s).

Insert programming code in a Lyx document

What is the best way of inserting python/C++ code in a Lyx document? The code is small examples less than 20 lines.
My Lyx document is using the Book document class.
Orjanp
I prefer to insert the listings as a child document, so the code is grabbed directly from a file that you can further edit and keep updated (you avoid to duplicate an information and maintenance is a lot easier).
To do this in Lyx:
Insert->File->Child document
Then in the window that will appear change the type to program listing and configure it as you need, for example you could want to enter the parameter language=Python (you can type a ? to view all the parameters).
A set of parameters I usually use is:
breaklines=true //--> breaks lines to margin
captionpos=b //--> caption at the bottom of the listing (default is "t")
frame=tb //--> frame at the top and at the bottom of the listing
language=Python //--> syntax highlighting for python
There should be an Insert -> Program Listing option. That uses listings Latex package, so you should have that installed. The support seems to have been added in Lyx 1.5, and from their screenshot, it seems it gives you a lot of customization options.
The insert->Program Listing feature works great. I just want to add that if you are on Mac, and try to directly paste, using command+V or right-click+paste, a block of code into the program listing, the whitespace will not be preserved, and you have to manually insert the whitespace by typing tabs, returns, etc.
A very easy way to get around this is is to paste using shift+command+V. This preserves all the whitespace of your original source code.

Resources