16 changed files with 637 additions and 97 deletions
@ -1,72 +0,0 @@
@@ -1,72 +0,0 @@
|
||||
<Components version="1.0"> |
||||
<System.Windows.Forms.UserControl> |
||||
<Name value="XmlUserControl1" /> |
||||
<ClientSize value="{Width=384, Height=355}" /> |
||||
<Controls> |
||||
<System.Windows.Forms.GroupBox> |
||||
<Name value="groupBox1" /> |
||||
<Location value="8, 8" /> |
||||
<Text value="${res:Dialog.ProjectOptions.BuildEvents}" /> |
||||
<Size value="364, 285" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<TabIndex value="0" /> |
||||
<Controls> |
||||
<System.Windows.Forms.ComboBox> |
||||
<Name value="runPostBuildEventComboBox" /> |
||||
<TabIndex value="8" /> |
||||
<Location value="6, 255" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<Size value="184, 21" /> |
||||
<FormattingEnabled value="True" /> |
||||
<DropDownStyle value="DropDownList" /> |
||||
</System.Windows.Forms.ComboBox> |
||||
<System.Windows.Forms.Label> |
||||
<Name value="label3" /> |
||||
<Location value="6, 229" /> |
||||
<Text value="${res:Dialog.ProjectOptions.BuildEvents.RunPostBuild}" /> |
||||
<Size value="352, 23" /> |
||||
<TextAlign value="BottomLeft" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<TabIndex value="7" /> |
||||
</System.Windows.Forms.Label> |
||||
<System.Windows.Forms.TextBox> |
||||
<Name value="postBuildEventTextBox" /> |
||||
<TabIndex value="5" /> |
||||
<Location value="6, 151" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<ScrollBars value="Both" /> |
||||
<Size value="348, 75" /> |
||||
<Multiline value="True" /> |
||||
</System.Windows.Forms.TextBox> |
||||
<System.Windows.Forms.Label> |
||||
<Name value="label2" /> |
||||
<Location value="6, 125" /> |
||||
<Text value="${res:Dialog.ProjectOptions.BuildEvents.PostBuild}" /> |
||||
<Size value="344, 23" /> |
||||
<TextAlign value="BottomLeft" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<TabIndex value="4" /> |
||||
</System.Windows.Forms.Label> |
||||
<System.Windows.Forms.TextBox> |
||||
<Name value="preBuildEventTextBox" /> |
||||
<TabIndex value="2" /> |
||||
<Location value="8, 49" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<ScrollBars value="Both" /> |
||||
<Size value="346, 75" /> |
||||
<Multiline value="True" /> |
||||
</System.Windows.Forms.TextBox> |
||||
<System.Windows.Forms.Label> |
||||
<Name value="label1" /> |
||||
<Location value="8, 23" /> |
||||
<Text value="${res:Dialog.ProjectOptions.BuildEvents.PreBuild}" /> |
||||
<Size value="344, 23" /> |
||||
<TextAlign value="BottomLeft" /> |
||||
<Anchor value="Top, Left, Right" /> |
||||
<TabIndex value="1" /> |
||||
</System.Windows.Forms.Label> |
||||
</Controls> |
||||
</System.Windows.Forms.GroupBox> |
||||
</Controls> |
||||
</System.Windows.Forms.UserControl> |
||||
</Components> |
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
<optionpanels:ProjectOptionPanel x:Class="ICSharpCode.SharpDevelop.Gui.OptionPanels.BuildEvents" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:core="http://icsharpcode.net/sharpdevelop/core" |
||||
xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets" |
||||
xmlns:project="clr-namespace:ICSharpCode.SharpDevelop.Project" |
||||
xmlns:gui="clr-namespace:ICSharpCode.SharpDevelop.Gui" |
||||
xmlns:optionpanels="clr-namespace:ICSharpCode.SharpDevelop.Gui.OptionPanels"> |
||||
<GroupBox Header="{core:Localize Dialog.ProjectOptions.BuildEvents}"> |
||||
<StackPanel> |
||||
<Label Content="{core:Localize Dialog.ProjectOptions.BuildEvents.PreBuild}" Target="{Binding ElementName=preBuild}"/> |
||||
<DockPanel> |
||||
<optionpanels:StorageLocationPicker Location="{Binding PreBuildEvent.Location}" DockPanel.Dock="Left" /> |
||||
<TextBox Name="preBuild" Text="{Binding PreBuildEvent.Value, UpdateSourceTrigger=PropertyChanged}" Height="75" |
||||
HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Visible" /> |
||||
</DockPanel> |
||||
|
||||
<Label Content="{core:Localize Dialog.ProjectOptions.BuildEvents.PostBuild}" Target="{Binding ElementName=postBuild}"/> |
||||
<DockPanel> |
||||
<optionpanels:StorageLocationPicker Location="{Binding PostBuildEvent.Location}" DockPanel.Dock="Left" /> |
||||
<TextBox Name="postBuild" Text="{Binding PostBuildEvent.Value, UpdateSourceTrigger=PropertyChanged}" Height="75" |
||||
HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Visible" /> |
||||
</DockPanel> |
||||
|
||||
<Label Content="{core:Localize Dialog.ProjectOptions.BuildEvents.RunPostBuild}" /> |
||||
<DockPanel> |
||||
<optionpanels:StorageLocationPicker Location="{Binding RunPostBuildEvent.Location}" DockPanel.Dock="Left" /> |
||||
<ComboBox gui:EnumBinding.EnumType="{x:Type project:RunPostBuildEvent}" SelectedValue="{Binding RunPostBuildEvent.Value}" /> |
||||
</DockPanel> |
||||
</StackPanel> |
||||
</GroupBox> |
||||
</optionpanels:ProjectOptionPanel> |
@ -0,0 +1,267 @@
@@ -0,0 +1,267 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel; |
||||
using System.Linq; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels |
||||
{ |
||||
/// <summary>
|
||||
/// Base class for project option panels with configuration picker.
|
||||
/// </summary>
|
||||
public class ProjectOptionPanel : UserControl, IOptionPanel, ICanBeDirty |
||||
{ |
||||
static ProjectOptionPanel() |
||||
{ |
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(ProjectOptionPanel), new FrameworkPropertyMetadata(typeof(ProjectOptionPanel))); |
||||
} |
||||
|
||||
public ProjectOptionPanel() |
||||
{ |
||||
this.DataContext = this; |
||||
} |
||||
|
||||
ComboBox configurationComboBox; |
||||
ComboBox platformComboBox; |
||||
MSBuildBasedProject project; |
||||
string activeConfiguration; |
||||
string activePlatform; |
||||
bool resettingIndex; |
||||
|
||||
protected virtual void Load(MSBuildBasedProject project, string configuration, string platform) |
||||
{ |
||||
foreach (IProjectProperty p in projectProperties.Values) |
||||
p.Load(project, configuration, platform); |
||||
this.IsDirty = false; |
||||
} |
||||
|
||||
protected virtual bool Save(MSBuildBasedProject project, string configuration, string platform) |
||||
{ |
||||
foreach (IProjectProperty p in projectProperties.Values) |
||||
p.Save(project, configuration, platform); |
||||
this.IsDirty = false; |
||||
return true; |
||||
} |
||||
|
||||
public override void OnApplyTemplate() |
||||
{ |
||||
base.OnApplyTemplate(); |
||||
configurationComboBox = Template.FindName("PART_configuration", this) as ComboBox; |
||||
platformComboBox = Template.FindName("PART_platform", this) as ComboBox; |
||||
} |
||||
|
||||
object owner; |
||||
|
||||
object IOptionPanel.Owner { |
||||
get { return owner; } |
||||
set { owner = value; } |
||||
} |
||||
|
||||
object IOptionPanel.Control { |
||||
get { return this; } |
||||
} |
||||
|
||||
void IOptionPanel.LoadOptions() |
||||
{ |
||||
ApplyTemplate(); |
||||
project = (MSBuildBasedProject)owner; |
||||
if (configurationComboBox != null) { |
||||
List<string> configurations = project.ConfigurationNames.Union(new[] { project.ActiveConfiguration }).ToList(); |
||||
configurations.Sort(); |
||||
configurationComboBox.ItemsSource = configurations; |
||||
configurationComboBox.SelectedItem = project.ActiveConfiguration; |
||||
configurationComboBox.SelectionChanged += comboBox_SelectionChanged; |
||||
} |
||||
if (platformComboBox != null) { |
||||
List<string> platforms = project.PlatformNames.Union(new[] { project.ActivePlatform }).ToList(); |
||||
platforms.Sort(); |
||||
platformComboBox.ItemsSource = platforms; |
||||
platformComboBox.SelectedItem = project.ActivePlatform; |
||||
platformComboBox.SelectionChanged += comboBox_SelectionChanged; |
||||
} |
||||
Load(); |
||||
} |
||||
|
||||
void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) |
||||
{ |
||||
if (resettingIndex) |
||||
return; |
||||
if (isDirty) { |
||||
if (!MessageService.AskQuestion("${res:Dialog.ProjectOptions.ContinueSwitchConfiguration}")) { |
||||
ResetComboBoxIndex(); |
||||
return; |
||||
} |
||||
if (!Save(project, activeConfiguration, activePlatform)) { |
||||
ResetComboBoxIndex(); |
||||
return; |
||||
} |
||||
project.Save(); |
||||
} |
||||
Load(); |
||||
} |
||||
|
||||
void ResetComboBoxIndex() |
||||
{ |
||||
resettingIndex = true; |
||||
if (configurationComboBox != null) |
||||
configurationComboBox.SelectedItem = activeConfiguration; |
||||
if (platformComboBox != null) |
||||
platformComboBox.SelectedItem = activePlatform; |
||||
resettingIndex = false; |
||||
} |
||||
|
||||
void Load() |
||||
{ |
||||
if (configurationComboBox != null) |
||||
activeConfiguration = (string)configurationComboBox.SelectedItem; |
||||
else |
||||
activeConfiguration = project.ActiveConfiguration; |
||||
|
||||
if (platformComboBox != null) |
||||
activePlatform = (string)platformComboBox.SelectedItem; |
||||
else |
||||
activePlatform = project.ActivePlatform; |
||||
|
||||
Load(project, activeConfiguration, activePlatform); |
||||
} |
||||
|
||||
bool IOptionPanel.SaveOptions() |
||||
{ |
||||
return Save(project, activeConfiguration, activePlatform); |
||||
} |
||||
|
||||
bool isDirty; |
||||
|
||||
public bool IsDirty { |
||||
get { return isDirty; } |
||||
set { |
||||
if (isDirty != value) { |
||||
isDirty = value; |
||||
if (IsDirtyChanged != null) |
||||
IsDirtyChanged(this, EventArgs.Empty); |
||||
} |
||||
} |
||||
} |
||||
|
||||
public event EventHandler IsDirtyChanged; |
||||
|
||||
#region Manage MSBuild properties
|
||||
Dictionary<string, IProjectProperty> projectProperties = new Dictionary<string, IProjectProperty>(); |
||||
|
||||
public ProjectProperty<string> GetProperty(string propertyName, string defaultValue, |
||||
TextBoxEditMode textBoxEditMode = TextBoxEditMode.EditEvaluatedProperty, |
||||
PropertyStorageLocations defaultLocation = PropertyStorageLocations.Base) |
||||
{ |
||||
IProjectProperty existingProperty; |
||||
if (projectProperties.TryGetValue(propertyName, out existingProperty)) |
||||
return (ProjectProperty<string>)existingProperty; |
||||
|
||||
bool treatAsLiteral = (textBoxEditMode == TextBoxEditMode.EditEvaluatedProperty); |
||||
ProjectProperty<string> newProperty = new ProjectProperty<string>(this, propertyName, defaultValue, defaultLocation, treatAsLiteral); |
||||
projectProperties.Add(propertyName, newProperty); |
||||
return newProperty; |
||||
} |
||||
|
||||
public ProjectProperty<T> GetProperty<T>(string propertyName, T defaultValue, |
||||
PropertyStorageLocations defaultLocation = PropertyStorageLocations.Base) |
||||
{ |
||||
IProjectProperty existingProperty; |
||||
if (projectProperties.TryGetValue(propertyName, out existingProperty)) |
||||
return (ProjectProperty<T>)existingProperty; |
||||
|
||||
ProjectProperty<T> newProperty = new ProjectProperty<T>(this, propertyName, defaultValue, defaultLocation, true); |
||||
projectProperties.Add(propertyName, newProperty); |
||||
return newProperty; |
||||
} |
||||
|
||||
interface IProjectProperty |
||||
{ |
||||
void Load(MSBuildBasedProject project, string configuration, string platform); |
||||
void Save(MSBuildBasedProject project, string configuration, string platform); |
||||
} |
||||
|
||||
public class ProjectProperty<T> : IProjectProperty, INotifyPropertyChanged |
||||
{ |
||||
readonly ProjectOptionPanel parentPanel; |
||||
readonly string propertyName; |
||||
readonly T defaultValue; |
||||
readonly PropertyStorageLocations defaultLocation; |
||||
readonly bool treatPropertyValueAsLiteral; |
||||
T val; |
||||
PropertyStorageLocations location; |
||||
|
||||
public ProjectProperty(ProjectOptionPanel parentPanel, string propertyName, T defaultValue, PropertyStorageLocations defaultLocation, bool treatPropertyValueAsLiteral) |
||||
{ |
||||
this.parentPanel = parentPanel; |
||||
this.propertyName = propertyName; |
||||
this.defaultValue = defaultValue; |
||||
this.defaultLocation = defaultLocation; |
||||
this.treatPropertyValueAsLiteral = treatPropertyValueAsLiteral; |
||||
|
||||
this.val = defaultValue; |
||||
this.location = defaultLocation; |
||||
} |
||||
|
||||
public string PropertyName { |
||||
get { return propertyName; } |
||||
} |
||||
|
||||
public T Value { |
||||
get { return val; } |
||||
set { |
||||
if (!object.Equals(val, value)) { |
||||
val = value; |
||||
if (PropertyChanged != null) |
||||
PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs("Value")); |
||||
|
||||
parentPanel.IsDirty = true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public PropertyStorageLocations Location { |
||||
get { return location; } |
||||
set { |
||||
if (location != value) { |
||||
location = value; |
||||
if (PropertyChanged != null) |
||||
PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs("Location")); |
||||
|
||||
parentPanel.IsDirty = true; |
||||
} |
||||
} |
||||
} |
||||
|
||||
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; |
||||
|
||||
public void Load(MSBuildBasedProject project, string configuration, string platform) |
||||
{ |
||||
PropertyStorageLocations newLocation; |
||||
string v; |
||||
if (treatPropertyValueAsLiteral) |
||||
v = project.GetProperty(configuration, platform, propertyName, out newLocation); |
||||
else |
||||
v = project.GetUnevalatedProperty(configuration, platform, propertyName, out newLocation); |
||||
|
||||
if (newLocation == PropertyStorageLocations.Unknown) |
||||
newLocation = defaultLocation; |
||||
|
||||
this.Value = GenericConverter.FromString(v, defaultValue); |
||||
this.Location = newLocation; |
||||
} |
||||
|
||||
public void Save(MSBuildBasedProject project, string configuration, string platform) |
||||
{ |
||||
string newValue = GenericConverter.ToString(val); |
||||
project.SetProperty(configuration, platform, propertyName, newValue, location, treatPropertyValueAsLiteral); |
||||
} |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
@ -0,0 +1,62 @@
@@ -0,0 +1,62 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:core="http://icsharpcode.net/sharpdevelop/core" |
||||
xmlns:optionpanels="clr-namespace:ICSharpCode.SharpDevelop.Gui.OptionPanels"> |
||||
<Style TargetType="{x:Type optionpanels:ProjectOptionPanel}" BasedOn="{StaticResource {x:Type UserControl}}"> |
||||
<Setter Property="Control.Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="optionpanels:ProjectOptionPanel"> |
||||
<Border BorderThickness="{TemplateBinding Border.BorderThickness}" |
||||
Padding="{TemplateBinding Control.Padding}" |
||||
BorderBrush="{TemplateBinding Border.BorderBrush}" |
||||
Background="{TemplateBinding Panel.Background}" |
||||
SnapsToDevicePixels="True"> |
||||
<DockPanel> |
||||
<StackPanel DockPanel.Dock="Top" Orientation="Horizontal"> |
||||
<Label Content="{core:StringParse ${res:Dialog.ProjectOptions.Configuration}:}" Target="{Binding ElementName=PART_configuration}" /> |
||||
<ComboBox Name="PART_configuration" Width="120" /> |
||||
<Label Content="{core:StringParse ${res:Dialog.ProjectOptions.Platform}:}" Target="{Binding ElementName=PART_platform}" /> |
||||
<ComboBox Name="PART_platform" Width="120" /> |
||||
</StackPanel> |
||||
<Line X1="0" X2="1" Margin="0,4" StrokeThickness="3" Stroke="Gray" DockPanel.Dock="Top" Stretch="Fill"/> |
||||
<ContentPresenter Content="{TemplateBinding ContentControl.Content}" |
||||
ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" |
||||
ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" |
||||
HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" |
||||
VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" |
||||
SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" /> |
||||
</DockPanel> |
||||
</Border> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
|
||||
<Style TargetType="{x:Type optionpanels:StorageLocationPicker}"> |
||||
<Setter Property="HorizontalAlignment" Value="Center" /> |
||||
<Setter Property="VerticalAlignment" Value="Center" /> |
||||
<Setter Property="Width" Value="20" /> |
||||
<Setter Property="Height" Value="20" /> |
||||
<Setter Property="Margin" Value="0,0,7,0" /> |
||||
<Setter Property="Control.Template"> |
||||
<Setter.Value> |
||||
<ControlTemplate TargetType="optionpanels:StorageLocationPicker"> |
||||
<Button Name="PART_button" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"> |
||||
<Grid> |
||||
<Ellipse Name="ellipse" Fill="{TemplateBinding EllipseBackground}" Width="8" Height="8" HorizontalAlignment="Center" VerticalAlignment="Center" /> |
||||
<Path Name="uPath" Data="M .5,.5 V 6.5 H 4.5 V 0.5" SnapsToDevicePixels="True" |
||||
StrokeThickness="1" Stroke="DarkGreen" |
||||
HorizontalAlignment="Right" VerticalAlignment="Bottom" Visibility="Collapsed" /> |
||||
</Grid> |
||||
</Button> |
||||
<ControlTemplate.Triggers> |
||||
<Trigger Property="IsUserFile" Value="true"> |
||||
<Setter TargetName="uPath" Property="Visibility" Value="Visible" /> |
||||
<Setter TargetName="ellipse" Property="HorizontalAlignment" Value="Left" /> |
||||
<Setter TargetName="ellipse" Property="VerticalAlignment" Value="Top" /> |
||||
</Trigger> |
||||
</ControlTemplate.Triggers> |
||||
</ControlTemplate> |
||||
</Setter.Value> |
||||
</Setter> |
||||
</Style> |
||||
</ResourceDictionary> |
@ -0,0 +1,149 @@
@@ -0,0 +1,149 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Media; |
||||
|
||||
using ICSharpCode.Core.Presentation; |
||||
using ICSharpCode.SharpDevelop.Project; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Gui.OptionPanels |
||||
{ |
||||
/// <summary>
|
||||
/// Allows choosing the storage location for an MSBuild property.
|
||||
/// </summary>
|
||||
public class StorageLocationPicker : Control |
||||
{ |
||||
static StorageLocationPicker() |
||||
{ |
||||
// Style is defined in ProjectOptionPanel.xaml
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(StorageLocationPicker), new FrameworkPropertyMetadata(typeof(StorageLocationPicker))); |
||||
} |
||||
|
||||
public static readonly DependencyProperty LocationProperty = |
||||
DependencyProperty.Register( |
||||
"Location", typeof(PropertyStorageLocations), typeof(StorageLocationPicker), |
||||
new FrameworkPropertyMetadata(PropertyStorageLocations.Base, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, |
||||
OnLocationChanged, CoerceLocation)); |
||||
|
||||
public PropertyStorageLocations Location { |
||||
get { return (PropertyStorageLocations)GetValue(LocationProperty); } |
||||
set { SetValue(LocationProperty, value); } |
||||
} |
||||
|
||||
internal static readonly DependencyProperty EllipseBackgroundProperty = |
||||
DependencyProperty.Register("EllipseBackground", typeof(Brush), typeof(StorageLocationPicker), |
||||
new FrameworkPropertyMetadata(Brushes.Black)); |
||||
|
||||
internal Brush EllipseBackground { |
||||
get { return (Brush)GetValue(EllipseBackgroundProperty); } |
||||
set { SetValue(EllipseBackgroundProperty, value); } |
||||
} |
||||
|
||||
internal static readonly DependencyProperty IsUserFileProperty = |
||||
DependencyProperty.Register("IsUserFile", typeof(bool), typeof(StorageLocationPicker), |
||||
new FrameworkPropertyMetadata(false)); |
||||
|
||||
internal bool IsUserFile { |
||||
get { return (bool)GetValue(IsUserFileProperty); } |
||||
set { SetValue(IsUserFileProperty, value); } |
||||
} |
||||
|
||||
static void OnLocationChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) |
||||
{ |
||||
StorageLocationPicker p = o as StorageLocationPicker; |
||||
if (p != null) { |
||||
PropertyStorageLocations location = (PropertyStorageLocations)e.NewValue; |
||||
p.IsUserFile = (location & PropertyStorageLocations.UserFile) == PropertyStorageLocations.UserFile; |
||||
switch (location & PropertyStorageLocations.ConfigurationAndPlatformSpecific) { |
||||
case PropertyStorageLocations.ConfigurationSpecific: |
||||
p.EllipseBackground = Brushes.Blue; |
||||
break; |
||||
case PropertyStorageLocations.PlatformSpecific: |
||||
p.EllipseBackground = Brushes.Red; |
||||
break; |
||||
case PropertyStorageLocations.ConfigurationAndPlatformSpecific: |
||||
p.EllipseBackground = Brushes.Violet; |
||||
break; |
||||
default: |
||||
p.EllipseBackground = Brushes.Black; |
||||
break; |
||||
} |
||||
if (p.contextMenu != null) { |
||||
p.SetIsCheckedOnMenu(location); |
||||
} |
||||
} |
||||
} |
||||
|
||||
static object CoerceLocation(DependencyObject d, object baseValue) |
||||
{ |
||||
PropertyStorageLocations location = (PropertyStorageLocations)baseValue; |
||||
if ((location & PropertyStorageLocations.ConfigurationAndPlatformSpecific) != 0) { |
||||
// remove 'Base' flag if any of the specific flags is set
|
||||
location &= ~PropertyStorageLocations.Base; |
||||
} else { |
||||
// otherwise, add 'Base' flag
|
||||
location |= PropertyStorageLocations.Base; |
||||
} |
||||
return location; |
||||
} |
||||
|
||||
ContextMenu contextMenu; |
||||
|
||||
public override void OnApplyTemplate() |
||||
{ |
||||
base.OnApplyTemplate(); |
||||
Button button = Template.FindName("PART_button", this) as Button; |
||||
if (button != null) { |
||||
button.Click += button_Click; |
||||
|
||||
contextMenu = new ContextMenu(); |
||||
contextMenu.Items.Add(CreateMenuItem("${res:Dialog.ProjectOptions.ConfigurationSpecific}", PropertyStorageLocations.ConfigurationSpecific)); |
||||
contextMenu.Items.Add(CreateMenuItem("${res:Dialog.ProjectOptions.PlatformSpecific}", PropertyStorageLocations.PlatformSpecific)); |
||||
contextMenu.Items.Add(CreateMenuItem("${res:Dialog.ProjectOptions.StoreInUserFile}", PropertyStorageLocations.UserFile)); |
||||
contextMenu.Items.Add(new Separator()); |
||||
|
||||
MenuItem helpButton = new MenuItem(); |
||||
helpButton.SetValueToExtension(MenuItem.HeaderProperty, new LocalizeExtension("Global.HelpButtonText")); |
||||
helpButton.Click += delegate(object sender, RoutedEventArgs e) { |
||||
e.Handled = true; |
||||
Core.MessageService.ShowMessage("${res:Dialog.ProjectOptions.StorageLocationHelp}"); |
||||
}; |
||||
contextMenu.Items.Add(helpButton); |
||||
|
||||
button.ContextMenu = contextMenu; |
||||
SetIsCheckedOnMenu(this.Location); |
||||
} |
||||
} |
||||
|
||||
void SetIsCheckedOnMenu(PropertyStorageLocations location) |
||||
{ |
||||
((MenuItem)contextMenu.Items[0]).IsChecked = (location & PropertyStorageLocations.ConfigurationSpecific) != 0; |
||||
((MenuItem)contextMenu.Items[1]).IsChecked = (location & PropertyStorageLocations.PlatformSpecific) != 0; |
||||
((MenuItem)contextMenu.Items[2]).IsChecked = (location & PropertyStorageLocations.UserFile) != 0; |
||||
} |
||||
|
||||
MenuItem CreateMenuItem(string text, PropertyStorageLocations location) |
||||
{ |
||||
MenuItem item = new MenuItem(); |
||||
item.SetValueToExtension(MenuItem.HeaderProperty, new StringParseExtension(text)); |
||||
item.Click += delegate(object sender, RoutedEventArgs e) { |
||||
if ((this.Location & location) == 0) { |
||||
this.Location |= location; |
||||
} else { |
||||
this.Location &= ~location; |
||||
} |
||||
e.Handled = true; |
||||
}; |
||||
return item; |
||||
} |
||||
|
||||
void button_Click(object sender, RoutedEventArgs e) |
||||
{ |
||||
e.Handled = true; |
||||
contextMenu.IsOpen = true; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,79 @@
@@ -0,0 +1,79 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel; |
||||
using System.Reflection; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Controls.Primitives; |
||||
using System.Windows.Data; |
||||
using System.Windows.Documents; |
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.Core.Presentation; |
||||
using ICSharpCode.SharpDevelop.Widgets; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Gui |
||||
{ |
||||
/// <summary>
|
||||
/// Used to bind ComboBoxes or RadioButtonGroups to enums.
|
||||
/// </summary>
|
||||
public static class EnumBinding |
||||
{ |
||||
public static readonly DependencyProperty EnumTypeProperty = |
||||
DependencyProperty.RegisterAttached("EnumType", typeof(Type), typeof(EnumBinding), |
||||
new FrameworkPropertyMetadata(OnEnumTypePropertyChanged)); |
||||
|
||||
public static Type GetEnumType(Selector element) |
||||
{ |
||||
return (Type)element.GetValue(EnumTypeProperty); |
||||
} |
||||
|
||||
public static void SetEnumType(Selector element, Type enumType) |
||||
{ |
||||
element.SetValue(EnumTypeProperty, enumType); |
||||
} |
||||
|
||||
static string GetDescription(FieldInfo field) |
||||
{ |
||||
foreach (DescriptionAttribute d in field.GetCustomAttributes(typeof(DescriptionAttribute), false)) |
||||
return d.Description; |
||||
return field.Name; |
||||
} |
||||
|
||||
static void OnEnumTypePropertyChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) |
||||
{ |
||||
Type enumType = e.NewValue as Type; |
||||
if (enumType != null && enumType.IsEnum) { |
||||
ComboBox comboBox = o as ComboBox; |
||||
if (comboBox != null) { |
||||
comboBox.SelectedValuePath = "Tag"; |
||||
comboBox.Items.Clear(); |
||||
foreach (FieldInfo field in enumType.GetFields()) { |
||||
if (field.IsStatic) { |
||||
ComboBoxItem item = new ComboBoxItem(); |
||||
item.Tag = field.GetValue(null); |
||||
string description = GetDescription(field); |
||||
item.SetValueToExtension(ComboBoxItem.ContentProperty, new StringParseExtension(description)); |
||||
comboBox.Items.Add(item); |
||||
} |
||||
} |
||||
} |
||||
RadioButtonGroup rbg = o as RadioButtonGroup; |
||||
if (rbg != null) { |
||||
rbg.Items.Clear(); |
||||
foreach (FieldInfo field in enumType.GetFields()) { |
||||
if (field.IsStatic) { |
||||
RadioButton b = new RadioButton(); |
||||
b.Tag = field.GetValue(null); |
||||
string description = GetDescription(field); |
||||
b.SetValueToExtension(RadioButton.ContentProperty, new StringParseExtension(description)); |
||||
rbg.Items.Add(b); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,7 @@
@@ -0,0 +1,7 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
> |
||||
<ResourceDictionary.MergedDictionaries> |
||||
<ResourceDictionary Source="/ICSharpCode.SharpDevelop;component/Src/Gui/Dialogs/OptionPanels/ProjectOptions/ProjectOptionPanel.xaml" /> |
||||
</ResourceDictionary.MergedDictionaries> |
||||
</ResourceDictionary> |
Loading…
Reference in new issue