Added toolbox panel

This commit is contained in:
2014-10-11 10:33:59 +03:00
parent ba0101374e
commit ed320b455c
4 changed files with 294 additions and 37 deletions

View 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>

View 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
}
}