How does "Save as Live Template..." work in Android Studio? - android-studio

I select the following code:
//This is for debugging Live Template
try {
} catch (Exception ex) {
}
then click Tools > Save as Live Template...
Nothing happens. Could anyone offer a tip on how to select a snippet and save as a live template?

https://youtrack.jetbrains.com/issue/IDEA-174644 -- this looks like your case.
It's fixed for 172/173.xxx branches -- no idea what Android Studio version it would be.
Workaround for now -- make selection with no leading whitespace .. and edit created Live Template after if required.

Related

ReSharper - Document Saved Event For Inactive File in Visual Studio

I’ve set up my own source control plug-in for Visual Studio.
It’s registered with visual studio and can be selected from the list of Source Control plug-ins.
I’ve got no issues with files that are modified from with in Visual Studio as I’m using to catch the event before save:
IVsRunningDocTableEvents3
If the file isn’t loaded as an active document in Visual Studio, I’m having problems detecting that it is about to be edited so I can check it out of Source Control.
I’ve tried using the ReSharper event – DocumentManagerOperations suggested here:
https://resharper-support.jetbrains.com/hc/en-us/community/posts/205991489-Document-Saved-Event
I’m having issues detecting if these types of files need checked out:
.DotSettings. – When saving the ReSharper options settings
csproj – When adding Nuget Packages with ReSharper.
.cs when editing files that are not opened in VS with ReSharper, i.e.
fix naming in project.
Is there an event that’s triggered when a file is edited but not loaded?
Thank you!
I used the interface:
IVsQueryEditQuerySave2
More information here:
https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.shell.interop.ivsqueryeditquerysave2?view=visualstudiosdk-2017
And made use of:
public int QueryEditFiles(uint rgfQueryEdit, int cFiles, string[] rgpszMkDocuments, uint[] rgrgf,
VSQEQS_FILE_ATTRIBUTE_DATA[] rgFileInfo, out uint pfEditVerdict, out uint prgfMoreInfo)
And:
public int QuerySaveFiles(uint rgfQuerySave, int cFiles, string[] rgpszMkDocuments, uint[] rgrgf,
VSQEQS_FILE_ATTRIBUTE_DATA[] rgFileInfo, out uint pdwQsResult)
something like this:
if (rgfQueryEdit != (uint)tagVSQueryEditFlags.QEF_ReportOnly)
{
if (rgpszMkDocuments != null)
{
foreach (var doc in rgpszMkDocuments)
{
//Do Something
Hope that helps you out.

Disable warning lint for a method in external library in Android Studio

In my Android project I have an external library with following method:
// Some external library
class Foo {
#CheckReturnValue
public final Bar returnBar(Bar bar) {
...
}
}
I have to call this method a lot in my project, but I do not need the returned value of this method. All I need is the side effect of the method. So this is how I use it:
fooInstance.returnBar(barInstance) // ignore returned value
The problem with the above code is that Android Studio editor will show CheckResult warning lint. What I can do is to either just live with that warning lint or disable CheckResult for the entire project or module, but I was wondering if there is a better approach to this warning.
What I cannot do is to put SuppressLint because I will be using that method 100 < times in my project and adding SuppressLint to every single usage is not really feasible.
I already went through Android Studio inspection settings but unfortunately was not able to find anything that can help. I would be grateful if you could provide literally any thought on this problem.

How do i get current Branch path from Source control explorer using VS package

I have created VS extension that creates a menu command on Source control explorer by right click on that it open custom form,Now i want to display current TFS path(from where user right click) in that custom form.Same as TFS "Branching and Merging => Branch" Source Path.
Any help Appreciate.
You can use the VersionControlExplorerExt object with its properties SelectedItems, CurrentFolderItem, etc. From a package it would be something like:
private void MenuItemCallback(object sender, EventArgs e)
{
Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt versionControlExt;
Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExplorerExt versionControlExplorerExt;
EnvDTE.DTE dte;
try
{
dte = base.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;
versionControlExt = dte.GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt")
as Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt;
versionControlExplorerExt = versionControlExt.Explorer;
MessageBox.Show(versionControlExplorerExt.CurrentFolderItem.LocalPath);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
The extensibility for Source Control Explorer should be exposed through the VersionControlExt.Explorer class. The VersionControlExt.Explorer.SelectedItems property should contain the server paths for the selected items. Here is an old blog post that might also have some useful information for writing extensions.

Visual Studio Addin not showing

I've created very simple Visual Studio Add-in, ala this article by JP Booodhoo.
http://codebetter.com/jpboodhoo/2007/09/04/macro-to-aid-bdd-test-naming-style/
The addin works in debug, so if I F5 in the add in solution, and open a solution then the addin shows in the tools. However, it doesn't show when not debugging. i.e. after I've deployed the addin, closed and re-opened my solution.
Am I missing something?
In terms of deployment, I followed the deployment steps in this article and deployed it to C:\Users[your user name]\Documents\Visual Studio 2012\Addins
Alternative to macros in Visual Studio 2012
public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
{
handled = false;
if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
{
if(commandName == "KinghamExtensions.Connect.KinghamExtensions")
{
var selection = (TextSelection)(_applicationObject.ActiveDocument.Selection);
selection.SelectLine();
if (selection.Text == "") return;
var prefix = "public void ";
var index = selection.Text.IndexOf(prefix);
prefix = selection.Text.Substring(0, index) + prefix;
var description = selection.Text.Replace(prefix, String.Empty);
selection.Text = prefix + description.Replace(" ", "_").Replace("'", "_");
selection.LineDown();
selection.EndOfLine();
handled = true;
}
}
}
As I say, the code works when running the addin from vs in debug, but doesn't show in the tools menu.
Also, it doesn't show up in the keyboard options like the Git Extensions addin does meaning I can't assign a key binding.
Any thoughts?
It is hard to answer by the information you given, but at first you should check the followings:
Your AddIn should appear in the Tools>Add-in Managger...
If you set the first check box before it, than it should be loaded.
If it isn't and you get an error message, click to no, else the Studio will rename the deployed .AddIn file.
You should check if your release assembly is at the place referenced by the Assembly element like this: <Assembly>C:\Users[your user name]\Documents\Visual Studio 2012\Projects\MyAddin1\MyAddin1\bin\MyAddin1.dll</Assembly>
in the .AddIn file deployed by Visual Studio to the AddIn folder you mentioned in your question.
If it is, and the error pesrists, you should add some log to your Add-In (a Windows MessageBox will do)
and place it to the OnConnection method. The error can appear either OnConnection throws an Exception while the IDE trying to load it, or the FullClassName element in the AddIn file refers to an other name than your Connection class has.
If you get no errors and your OnConnection runs properly, then it could be an exception thrown while your code is adding your command, - if you do the same way as it is in a generated Add-In template in a try/catch block- and you need to resolve it.

Possible to regenerate designer.cs file without Visual Studio?

I have few frequently changeable fields stored in Resources.resx which auto generates the file Resources.designer.cs. It has email addresses, location paths which are to be updated based on needs
Now I would like to make the application usable even for a non developer - Even a lay man must be able to edit the email address & Paths.
Had a thought that if someone edits the .resx file(which is easily editable even in notepad) can I write some .exe code to auto generate the corresponding designer.cs for it?
Thanks for understanding..
If visual studio can do it, you can do it. But I think letting a non-technical person edit an xml file is asking for trouble. What I would do is build a small editing tool which pulls out only those fields you want to change, displays them in a simple form for altering, then writes them back to to the resx before rebuilding the designer.
I have done something similar to this for editing an application.exe.config file so that configurations can be changed without danger of (even a technical person) killing the thing with a typo, which is all too easy.
You could use something like
private void ReadResxFile(string filename)
{
if (System.IO.File.Exists(filename))
{
using (ResXResourceReader reader = new ResXResourceReader(filename))
{
//TODO
}
}
}
public void SaveResxAs(string fileName, string key, string value)
{
try
{
using (ResXResourceWriter writer = new ResXResourceWriter(fileName))
{
writer.AddResource(key, value);
writer.Generate();
}
}
catch (Exception error)
{
throw error;
}
}

Resources