mirror of
				https://github.com/chibicitiberiu/rainmeter-studio.git
				synced 2024-02-24 04:33:31 +00:00 
			
		
		
		
	Added toolbox panel
This commit is contained in:
		@@ -143,7 +143,7 @@
 | 
				
			|||||||
        <GridSplitter Grid.Row="2" Grid.Column="1"
 | 
					        <GridSplitter Grid.Row="2" Grid.Column="1"
 | 
				
			||||||
                      HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
 | 
					                      HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <!-- Document panel -->
 | 
					        <!-- Document area -->
 | 
				
			||||||
        <ad:DockingManager 
 | 
					        <ad:DockingManager 
 | 
				
			||||||
            x:Name="dockingManager"
 | 
					            x:Name="dockingManager"
 | 
				
			||||||
            Grid.Row="2">
 | 
					            Grid.Row="2">
 | 
				
			||||||
@@ -152,7 +152,9 @@
 | 
				
			|||||||
                <adlayout:LayoutRoot.LeftSide>
 | 
					                <adlayout:LayoutRoot.LeftSide>
 | 
				
			||||||
                    <adlayout:LayoutAnchorSide>
 | 
					                    <adlayout:LayoutAnchorSide>
 | 
				
			||||||
                        <adlayout:LayoutAnchorGroup>
 | 
					                        <adlayout:LayoutAnchorGroup>
 | 
				
			||||||
                            <adlayout:LayoutAnchorable Title="Toolbox" />
 | 
					                            <adlayout:LayoutAnchorable Title="Toolbox">
 | 
				
			||||||
 | 
					                                <uiPanels:ToolboxPanel x:Name="toolboxPanel" />
 | 
				
			||||||
 | 
					                            </adlayout:LayoutAnchorable>
 | 
				
			||||||
                        </adlayout:LayoutAnchorGroup>
 | 
					                        </adlayout:LayoutAnchorGroup>
 | 
				
			||||||
                    </adlayout:LayoutAnchorSide>
 | 
					                    </adlayout:LayoutAnchorSide>
 | 
				
			||||||
                </adlayout:LayoutRoot.LeftSide>
 | 
					                </adlayout:LayoutRoot.LeftSide>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -14,6 +14,7 @@ using System.Windows.Navigation;
 | 
				
			|||||||
using System.Windows.Shapes;
 | 
					using System.Windows.Shapes;
 | 
				
			||||||
using RainmeterStudio.Business;
 | 
					using RainmeterStudio.Business;
 | 
				
			||||||
using RainmeterStudio.Core.Editor;
 | 
					using RainmeterStudio.Core.Editor;
 | 
				
			||||||
 | 
					using RainmeterStudio.Core.Editor.Features;
 | 
				
			||||||
using RainmeterStudio.Core.Model;
 | 
					using RainmeterStudio.Core.Model;
 | 
				
			||||||
using RainmeterStudio.Core.Model.Events;
 | 
					using RainmeterStudio.Core.Model.Events;
 | 
				
			||||||
using RainmeterStudio.UI.Controller;
 | 
					using RainmeterStudio.UI.Controller;
 | 
				
			||||||
