Browse Source

- implemented SelectCulturePanel as WPF OptionPanel

- added NumericUpDown to ICSharpCode.Core.Presentation

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@5475 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Siegfried Pammer 16 years ago
parent
commit
3d952fe24c
  1. 2
      AddIns/ICSharpCode.SharpDevelop.addin
  2. 8
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  3. 110
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/SelectCulturePanel.cs
  4. 79
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/SelectCulturePanel.xaml
  5. 58
      src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/SelectCulturePanel.xaml.cs
  6. 12
      src/Main/Base/Project/Src/Services/Language/Language.cs
  7. 27
      src/Main/Base/Project/Src/Services/Language/LanguageService.cs
  8. 111
      src/Main/ICSharpCode.Core.Presentation/DragListener.cs
  9. 8
      src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj
  10. 11
      src/Main/ICSharpCode.Core.Presentation/LocalizeExtension.cs
  11. 302
      src/Main/ICSharpCode.Core.Presentation/NumericUpDown.cs
  12. 140
      src/Main/ICSharpCode.Core.Presentation/NumericUpDown.xaml
  13. 12
      src/Main/ICSharpCode.Core.Presentation/OptionBinding.cs

2
AddIns/ICSharpCode.SharpDevelop.addin

@ -1032,7 +1032,7 @@ @@ -1032,7 +1032,7 @@
label = "${res:Dialog.Options.TreeViewOptions.SharpDevelopOptionsText}">
<OptionPanel id = "SelectCulture"
label = "${res:Dialog.Options.IDEOptions.SelectCulture.PanelName}"
class = "ICSharpCode.SharpDevelop.Gui.OptionPanels.IDEOptionPanel"/>
class = "ICSharpCode.SharpDevelop.Gui.OptionPanels.SelectCulturePanel"/>
<OptionPanel id = "SelectStyle"
label = "${res:Dialog.Options.IDEOptions.SelectVisualStyle.PanelName}"
class = "ICSharpCode.SharpDevelop.Gui.OptionPanels.SelectStylePanel"/>

8
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -183,6 +183,10 @@ @@ -183,6 +183,10 @@
<Compile Include="Src\Gui\Dialogs\OpenWithDialog.Designer.cs">
<DependentUpon>OpenWithDialog.cs</DependentUpon>
</Compile>
<Compile Include="Src\Gui\Dialogs\OptionPanels\IDEOptions\SelectCulturePanel.xaml.cs">
<DependentUpon>SelectCulturePanel.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Src\Gui\Dialogs\OptionPanels\XmlFormsOptionPanel.cs" />
<Compile Include="Src\Gui\Dialogs\SolutionConfiguration\AddNewConfigurationDialog.cs" />
<Compile Include="Src\Gui\Dialogs\SolutionConfiguration\AddNewConfigurationDialog.Designer.cs">
@ -364,9 +368,6 @@ @@ -364,9 +368,6 @@
<Compile Include="Src\Gui\Dialogs\OptionPanels\IDEOptions\LoadSavePanel.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Src\Gui\Dialogs\OptionPanels\IDEOptions\SelectCulturePanel.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Src\Gui\Dialogs\OptionPanels\IDEOptions\SelectStylePanel.cs">
<SubType>UserControl</SubType>
</Compile>
@ -808,6 +809,7 @@ @@ -808,6 +809,7 @@
<Page Include="Src\Gui\Dialogs\GotoDialog.xaml">
<DependentUpon>GotoDialog.cs</DependentUpon>
</Page>
<Page Include="Src\Gui\Dialogs\OptionPanels\IDEOptions\SelectCulturePanel.xaml" />
<Page Include="Src\Gui\Dialogs\TabbedOptionsDialog.xaml" />
<Page Include="Src\Gui\Dialogs\TreeViewOptionsDialog.xaml" />
<Page Include="Src\Gui\Workbench\WpfWorkbench.xaml" />

110
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/SelectCulturePanel.cs

