SDK 9.0. Where the IActionHandler is?

198 views
Skip to first unread message

Dmitry Dolotovskikh

unread,
Dec 9, 2014, 4:12:22 AM12/9/14
to resharpe...@googlegroups.com
Hi

I can't find it namespace.

Thanks
Dmitry

Matt Ellis

unread,
Dec 9, 2014, 4:51:42 AM12/9/14
to resharpe...@googlegroups.com
IActionHandler has been replaced by IExecutableAction. You should be able to just change the interface and recompile (hopefully). The action subsystem has had an overhaul with this release. One gotcha is that each action requires a UNIQUE ID. Unfortunately, there is currently no guidance about making sure the ID is unique across all extensions - I think we're going to have to do something to address this with 9.1

Dmitry Dolotovskikh

unread,
Dec 9, 2014, 5:44:31 AM12/9/14
to resharpe...@googlegroups.com
In 8.2 ActionHandler attribute required string parameter, but now is System.Type. What should I use for that

[ActionHandler("SPCAFContrib.ReSharper.About")]
public class AboutAction : IExecutableAction
{
}

Matt Ellis

unread,
Dec 9, 2014, 6:53:11 AM12/9/14
to resharpe...@googlegroups.com
You need to use ActionAttribute, not the ActionHandler attribute. The ActionAttribute defines a new action, and the default handler for it. ActionHandler allows overriding a particular Action, which is passed in as a type.

Dmitry Dolotovskikh

unread,
Dec 30, 2014, 7:37:38 AM12/30/14
to resharpe...@googlegroups.com
Hi

1. I have in Assembly.cs

[assembly: ActionsXml("SPCAFContrib.ReSharper.Actions.xml")]

2. Actions.xml is defined as embedded resource 

<?xml version="1.0" encoding="utf-8" ?>
<actions>
 
<insert group-id="ReSharper" position="last">
   
<action-group id="SPCAFContrib.ReSharper" text="SPCAF Contrib">
     
<action id="SPCAFContrib.ReSharper.About" text="About SPCAF Contrib ReSharper Plugin"/>
     
<!-- to break up elements use <separator/> -->
   
</action-group>
 
</insert>
</actions>

3. Action handler is defined as 

[Action("SPCAFContrib.ReSharper.About", Id = 10101)]
   
public class AboutAction : IExecutableAction
   
{
       
public bool Update(IDataContext context, ActionPresentation presentation, DelegateUpdate nextUpdate)
       
{
           
// return true or false to enable/disable this action
           
return true;
       
}


       
public void Execute(IDataContext context, DelegateExecute nextExecute)
       
{
           
MessageBox.Show(
             
"Essential tool to ensure SharePoint code quality.\r\nVisit our site http://spcafcontrib.codeplex.com",
             
"About SPCAF Contrib ReSharper Plugin",
             
MessageBoxButtons.OK,
             
MessageBoxIcon.Information);
       
}
   
}


But there is no custom item in the ReSharper menu.
What I should do next/more?

Thanks

Matt Ellis

unread,
Jan 2, 2015, 6:51:13 AM1/2/15
to resharpe...@googlegroups.com
Hi Dmitry. The actions.xml file is no longer used, and it can be removed. Instead, everything is defined in code.

Your class has defined an action, but hasn't declared where it should be used. You can do this in two ways, directly on the action, or by including the action in a group defined elsewhere.

To declare it directly on the action, your action class should implement one of IInsertAfter, IInsertBefore, IInsertLast or IInsertFirst. These are generic interfaces, and take a type that must implement IAction as a type parameter, e.g. IInsertFirst<ToolsMenu> will insert the menu as the first item in the Tools menu (if multiple items are inserted "first", then order is unspecified). These groups should be attributed with [ActionGroup(…)]. Or you can use IInsertAfter or IInsertBefore. These take a menu group type, and an anchor, to be inserted before/after, e.g. IInsertAfter<ToolsMenu, ValidateRegularExpressionStandaloneAction>.

Alternatively, you can not specify the insertion point on an action (e.g. you want to use the action in multiple places), and include it in the declaration of a group. In this case, you define an action class that lists the actions it wants in its group as constructor parameters. Order is important here. E.g. 

// Group, inserted at the end of the Tools menu
public class MyGroupMenu : IAction, IInsertLast<ToolsMenu>
{
  public MyGroupMenu(MyAction1 action1, MyAction2 action2)
  {
    // Do nothing, this is a group, doesn't need to do anything else
  }
}

Regards
Matt

Dmitry Dolotovskikh

unread,
Jan 2, 2015, 5:09:48 PM1/2/15
to resharpe...@googlegroups.com
Hi Matt

Thanks for support on the weekend.

I started from first approached and implemented my action as

[Action("About", Id = 10102)]
   
public class AboutAction : IExecutableAction, IInsertAfter<HelpMenu, ShowHelpAction>

   
{
       
public bool Update(IDataContext context, ActionPresentation presentation, DelegateUpdate nextUpdate)
       
{
           
// return true or false to enable/disable this action
           
return true;
       
}


       
public void Execute(IDataContext context, DelegateExecute nextExecute)
       
{
           
MessageBox.Show(

             
"Essential tool to ensure SharePoint code quality.\r\nVisit our site http://docs.subpointsolutions.com/",

             
"About SPCAF Contrib ReSharper Plugin",
             
MessageBoxButtons.OK,
             
MessageBoxIcon.Information);
       
}
   
}

But after run the Help menu has not been affected with my About action.
How about Id? Is it value in the ActionAttribute 

[Action("About", Id = 10102)]

correct? I took it from the ceiling.

Next, I implemented my own action group and got the same  - nothing in help menu

    [ActionGroup("SPCAFContrib.ReSharper", ActionGroupInsertStyles.Submenu, Id = 10101, Text = "SPCAF Contrib")]
   
public class SPCAFContribMenuGroup : IAction, IInsertAfter<VsMainMenuGroup, HelpMenu>
    {
       
public SPCAFContribMenuGroup(AboutAction aboutAction)
       
{
       
}
   
}


Where am I wrong?

Matthew Ellis

unread,
Jan 2, 2015, 5:20:11 PM1/2/15
to resharpe...@googlegroups.com, resharpe...@googlegroups.com
Ah, there is something else - every time you change anything to do with action registration (id, text, location, etc), you’ll need to re-register the plugin. That is, reinstall it - actions are statically registered during installation.



--
You received this message because you are subscribed to the Google Groups "resharper-plugins" group.
To unsubscribe from this group and stop receiving emails from it, send an email to resharper-plug...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
Message has been deleted
0 new messages