Mini Kabibi Habibi
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Windows
Imports System.ComponentModel
Imports System.Diagnostics
Imports DevExpress.Xpf.Docking
Imports System.Windows.Input
Imports System.Collections.ObjectModel
Imports System.Collections.Specialized
Imports System.Windows.Data
Imports System.Windows.Media
Imports System.Windows.Media.Imaging
Imports Microsoft.Win32
Imports System.IO
Imports System.Windows.Controls
Imports DevExpress.Xpf.DemoBase.Helpers
Imports DevExpress.DemoData.Utils
Imports DevExpress.Xpf.DemoBase.Helpers.TextColorizer
Namespace DockingDemo.MVVM
Public Class VS2010DocumentViewModel
Inherits DocumentViewModel
Private privateCodeLanguageText As CodeLanguageText
Public Property CodeLanguageText() As CodeLanguageText
Get
Return privateCodeLanguageText
End Get
Private Set(ByVal value As CodeLanguageText)
privateCodeLanguageText = value
End Set
End Property
Private privateCodeLanguage As CodeLanguage
Public Property CodeLanguage() As CodeLanguage
Get
Return privateCodeLanguage
End Get
Private Set(ByVal value As CodeLanguage)
privateCodeLanguage = value
End Set
End Property
Protected Overrides ReadOnly Property TargetName() As String
Get
Return "DocumentHost"
End Get
End Property
Public Sub New(ByVal displayName As String)
MyBase.New(displayName)
End Sub
Public Sub New()
End Sub
Private Shared count As Integer = 0
Public Overrides Function Open() As Boolean
CodeLanguage = If(count Mod 2 = 0, CodeLanguage.XAML, CodeLanguage.CS)
count += 1
DisplayName = String.Format("File{0}.{1}", count, CodeLanguage.ToString().ToLower())
Glyph = New BitmapImage(New Uri("/DockingDemo;component/Images/VS2010Docking/FileCS_16x16.png", UriKind.Relative))
Description = If(CodeLanguage = CodeLanguage.XAML, "Windows Markup File", "Visual C# Source file")
Footer = String.Format("c:\...\DockingDemo\{0}", DisplayName)
Dim filename As String = "VS2010Docking." & CodeLanguage.ToString().ToLower()
CodeLanguageText = New CodeLanguageText(CodeLanguage, Function() GetCodeText(filename))
Return True
End Function
Private Function GetCodeText(ByVal name As String) As String
Dim [assembly] As System.Reflection.Assembly = GetType(VS2010DocumentViewModel).Assembly
Using stream As Stream = AssemblyHelper.GetEmbeddedResourceStream([assembly], DemoHelper.GetPath("Docs/", [assembly]) & name, True)
If stream Is Nothing Then
Return String.Empty
End If
Using reader As New StreamReader(stream)
Return reader.ReadToEnd()
End Using
End Using
End Function
End Class
Public Class VS2010MainWindowViewModel
Inherits MainWindowViewModel
Public Sub New()
End Sub
Protected Overrides Sub InitDefaultLayout()
OpenOrCloseWorkspace(_ToolboxViewModel)
OpenOrCloseWorkspace(_SolutionExplorerViewModel)
OpenOrCloseWorkspace(_PropertiesViewModel)
OpenOrCloseWorkspace(_ErrorListViewModel)
Dim document As New VS2010DocumentViewModel()
document.Open()
OpenOrCloseWorkspace(document, True)
End Sub
Protected Overrides Function GetDocumentViewModel() As DocumentViewModel
Return New VS2010DocumentViewModel()
End Function
Protected Overrides Function CreateFileCommands() As List(Of CommandViewModel)
Dim newCommand As New CommandViewModel("New", Nothing) With {.IsSubItem = True}
Dim newProject As New CommandViewModel("Project...", New RelayCommand(New Action(Of Object)(AddressOf OnNewFileExecuted))) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/NewProject_16x16.png"), .KeyGesture = KeyGestureHelper.GetKeyGesure(Key.N, ModifierKeys.Control Or ModifierKeys.Shift)}
Dim newWebSite As New CommandViewModel("Web Site...", Nothing) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/Solution Explorer.png"), .KeyGesture = KeyGestureHelper.GetKeyGesure(Key.N, ModifierKeys.Shift Or ModifierKeys.Alt), .IsEnabled = False}
Dim newFile As New CommandViewModel("File...", New RelayCommand(New Action(Of Object)(AddressOf OnNewFileExecuted))) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/File_16x16.png"), .KeyGesture = KeyGestureHelper.GetKeyGesure(Key.N, ModifierKeys.Control)}
newCommand.Commands = New List(Of CommandViewModel) (New CommandViewModel() {newProject, newFile})
Dim openCommand As New CommandViewModel("Open", Nothing) With {.IsSubItem = True}
Dim openProject As New CommandViewModel("Project/Solution...", Nothing) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/OpenSolution_16x16.png"), .KeyGesture = KeyGestureHelper.GetKeyGesure(Key.O, ModifierKeys.Control Or ModifierKeys.Shift), .IsEnabled = False}
Dim openWebSite As New CommandViewModel("Web Site...", Nothing) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/Solution Explorer.png"), .KeyGesture = KeyGestureHelper.GetKeyGesure(Key.O, ModifierKeys.Shift Or ModifierKeys.Alt), .IsEnabled = False}
Dim openFile As New CommandViewModel("File...", New RelayCommand(New Action(Of Object)(AddressOf OnNewFileExecuted))) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/OpenFile_16x16.png"), .KeyGesture = KeyGestureHelper.GetKeyGesure(Key.O, ModifierKeys.Control)}
openCommand.Commands = New List(Of CommandViewModel) (New CommandViewModel() {openProject, openFile})
Dim closeFile As New CommandViewModel("Close", New RelayCommand(New Action(Of Object)(AddressOf OnCloseFileExecuted)))
Dim closeSolution As New CommandViewModel("Close Solution", Nothing) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/CloseSolution_16x16.png")}
Dim save As New CommandViewModel("Save", Nothing) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/Save_16x16.png"), .KeyGesture = KeyGestureHelper.GetKeyGesure(Key.S, ModifierKeys.Control)}
Dim saveAll As New CommandViewModel("Save All", Nothing) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/SaveAll_16x16.png"), .KeyGesture = KeyGestureHelper.GetKeyGesure(Key.S, ModifierKeys.Control Or ModifierKeys.Shift)}
Dim recentFilesCommand As New CommandViewModel("Recent files", Nothing) With {.IsSubItem = True}
Dim recentProjectsCommand As New CommandViewModel("Recent projects and solutions", Nothing) With {.IsSubItem = True}
Return New List(Of CommandViewModel) (New CommandViewModel() {newCommand, openCommand, GetSeparator(), closeFile, closeSolution, GetSeparator(), save, saveAll, GetSeparator(), recentFilesCommand, recentProjectsCommand})
End Function
Private Function GetSeparator() As CommandViewModel
Return New CommandViewModel("", Nothing) With {.IsSeparator = True}
End Function
Protected Overrides Function CreateBars() As List(Of BarModel)
Dim bars As List(Of BarModel) = MyBase.CreateBars()
Dim model As New BarModel("Standard")
Dim commands = CreateToolbarCommands()
For Each cmd In commands
model.Commands.Add(cmd)
Next cmd
bars.Add(model)
Return bars
End Function
Private Function CreateToolbarCommands() As List(Of CommandViewModel)
Dim newProject As New CommandViewModel("New Project", New RelayCommand(New Action(Of Object)(AddressOf OnNewFileExecuted))) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/NewProject_16x16.png"), .KeyGesture = KeyGestureHelper.GetKeyGesure(Key.N, ModifierKeys.Control Or ModifierKeys.Shift)}
Dim newFile As New CommandViewModel("Add New Item", New RelayCommand(New Action(Of Object)(AddressOf OnNewFileExecuted))) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/File_16x16.png"), .KeyGesture = KeyGestureHelper.GetKeyGesure(Key.N, ModifierKeys.Control)}
Dim openFile As New CommandViewModel("Open File", New RelayCommand(New Action(Of Object)(AddressOf OnNewFileExecuted))) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/OpenFile_16x16.png"), .KeyGesture = KeyGestureHelper.GetKeyGesure(Key.O, ModifierKeys.Control)}
Dim save As New CommandViewModel("Save", Nothing) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/Save_16x16.png"), .KeyGesture = KeyGestureHelper.GetKeyGesure(Key.S, ModifierKeys.Control)}
Dim saveAll As New CommandViewModel("Save All", Nothing) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/SaveAll_16x16.png"), .KeyGesture = KeyGestureHelper.GetKeyGesure(Key.S, ModifierKeys.Control Or ModifierKeys.Shift)}
Dim cut As New CommandViewModel("Cut", Nothing) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/Cut_16x16.png"), .KeyGesture = KeyGestureHelper.GetKeyGesure(Key.S, ModifierKeys.Control Or ModifierKeys.Shift)}
Dim copy As New CommandViewModel("Copy", Nothing) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/Copy_16x16.png"), .KeyGesture = KeyGestureHelper.GetKeyGesure(Key.S, ModifierKeys.Control Or ModifierKeys.Shift)}
Dim paste As New CommandViewModel("Paste", Nothing) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/Paste_16x16.png"), .KeyGesture = KeyGestureHelper.GetKeyGesure(Key.S, ModifierKeys.Control Or ModifierKeys.Shift)}
Dim undo As New CommandViewModel("Undo", Nothing) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/Undo_16x16.png"), .KeyGesture = KeyGestureHelper.GetKeyGesure(Key.S, ModifierKeys.Control Or ModifierKeys.Shift)}
Dim redo As New CommandViewModel("Redo", Nothing) With {.Glyph = GlyphHelper.GetGlyph("/Images/VS2010Docking/Redo_16x16.png"), .KeyGesture = KeyGestureHelper.GetKeyGesure(Key.S, ModifierKeys.Control Or ModifierKeys.Shift)}
Return New List(Of CommandViewModel) (New CommandViewModel() {newProject, newFile, openFile, save, saveAll, GetSeparator(), cut, copy, paste, GetSeparator(), undo, redo})
End Function
Private Sub OnNewFileExecuted(ByVal param As Object)
Dim document As New VS2010DocumentViewModel()
document.Open()
OpenOrCloseWorkspace(document, True)
End Sub
Private Sub OnCloseFileExecuted(ByVal param As Object)
End Sub
Private NotInheritable Class KeyGestureHelper
Private Sub New()
End Sub
Public Shared Function GetKeyGesure(ByVal key As Key, ByVal modifiers As ModifierKeys) As KeyGesture
Dim k As New KeyGesture(key, modifiers)
Dim s As String = k.GetDisplayStringForCulture(System.Globalization.CultureInfo.InvariantCulture)
Return New KeyGesture(key, modifiers)
End Function
End Class
End Class
End Namespace