@ -1,110 +0,0 @@ @@ -1,110 +0,0 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.Core;
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
{
public class IDEOptionPanel : XmlFormsOptionPanel
{
readonly static string uiLanguageProperty = "CoreProperties.UILanguage";
ListView listView = new ListView();
Label newCulture = new Label();
string SelectedCulture {
get {
if (listView.SelectedItems.Count > 0) {
return listView.SelectedItems[0].SubItems[1].Text;
}
return null;
}
}
string SelectedCountry {
get {
if (listView.SelectedItems.Count > 0) {
return listView.SelectedItems[0].Text;
}
return null;
}
}
public override bool StorePanelContents()
{
if (SelectedCulture != null) {
PropertyService.Set(uiLanguageProperty, SelectedCulture);
}
return true;
}
void ChangeCulture(object sender, EventArgs e)
{
newCulture.Text = ResourceService.GetString("Dialog.Options.IDEOptions.SelectCulture.UILanguageSetToLabel") + " " + SelectedCountry;
}
string GetCulture(string languageCode)
{
foreach (Language language in LanguageService.Languages) {
if (languageCode.StartsWith(language.Code)) {
return language.Name;
}
}
return "English";
}
public IDEOptionPanel()// : base(panelName)
{
listView.Location = new Point(8, 8);
listView.Size = new Size(136, 200);
listView.LargeImageList = LanguageService.LanguageImageList;
listView.ItemActivate += new EventHandler(ChangeCulture);
listView.Sorting = SortOrder.Ascending;
listView.Activation = ItemActivation.OneClick;
listView.Anchor = (System.Windows.Forms.AnchorStyles.Top |
(System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right));
listView.MultiSelect = false;
foreach (Language language in LanguageService.Languages) {
listView.Items.Add(new ListViewItem(new string[] {language.Name, language.Code}, language.ImageIndex));
}
this.Controls.Add(listView);
Label culture = new Label();
culture.Location = new Point(8, 220);
culture.Size = new Size(350, 16);
culture.Anchor = (System.Windows.Forms.AnchorStyles.Top |
(System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right));
Dock = DockStyle.Fill;
culture.Text = ResourceService.GetString("Dialog.Options.IDEOptions.SelectCulture.CurrentUILanguageLabel") + " " + GetCulture(PropertyService.Get(uiLanguageProperty, "en"));
this.Controls.Add(culture);
Label descr = new Label();
descr.Location = new Point(8, 280);
descr.Size = new Size(390, 50);
descr.Text = ResourceService.GetString("Dialog.Options.IDEOptions.SelectCulture.DescriptionText");
descr.Anchor = (System.Windows.Forms.AnchorStyles.Top |
(System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right));
this.Controls.Add(descr);
newCulture.Location = new Point(8, 240);
newCulture.Size = new Size(360, 50);
newCulture.Anchor = (System.Windows.Forms.AnchorStyles.Top |
(System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right));
this.Controls.Add(newCulture);
}
}
}

79
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/SelectCulturePanel.xaml

