diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2017-12-14 14:43:25 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2017-12-14 14:43:25 +0200 |
| commit | e352c4e5f742585e4feeb2ca3183bd4d0282a567 (patch) | |
| tree | e93b09e5fc5ed12e0e4ae9b6d2e268e3bc0c5d1e /Software/Visual_Studio/MachineStudio | |
| parent | b6615cec573616c9b6469c010982dda689ee3844 (diff) | |
| download | Tango-e352c4e5f742585e4feeb2ca3183bd4d0282a567.tar.gz Tango-e352c4e5f742585e4feeb2ca3183bd4d0282a567.zip | |
Implemented new MDI Container Control !
Diffstat (limited to 'Software/Visual_Studio/MachineStudio')
10 files changed, 288 insertions, 64 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Managers/RegisteredView.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Managers/RegisteredView.cs index 00c7d341a..fc9051edb 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Managers/RegisteredView.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Managers/RegisteredView.cs @@ -1,21 +1,25 @@ -using System; +using MaterialDesignThemes.Wpf; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using Tango.Core.Commands; +using Tango.MachineStudio.Common.Controls; namespace Tango.MachineStudio.DB.Managers { - public class RegisteredView + public class RegisteredView : MdiChild { - public String Header { get; set; } - public FrameworkElement View { get; set; } + private static Random rnd = new Random(); + public RelayCommand AddCommand { get; set; } public RegisteredView(String header, FrameworkElement view, Action action) { + Location = new Point(rnd.Next(30, 200), rnd.Next(30, 200)); + Icon = PackIconKind.Table; Header = header; View = view; diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/MainDBView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/MainDBView.xaml index 5ba51fea8..c7c636d53 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/MainDBView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.DB/Views/MainDBView.xaml @@ -9,6 +9,7 @@ xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:managers="clr-namespace:Tango.MachineStudio.DB.Managers" + xmlns:commonControls="clr-namespace:Tango.MachineStudio.Common.Controls;assembly=Tango.MachineStudio.Common" xmlns:local="clr-namespace:Tango.MachineStudio.DB.Views" mc:Ignorable="d" d:DesignHeight="720" d:DesignWidth="1270" Background="White" DataContext="{Binding MainViewVM, Source={StaticResource Locator}}"> @@ -44,9 +45,8 @@ <Grid.Background> <ImageBrush ImageSource="../Images/seamless-grid.jpg" Stretch="None" TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,32,32"></ImageBrush> </Grid.Background> - <dockablz:Layout ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Visible" FloatingItemsSource="{x:Static managers:ViewsManager.DisplayedViews}" FloatingItemDisplayMemberPath="View" FloatingItemHeaderMemberPath="Header"> - </dockablz:Layout> + <commonControls:MdiContainerControl ItemsSource="{x:Static managers:ViewsManager.DisplayedViews}"></commonControls:MdiContainerControl> </Grid> </Grid> </Grid> diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiChild.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiChild.cs new file mode 100644 index 000000000..469e3fda5 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiChild.cs @@ -0,0 +1,58 @@ +using MaterialDesignThemes.Wpf; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using Tango.Core.Commands; + +namespace Tango.MachineStudio.Common.Controls +{ + public class MdiChild : DependencyObject + { + public MdiChild() + { + + } + + public MdiChild(String header, FrameworkElement view) : this() + { + Header = header; + View = view; + } + + public PackIconKind Icon + { + get { return (PackIconKind)GetValue(IconProperty); } + set { SetValue(IconProperty, value); } + } + public static readonly DependencyProperty IconProperty = + DependencyProperty.Register("Icon", typeof(PackIconKind), typeof(MdiChild), new PropertyMetadata(PackIconKind.LaptopWindows)); + + public String Header + { + get { return (String)GetValue(HeaderProperty); } + set { SetValue(HeaderProperty, value); } + } + public static readonly DependencyProperty HeaderProperty = + DependencyProperty.Register("Header", typeof(String), typeof(MdiChild), new PropertyMetadata(null)); + + public FrameworkElement View + { + get { return (FrameworkElement)GetValue(ViewProperty); } + set { SetValue(ViewProperty, value); } + } + public static readonly DependencyProperty ViewProperty = + DependencyProperty.Register("View", typeof(FrameworkElement), typeof(MdiChild), new PropertyMetadata(null)); + + public Point Location + { + get { return (Point)GetValue(LocationProperty); } + set { SetValue(LocationProperty, value); } + } + public static readonly DependencyProperty LocationProperty = + DependencyProperty.Register("Location", typeof(Point), typeof(MdiChild), new PropertyMetadata(new Point())); + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml new file mode 100644 index 000000000..3896347fe --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml @@ -0,0 +1,75 @@ +<UserControl x:Class="Tango.MachineStudio.Common.Controls.MdiContainerControl" + 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" + xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:local="clr-namespace:Tango.MachineStudio.Common.Controls" + xmlns:converters="clr-namespace:Tango.MachineStudio.Common.Converters" + mc:Ignorable="d" + d:DesignHeight="300" d:DesignWidth="300" Background="White"> + + <UserControl.Resources> + <converters:PointToMarginConverter x:Key="PointToMarginConverter"></converters:PointToMarginConverter> + </UserControl.Resources> + + <Grid> + <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> + <ItemsControl ItemsSource="{Binding RelativeSource={RelativeSource AncestorType=UserControl,Mode=FindAncestor},Path=ItemsSource}" x:Name="itemsControl"> + <ItemsControl.ItemsPanel> + <ItemsPanelTemplate> + <Canvas x:Name="canvas" HorizontalAlignment="Left" VerticalAlignment="Top"></Canvas> + </ItemsPanelTemplate> + </ItemsControl.ItemsPanel> + <ItemsControl.ItemContainerStyle> + <Style TargetType="FrameworkElement"> + <Setter Property="Canvas.Left" Value="{Binding Location.X}"></Setter> + <Setter Property="Canvas.Top" Value="{Binding Location.Y}"></Setter> + <EventSetter Event="PreviewMouseDown" Handler="OnControlMouseDown"></EventSetter> + </Style> + </ItemsControl.ItemContainerStyle> + <ItemsControl.ItemTemplate> + <DataTemplate> + <Grid> + <Grid.Effect> + <DropShadowEffect ShadowDepth="0" BlurRadius="10" /> + </Grid.Effect> + <Grid> + <Grid.RowDefinitions> + <RowDefinition Height="25"/> + <RowDefinition Height="277*"/> + </Grid.RowDefinitions> + + <Grid Background="{StaticResource AccentColorBrush}"> + <Thumb Opacity="0" DragDelta="OnControlDragging" Tag="{Binding}"></Thumb> + <DockPanel LastChildFill="False"> + <StackPanel IsHitTestVisible="False" DockPanel.Dock="Left" VerticalAlignment="Center" Orientation="Horizontal" Margin="5 0 0 0"> + <materialDesign:PackIcon Kind="{Binding Icon}" Foreground="White"></materialDesign:PackIcon> + <TextBlock Margin="5 0 0 0" VerticalAlignment="Center" Foreground="White" Text="{Binding Header}"></TextBlock> + </StackPanel> + + <StackPanel DockPanel.Dock="Right" VerticalAlignment="Center" Orientation="Horizontal"> + <Button Foreground="White" Style="{StaticResource MaterialDesignFlatButton}" ToolTip="Close" Width="24" Height="24" Padding="0" Click="OnControlClosed" Tag="{Binding}"> + <materialDesign:PackIcon Kind="WindowClose" /> + </Button> + </StackPanel> + </DockPanel> + </Grid> + + <Grid Grid.Row="1" MinWidth="100" MinHeight="100"> + <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"> + <ContentPresenter Content="{Binding View}"></ContentPresenter> + </ScrollViewer> + + <Thumb HorizontalAlignment="Right" VerticalAlignment="Stretch" Opacity="0" Width="5" Cursor="SizeWE" DragDelta="OnControlSizeRight" Tag="{Binding}"></Thumb> + <Thumb HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Opacity="0" Height="5" Cursor="SizeNS" DragDelta="OnControlSizeBottom" Tag="{Binding}"></Thumb> + <Thumb HorizontalAlignment="Right" VerticalAlignment="Bottom" Opacity="0" Height="10" Width="10" Cursor="SizeNWSE" DragDelta="OnControlResize" Tag="{Binding}"></Thumb> + </Grid> + </Grid> + </Grid> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ItemsControl> + </ScrollViewer> + </Grid> +</UserControl> diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml.cs new file mode 100644 index 000000000..dbf4ee74b --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Controls/MdiContainerControl.xaml.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Controls.Primitives; +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 Tango.SharedUI.Helpers; + +namespace Tango.MachineStudio.Common.Controls +{ + /// <summary> + /// Interaction logic for MdiContainerControl.xaml + /// </summary> + public partial class MdiContainerControl : UserControl + { + private const int MIN_SIZE = 200; + + public MdiContainerControl() + { + InitializeComponent(); + } + + public IEnumerable ItemsSource + { + get { return (IEnumerable)GetValue(ItemsSourceProperty); } + set { SetValue(ItemsSourceProperty, value); } + } + public static readonly DependencyProperty ItemsSourceProperty = + DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(MdiContainerControl), new PropertyMetadata(null)); + + private void OnControlDragging(object sender, DragDeltaEventArgs e) + { + var mdiControl = GetSenderTag<MdiChild>(sender); + mdiControl.Location = new Point(mdiControl.Location.X + e.HorizontalChange, mdiControl.Location.Y + e.VerticalChange); + FitCanvas(); + } + + private T GetSenderTag<T>(object sender) where T : class + { + return (T)((sender as FrameworkElement).Tag); + } + + private void FitCanvas() + { + Canvas canvas = GetCanvas(); + canvas.Width = canvas.Children.OfType<FrameworkElement>().Max(x => Canvas.GetLeft(x) + x.ActualWidth); + canvas.Height = canvas.Children.OfType<FrameworkElement>().Max(x => Canvas.GetTop(x) + x.ActualHeight); + } + + private Canvas GetCanvas() + { + return UIHelper.FindChild<Canvas>(itemsControl, "canvas"); + } + + + private void OnControlMouseDown(object sender, MouseButtonEventArgs e) + { + Canvas.SetZIndex(sender as FrameworkElement, GetCanvas().Children.OfType<FrameworkElement>().Max(x => Canvas.GetZIndex(x) + 1)); + } + + private void OnControlSizeRight(object sender, DragDeltaEventArgs e) + { + var mdiControl = GetSenderTag<MdiChild>(sender); + if (double.IsNaN(mdiControl.View.Width)) mdiControl.View.Width = mdiControl.View.ActualWidth; + if (mdiControl.View.Width + e.HorizontalChange > MIN_SIZE) mdiControl.View.Width += e.HorizontalChange; + } + + private void OnControlSizeBottom(object sender, DragDeltaEventArgs e) + { + var mdiControl = GetSenderTag<MdiChild>(sender); + if (double.IsNaN(mdiControl.View.Height)) mdiControl.View.Height = mdiControl.View.ActualHeight; + if (mdiControl.View.Height + e.VerticalChange > MIN_SIZE) mdiControl.View.Height += e.VerticalChange; + } + + private void OnControlResize(object sender, DragDeltaEventArgs e) + { + var mdiControl = GetSenderTag<MdiChild>(sender); + + if (double.IsNaN(mdiControl.View.Height)) mdiControl.View.Height = mdiControl.View.ActualHeight; + if (double.IsNaN(mdiControl.View.Width)) mdiControl.View.Width = mdiControl.View.ActualWidth; + + if (mdiControl.View.Height + e.VerticalChange > MIN_SIZE) mdiControl.View.Height += e.VerticalChange; + if (mdiControl.View.Width + e.HorizontalChange > MIN_SIZE) mdiControl.View.Width += e.HorizontalChange; + } + + private void OnControlClosed(object sender, RoutedEventArgs e) + { + (ItemsSource as IList).Remove(GetSenderTag<MdiChild>(sender)); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Converters/PointToMarginConverter.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Converters/PointToMarginConverter.cs new file mode 100644 index 000000000..e6587b1ee --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Converters/PointToMarginConverter.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Data; + +namespace Tango.MachineStudio.Common.Converters +{ + public class PointToMarginConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + Point p = (Point)value; + return new Thickness(p.X, p.Y, 0, 0); + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj index 0a73c396b..28c2ba817 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/Tango.MachineStudio.Common.csproj @@ -53,19 +53,20 @@ <Reference Include="PresentationFramework" /> </ItemGroup> <ItemGroup> - <Page Include="UserControl1.xaml"> - <Generator>MSBuild:Compile</Generator> + <Page Include="Controls\MdiContainerControl.xaml"> <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> </Page> <Compile Include="..\..\Versioning\GlobalVersionInfo.cs"> <Link>GlobalVersionInfo.cs</Link> </Compile> + <Compile Include="Controls\MdiChild.cs" /> + <Compile Include="Controls\MdiContainerControl.xaml.cs"> + <DependentUpon>MdiContainerControl.xaml</DependentUpon> + </Compile> + <Compile Include="Converters\PointToMarginConverter.cs" /> <Compile Include="IStudioModule.cs" /> <Compile Include="Notifications\INotificationProvider.cs" /> - <Compile Include="UserControl1.xaml.cs"> - <DependentUpon>UserControl1.xaml</DependentUpon> - <SubType>Code</SubType> - </Compile> </ItemGroup> <ItemGroup> <Compile Include="Properties\AssemblyInfo.cs"> @@ -91,5 +92,15 @@ <LastGenOutput>Settings.Designer.cs</LastGenOutput> </None> </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\Tango.Core\Tango.Core.csproj"> + <Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project> + <Name>Tango.Core</Name> + </ProjectReference> + <ProjectReference Include="..\..\Tango.SharedUI\Tango.SharedUI.csproj"> + <Project>{8491d07b-c1f6-4b62-a412-41b9fd2d6538}</Project> + <Name>Tango.SharedUI</Name> + </ProjectReference> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/UserControl1.xaml b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/UserControl1.xaml deleted file mode 100644 index 68210e9f6..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/UserControl1.xaml +++ /dev/null @@ -1,12 +0,0 @@ -<UserControl x:Class="Tango.MachineStudio.Common.UserControl1" - 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" - xmlns:local="clr-namespace:Tango.MachineStudio.Common" - mc:Ignorable="d" - d:DesignHeight="300" d:DesignWidth="300"> - <Grid> - - </Grid> -</UserControl> diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/UserControl1.xaml.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/UserControl1.xaml.cs deleted file mode 100644 index 9028e3810..000000000 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.Common/UserControl1.xaml.cs +++ /dev/null @@ -1,28 +0,0 @@ -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; - -namespace Tango.MachineStudio.Common -{ - /// <summary> - /// Interaction logic for UserControl1.xaml - /// </summary> - public partial class UserControl1 : UserControl - { - public UserControl1() - { - InitializeComponent(); - } - } -} diff --git a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs index 5fb4b436d..e0aff5be3 100644 --- a/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Tango.MachineStudio.UI/ViewModels/MainViewVM.cs @@ -61,18 +61,7 @@ namespace Tango.MachineStudio.UI.ViewModels try { Assembly moduleAssembly = null; - String pdbFile = Path.ChangeExtension(file, ".pdb"); - var data = File.ReadAllBytes(file); - - if (File.Exists(pdbFile)) - { - var pdbData = File.ReadAllBytes(pdbFile); - moduleAssembly = Assembly.Load(data, pdbData); - } - else - { - moduleAssembly = Assembly.Load(data); - } + moduleAssembly = Assembly.LoadFrom(file); if (moduleAssembly != null) { |
