Resharper live templates - inn & ifn - resharper

Do I have something similiar to intelij's "ifn" and "inn" live template in ReSharper?
("if not null" and "if null" templates )
Thanks.

ReSharper doesn't have these built in, but you can easily write them yourself.
Just go to ReSharper > Templates Explorer... > Surround Templates and add a new template with something like this:
if ($SELECTION$ == null)
{
throw new ArgumentNullException("$SELECTION$");
}
Then you can select something and hit Ctrl+E, U to surround the selection with your template:
In my case, I added it to the quicklist with the letter F.
If you want to be able to type ifn and press Tab, you need to add a Live Template. This can be done in the Template Explorer, under Live Templates, but the content has to be different:
if ($ARGUMENT$ == null)
{
throw new ArgumentNullException("$ARGUMENT$");
}
or maybe:
if ($ARGUMENT$ == null)
{
$END$
}
Then you can write ifn (if that was the shortcut you specified) and press Tab

Related

Get name of current fragment in activity. Android Studio

I have an framelayout which loads 6 different fragment. Is there any way to find the name of the current fragment in framelayout from activity.
Fragment1
getFragmentManager().beginTransaction().replace(
R.id.main,Fragment.instantiate(LoadingScreen.this,
"com.myapp.fragments.fragment1",bundle)).commit();
Fragment2
getFragmentManager().beginTransaction().replace(
R.id.main,Fragment.instantiate(LoadingScreen.this,
"com.myapp.fragments.fragment2",bundle)).commit();
I need to know which fragment is live in the framelayout, from activity. Since two different fragments are loaded in the same layout.
If you want to know which fragment is loaded in the layout, you can do something like this:
Fragment f = getSupportFragmentManager().findFragmentById(R.id.main);
if(f instanceof Fragment1){
//do something
}
else if(f instanceof Fragment2){
//do something
}
If you want to know class name then use:
String name = f.getClass().getCanonicalName()
You can use findFragmentById() it will return the current fragment in the container.

Do these hotkeys exist for Flash Pro CS6?

1) when you are in edit mode for one symbol, go into edit for the next symbol in library
2) automatically put cursor in the instance name box for selected movieClip
As far as I know there are is no way to put shorcuts for moving around "inside of the library panel"
A duplicate and edit shortcut would sure be nice though. I can't even find where you would do it in custom shortcuts.
The examples you have listed do not have shortcut keys because they are not default tasks inside of the IDE. That being said you can create ways to do those examples using JSFL to first create a command and then assign a keyboard shortcut to that command. As an example I will include a script for the second item in your list.
2) automatically put cursor in the instance name box for selected
movieClip
There currently isn't a way to tell the IDE to send the cursor to the instance name box in the properties panel, but you can get around that by using JSFL. Let's make our own instance name box pop up.
Here is the code required to do this:
// Assign Instance Name - Andrew Doll
/* This code will provide a prompt for the user to assign an instance name to a selected symbol on the stage. The great thing about using a
// prompt is that the focus is already in the input field of the prompt. To speed up your workflow I recommend assigning a keyboard
// shortcut to this command.
*/
// Check to see if there is a file open first.
var dom = fl.getDocumentDOM();
if (dom == null)
{
alert("Please open a file.");
}
else
{
// Make sure to only select one symbol on the stage at a time.
if (dom.selection.length > 1)
{
alert("You can only select one symbol to assign an instance name to. Please make only a single selection on the stage.");
}
// Make sure that you have at least one symbol selected.
else if (dom.selection.length == 0)
{
alert("You need to select a symbol on the stage to assign an instance name.");
}
// Make sure that the symbol you have selected is a movie clip or a button.
else if (dom.selection[0].symbolType == "graphic" || dom.selection[0].elementType != "instance")
{
alert("Your selection needs to be a button or a movie clip symbol.");
}
else
{
// Pop up a prompt for the user to assign an instance name with.
var iName = prompt("Assign an instance name to the selected symbol.");
// If the user cancels then do nothing.
if (iName == null)
{
// Do Nothing.
}
else
{
// Assign the instance name to the selected symbol.
dom.selection[0].name = iName;
}
}
}
Save this command as a JSFL script in the commands folder in your Flash config directory and then assign a keyboard shortcut to it.

text field attributes/methods dynamics crm 2011