@@ -27,13 +28,30 @@ namespace RainmeterStudio.UI
 | 
				
			|||||||
    /// </summary>
 | 
					    /// </summary>
 | 
				
			||||||
    public partial class MainWindow : Window
 | 
					    public partial class MainWindow : Window
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Gets or sets the document controller
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
        public DocumentController DocumentController { get; set; }
 | 
					        public DocumentController DocumentController { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Gets or sets the project controller
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
        public ProjectController ProjectController { get; set; }
 | 
					        public ProjectController ProjectController { get; set; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Gets the project panel
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
        public ProjectPanel ProjectPanel { get { return projectPanel; } }
 | 
					        public ProjectPanel ProjectPanel { get { return projectPanel; } }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private Dictionary<LayoutDocument, IDocumentEditor> _openedDocuments = new Dictionary<LayoutDocument, IDocumentEditor>();
 | 
					        private Dictionary<LayoutDocument, IDocumentEditor> _openedDocuments = new Dictionary<LayoutDocument, IDocumentEditor>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #region Constructor
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Initializes the main window
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        /// <param name="projCtrl">The project controller</param>
 | 
				
			||||||
 | 
					        /// <param name="docCtrl">The document controller</param>
 | 
				
			||||||
        public MainWindow(ProjectController projCtrl, DocumentController docCtrl)
 | 
					        public MainWindow(ProjectController projCtrl, DocumentController docCtrl)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            InitializeComponent();
 | 
					            InitializeComponent();
 | 
				
			||||||
@@ -52,35 +70,62 @@ namespace RainmeterStudio.UI
 | 
				
			|||||||
            this.AddKeyBinding(ProjectController.ProjectOpenCommand);
 | 
					            this.AddKeyBinding(ProjectController.ProjectOpenCommand);
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
            // Subscribe to events
 | 
					            // Subscribe to events
 | 
				
			||||||
            DocumentController.DocumentOpened += documentController_DocumentOpened;
 | 
					            DocumentController.DocumentOpened += DocumentController_DocumentOpened;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Initialize panels
 | 
					            // Initialize panels
 | 
				
			||||||
            projectPanel.ProjectController = ProjectController;
 | 
					            projectPanel.ProjectController = ProjectController;
 | 
				
			||||||
            projectPanel.DocumentController = DocumentController;
 | 
					            projectPanel.DocumentController = DocumentController;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        void documentController_DocumentOpened(object sender, DocumentOpenedEventArgs e)
 | 
					        #endregion
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // Create a new panel
 | 
					 | 
				
			||||||
            LayoutDocument document = new LayoutDocument();
 | 
					 | 
				
			||||||
            _openedDocuments.Add(document, e.Editor);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            document.Content = e.Editor.EditorUI;
 | 
					        #region Document opened event handler
 | 
				
			||||||
            document.Closing += document_Closing;
 | 
					
 | 
				
			||||||
            document.Closed += document_Closed;
 | 
					        void DocumentController_DocumentOpened(object sender, DocumentOpenedEventArgs e)
 | 
				
			||||||
            document.Title = GetDocumentTitle(e.Document);
 | 
					 | 
				
			||||||
            document.IsActiveChanged += new EventHandler((sender2, e2) =>
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            OpenDocument(e.Editor);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #region Document events
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        void Document_IsActiveChanged(object sender, EventArgs e)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            LayoutDocument document = (LayoutDocument)sender;
 | 
				
			||||||
 | 
					            IDocumentEditor editor = _openedDocuments[document];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (document.IsActive)
 | 
					            if (document.IsActive)
 | 
				
			||||||
                    DocumentController.ActiveDocumentEditor = e.Editor;
 | 
					            {
 | 
				
			||||||
            });
 | 
					                // Set active editor in controller
 | 
				
			||||||
 | 
					                DocumentController.ActiveDocumentEditor = editor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            documentPane.Children.Add(document);
 | 
					                // Set up toolbox
 | 
				
			||||||
            documentPane.SelectedContentIndex = documentPane.IndexOf(document);
 | 
					                SetUpToolbox(editor);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                // Disable drop, so that we don't drop invalid items in an editor
 | 
				
			||||||
 | 
					                editor.EditorUI.AllowDrop = false;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            e.Document.PropertyChanged += Document_PropertyChanged;
 | 
					        void Document_Closed(object sender, EventArgs e)
 | 
				
			||||||
            if (e.Document.Reference != null)
 | 
					        {
 | 
				
			||||||
                e.Document.Reference.PropertyChanged += Reference_PropertyChanged;
 | 
					            CloseDocument((LayoutDocument)sender);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        void Document_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            // Get editor
 | 
				
			||||||
 | 
					            var document = (LayoutDocument)sender;
 | 
				
			||||||
 | 
					            var editor = _openedDocuments[document];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Try to close active document
 | 
				
			||||||
 | 
					            if (!DocumentController.Close(editor))
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                e.Cancel = true;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void Document_PropertyChanged(object sender, PropertyChangedEventArgs e)
 | 
					        private void Document_PropertyChanged(object sender, PropertyChangedEventArgs e)
 | 
				
			||||||
@@ -125,6 +170,23 @@ namespace RainmeterStudio.UI
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #region Window events
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            // Try to close
 | 
				
			||||||
 | 
					            if (!DocumentController.CloseAll())
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                e.Cancel = true;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #endregion
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #region Helper methods
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private string GetDocumentTitle(IDocument document)
 | 
					        private string GetDocumentTitle(IDocument document)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            string documentName;
 | 
					            string documentName;
 | 
				
			||||||
@@ -152,31 +214,52 @@ namespace RainmeterStudio.UI
 | 
				
			|||||||
            return documentName;
 | 
					            return documentName;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        void document_Closed(object sender, EventArgs e)
 | 
					        private LayoutDocument OpenDocument(IDocumentEditor editor)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var layoutDocument = (LayoutDocument)sender;
 | 
					            // Create document
 | 
				
			||||||
 | 
					            LayoutDocument document = new LayoutDocument();
 | 
				
			||||||
 | 
					            document.Content = editor.EditorUI;
 | 
				
			||||||
 | 
					            document.Title = GetDocumentTitle(editor.AttachedDocument);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Set up events
 | 
				
			||||||
 | 
					            document.Closing += Document_Closing;
 | 
				
			||||||
 | 
					            document.Closed += Document_Closed;
 | 
				
			||||||
 | 
					            document.IsActiveChanged += Document_IsActiveChanged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Add to dictionary
 | 
				
			||||||
 | 
					            _openedDocuments.Add(document, editor);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Add to layout
 | 
				
			||||||
 | 
					            documentPane.Children.Add(document);
 | 
				
			||||||
 | 
					            documentPane.SelectedContentIndex = documentPane.IndexOf(document);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Subscribe to document events
 | 
				
			||||||
 | 
					            editor.AttachedDocument.PropertyChanged += Document_PropertyChanged;
 | 
				
			||||||
 | 
					            if (editor.AttachedDocument.Reference != null)
 | 
				
			||||||
 | 
					                editor.AttachedDocument.Reference.PropertyChanged += Reference_PropertyChanged;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            return document;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        void document_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 | 
					        private void CloseDocument(LayoutDocument document)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            // Get editor
 | 
					            _openedDocuments.Remove(document);
 | 
				
			||||||
            var document = (LayoutDocument)sender;
 | 
					        }
 | 
				
			||||||
            var editor = _openedDocuments[document];
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Try to close active document
 | 
					        private void SetUpToolbox(IDocumentEditor editor)
 | 
				
			||||||
            if (!DocumentController.Close(editor))
 | 
					 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
                e.Cancel = true;
 | 
					            var toolboxProvider = editor as IToolboxProvider;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Set toolbar panel
 | 
				
			||||||
 | 
					            toolboxPanel.ItemsSource = toolboxProvider;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // Enable 'allow drop'
 | 
				
			||||||
 | 
					            if (toolboxProvider != null)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                editor.EditorUI.AllowDrop = true;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 | 
					        #endregion
 | 
				
			||||||
        {
 | 
					 | 
				
			||||||
            // Try to close
 | 
					 | 
				
			||||||
            if (!DocumentController.CloseAll())
 | 
					 | 
				
			||||||
            {
 | 
					 | 
				
			||||||
                e.Cancel = true;
 | 
					 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
							
								
								
									
										63
									
								
								RainmeterStudio/UI/Panels/ToolboxPanel.xaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										63
									
								
								RainmeterStudio/UI/Panels/ToolboxPanel.xaml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,63 @@
 | 
				
			|||||||
 | 
					<UserControl x:Class="RainmeterStudio.UI.Panels.ToolboxPanel"
 | 
				
			||||||
 | 
					             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
 | 
				
			||||||
 | 
					             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
 | 
				
			||||||
 | 
					             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
 | 
				
			||||||
 | 
					             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
 | 
				
			||||||
 | 
					             mc:Ignorable="d" 
 | 
				
			||||||
 | 
					             d:DesignHeight="300" d:DesignWidth="300">
 | 
				
			||||||
 | 
					    <UserControl.Resources>
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        <Style x:Key="ToolboxListViewStyle" TargetType="ListView">
 | 
				
			||||||
 | 
					            <Style.Triggers>
 | 
				
			||||||
 | 
					                <Trigger Property="HasItems" Value="False">
 | 
				
			||||||
 | 
					                    <Setter Property="Template">
 | 
				
			||||||
 | 
					                        <Setter.Value>
 | 
				
			||||||
 | 
					                            <ControlTemplate TargetType="ListView">
 | 
				
			||||||
 | 
					                                <Grid>
 | 
				
			||||||
 | 
					                                    <TextBlock TextAlignment="Center"
 | 
				
			||||||
 | 
					                                               HorizontalAlignment="Center"
 | 
				
			||||||
 | 
					                                               VerticalAlignment="Center"
 | 
				
			||||||
 | 
					                                               TextWrapping="Wrap" 
 | 
				
			||||||
 | 
					                                               Text="There are no toolbox items available for the active document." />
 | 
				
			||||||
 | 
					                                </Grid>
 | 
				
			||||||
 | 
					                            </ControlTemplate>
 | 
				
			||||||
 | 
					                        </Setter.Value>
 | 
				
			||||||
 | 
					                    </Setter>
 | 
				
			||||||
 | 
					                </Trigger>
 | 
				
			||||||
 | 
					            </Style.Triggers>
 | 
				
			||||||
 | 
					        </Style>
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    </UserControl.Resources>
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    <Grid>
 | 
				
			||||||
 | 
					        <Grid.RowDefinitions>
 | 
				
			||||||
 | 
					            <RowDefinition Height="Auto" />
 | 
				
			||||||
 | 
					            <RowDefinition />
 | 
				
			||||||
 | 
					        </Grid.RowDefinitions>
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        <DockPanel Grid.Row="0" LastChildFill="True">
 | 
				
			||||||
 | 
					            <Button DockPanel.Dock="Right">Search</Button>
 | 
				
			||||||
 | 
					            <TextBox Name="searchTextBox"/>
 | 
				
			||||||
 | 
					        </DockPanel>
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        <ListView Name="listItems"
 | 
				
			||||||
 | 
					                  Style="{StaticResource ToolboxListViewStyle}"
 | 
				
			||||||
 | 
					                  Grid.Row="2">
 | 
				
			||||||
 | 
					            <ListView.ItemContainerStyle>
 | 
				
			||||||
 | 
					                <Style TargetType="ListViewItem">
 | 
				
			||||||
 | 
					                    <EventSetter Event="PreviewMouseMove" Handler="Item_PreviewMouseMove" />
 | 
				
			||||||
 | 
					                    <EventSetter Event="PreviewMouseDoubleClick" Handler="Item_PreviewMouseDoubleClick" />
 | 
				
			||||||
 | 
					                </Style>
 | 
				
			||||||
 | 
					            </ListView.ItemContainerStyle>
 | 
				
			||||||
 | 
					            <ListView.ItemTemplate>
 | 
				
			||||||
 | 
					                <DataTemplate>
 | 
				
			||||||
 | 
					                    <DockPanel LastChildFill="True" ToolTip="{Binding ToolTip}">
 | 
				
			||||||
 | 
					                        <Image Width="16" Height="16" Source="{Binding Icon}" DockPanel.Dock="Left" />
 | 
				
			||||||
 | 
					                        <TextBlock Text="{Binding DisplayText}" />
 | 
				
			||||||
 | 
					                    </DockPanel>
 | 
				
			||||||
 | 
					                </DataTemplate>
 | 
				
			||||||
 | 
					            </ListView.ItemTemplate>
 | 
				
			||||||
 | 
					        </ListView>
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					    </Grid>
 | 
				
			||||||
 | 
					</UserControl>
 | 
				
			||||||
							
								
								
									
										109
									
								
								RainmeterStudio/UI/Panels/ToolboxPanel.xaml.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										109
									
								
								RainmeterStudio/UI/Panels/ToolboxPanel.xaml.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,109 @@
 | 
				
			|||||||
 | 
					using System;
 | 
				
			||||||
 | 
					using System.Collections.Generic;
 | 
				
			||||||
 | 
					using System.Linq;
 | 
				
			||||||
 | 
					using System.Text;
 | 
				
			||||||
 | 
					using System.Threading.Tasks;
 | 
				
			||||||
 | 
					using System.Windows;
 | 
				
			||||||
 | 
					using System.Windows.Controls;
 | 
				
			||||||
 | 
					using System.Windows.Data;
 | 
				
			||||||
 | 
					using System.Windows.Documents;
 | 
				
			||||||
 | 
					using System.Windows.Input;
 | 
				
			||||||
 | 
					using System.Windows.Media;
 | 
				
			||||||
 | 
					using System.Windows.Media.Imaging;
 | 
				
			||||||
 | 
					using System.Windows.Navigation;
 | 
				
			||||||
 | 
					using System.Windows.Shapes;
 | 
				
			||||||
 | 
					using RainmeterStudio.Core.Editor.Features;
 | 
				
			||||||
 | 
					using RainmeterStudio.UI.ViewModel;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					namespace RainmeterStudio.UI.Panels
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    /// <summary>
 | 
				
			||||||
 | 
					    /// Interaction logic for ToolboxPanel.xaml
 | 
				
			||||||
 | 
					    /// </summary>
 | 
				
			||||||
 | 
					    public partial class ToolboxPanel : UserControl
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        private IToolboxProvider _itemsSource = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Gets or sets the items source
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        public IToolboxProvider ItemsSource
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            get
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                return _itemsSource;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            set
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                // Unsubscribe from old items source
 | 
				
			||||||
 | 
					                if (_itemsSource != null)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    _itemsSource.ToolboxItemsChanged -= ItemsSource_ToolboxItemsChanged;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // Change items source
 | 
				
			||||||
 | 
					                _itemsSource = value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // Subscribe to new items source
 | 
				
			||||||
 | 
					                if (_itemsSource != null)
 | 
				
			||||||
 | 
					                {
 | 
				
			||||||
 | 
					                    value.ToolboxItemsChanged += ItemsSource_ToolboxItemsChanged;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                // Refresh items
 | 
				
			||||||
 | 
					                RefreshItems();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        /// <summary>
 | 
				
			||||||
 | 
					        /// Initializes the toolbox panel
 | 
				
			||||||
 | 
					        /// </summary>
 | 
				
			||||||
 | 
					        public ToolboxPanel()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            InitializeComponent();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        private void RefreshItems()
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if (_itemsSource == null)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                listItems.ItemsSource = Enumerable.Empty<ToolboxItemViewModel>();
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                listItems.ItemsSource = _itemsSource.ToolboxItems.Select(item => new ToolboxItemViewModel(item));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        void ItemsSource_ToolboxItemsChanged(object sender, EventArgs e)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            RefreshItems();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #region Adding to editor (drag and double clicking)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        void Item_PreviewMouseMove(object sender, MouseEventArgs e)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            var treeViewItem = sender as TreeViewItem;
 | 
				
			||||||
 | 
					            var item = treeViewItem.Header as ToolboxItem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (item != null && e.LeftButton == MouseButtonState.Pressed)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                DragDrop.DoDragDrop(this, item, DragDropEffects.Move);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        void Item_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            var treeViewItem = sender as TreeViewItem;
 | 
				
			||||||
 | 
					            var item = treeViewItem.Header as ToolboxItem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (item != null)
 | 
				
			||||||
 | 
					            {
 | 
				
			||||||
 | 
					                ItemsSource.ToolboxItemDrop(item);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        #endregion
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user