
Explorer的功能,在选中文件时的右键菜单中参加添加一个自定义命令,执行这个命令时查看选中文件的大小。好了,现在开始 *** 练起来。
首先启动Visual Studio创建一个Class library的项目。对于Vault 2014,.net
framework选择4.0。然后添加一些必要的引用,对于这个例子需要添加的引用如下,所有这些程序集都可以从Vault SDK中找到:
"Autodesk.Connectivity.WebServices.dll"
"Autodesk.Connectivity.Explorer.Extensibility.dll"
"Autodesk.Connectivity.Extensibility.Framework.dll"
Autodesk.DataManagement.Client.Framework.dll
Autodesk.DataManagement.Client.Framework..Vault.dll
对于这些引用,要把Copy Local改成false,因为Vault Explorer都已经包含这些程序集了。
下面来写点代码,对于Vault Explorer扩展程序,必须给程序集的AssemblyInfo中添加以下5个程序集属性,否则的话你的扩展程序将不能进行:
//必须包含下面5个程序集属性,否则不能运行
//[assembly: AssemblyCompany("Autodesk")]
//[assembly:AssemblyProduct("HelloWorldVaultExplorerExtension")]
//[assembly:AssemblyDescription("This is a sample application to extend vault explorer")]
//这里的GUID可以用Visual Studio的工具生成, 工具-->生成GUID
[assembly: Autodesk.Connectivity.Extensibility.Framework.ExtensionId("9FB25A13-242C-4BAE-93B5-B08D77B619CA")]
//对应Vault的版本号,对应Vault 2014,版本号为6.0
[assembly: Autodesk.Connectivity.Extensibility.Framework.ApiVersion("6.0")]
一般前面三个是通用的,VS都已经加好了你只要保证他们的值正确就行了,查看的方法岩皮就是,进入项目的属性,程粗野差序选项卡,上面有个程序集信息按钮:
为了让Vault Explorer认识这是Vault
explorer的插件,我们还需要定义一个.vcet.config文件,这个就是一个xml,内容如下,你可以从Vault
SDK中的帮助文件中找到模版,把内容改一下就行了。注意其中加粗的部分,格式的 “程序集名.类名, 程序集名”:
<?xml version="1.0" encoding="utf-8" ?>脊源
<configuration>
<connectivity.ExtensionSettings3>
<extension
interface="Autodesk.Connectivity.Explorer.Extensibility.IExplorerExtension, Autodesk.Connectivity.Explorer.Extensibility, Version=18.0.0.0, Culture=neutral, PublicKeyToken=aa20f34aedd220e1"
type="HelloWorldVaultExplorer.HelloWorld, HelloWorldVaultExplorer">
</extension>
</connectivity.ExtensionSettings3>
</configuration>
在Build时要把这个文件拷贝到输出目录:
然后添加一个public的类,并且实现IExplorerExtension接口, 下面是全部代码,包括注释:
using Autodesk.Connectivity.Explorer.Extensibility
using Autodesk.Connectivity.WebServices
using System
using System.Collections.Generic
using System.Linq
using System.Reflection
using System.Text
using System.Windows.Forms
using VDF = Autodesk.DataManagement.Client.Framework
之前都是用VBA来开发Office解决方案的,后来微软开发出了VSTO这个工具包来创建自定义的Office应用程序,使得开发Office应用程序更加简单,并且用VSTO来开发office应用程序可以使用Visual studio开发环境中的众多功能和CLR提供的内存管理,垃圾回收等功能。Office应用程序如Word,Excel和Outlook都是用非托管代码来写备型迟的, 而我们创建的VSTO工程使用的是托管代码,这时候就需要使用互 *** 作程序集来与Office应用程序里的非托管COM对象交互,然后主互 *** 作程序集(PIA)指的是官方发布的互 *** 作程序集,如果电脑中安装了PIA,当你添加对类库的引用时,那么Visual Studio会自动加载PIA,微软为Office应用程序提供了PIA,如EXcel PIA就是Microsof.Office.Interop.Excel.dll,其他应用程序也类似。当安装了Office产品后,PIA会自动安装在电脑的GAC目录里,每当创建一个VSTO解决方案, Visual Studio会自动为该解决方案加载合适的Office PIA引用和其他程序集
宿主项是表示Office对象模型入口点的类。应用程序外接程序租培使用Microsoft.Office.Tools.AddIn类为宿主仿李项,此宿主项提供对宿主应用程序和成员的对象模型的访问,可以通过宿主项添加数据绑定的能力和提供额外的事件来扩展本地Office文档。而创建一个Excel解决方案会创建4个Excel宿主项:Workbook,Sheet1,Sheet2和Sheet3.
在开始之前,先准备Visual Studio 2012 SDK安装好SDK后,进入VS。先新建一个Project,在闷伏裂“其它项目类型”那里找到“Visual Studio Package”厅培
接下来的对话框里,选“C#”,然后基本是下一步。在最后一步把那两个复选框取消,因为那个在这里没什么用处。最后就成功新建了个VS扩展的Project
三、初步改造
第一步我们给VS加上背景图。首先对Project添加WPF的程序集为引用,有四个,分别为“PresentationCore”、“PresentationFramework”、“System.Xaml”、“WindowsBase”。然后打开“XXXPackage.cs”(XXX一般为这个Project的名字)文件,代码如下:
usingMicrosoft.VisualStudio.Shell
usingMicrosoft.VisualStudio.Shell.Interop
using System
using System.Runtime.InteropServices
using System.Windows
using System.Windows.Controls
using System.Windows.Media
using System.Windows.Media.Imaging
namespace Moen.IDEBackground //命名空间自己修改回自己用的
{
[PackageRegistration(UseManagedResourcesOnly = true)]
[InstalledProductRegistration("#110", "#112","1.0", IconResourceID = 400)]
[Guid(GuidList.guidIDE_BackgroundPkgString)]
[ProvideAutoLoad(UIContextGuids.NoSolution)]
[ProvideAutoLoad(UIContextGuids.SolutionExists)]
public sealed class IDEBackgroundPackage :Package
{
protected override void Initialize()
{
base.Initialize()
Application.Current.MainWindow.Loaded += MainWindow_Loaded
}
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
var rWindow = (Window)sender
//加载图片
var rImageSource =BitmapFrame.Create(new Uri(@"G:\Picture\Pool\絵师100人展02_p109.png"/*图片路径*/),BitmapCreateOptions.None, BitmapCacheOption.OnLoad)
rImageSource.Freeze()
var rImageControl = new Image()
{
Source = rImageSource,
Stretch =Stretch.UniformToFill, //按比蚂闭例填充
HorizontalAlignment =HorizontalAlignment.Center, //水平方向中心对齐
VerticalAlignment =VerticalAlignment.Center, //垂直方向中心对齐
}
Grid.SetRowSpan(rImageControl, 4)
var rRootGrid =(Grid)rWindow.Template.FindName("RootGrid", rWindow)
rRootGrid.Children.Insert(0, rImageControl)
}
}
}
代码修改一下后,调试,这时就会编译扩展,然后启动实验用VS。(如果这是第一次启动实验用VS,可能要像刚安装完VS那样设置一下)接着你会看到角落处显现出那张背景图
(免调试进入实验用VS方法:开始菜单->Microsoft Visual Studio 2012->Microsoft Visual Studio SDK->Tools->Start Experimental Instance of Visual Studio 2012)
四、修改皮肤配色
为了方便,在实验用VS处进入“工具->扩展功能和更新程序”,选“在线”部分,然后在中间找到“Visual Studio 2012 Color ThemeEditor”并安装,重启实验用VS
重启后,进入“工具->CustomizeColors”。本例子已深色为基础,于是在左边“New Theme”处,直接在文本框输入一个皮肤名,然后点“Create”。这样就进入了皮肤配色表
首先把主界面那一大块灰色给除掉。找到“Environment→ EnvironmentBackgroundGradient”为开头的,统统都把不透明度设为0。然后点表左上角的“Save andApply Theme”,关掉所有页面。然后你就会看到背景啦
再继续,找到“Environment→ MainWindowActiveCaption”、“Environment→ MainWindowInactiveCaption”、“Environment→ CommandShelfBackgroundGradientXXX”、“Environment→ CommandShelfHighlightGradientXXX”、“Environment→ CommandBarGradientXXX”、“Environment→ CommandBarToolBarBorder”,都把不透明度设为0,
然后应用。上面那部分灰色的也没啦
至于这些是对应哪里的呢,可以通过那名字来确定,不过不准。要详细弄清楚很麻烦,要用反编译软件反要修改的控件的xaml文档,找到对应的画刷名。非常复杂,所以我这里提供我自己用的。在“Customize Colors”那里点“Import Theme”即可
五、编辑器
到目前为止,打开文件后,编辑器的背景还是黑的。接下来就是把这层黑的去掉
先打开“source.extension.vsixmanifest”文件,进入“Assets”选项卡,单击“New”按钮。在d出的对话框里,“Type”选“Microsoft.VisualStudio.MefComponent”,“Source”选“Aproject in current solution”,“Project”选当前的Project,目前应该就一个选项的。最后OK
接下来新建一个文件,这里就叫“EditorBackground.cs”
在输入代码前添加几个引用——System.ComponentModel.Composition、Microsoft.VisualStudio.CoreUtility、Microsoft.VisualStudio.Text.UI、Microsoft.VisualStudio.Text.UI.Wpf(后三个在“扩展”处找)
搞定后文件代码如下:
usingMicrosoft.VisualStudio.Text.Classification
usingMicrosoft.VisualStudio.Text.Editor
usingMicrosoft.VisualStudio.Utilities
usingSystem
usingSystem.ComponentModel.Composition
usingSystem.Windows
usingSystem.Windows.Controls
usingSystem.Windows.Media
using System.Windows.Threading
namespaceMoen.IDEBackground
{
[Export(typeof(IWpfTextViewCreationListener))]
[ContentType("Text")]
[ContentType("BuildOutput")]
[TextViewRole(PredefinedTextViewRoles.Document)]
class Listener : IWpfTextViewCreationListener
{
[Import]
IEditorFormatMapServiceEditorFormatMapService = null
public voidTextViewCreated(IWpfTextView rpTextView)
{
new EditorBackground(rpTextView)
//去掉断点边栏的背景
var rProperties =EditorFormatMapService.GetEditorFormatMap(rpTextView).GetProperties("IndicatorMargin")
rProperties["BackgroundColor"] = Colors.Transparent
rProperties["Background"]= Brushes.Transparent
}
}
class EditorBackground
{
IWpfTextView r_TextView
ContentControl r_Control
Grid r_ParentGrid
Canvas r_ViewStack
public EditorBackground(IWpfTextViewrpTextView)
{
r_TextView = rpTextView
r_Control = (ContentControl)r_TextView
r_TextView.Background =Brushes.Transparent
r_TextView.BackgroundBrushChanged+= TextView_BackgroundBrushChanged
r_TextView.Closed +=TextView_Closed
r_Control.Loaded +=TextView_Loaded
}
void MakeBackgroundTransparent()
{
r_TextView.Background =Brushes.Transparent
r_ViewStack.Background =Brushes.Transparent
r_ParentGrid.ClearValue(Grid.BackgroundProperty)
}
void TextView_Loaded(object sender,RoutedEventArgs e)
{
if (r_ParentGrid == null)
r_ParentGrid =(Grid)r_Control.Parent
if (r_ViewStack == null)
r_ViewStack =(Canvas)r_Control.Content
MakeBackgroundTransparent()
}
voidTextView_BackgroundBrushChanged(object sender, BackgroundBrushChangedEventArgse)
{
r_Control.Dispatcher.BeginInvoke(new Action(() =>
{
while (r_ParentGrid.Background!= null)
MakeBackgroundTransparent()
}), DispatcherPriority.Render)
}
void TextView_Closed(object sender,EventArgs e)
{
//清除委托,以防内存泄露
r_TextView.Closed -=TextView_Closed
r_TextView.BackgroundBrushChanged-= TextView_BackgroundBrushChanged
}
}
}
调试进入实验用VS,进入配色表,找到“Environment →EnvironmentBackground”,设置一个颜色值(我这里是#A0000000),作为编辑器的背景色。再找到“Environment → Window”设置为透明
六、结尾
基本的VS界面改造就是这么多了。不过有个棘手的问题——xaml编辑器和个别的编辑器(如HTML的)因为是承载在VS的一个子窗口上,而这个窗口的背景是黑色的。目前仍在研究中……
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)