From 27f1e11aafadcd4a35cc22209e1c2564438d6a68 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Wed, 27 Oct 2010 07:51:44 +0200 Subject: [PATCH] VB: Added My-namespace support for WPF --- .../templates/project/VBNet/MyWpfExtension.vb | 120 ++++++++++++++++++ .../project/VBNet/WPFApplication.xpt | 1 + .../project/VBNet/WPFAssemblyInfo.vb | 2 +- .../VBNet/WPFNavigationApplication.xpt | 1 + .../Project/Src/MyNamespaceBuilder.cs | 3 + 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 data/templates/project/VBNet/MyWpfExtension.vb diff --git a/data/templates/project/VBNet/MyWpfExtension.vb b/data/templates/project/VBNet/MyWpfExtension.vb new file mode 100644 index 0000000000..becbd52184 --- /dev/null +++ b/data/templates/project/VBNet/MyWpfExtension.vb @@ -0,0 +1,120 @@ +Namespace My + + + Module MyWpfExtension + Private m_computer As MyComputer + Private m_user As MyUser + Private m_windows As MyWindows + Private m_log As MyLog + + ''' + ''' Returns the application object for the running application + ''' + Friend ReadOnly Property Application() As MyApplication + Get + Return CType(Global.System.Windows.Application.Current, MyApplication) + End Get + End Property + + ''' + ''' Returns information about the host computer. + ''' + Friend ReadOnly Property Computer() As Global.Microsoft.VisualBasic.Devices.Computer + Get + If m_computer Is Nothing Then + m_computer = New MyComputer() + End If + Return m_computer + End Get + End Property + + ''' + ''' Returns information for the current user. If you wish to run the application with the current + ''' Windows user credentials, call My.User.InitializeWithWindowsUser(). + ''' + Friend ReadOnly Property User() As Global.Microsoft.VisualBasic.ApplicationServices.User + Get + If m_user Is Nothing Then + m_user = New MyUser() + End If + Return m_user + End Get + End Property + + ''' + ''' Returns the application log. The listeners can be configured by the application's configuration file. + ''' + Friend ReadOnly Property Log() As Global.Microsoft.VisualBasic.Logging.Log + Get + If m_log Is Nothing Then + m_log = New MyLog() + End If + Return m_log + End Get + End Property + + ''' + ''' Returns the collection of Windows defined in the project. + ''' + Friend ReadOnly Property Windows() As MyWindows + + Get + If m_windows Is Nothing Then + m_windows = New MyWindows() + End If + Return m_windows + End Get + End Property + + + Friend NotInheritable Class MyWindows + + Private Shared Function Create__Instance__(Of T As {New, Global.System.Windows.Window})(ByVal Instance As T) As T + If Instance Is Nothing Then + If m_WindowBeingCreated IsNot Nothing Then + If m_WindowBeingCreated.ContainsKey(GetType(T)) = True Then + Throw New Global.System.InvalidOperationException("The window cannot be accessed via My.Windows from the Window constructor.") + End If + Else + m_WindowBeingCreated = New Global.System.Collections.Hashtable() + End If + m_WindowBeingCreated.Add(GetType(T), Nothing) + Return New T() + m_WindowBeingCreated.Remove(GetType(T)) + Else + Return Instance + End If + End Function + + + Private Sub Dispose__Instance__(Of T As Global.System.Windows.Window)(ByRef instance As T) + instance = Nothing + End Sub + + Private Shared m_WindowBeingCreated As Global.System.Collections.Hashtable + End Class + End Module +End Namespace + +Partial Class MyComputer + Inherits Global.Microsoft.VisualBasic.Devices.Computer +End Class + +Partial Class MyUser + Inherits Global.Microsoft.VisualBasic.ApplicationServices.User +End Class + +Partial Class MyLog + Inherits Global.Microsoft.VisualBasic.Logging.Log +End Class + +Partial Class MyApplication + Inherits Global.System.Windows.Application + + Friend ReadOnly Property Info() As Global.Microsoft.VisualBasic.ApplicationServices.AssemblyInfo + + Get + Return New Global.Microsoft.VisualBasic.ApplicationServices.AssemblyInfo(Global.System.Reflection.Assembly.GetExecutingAssembly()) + End Get + End Property +End Class \ No newline at end of file diff --git a/data/templates/project/VBNet/WPFApplication.xpt b/data/templates/project/VBNet/WPFApplication.xpt index d4f3eb6ce9..46d09d08a3 100644 --- a/data/templates/project/VBNet/WPFApplication.xpt +++ b/data/templates/project/VBNet/WPFApplication.xpt @@ -97,6 +97,7 @@ Namespace ${StandardNamespace} End Namespace]]> + diff --git a/data/templates/project/VBNet/WPFAssemblyInfo.vb b/data/templates/project/VBNet/WPFAssemblyInfo.vb index 3326f00046..1943cba97e 100644 --- a/data/templates/project/VBNet/WPFAssemblyInfo.vb +++ b/data/templates/project/VBNet/WPFAssemblyInfo.vb @@ -14,7 +14,7 @@ Imports System.Windows ' the NeutralResourceLanguage attribute below. Update the "en-US" in ' the line below to match the UICulture setting in the project file. - +' ' themeDictionaryLocation = where theme specific resource dictionaries are located ' (used if a resource is not found in the page, diff --git a/data/templates/project/VBNet/WPFNavigationApplication.xpt b/data/templates/project/VBNet/WPFNavigationApplication.xpt index 596efe3da4..9c9b8b05c1 100644 --- a/data/templates/project/VBNet/WPFNavigationApplication.xpt +++ b/data/templates/project/VBNet/WPFNavigationApplication.xpt @@ -101,6 +101,7 @@ Namespace ${StandardNamespace} End Namespace]]> + diff --git a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/MyNamespaceBuilder.cs b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/MyNamespaceBuilder.cs index b7e23e8683..a703211c44 100644 --- a/src/AddIns/BackendBindings/VBNetBinding/Project/Src/MyNamespaceBuilder.cs +++ b/src/AddIns/BackendBindings/VBNetBinding/Project/Src/MyNamespaceBuilder.cs @@ -15,6 +15,9 @@ namespace ICSharpCode.VBNetBinding /// public static void BuildNamespace(VBNetProject project, IProjectContent pc) { + if ("custom".Equals(project.GetEvaluatedProperty("MyType"), StringComparison.OrdinalIgnoreCase)) + return; + ICompilationUnit cu = new DefaultCompilationUnit(pc); //cu.FileName = "GeneratedMyNamespace.vb"; // leave FileName null - fixes SD2-854 string ns;