I'm looking a method or way how to check that the text field in crm form is "null"
I've got a tab, there are section and text field inside of it;
furthermore, I'm using that function in order to hide/show tab.
function setVisibleTabSection(tabname, TextFieldName, show) {
var tab = Xrm.Page.ui.tabs.get(tabname);
if (tab != null) {
if (TextFieldName == null)
tab.setVisible(show);
else {
var section = Xrm.Page.data.entity.attributes.get(TextFieldName).getValue();
if (section != null) {
show == true;
tab.setVisible(show);
}
}
}
}
however, It doesn't work. There is nothing inside of the text box, and the tab expanded anyway.
by the way, parameters, which I give the function: "tab_8", "new_conf_report", false
where the secon one the name of the text field
Try
if (section != null && section !="")...
You may find that a field which is initially blank is null, whereas one from which you have deleted content but not yet saved the form is simply an empty string.
Certainly worth a shot.
show==true
is incorrect as others have pointed out (needs to be show=true) but is simply redundant as written inside the same IF statement, just replace next line as:
tab.setVisible(true);
It is possible you intended "show" to be the default tab state to use if text field is not empty, in which case just move this line outside the IF instead of changing it (as shown below)
It looks like the construction using the third "show" parameter is to allow you to use the function to set the tab state to a specific state of shown or not without looking for a text field value at all. You would need to pass parameters as eg tabname,,true - you might consider swapping the TextFieldName and Show parameters so it is easier to just drop the third rather than remember to double-comma.
While we're fixing stuff, lets replace that variable "section" with something with a more meaningful name:
function setVisibleTabSection(tabname, show, TextFieldName) //usage: show is state Tab will have if no TextFieldName is specified, or if text field is empty
{
var tab = Xrm.Page.ui.tabs.get(tabname);
if (tab != null)
{
if (show==null){show=true;}
if (TextFieldName == null)
{
tab.setVisible(show);
}
else
{
var strFieldValue = Xrm.Page.data.entity.attributes.get(TextFieldName).getValue();
if (strFieldValue != null && strFieldValue !="")
{show=true;}
tab.setVisible(show);
}
}
}
I don't see anything wrong with your Javascript (besides what Guido points out, which basically will only set the tab to visible if you pass in true for show). Use the debugging tool within IE by pushing F12, and set a break point at the top of your function to see where your logic is failing.
If you've never debugged javascript before, see http://social.technet.microsoft.com/wiki/contents/articles/3256.how-to-debug-jscript-in-microsoft-dynamics-crm-2011.aspx
or
How to debug jScript for Dynamics CRM?
I think there is a typo in the code:
show == true;
actually the code (assuming "=" instead of "==") will show always the tab if TextFieldName isn't empty, removing that line will show/hide the tab according to show parameter value
It seems to work when I run it but I'm not sure what you'd expect it to do so it might not be working the way you'd like it to. :)
function setVisibleTabSection(tabName, textFieldName, show) {
var tab = Xrm.Page.ui.tabs.get(tabName);
if(!tab) return;
if (!TextFieldName)
tab.setVisible(show);
else {
var section = Xrm.Page.data.entity.attributes.get(textFieldName).getValue();
if (section)
tab.setVisible(true);
}
}

Make ReSharper reformat code according to StyleCop rule SA1206: The 'static' keyword must come before the 'other' keyword in the element declaration

I suspect I should create a pattern in ReSharper / Options / Languages / C# / Formatting Style / Type Membership Layout for this. I am currently using the default pattern and I would like some help from someone who is good at them.
I want this to be WRONG:
public new static Age Empty {
get {
return empty;
}
set {
empty = value;
}
}
And this to be right:
public static new Age Empty {
get {
return empty;
}
set {
empty = value;
}
}
In other words, I want static to come before other keywords, like new. Currently ReSharper 5.1 does it the "wrong" way.
ReSharper now has the possibility to configure the arrangement of modifiers.
Open the ReSharper options and go to Code Editing | C# | Code Style. In the Modifiers section Modifiers order you can reorder the arrangement according to your needs (see ReSharper online help: Arranging Modifiers).
To satisfy StyleCop's rule SA1206 move the static modifier above the new modifier:
It is impossible.

Can I change the way ReSharper generates properties?

Is it possible to change the way that Resharper formats properties?
I don't like:
public string Foo
{
get
{
return bar;
}
set
{
bar = value;
}
}
I like:
public string Foo
{
get { return bar; }
set { bar = value; }
}
You sure can, just go to Resharper > Options > Languages > C# > Formatting Style
and tick "place simple property/indexer/event declaration on a single line"
Updated for Resharper 8.2:
Resharper > Options > Code Editing > C# > Formatting Style > Line Breaks and Wrapping > Other > Place simple property/indexer/event declaration on single line
If you're using the code expansion template to produce a property, you can update the template in the ReSharper Settings at: ReSharper >> Live Templates >> Predefined Templates >> C# >> prop.
If you're referring to the code produced by refactoring commands, I don't believe it's configurable. However, you may be able to run Code Cleanup and have it reformat.

Resources