@ -0,0 +1,79 @@ @@ -0,0 +1,79 @@
<gui:OptionPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sd="http://icsharpcode.net/sharpdevelop/core"
xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ICSharpCode.SharpDevelop.Gui.OptionPanels"
x:Name="window"
x:Class="ICSharpCode.SharpDevelop.Gui.OptionPanels.SelectCulturePanel">
<gui:OptionPanel.Resources>
<Style TargetType="{x:Type ListView}" BasedOn="{StaticResource {x:Type ListBox}}">
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="BorderThickness" Value="0.5" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Border Name="bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Margin="{TemplateBinding Margin}">
<ScrollViewer Margin="{TemplateBinding Padding}">
<WrapPanel ItemWidth="96" ItemHeight="64" IsItemsHost="True" MinWidth="50" Width="{Binding ActualWidth,RelativeSource={RelativeSource AncestorType=ScrollContentPresenter}}"></WrapPanel>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}">
<Setter Property="Padding" Value="3" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<Grid HorizontalAlignment="Center" VerticalAlignment="Top">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Image HorizontalAlignment="Center" Width="32">
<Image.Source>
<BitmapImage UriSource="{Binding ImagePath}" DecodePixelWidth="32" DecodePixelHeight="24" />
</Image.Source>
</Image>
<TextBlock Grid.Row="1" HorizontalAlignment="Center" TextAlignment="Center" TextWrapping="Wrap" Text="{Binding Name}" />
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ImageView},ResourceId=ImageView}" />
<Style x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:ImageView},ResourceId=ImageViewItem}" />
</gui:OptionPanel.Resources>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListView x:Name="listView" Margin="5,0" Height="200" SelectedItem="{sd:OptionBinding local:SelectCulturePanel.CurrentLanguage}">
<ListView.View>
<local:ImageView />
</ListView.View>
</ListView>
<TextBlock Grid.Row="1" Margin="5,0">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} {1}">
<sd:LocalizeExtension Key="Dialog.Options.IDEOptions.SelectCulture.CurrentUILanguageLabel" />
<Binding Path="SelectedItem.Name" ElementName="listView" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock Grid.Row="2" Margin="5,0">
<TextBlock.Text>
<MultiBinding StringFormat="{}{0} {1}">
<sd:LocalizeExtension Key="Dialog.Options.IDEOptions.SelectCulture.CurrentUILanguageLabel" />
<Binding Path="CurrentLanguage.Name" ElementName="window" />
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<TextBlock Grid.Row="3" TextWrapping="Wrap" Text="{sd:Localize Dialog.Options.IDEOptions.SelectCulture.DescriptionText}" Margin="5" />
</Grid>
</gui:OptionPanel>

58
src/Main/Base/Project/Src/Gui/Dialogs/OptionPanels/IDEOptions/SelectCulturePanel.xaml.cs

@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Siegfried Pammer" email="siegfriedpammer@gmail.com" />
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels
{
public partial class SelectCulturePanel : OptionPanel
{
public SelectCulturePanel()
{
InitializeComponent();
listView.ItemsSource = LanguageService.Languages;
}
static readonly string langPropName = "CoreProperties.UILanguage";
public static Language CurrentLanguage {
get { return GetCulture(PropertyService.Get(langPropName, "en")); }
set { PropertyService.Set(langPropName, value.Code); }
}
static Language GetCulture(string languageCode)
{
return LanguageService.Languages.FirstOrDefault(x => x.Code.StartsWith(languageCode))
?? LanguageService.Languages.First(x => x.Code.StartsWith("en"));
}
}
public class ImageView : ViewBase
{
protected override object DefaultStyleKey
{
get { return new ComponentResourceKey(GetType(), "ImageView"); }
}
protected override object ItemContainerDefaultStyleKey
{
get { return new ComponentResourceKey(GetType(), "ImageViewItem"); }
}
}
}

12
src/Main/Base/Project/Src/Services/Language/Language.cs

@ -13,7 +13,7 @@ namespace ICSharpCode.SharpDevelop @@ -13,7 +13,7 @@ namespace ICSharpCode.SharpDevelop
{
string name;
string code;
int imageIndex;
string imagePath;
public string Name {
get {
@ -27,17 +27,17 @@ namespace ICSharpCode.SharpDevelop @@ -27,17 +27,17 @@ namespace ICSharpCode.SharpDevelop
}
}
public int ImageIndex {
public string ImagePath {
get {
return imageIndex;
return imagePath;
}
}
}
public Language(string name, string code, int imageIndex)
public Language(string name, string code, string imagePath)
{
this.name = name;
this.code = code;
this.imageIndex = imageIndex;
this.imagePath = imagePath;
}
}
}

27
src/Main/Base/Project/Src/Services/Language/LanguageService.cs

