您的位置:首页 > Web前端 > JavaScript

Visual Studio中View页面与Js页面用快捷键互相跳转

2015-10-15 17:54 621 查看
公司开发的项目使用的是Mvc框架,且Js与View页面是分开在两个文件夹下的,所以如果在View页面转到Js页面或者反过来都要先找到页面打开,很不方便.于是我做了一个VS外接程序可以很方便的用快捷键就直接互相跳转.

公司网站目录是如下图所示:View目录有Js分别在两个文件夹下:Views与Scripts



先打开VS新建项目:VS外接程序



因为我是用C#开发的所以选择Using C#



然后在下面这个图选中创建Tool这个选项



打开Connect.cs文件修改OnConnection中的一行

Command command = commands.AddNamedCommand2(_addInInstance, "MyAddinJSView", "JSView互跳", "JSView互跳", true, 59, ref contextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled, (int)vsCommandStyle.vsCommandStylePictAndText, vsCommandControlType.vsCommandControlTypeButton);


修改Exec方法如下

public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
{
handled = false;
if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
{
if (commandName == "MyAddinJSView.Connect.MyAddinJSView")
{
handled = true;
try
{
var file = _applicationObject.ActiveDocument;
string opFile = string.Empty;
if (file.FullName.ToLower().EndsWith(".cshtml"))
{
opFile = file.FullName.ToLower().Replace(@"\views\", @"\scripts\").Replace(".cshtml", ".js");
}
else if (file.FullName.ToLower().EndsWith(".js"))
{
opFile = file.FullName.ToLower().Replace(@"\scripts\", @"\views\").Replace(".js", ".cshtml");
}
if (!string.IsNullOrEmpty(opFile))
{
_applicationObject.ItemOperations.OpenFile(opFile);
}
}
catch (Exception)
{
}
return;
}
}
}


然后生成dll把MyAddinJSView.dll考到一个目录下

打开MyAddinJSView - For Testing.AddIn文件所在的目录,我的是在
C:\Users\Administrator\Documents\Visual Studio 2013\Addins下

修改 <Assembly>D:\LN\项目\MyAddinJSView\MyAddinJSView\bin\MyAddinJSView.dll</Assembly>为MyAddinJSView.dll的目录

这时候在打开vs在工具下面又一个js互跳的菜单了,如果没有则在工具>外接程序里面启用一下试试看

然后打开工具>自定义,点击下面的键盘按钮



在显示命令包含里面打myadd搜到我们新增的菜单设个快捷键并点击分配按钮就可以了

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: