Is there something like Emacs' toggle-read-only in Visual Studio? - visual-studio

The subject says it all. Is there an easy way to toggle the editability of a buffer in Visual Studio? This would be similar to the toggle-read-only command in Emacs.
I am not looking to change the file attribute ... just whether I can edit the file while it is open in Visual Studio. I am using 2008 and 2005.
Why would I want to do this? I tend to have several files open at the same time .... for days at a time sometimes (perhaps a bad habit) and I have +/- a char or few here and there without meaning to or noticing ... also worried about "the cat walking across the keyboard"
Besides ... an "ancient" code editor like emacs has it :) and I grew to expect the feature.
TIA!

There is an extension for Visual Studio called CodeMaid that will give you a Read-Only Toggle per file.
http://www.codemaid.net/documentation/#andmore
You can download it at http://visualstudiogallery.msdn.microsoft.com/76293c4d-8c16-4f4a-aee6-21f83a571496

You can use this piece of vba
Public Sub ToggleReadOnly()
Dim doc As Document
doc = DTE.ActiveDocument
If (doc.ReadOnly) Then
doc.ReadOnly = False
Else
doc.ReadOnly = True
End If
End Sub
Note: the msdn documentation specifically mentions that the property ReadOnly shouldn't' be used explicit but I verified that this works for me on vs.net 2005.
I also verified that the actual file attribute isn't changed.

I'm not aware of anything that will quickly achieve what you're looking for. Furthermore, I'm not really sure why you would need such a thing. Typically I use subversion to tell me which files have been changed and where they have been modified that way I can revert anything that doesn't belong.
Can you expand on your question a little to let us know what your usecase is?
If you really need to toggle readonly....perhaps you can:
Right click on the file
Select Open Containing Folder
Right click on the file and choose properties
Check the readonly checkbox

Start Tools->Macros->Macro IDE. Add new module (described here in details) and define there procedure as follows:
Imports EnvDTE
Public Sub SwitchReadOnly()
DTE.ActiveDocument.ReadOnly = Not DTE.ActiveDocument.ReadOnly
End Sub
Assign macro to keyboard key(described here in details). That's all.

Related

Visual Studio Intellisense describing the property/method not working

I was using Visual Studio 2012 and it used to give the description of a property/method, which doesn't seem to work in VS2019. Is there an option that I will have to enable for this to work?
Below screesnhot is an example of File Input/Output operation:
When I scroll/hover over ios::app, it should give a description "Append to the end of the file" which it does not.
Second concern is that it is giving me a lot of other options as well (marked as * in VS). Is there an option to disable that permanently?
Final concern is that, when I hover over a function, it will display the parameters that the function is expecting (Or list of suggestions if the function is overloaded). But for some reason, in the below case, it is displaying along with namespace. Is there an option to disable that?
public static constexpr std::_losb::_Openmode std::_losb::app = (std::_losb::_Openmode)8

Creating a custom Word Add-In/VSTO

I am attempting to create a Word add-in for Office 2010. I have used Visual Basic in the past but moved on to PowerShell for most of my scripting now.
However, when I'm in Visual Studio creating a new Add-In, I have to use Visual Basic (or C++ but i'm a lot more familiar with VB) and i'm running into problems.
The main problem being, I've never done this before and i've never been asked to do this so I've never looked into how it works.
So far, I've created the project and the ribbon icons. I have 2 icons. One is meant to print the name of the current active file into the document (at the end of the document no matter where I'm at IN the document) and the other is meant to print the path to the active document wherever my cursor is inside the document.
So...I don't expect anyone to write my code for me but, if someone could point me in the direction of a quick "How-To" for these items, i'd appreciate it!
Last update. Google-Fu came through. Looks like I have it working as I want it. In case anyone stumbles onto this thread looking for the same thing, here's what I did.
To insert at the end of a document:
Dim docName = Globals.ThisAddIn.Application.ActiveDocument
Globals.ThisAddIn.Application.ActiveDocument.Content.InsertAfter(Text:=vbCrLf & docName.Name)
To insert at the cursor
Dim docName = Globals.ThisAddIn.Application.ActiveDocument
Globals.ThisAddIn.Application.Selection.InsertAfter(Text:=docName.Path)
Thanks for helping me think through this!

Disable Visual Studio's validation of non xml files that look like xml?

This is a repeat of a question asked by someone else way back in 2008
, but it appears there was no real answer back then and this is still a problem.
I am writing a Visual Studio extension for files which look like XML but are not, and do not end in an xml extension. (I am using .csp) However Visual Studio continues to parse and highlight the file as if it was XML. This makes it difficult to get my own parsing and error processing to work.
Is there any way to programmatically tell visual studio that the file is not XML?
See also similar issue on MS forum
Since you have your own file extension, yes there is! It's simply a matter of editor priority. The XML-sniffer editor is only given a chance to claim the file if nobody else with higher priority does so first. It does so by registering the special * file extension as editable, then grabbing the file if it looks like XML -- but that * extension registration only has a priority of 33.
All you need to do is make sure your editor is registered properly with a higher priority. On your package, make sure you have the ProvideEditorExtension attribute. I suggest a priority of 50 to start with (higher numbers have higher priority).
[ProvideEditorExtension(typeof(CspEditorFactory), ".csp", 50)]
If you don't already have an editor factory, there's a good walkthrough on MSDN about how to create one.

Where is where is microsoft.office.tools.word.factory?

I'm in VS2010, in a new Word Add-In project. This is my first attempt at Word development using VSTO. The example I'm trying has this line:
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
But when I add this line Visual Studio says it can't find "Factory". Indeed, it's not in Intellisense.
I've got references to:
Accessibility
Microsoft.Office.Interop.Word
Microsoft.Office.Tools.Common.v9.0
Microsoft.Office.Tools.v9.0
Microsoft.Office.Tools.Word.v9.0
Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0
Office
and all the usual System references.
Where am I going wrong and why can't I get to "Factory"?
stdole
That example looks a bit weird to me. Never seen that sort of reference before.
Generally, with Vsto, you hook into EVENTS on, say, the main Word App object.
Then, from within the event, you usually are passed a reference to the particular DOC object that the event is occurring for (say, being opened or saved, etc). In that way, there shouldn't be any need for using the "globals" object or the "factory" object, whereever they might be.
What method is that code in? A little more context might help.
I think the recommended way of doing this is:
Globals.ThisAddin.Application.ActiveDocument

Search Value in VS2010 Debug Locals and/or expand all Nodes

does someone might know how to search for a value in the locals
in visual studio 2010
or at least how can I expand all nodes, subnodes?
if you record a macro on activating locals tools window on VS2010 it will generated this line of code,
DTE.Windows.Item(EnvDTE.Constants.vsWindowKindLocals).Activate()
after debugging this code and inspecting DTE.Windows'ActiveWindow when the active window is local I unfortunately couldn't find anything helpful, but give it a try and you may find sth helpful
if you just need parameters of a method you can use MethodBase.GetCurrentMethod() in System.Reflection namespace and it will serve you well by this private memeber
((System.Reflection.RuntimeMethodInfo)(currentMethod)).m_parameters
that you can read programmatically by reflection or just quick watch it
There are several items here that would let you do what you need, but you'll likely have to tweak the code first:
http://www.codeproject.com/info/search.aspx?artkw=quickwatch&sbo=kw

Resources