@ -7,6 +7,7 @@ @@ -7,6 +7,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
@ -20,16 +21,9 @@ namespace ICSharpCode.SharpDevelop @@ -20,16 +21,9 @@ namespace ICSharpCode.SharpDevelop
{
static string languagePath = Path.Combine(PropertyService.DataDirectory, "resources", "languages");
static ImageList languageImageList = null;
static ArrayList languages = null;
static List<Language> languages = null;
public static ImageList LanguageImageList {
get {
return languageImageList;
}
}
public static ArrayList Languages {
public static List<Language> Languages {
get {
return languages;
}
@ -37,10 +31,7 @@ namespace ICSharpCode.SharpDevelop @@ -37,10 +31,7 @@ namespace ICSharpCode.SharpDevelop
static LanguageService()
{
languageImageList = new ImageList();
languageImageList.ColorDepth = ColorDepth.Depth32Bit;
languages = new ArrayList();
LanguageImageList.ImageSize = new Size(46, 38);
languages = new List<Language>();
XmlDocument doc = new XmlDocument();
doc.Load(Path.Combine(languagePath, "LanguageDefinition.xml"));
@ -50,13 +41,13 @@ namespace ICSharpCode.SharpDevelop @@ -50,13 +41,13 @@ namespace ICSharpCode.SharpDevelop
foreach (XmlNode node in nodes) {
XmlElement el = node as XmlElement;
if (el != null) {
languages.Add(new Language(el.Attributes["name"].InnerText,
el.Attributes["code"].InnerText,
LanguageImageList.Images.Count));
LanguageImageList.Images.Add(new Bitmap(Path.Combine(languagePath, el.Attributes["icon"].InnerText)));
languages.Add(new Language(
el.Attributes["name"].InnerText,
el.Attributes["code"].InnerText,
Path.Combine(languagePath, el.Attributes["icon"].InnerText)
));
}
}
}
}
}

111
src/Main/ICSharpCode.Core.Presentation/DragListener.cs

@ -0,0 +1,111 @@ @@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Diagnostics;
namespace ICSharpCode.Core.Presentation
{
public delegate void DragHandler(DragListener drag);
public class DragListener
{
static DragListener()
{
InputManager.Current.PostProcessInput += new ProcessInputEventHandler(PostProcessInput);
}
public DragListener(IInputElement target)
{
Target = target;
Target.PreviewMouseLeftButtonDown += Target_MouseDown;
Target.PreviewMouseMove += Target_MouseMove;
Target.PreviewMouseLeftButtonUp += Target_MouseUp;
}
static DragListener CurrentListener;
static void PostProcessInput(object sender, ProcessInputEventArgs e)
{
if (CurrentListener != null) {
var a = e.StagingItem.Input as KeyEventArgs;
if (a != null && a.Key == Key.Escape) {
Mouse.Capture(null);
CurrentListener.IsDown = false;
CurrentListener.IsCanceled = true;
CurrentListener.Complete();
}
}
}
void Target_MouseDown(object sender, MouseButtonEventArgs e)
{
StartPoint = Mouse.GetPosition(null);
CurrentPoint = StartPoint;
DeltaDelta = new Vector();
IsDown = true;
IsCanceled = false;
}
void Target_MouseMove(object sender, MouseEventArgs e)
{
if (IsDown) {
DeltaDelta = e.GetPosition(null) - CurrentPoint;
CurrentPoint += DeltaDelta;
if (!IsActive) {
if (Math.Abs(Delta.X) >= SystemParameters.MinimumHorizontalDragDistance ||
Math.Abs(Delta.Y) >= SystemParameters.MinimumVerticalDragDistance) {
IsActive = true;
CurrentListener = this;
if (Started != null) {
Started(this);
}
}
}
if (IsActive && Changed != null) {
Changed(this);
}
}
}
void Target_MouseUp(object sender, MouseButtonEventArgs e)
{
IsDown = false;
if (IsActive) {
Complete();
}
}
void Complete()
{
IsActive = false;
CurrentListener = null;
if (Completed != null) {
Completed(this);
}
}
public event DragHandler Started;
public event DragHandler Changed;
public event DragHandler Completed;
public IInputElement Target { get; private set; }
public Point StartPoint { get; private set; }
public Point CurrentPoint { get; private set; }
public Vector DeltaDelta { get; private set; }
public bool IsActive { get; private set; }
public bool IsDown { get; private set; }
public bool IsCanceled { get; private set; }
public Vector Delta {
get { return CurrentPoint - StartPoint; }
}
}
}

8
src/Main/ICSharpCode.Core.Presentation/ICSharpCode.Core.Presentation.csproj

@ -69,7 +69,11 @@ @@ -69,7 +69,11 @@
<Compile Include="..\GlobalAssemblyInfo.cs">
<Link>Properties\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="DragListener.cs" />
<Compile Include="GlobalStyles.cs" />
<Compile Include="NumericUpDown.cs">
<DependentUpon>NumericUpDown.xaml</DependentUpon>
</Compile>
<Compile Include="RestrictDesiredSize.cs" />
<Compile Include="SortableGridViewColumn.cs" />
<Compile Include="CollapsiblePanel.cs" />
@ -109,6 +113,10 @@ @@ -109,6 +113,10 @@
<Folder Include="Menu" />
<Folder Include="themes" />
<Folder Include="ToolBar" />
<Page Include="NumericUpDown.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="themes\Aero.NormalColor.xaml" />
<Page Include="themes\generic.xaml" />
</ItemGroup>

11
src/Main/ICSharpCode.Core.Presentation/LocalizeExtension.cs

@ -26,8 +26,19 @@ namespace ICSharpCode.Core.Presentation @@ -26,8 +26,19 @@ namespace ICSharpCode.Core.Presentation
this.UpdateOnLanguageChange = true;
}
public LocalizeExtension()
{
this.UsesAccessors = true;
this.UpdateOnLanguageChange = true;
}
string key;
public string Key {
get { return key; }
set { key = value; }
}
/// <summary>
/// Set whether the text uses accessors.
/// If set to true (default), accessors will be converted to WPF syntax.

302
src/Main/ICSharpCode.Core.Presentation/NumericUpDown.cs

@ -0,0 +1,302 @@ @@ -0,0 +1,302 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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 System.Windows.Controls.Primitives;
using System.Globalization;
using System.Diagnostics;
namespace ICSharpCode.Core.Presentation
{
public class NumericUpDown : Control
{
static NumericUpDown()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(NumericUpDown),
new FrameworkPropertyMetadata(typeof(NumericUpDown)));
}
TextBox textBox;
DragRepeatButton upButton;
DragRepeatButton downButton;
public static readonly DependencyProperty DecimalPlacesProperty =
DependencyProperty.Register("DecimalPlaces", typeof(int), typeof(NumericUpDown));
public int DecimalPlaces {
get { return (int)GetValue(DecimalPlacesProperty); }
set { SetValue(DecimalPlacesProperty, value); }
}
public static readonly DependencyProperty MinimumProperty =
DependencyProperty.Register("Minimum", typeof(double), typeof(NumericUpDown));
public double Minimum {
get { return (double)GetValue(MinimumProperty); }
set { SetValue(MinimumProperty, value); }
}
public static readonly DependencyProperty MaximumProperty =
DependencyProperty.Register("Maximum", typeof(double), typeof(NumericUpDown),
new FrameworkPropertyMetadata(100.0));
public double Maximum {
get { return (double)GetValue(MaximumProperty); }
set { SetValue(MaximumProperty, value); }
}
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register("Value", typeof(double), typeof(NumericUpDown),
new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
public double Value {
get { return (double)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
public static readonly DependencyProperty SmallChangeProperty =
DependencyProperty.Register("SmallChange", typeof(double), typeof(NumericUpDown),
new FrameworkPropertyMetadata(1.0));
public double SmallChange {
get { return (double)GetValue(SmallChangeProperty); }
set { SetValue(SmallChangeProperty, value); }
}
public static readonly DependencyProperty LargeChangeProperty =
DependencyProperty.Register("LargeChange", typeof(double), typeof(NumericUpDown),
new FrameworkPropertyMetadata(10.0));
public double LargeChange {
get { return (double)GetValue(LargeChangeProperty); }
set { SetValue(LargeChangeProperty, value); }
}
bool IsDragging {
get {
return upButton.IsDragging;
}
set {
upButton.IsDragging = value; downButton.IsDragging = value;
}
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
upButton = (DragRepeatButton)Template.FindName("PART_UpButton", this);
downButton = (DragRepeatButton)Template.FindName("PART_DownButton", this);
textBox = (TextBox)Template.FindName("PART_TextBox", this);
upButton.Click += new RoutedEventHandler(upButton_Click);
downButton.Click += new RoutedEventHandler(downButton_Click);
var upDrag = new DragListener(upButton);
var downDrag = new DragListener(downButton);
upDrag.Started += drag_Started;
upDrag.Changed += drag_Changed;
upDrag.Completed += drag_Completed;
downDrag.Started += drag_Started;
downDrag.Changed += drag_Changed;
downDrag.Completed += drag_Completed;
Print();
}
void drag_Started(DragListener drag)
{
OnDragStarted();
}
void drag_Changed(DragListener drag)
{
IsDragging = true;
MoveValue(-drag.DeltaDelta.Y * SmallChange);
}
void drag_Completed(DragListener drag)
{
IsDragging = false;
OnDragCompleted();
}
void downButton_Click(object sender, RoutedEventArgs e)
{
if (!IsDragging) SmallDown();
}
void upButton_Click(object sender, RoutedEventArgs e)
{
if (!IsDragging) SmallUp();
}
protected virtual void OnDragStarted()
{
}
protected virtual void OnDragCompleted()
{
}
public void SmallUp()
{
MoveValue(SmallChange);
}
public void SmallDown()
{
MoveValue(-SmallChange);
}
public void LargeUp()
{
MoveValue(LargeChange);
}
public void LargeDown()
{
MoveValue(-LargeChange);
}
void MoveValue(double delta)
{
double result;
if (double.IsNaN(Value) || double.IsInfinity(Value)) {
SetValue(delta);
}
else if (double.TryParse(textBox.Text, out result)) {
SetValue(result + delta);
}
else {
SetValue(Value + delta);
}
}
void Print()
{
if (textBox != null) {
textBox.Text = Value.ToString("F" + DecimalPlaces);
textBox.CaretIndex = int.MaxValue;
}
}
//wpf bug?: Value = -1 updates bindings without coercing, workaround
//update: not derived from RangeBase - no problem
void SetValue(double newValue)
{
newValue = CoerceValue(newValue);
if (Value != newValue) {
Value = newValue;
}
}
double CoerceValue(double newValue)
{
return Math.Max(Minimum, Math.Min(newValue, Maximum));
}
protected override void OnPreviewKeyDown(KeyEventArgs e)
{
base.OnPreviewKeyDown(e);
if (e.Key == Key.Enter) {
double result;
if (double.TryParse(textBox.Text, out result)) {
SetValue(result);
}
else {
Print();
}
textBox.SelectAll();
e.Handled = true;
}
else if (e.Key == Key.Up) {
SmallUp();
e.Handled = true;
}
else if (e.Key == Key.Down) {
SmallDown();
e.Handled = true;
}
else if (e.Key == Key.PageUp) {
LargeUp();
e.Handled = true;
}
else if (e.Key == Key.PageDown) {
LargeDown();
e.Handled = true;
}
//else if (e.Key == Key.Home) {
// Maximize();
// e.Handled = true;
//}
//else if (e.Key == Key.End) {
// Minimize();
// e.Handled = true;
//}
}
//protected override void OnMouseWheel(MouseWheelEventArgs e)
//{
// if (e.Delta > 0)
// {
// if (Keyboard.IsKeyDown(Key.LeftShift))
// {
// LargeUp();
// }
// else
// {
// SmallUp();
// }
// }
// else
// {
// if (Keyboard.IsKeyDown(Key.LeftShift))
// {
// LargeDown();
// }
// else
// {
// SmallDown();
// }
// }
// e.Handled = true;
//}
protected override void OnPropertyChanged(DependencyPropertyChangedEventArgs e)
{
base.OnPropertyChanged(e);
if (e.Property == ValueProperty) {
Value = CoerceValue((double)e.NewValue);
Print();
}
else if (e.Property == SmallChangeProperty &&
ReadLocalValue(LargeChangeProperty) == DependencyProperty.UnsetValue) {
LargeChange = SmallChange * 10;
}
}
}
public class DragRepeatButton : RepeatButton
{
public static readonly DependencyProperty IsDraggingProperty =
DependencyProperty.Register("IsDragging", typeof(bool), typeof(DragRepeatButton));
public bool IsDragging {
get { return (bool)GetValue(IsDraggingProperty); }
set { SetValue(IsDraggingProperty, value); }
}
}
}

140
src/Main/ICSharpCode.Core.Presentation/NumericUpDown.xaml

@ -0,0 +1,140 @@ @@ -0,0 +1,140 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:ICSharpCode.Core.Presentation">
<Brush x:Key="ButtonNormal">#DADFEA</Brush>
<Brush x:Key="ButtonHover">#E6EBEF</Brush>
<Brush x:Key="ButtonPressed">#B6BDD3</Brush>
<Brush x:Key="BorderBrush">#7F9DB9</Brush>
<Brush x:Key="ArrowBrush">Black</Brush>
<Brush x:Key="ArrowsBorderBrush">#B6BDD3</Brush>
<Style x:Key="UpButton"
TargetType="RepeatButton">
<Setter Property="Focusable"
Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:DragRepeatButton}">
<Border x:Name="bg"
Background="{StaticResource ButtonNormal}"
CornerRadius="2 2 0 0">
<Path Fill="{StaticResource ArrowBrush}"
Data="M 0 3 L 3.5 0 L 7 3"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter TargetName="bg"
Property="Background"
Value="{StaticResource ButtonHover}" />
</Trigger>
<Trigger Property="IsMouseCaptured"
Value="True">
<Setter TargetName="bg"
Property="Background"
Value="{StaticResource ButtonPressed}" />
</Trigger>
<Trigger Property="IsDragging"
Value="True">
<Setter TargetName="bg"
Property="Background"
Value="{StaticResource ButtonPressed}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="DownButton"
TargetType="RepeatButton">
<Setter Property="Focusable"
Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:DragRepeatButton}">
<Border x:Name="bg"
Background="{StaticResource ButtonNormal}"
CornerRadius="0 0 2 2">
<Path Fill="{StaticResource ArrowBrush}"
Data="M 0 0 L 3.5 3 L 7 0"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter TargetName="bg"
Property="Background"
Value="{StaticResource ButtonHover}" />
</Trigger>
<Trigger Property="IsMouseCaptured"
Value="True">
<Setter TargetName="bg"
Property="Background"
Value="{StaticResource ButtonPressed}" />
</Trigger>
<Trigger Property="IsDragging"
Value="True">
<Setter TargetName="bg"
Property="Background"
Value="{StaticResource ButtonPressed}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Controls:NumericUpDown}">
<Setter Property="Background"
Value="White" />
<Setter Property="BorderThickness"
Value="1" />
<Setter Property="BorderBrush"
Value="{StaticResource BorderBrush}" />
<Setter Property="Focusable"
Value="False" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Controls:NumericUpDown}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="15" />
</Grid.ColumnDefinitions>
<TextBox x:Name="PART_TextBox"
BorderThickness="0"
Background="{x:Null}"
Foreground="{TemplateBinding Foreground}"
Grid.RowSpan="2" />
<Controls:DragRepeatButton x:Name="PART_UpButton"
Style="{StaticResource UpButton}"
Grid.Column="1" />
<Controls:DragRepeatButton x:Name="PART_DownButton"
Style="{StaticResource DownButton}"
Grid.Column="1"
Grid.Row="1" />
<Border Grid.Column="1"
Grid.RowSpan="2"
BorderBrush="{StaticResource ArrowsBorderBrush}"
BorderThickness="1"
CornerRadius="2" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>

12
src/Main/ICSharpCode.Core.Presentation/OptionBinding.cs

@ -33,7 +33,17 @@ namespace ICSharpCode.Core.Presentation @@ -33,7 +33,17 @@ namespace ICSharpCode.Core.Presentation
/// </example>
public class OptionBinding : MarkupExtension
{
public string FullPropertyName { get; set; }
string fullPropertyName;
public string FullPropertyName {
get { return fullPropertyName; }
set {
if (!regex.IsMatch(value))
throw new ArgumentException("parameter must have the following format: namespace:ClassName.FieldOrProperty", "propertyName");
fullPropertyName = value;
}
}
static readonly Regex regex = new Regex("^.+\\:.+\\..+$", RegexOptions.Compiled);

Loading…
Cancel
Save