Imported Upstream version 4.3.2.467

Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
Xamarin Public Jenkins
2016-02-22 11:00:01 -05:00
parent f302175246
commit f3e3aab35a
4097 changed files with 122406 additions and 82300 deletions

View File

@@ -0,0 +1,31 @@
//----------------------------------------------------------------
// <copyright company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//----------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System.Activities.Presentation.Converters;
using System.Windows.Data;
internal sealed class ArgumentIdentifierTrimConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value != null)
{
return value;
}
return string.Empty;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// delegate to VBIdentifierTrimConverter.ConvertBack, because VBIdentifierTrimConverter is internal and cannot be directly referenced from XAML.
VBIdentifierTrimConverter converter = new VBIdentifierTrimConverter();
return converter.ConvertBack(value, targetType, parameter, culture);
}
}
}

View File

@@ -0,0 +1,120 @@
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System.Activities.Presentation;
using System.Activities.Presentation.Metadata;
using System.Activities.Statements;
using System.ComponentModel;
using System.Activities.Presentation.Model;
using System.Runtime;
using Microsoft.VisualBasic.Activities;
using System.Reflection;
using System.Activities.Presentation.PropertyEditing;
using System.Activities.Presentation.View;
using System.Collections.Generic;
partial class AssignDesigner
{
const string ToPropertyName = "To";
const string ValuePropertyName = "Value";
PropertyChangedEventHandler modelItemPropertyChangedHandler;
public AssignDesigner()
{
this.InitializeComponent();
}
PropertyChangedEventHandler ModelItemPropertyChangedHandler
{
get
{
if (this.modelItemPropertyChangedHandler == null)
{
this.modelItemPropertyChangedHandler = new PropertyChangedEventHandler(modelItem_PropertyChanged);
}
return this.modelItemPropertyChangedHandler;
}
}
protected override void OnInitialized(EventArgs e)
{
base.OnInitialized(e);
this.Unloaded += (sender, eventArgs) =>
{
AssignDesigner designer = sender as AssignDesigner;
if (designer != null && designer.ModelItem != null)
{
designer.ModelItem.PropertyChanged -= designer.ModelItemPropertyChangedHandler;
}
};
}
internal static void RegisterMetadata(AttributeTableBuilder builder)
{
Type assignType = typeof(Assign);
builder.AddCustomAttributes(assignType, new DesignerAttribute(typeof(AssignDesigner)));
builder.AddCustomAttributes(assignType, new ActivityDesignerOptionsAttribute { AllowDrillIn = false });
Func<Activity, IEnumerable<ArgumentAccessor>> argumentAccessorGenerator = (activity) =>
{
return new ArgumentAccessor[]
{
new ArgumentAccessor
{
Getter = (ownerActivity) => ((Assign)ownerActivity).To,
Setter = (ownerActivity, arg) => ((Assign)ownerActivity).To = arg as OutArgument,
},
new ArgumentAccessor
{
Getter = (ownerActivity) => ((Assign)ownerActivity).Value,
Setter = (ownerActivity, arg) => ((Assign)ownerActivity).Value = arg as InArgument,
},
};
};
ActivityArgumentHelper.RegisterAccessorsGenerator(assignType, argumentAccessorGenerator);
}
protected override void OnModelItemChanged(object newItem)
{
ModelItem modelItem = newItem as ModelItem;
if (modelItem != null)
{
modelItem.PropertyChanged += ModelItemPropertyChangedHandler;
}
base.OnModelItemChanged(newItem);
}
void modelItem_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
//if the To argument has changed, we may need to update the Value argument's type
if (e.PropertyName == ToPropertyName)
{
Fx.Assert(this.ModelItem != null, "modelItem could not be null if we recent property changed event from it");
ModelProperty valueProperty = this.ModelItem.Properties[ValuePropertyName];
ModelProperty toProperty = this.ModelItem.Properties[ToPropertyName];
Fx.Assert(valueProperty != null, "Value model property could not be null");
Fx.Assert(toProperty != null, "To model property could not be null");
Argument value = valueProperty.ComputedValue as Argument;
Argument to = toProperty.ComputedValue as Argument;
if (value != null)
{
Type targetType = to == null ? typeof(object) : to.ArgumentType;
if (value.ArgumentType != targetType)
{
valueProperty.SetValue(MorphHelpers.MorphArgument(valueProperty.Value, targetType));
}
}
}
}
}
}

View File

@@ -0,0 +1,28 @@
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System.Activities.Presentation.Metadata;
using System.Activities.Statements;
using System.ComponentModel;
partial class CancellationScopeDesigner
{
public CancellationScopeDesigner()
{
this.InitializeComponent();
}
public static void RegisterMetadata(AttributeTableBuilder builder)
{
Type type = typeof(CancellationScope);
builder.AddCustomAttributes(type, new DesignerAttribute(typeof(CancellationScopeDesigner)));
builder.AddCustomAttributes(type, type.GetProperty("Body"), BrowsableAttribute.No);
builder.AddCustomAttributes(type, type.GetProperty("CancellationHandler"), BrowsableAttribute.No);
builder.AddCustomAttributes(type, type.GetProperty("Variables"), BrowsableAttribute.No);
}
}
}

View File

@@ -0,0 +1,179 @@
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System.Activities.Presentation;
using System.Activities.Presentation.Annotations;
using System.Activities.Presentation.Metadata;
using System.Activities.Presentation.Model;
using System.Activities.Presentation.View;
using System.Activities.Statements;
using System.ComponentModel;
using System.Runtime;
using System.Windows;
using System.Windows.Input;
partial class CaseDesigner
{
public CaseDesigner()
{
this.InitializeComponent();
this.DragHandle = null;
this.Loaded += (sender, e) =>
{
Selection selection = this.Context.Items.GetValue<Selection>();
if (selection != null)
{
ModelItem primarySelection = selection.PrimarySelection;
this.ExpandState = SwitchDesigner.IsDescendantOfCase(this.ModelItem, primarySelection);
if (this.ExpandState)
{
// If current focus is at another part, we need to focus this designer
// to trigger selection changed, then this part will expand and another
// expanded part will collapse. Then we focus on the activity it contains
// if there is one.
this.ModelItem.Highlight();
if (this.ModelItem != primarySelection && primarySelection.View != null)
{
primarySelection.Highlight();
}
}
}
};
}
// When the CaseDesigner is collapsed, its CaseKeyBox will be disabled. Thus CaseKeyBox.RegainFocus() doesn't
// work in such situation, we must re-focus the CaseDesigner to expand it first to re-enable the CaseKeyBox.
// This situation happens when inputting and invalid case key value and clicking on another Case or Default in
// the same parent SwitchDesigner.
public Action<CaseKeyBox> FocusSelf
{
get
{
return (ckb) =>
{
Keyboard.Focus((IInputElement)this);
};
}
}
public static void RegisterMetadata(AttributeTableBuilder builder)
{
Type type = typeof(ModelItemKeyValuePair<,>);
builder.AddCustomAttributes(type, new DesignerAttribute(typeof(CaseDesigner)));
builder.AddCustomAttributes(type, type.GetProperty("Value"), BrowsableAttribute.No);
builder.AddCustomAttributes(type, new ActivityDesignerOptionsAttribute { AllowDrillIn = false });
}
void AttachDisplayName()
{
AttachedPropertiesService attachedPropertiesService = this.Context.Services.GetService<AttachedPropertiesService>();
Fx.Assert(attachedPropertiesService != null, "AttachedPropertiesService is not available.");
Type modelItemType = this.ModelItem.ItemType;
foreach (AttachedProperty property in attachedPropertiesService.GetAttachedProperties(modelItemType))
{
if (property.Name == "DisplayName" && property.OwnerType == modelItemType)
{
return;
}
}
AttachedProperty<string> displayNameProperty = new AttachedProperty<string>
{
Name = "DisplayName",
OwnerType = modelItemType,
Getter = (modelItem) => { return "Case"; }
};
attachedPropertiesService.AddProperty(displayNameProperty);
}
protected override void OnModelItemChanged(object newItem)
{
base.OnModelItemChanged(newItem);
this.AttachDisplayName();
}
protected override void OnMouseDown(MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && e.ClickCount == 2)
{
SwitchTryCatchDesignerHelper.MakeParentRootDesigner<SwitchDesigner>(this);
e.Handled = true;
}
else if (e.LeftButton == MouseButtonState.Pressed)
{
Keyboard.Focus(this);
e.Handled = true;
this.Designer.ShouldStillAllowRubberBandEvenIfMouseLeftButtonDownIsHandled = true;
}
else if (e.RightButton == MouseButtonState.Pressed)
{
if (this.ShowExpanded)
{
Keyboard.Focus(this);
}
e.Handled = true;
}
}
protected override void OnMouseUp(MouseButtonEventArgs e)
{
// avoid context menu upon right-click when it's collapsed
if (!this.ShowExpanded && e.RightButton == MouseButtonState.Released)
{
e.Handled = true;
}
}
void OnAddAnnotationCommandCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if (EditingContextUtilities.GetSingleSelectedModelItem(this.Context) == this.ModelItem)
{
ContextMenuUtilities.OnAddAnnotationCommandCanExecute(e, this.Context, this.FindSwitch());
}
}
void OnAddAnnotationCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{
ContextMenuUtilities.OnAddAnnotationCommandExecuted(e, this.FindSwitch());
}
void OnEditAnnotationCommandCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if (EditingContextUtilities.GetSingleSelectedModelItem(this.Context) == this.ModelItem)
{
// call the same method as delete annotation command
ContextMenuUtilities.OnDeleteAnnotationCommandCanExecute(e, this.Context, this.FindSwitch());
}
}
void OnEditAnnotationCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{
ContextMenuUtilities.OnEditAnnotationCommandExecuted(e, this.FindSwitch());
}
void OnDeleteAnnotationCommandCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if (EditingContextUtilities.GetSingleSelectedModelItem(this.Context) == this.ModelItem)
{
ContextMenuUtilities.OnDeleteAnnotationCommandCanExecute(e, this.Context, this.FindSwitch());
}
}
void OnDeleteAnnotationCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{
ContextMenuUtilities.OnDeleteAnnotationCommandExecuted(e, this.FindSwitch());
}
private ModelItem FindSwitch()
{
return this.ModelItem.FindParent((ModelItem item) =>
{
return item.ItemType.IsGenericType && item.ItemType.GetGenericTypeDefinition() == typeof(Switch<>);
});
}
}
}

View File

@@ -0,0 +1,26 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System;
delegate bool CaseKeyValidationCallbackDelegate(object obj, out string reason);
interface ICaseKeyBoxView
{
// Some view level functionalities required (i.e. cannot be done by data binding)
void RegainFocus();
// Allow ViewModel to raise View events
void OnValueCommitted();
void OnEditCancelled();
// Pass public interface of this control to the ViewModel
bool DisplayHintText { get; }
object Value { get; set; }
Type ValueType { get; }
CaseKeyValidationCallbackDelegate CaseKeyValidationCallback { get; }
}
}

View File

@@ -0,0 +1,365 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System;
using System.Collections.ObjectModel;
using System.Windows;
using System.Linq;
using System.ComponentModel;
using System.Runtime;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Activities.Presentation.Model;
class CaseKeyBoxViewModel : DependencyObject
{
static readonly string Null = "(null)";
static readonly string Empty = "(empty)";
public static readonly DependencyProperty ComboBoxIsEditableProperty =
DependencyProperty.Register("ComboBoxIsEditable", typeof(bool), typeof(CaseKeyBoxViewModel), new UIPropertyMetadata(false));
public static readonly DependencyProperty ComboBoxVisibilityProperty =
DependencyProperty.Register("ComboBoxVisibility", typeof(Visibility), typeof(CaseKeyBoxViewModel), new UIPropertyMetadata(Visibility.Collapsed));
public static readonly DependencyProperty ComboBoxItemsProperty =
DependencyProperty.Register("ComboBoxItems", typeof(ObservableCollection<string>), typeof(CaseKeyBoxViewModel));
public static readonly DependencyProperty DataTemplateNameProperty =
DependencyProperty.Register("DataTemplateName", typeof(string), typeof(CaseKeyBoxViewModel), new UIPropertyMetadata("Label"));
public static readonly DependencyProperty TextProperty =
DependencyProperty.Register("Text", typeof(string), typeof(CaseKeyBoxViewModel), new UIPropertyMetadata(String.Empty));
public static readonly DependencyProperty TextBoxVisibilityProperty =
DependencyProperty.Register("TextBoxVisibility", typeof(Visibility), typeof(CaseKeyBoxViewModel), new UIPropertyMetadata(Visibility.Visible));
public const string BoxesTemplate = "Boxes";
public const string LabelTemplate = "Label";
string oldText = String.Empty;
public CaseKeyBoxViewModel(ICaseKeyBoxView view)
{
this.View = view;
}
public bool ComboBoxIsEditable
{
get { return (bool)GetValue(ComboBoxIsEditableProperty); }
set { SetValue(ComboBoxIsEditableProperty, value); }
}
public ObservableCollection<string> ComboBoxItems
{
get { return (ObservableCollection<string>)GetValue(ComboBoxItemsProperty); }
set { SetValue(ComboBoxItemsProperty, value); }
}
public Visibility ComboBoxVisibility
{
get { return (Visibility)GetValue(ComboBoxVisibilityProperty); }
set { SetValue(ComboBoxVisibilityProperty, value); }
}
public string DataTemplateName
{
get { return (string)GetValue(DataTemplateNameProperty); }
set { SetValue(DataTemplateNameProperty, value); }
}
public string Text
{
get { return (string)GetValue(TextProperty); }
set { SetValue(TextProperty, value); }
}
public Visibility TextBoxVisibility
{
get { return (Visibility)GetValue(TextBoxVisibilityProperty); }
set { SetValue(TextBoxVisibilityProperty, value); }
}
public bool IsBoxOnly
{
get;
set;
}
public bool OnEnterPressed()
{
return this.CommitChanges();
}
public void OnEscapePressed()
{
this.Text = oldText;
if (!this.IsBoxOnly)
{
this.DataTemplateName = CaseKeyBoxViewModel.LabelTemplate;
}
this.View.OnEditCancelled();
}
public void OnLabelGotFocus()
{
this.DataTemplateName = CaseKeyBoxViewModel.BoxesTemplate;
}
public bool OnLostFocus()
{
return CommitChanges();
}
public void OnValueChanged()
{
if (this.Value is ModelItem)
{
// Since Value is a DP, this code will trigger OnValueChanged once more.
this.Value = ((ModelItem)this.Value).GetCurrentValue();
return;
}
if (this.DataTemplateName != LabelTemplate && !this.IsBoxOnly)
{
this.DataTemplateName = LabelTemplate;
}
if (this.DisplayHintText)
{
this.Text = string.Empty;
return;
}
if (this.ValueType == null)
{
return;
}
if (this.ValueType.IsValueType)
{
if (this.Value == null)
{
this.Value = Activator.CreateInstance(this.ValueType);
}
}
if (this.Value == null)
{
this.Text = Null;
}
else if ((this.ValueType == typeof(string)) && string.Equals(this.Value, String.Empty))
{
this.Text = Empty;
}
else
{
TypeConverter converter = XamlUtilities.GetConverter(this.ValueType);
Fx.Assert(converter != null, "TypeConverter is not available");
try
{
this.Text = converter.ConvertToString(this.Value);
}
catch (ArgumentException)
{
this.Text = this.Value.ToString();
}
}
}
public void OnValueTypeChanged()
{
if (this.ValueType == null)
{
return;
}
bool isBool = this.ValueType == typeof(bool);
bool isEnum = this.ValueType.IsEnum;
if (isBool || isEnum)
{
this.ComboBoxVisibility = Visibility.Visible;
this.TextBoxVisibility = Visibility.Collapsed;
this.ComboBoxIsEditable = false;
if (isBool)
{
this.ComboBoxItems = new ObservableCollection<string> { "True", "False" };
}
else
{
this.ComboBoxItems = new ObservableCollection<string>(Enum.GetNames(this.ValueType).ToList());
}
}
else if (this.ValueType.IsValueType)
{
this.ComboBoxVisibility = Visibility.Collapsed;
this.TextBoxVisibility = Visibility.Visible;
this.ComboBoxIsEditable = false;
}
else
{
this.ComboBoxVisibility = Visibility.Visible;
this.TextBoxVisibility = Visibility.Collapsed;
this.ComboBoxIsEditable = true;
this.ComboBoxItems = new ObservableCollection<string> { Null };
if (this.ValueType == typeof(string))
{
this.ComboBoxItems.Add(Empty);
}
}
OnValueChanged();
}
public void SaveOldText()
{
this.oldText = this.Text;
}
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes",
Justification = "If conversion fails, the exception type is System.Exception.So we must catch all types of exceptions here.")]
[SuppressMessage("Reliability", "Reliability108:IsFatalRule",
Justification = "Catch all exceptions to prevent crash.")]
bool CommitChanges()
{
object result = null;
try
{
result = ResolveInputText();
}
catch
{
// ---- all
Fx.Assert(false, "Result should have been valid. Preview event handler should have handled the validation.");
return false;
}
this.Value = result;
if (this.DataTemplateName != CaseKeyBoxViewModel.LabelTemplate && !this.IsBoxOnly)
{
// this is for the case when setting this.Value to null. It looks like
// OnValueChanged won't get called because NULL is a default value for
// the CaseKeyBox instance in SwitchDesigner.
this.DataTemplateName = CaseKeyBoxViewModel.LabelTemplate;
}
this.View.OnValueCommitted();
return true;
}
object ResolveInputText()
{
object result = null;
if (this.ValueType == typeof(string))
{
if (this.Text.Equals(Null))
{
result = null;
}
else if (this.Text.Equals(Empty))
{
result = string.Empty;
}
else
{
result = this.Text;
}
}
else if (!this.ValueType.IsValueType && this.Text.Equals(Null))
{
result = null;
}
else
{
TypeConverter converter = XamlUtilities.GetConverter(this.ValueType);
Fx.Assert(converter != null, "TypeConverter is not available");
if (!converter.CanConvertFrom(typeof(string)) || !converter.CanConvertTo(typeof(string)))
{
throw FxTrace.Exception.AsError(new NotSupportedException(SR.NotSupportedCaseKeyStringConversion));
}
result = converter.ConvertFromString(this.Text);
// See if the result can be converted back to a string.
// For example, we have a enum Color {Black, White}.
// String "3" can be converted to integer 3, but integer 3
// cannot be converted back to a valid string for enum Color.
// In this case, we disallow string "3".
converter.ConvertToString(result);
}
string reason;
if (this.CaseKeyValidationCallback != null && !this.CaseKeyValidationCallback(result, out reason))
{
throw FxTrace.Exception.AsError(new ArgumentException(reason));
}
return result;
}
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes",
Justification = "If conversion fails, the exception type is System.Exception.So we must catch all types of exceptions here.")]
[SuppressMessage("Reliability", "Reliability108:IsFatalRule",
Justification = "Catch all exceptions to prevent crash.")]
public bool CanResolveInputText(out string reason)
{
reason = string.Empty;
try
{
ResolveInputText();
return true;
}
catch (Exception e)
{
reason = e.Message;
return false;
}
}
public bool TextHasBeenChanged()
{
string normalizedOldText = this.oldText;
string normalizedNewText = this.Text;
// Tricky: this.DisplayHintText = false => This CaseKeyBox is in CaseDesigner
// Here, when changing value of string value type from "(empty)" to "", we must
// consider the text hasn't been changed, such that we don't do commit-change.
// We normalize the strings for empty-string situation before we do comparison.
if (this.ValueType == typeof(string) && !this.DisplayHintText)
{
normalizedOldText = normalizedOldText == Empty ? string.Empty : normalizedOldText;
normalizedNewText = normalizedNewText == Empty ? string.Empty : normalizedNewText;
}
return normalizedOldText != normalizedNewText;
}
ICaseKeyBoxView View { get; set; }
bool DisplayHintText
{
get { return this.View.DisplayHintText; }
}
object Value
{
get { return this.View.Value; }
set { this.View.Value = value; }
}
Type ValueType
{
get { return this.View.ValueType; }
}
CaseKeyValidationCallbackDelegate CaseKeyValidationCallback
{
get { return this.View.CaseKeyValidationCallback; }
}
public void ResetText()
{
this.Text = string.Empty;
this.oldText = string.Empty;
}
}
}

View File

@@ -0,0 +1,324 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System;
using System.Activities.Presentation;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Threading;
partial class CaseKeyBox : UserControl, ICaseKeyBoxView
{
public static readonly DependencyProperty DisplayHintTextProperty =
DependencyProperty.Register("DisplayHintText", typeof(bool), typeof(CaseKeyBox));
public static readonly DependencyProperty LabelTextProperty =
DependencyProperty.Register("LabelText", typeof(string), typeof(CaseKeyBox), new UIPropertyMetadata(string.Empty));
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register("Value", typeof(object), typeof(CaseKeyBox), new PropertyMetadata(OnValueChanged));
public static readonly DependencyProperty ValueTypeProperty =
DependencyProperty.Register("ValueType", typeof(Type), typeof(CaseKeyBox), new PropertyMetadata(OnValueTypeChanged));
public static RoutedEvent ValueCommittedEvent =
EventManager.RegisterRoutedEvent("ValueCommitted", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(CaseKeyBox));
public static RoutedEvent EditCancelledEvent =
EventManager.RegisterRoutedEvent("EditCancelled", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(CaseKeyBox));
public static readonly DependencyProperty CaseKeyValidationCallbackProperty =
DependencyProperty.Register("CaseKeyValidationCallback", typeof(CaseKeyValidationCallbackDelegate), typeof(CaseKeyBox));
public static readonly DependencyProperty ErrorCallbackProperty =
DependencyProperty.Register("ErrorCallback", typeof(Action<CaseKeyBox>), typeof(CaseKeyBox));
public static readonly DependencyProperty CommitExplicitlyProperty =
DependencyProperty.Register("CommitExplicitly", typeof(bool), typeof(CaseKeyBox), new PropertyMetadata(false));
Control visibleBox;
public CaseKeyBox()
{
this.ViewModel = new CaseKeyBoxViewModel(this);
InitializeComponent();
}
public event RoutedEventHandler ValueCommitted
{
add { AddHandler(ValueCommittedEvent, value); }
remove { RemoveHandler(ValueCommittedEvent, value); }
}
public virtual void OnValueCommitted()
{
RoutedEventArgs args = new RoutedEventArgs();
args.RoutedEvent = ValueCommittedEvent;
RaiseEvent(args);
}
public event RoutedEventHandler EditCancelled
{
add { AddHandler(EditCancelledEvent, value); }
remove { RemoveHandler(EditCancelledEvent, value); }
}
public virtual void OnEditCancelled()
{
RoutedEventArgs args = new RoutedEventArgs();
args.RoutedEvent = EditCancelledEvent;
RaiseEvent(args);
}
public CaseKeyValidationCallbackDelegate CaseKeyValidationCallback
{
get { return (CaseKeyValidationCallbackDelegate)GetValue(CaseKeyValidationCallbackProperty); }
set { SetValue(CaseKeyValidationCallbackProperty, value); }
}
public Action<CaseKeyBox> ErrorCallback
{
get { return (Action<CaseKeyBox>)GetValue(ErrorCallbackProperty); }
set { SetValue(ErrorCallbackProperty, value); }
}
public bool CommitExplicitly
{
get { return (bool)GetValue(CommitExplicitlyProperty); }
set { SetValue(CommitExplicitlyProperty, value); }
}
public string LabelText
{
get { return (string)GetValue(LabelTextProperty); }
set { SetValue(LabelTextProperty, value); }
}
void DisableKeyboardLostFocus()
{
if (this.visibleBox != null)
{
this.visibleBox.LostKeyboardFocus -= OnLostKeyboardFocus;
}
}
void EnableKeyboardLostFocus()
{
if (!this.CommitExplicitly)
{
if (this.visibleBox != null)
{
this.visibleBox.LostKeyboardFocus += OnLostKeyboardFocus;
}
}
}
void ReportError(string errorMessage)
{
// Invoking error message box will cause LostFocus of the control.
// Thus we need to disable LostFocus first and then add the handlers back.
DisableKeyboardLostFocus();
ErrorReporting.ShowErrorMessage(errorMessage);
this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, (Action)(() =>
{
if (this.ErrorCallback != null)
{
this.ErrorCallback(this);
this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, (Action)(() =>
{
RegainFocus();
EnableKeyboardLostFocus();
}));
}
else
{
RegainFocus();
EnableKeyboardLostFocus();
}
}));
}
void OnBoxMouseUp(object sender, MouseButtonEventArgs e)
{
// disable the context menu for textbox and combobox
if (e.ChangedButton == MouseButton.Right && e.RightButton == MouseButtonState.Released)
{
e.Handled = true;
}
}
#region ICaseKeyBoxView Implementation
public bool DisplayHintText
{
get { return (bool)GetValue(DisplayHintTextProperty); }
set { SetValue(DisplayHintTextProperty, value); }
}
public object Value
{
get { return (object)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
public Type ValueType
{
get { return (Type)GetValue(ValueTypeProperty); }
set { SetValue(ValueTypeProperty, value); }
}
public void RegainFocus()
{
if (this.visibleBox != null)
{
Keyboard.Focus((IInputElement)this.visibleBox);
}
}
#endregion
#region Delegating Event Handlers
public CaseKeyBoxViewModel ViewModel { get; set; }
static void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs)
{
((CaseKeyBox)sender).ViewModel.OnValueChanged();
}
static void OnValueTypeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs)
{
((CaseKeyBox)sender).ViewModel.OnValueTypeChanged();
}
void OnLabelGotFocus(object sender, RoutedEventArgs e)
{
this.ViewModel.OnLabelGotFocus();
e.Handled = true;
}
void OnLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
e.Handled = true;
if (ComboBoxHelper.ShouldFilterUnnecessaryComboBoxEvent(sender as ComboBox))
{
return;
}
CommitChanges();
}
public bool CommitChanges()
{
UpdateSource(this.visibleBox);
if (this.CommitExplicitly || this.ViewModel.TextHasBeenChanged())
{
string reason = null;
if (!this.ViewModel.CanResolveInputText(out reason))
{
ReportError(reason);
return false;
}
else
{
return this.ViewModel.OnLostFocus();
}
}
else
{
CancelChanges();
return false;
}
}
public void CancelChanges()
{
DisableKeyboardLostFocus();
this.ViewModel.OnEscapePressed(); // simulate cancel
}
void OnBoxLoaded(object sender, RoutedEventArgs e)
{
UIElement box = (UIElement)sender;
ComboBox comboBox = box as ComboBox;
if (comboBox != null && comboBox.IsVisible)
{
ComboBoxHelper.SynchronizeComboBoxSelection(comboBox, this.ViewModel.Text);
}
if (box.IsVisible)
{
box.Focus();
}
Control control = sender as Control;
if (control != null && control.Visibility == Visibility.Visible)
{
this.visibleBox = control;
EnableKeyboardLostFocus();
}
this.ViewModel.SaveOldText();
}
void OnBoxUnloaded(object sender, RoutedEventArgs e)
{
if (this.visibleBox != null)
{
DisableKeyboardLostFocus();
this.visibleBox = null;
}
}
void OnBoxKeyDown(object sender, KeyEventArgs e)
{
if (!CommitExplicitly)
{
if (e.Key == Key.Escape)
{
e.Handled = true;
CancelChanges();
}
else if (e.Key == Key.Enter)
{
e.Handled = true;
CommitChanges();
}
}
}
void UpdateSource(object sender)
{
if (sender is TextBox)
{
BindingExpression binding = ((TextBox)sender).GetBindingExpression(TextBox.TextProperty);
if (binding != null)
{
binding.UpdateSource();
}
}
else if (sender is ComboBox)
{
BindingExpression binding = ((ComboBox)sender).GetBindingExpression(ComboBox.TextProperty);
if (binding != null)
{
binding.UpdateSource();
}
}
}
#endregion
public void ResetText()
{
this.ViewModel.ResetText();
}
}
}

View File

@@ -0,0 +1,34 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System.Windows.Data;
using System.Windows;
using System.Globalization;
class CaseKeyBoxIsEnabledConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
bool isReadOnly = (bool)values[0];
bool showExpanded = (bool)values[1];
if (isReadOnly)
{
return false;
}
else
{
return showExpanded;
}
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw FxTrace.Exception.AsError(new NotImplementedException());
}
}
}

View File

@@ -0,0 +1,33 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System.Globalization;
using System.Windows;
using System.Windows.Data;
class CaseLabelVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
bool isDefaultCase = (bool)value;
if (isDefaultCase)
{
return Visibility.Collapsed;
}
else
{
return Visibility.Visible;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw FxTrace.Exception.AsError(new NotImplementedException());
}
}
}

View File

@@ -0,0 +1,173 @@
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System;
using System.Activities.Presentation;
using System.Activities.Presentation.Annotations;
using System.Activities.Presentation.Metadata;
using System.Activities.Presentation.Model;
using System.Activities.Presentation.View;
using System.Activities.Statements;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using Microsoft.Activities.Presentation;
/// <summary>
/// Interaction logic for CatchDesigner.xaml
/// </summary>
partial class CatchDesigner
{
string exceptionTypeShortName = null;
string exceptionTypeFullName = null;
public CatchDesigner()
{
InitializeComponent();
this.DragHandle = null;
this.Loaded += (sender, e) =>
{
Selection selection = this.Context.Items.GetValue<Selection>();
if (selection != null)
{
ModelItem primarySelection = selection.PrimarySelection;
this.ExpandState = TryCatchDesigner.IsDescendantOfCatch(this.ModelItem, primarySelection);
if (this.ExpandState)
{
// If current focus is at another part, we need to focus this designer
// to trigger selection changed, then this part will expand and another
// expanded part will collapse. Then we focus on the activity it contains
// if there is one.
this.ModelItem.Highlight();
if (this.ModelItem != primarySelection && primarySelection.View != null)
{
primarySelection.Highlight();
}
}
}
};
}
internal static void RegisterMetadata(AttributeTableBuilder builder)
{
Type type = typeof(Catch<>);
builder.AddCustomAttributes(type, new DesignerAttribute(typeof(CatchDesigner)));
builder.AddCustomAttributes(type, type.GetProperty("Action"), BrowsableAttribute.No);
builder.AddCustomAttributes(type, new ActivityDesignerOptionsAttribute { AllowDrillIn = false });
}
public string ExceptionTypeShortName
{
get
{
if (this.exceptionTypeShortName == null)
{
this.exceptionTypeShortName = TypeNameHelper.GetDisplayName((Type)this.ModelItem.Properties["ExceptionType"].Value.GetCurrentValue(), false);
}
return this.exceptionTypeShortName;
}
}
public string ExceptionTypeFullName
{
get
{
if (this.exceptionTypeFullName == null)
{
this.exceptionTypeFullName = TypeNameHelper.GetDisplayName((Type)this.ModelItem.Properties["ExceptionType"].Value.GetCurrentValue(), true);
}
return this.exceptionTypeFullName;
}
}
protected override void OnMouseDown(MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && e.ClickCount == 2)
{
SwitchTryCatchDesignerHelper.MakeParentRootDesigner<TryCatchDesigner>(this);
e.Handled = true;
}
else if (e.LeftButton == MouseButtonState.Pressed)
{
Keyboard.Focus(this);
e.Handled = true;
this.Designer.ShouldStillAllowRubberBandEvenIfMouseLeftButtonDownIsHandled = true;
}
else if (e.RightButton == MouseButtonState.Pressed)
{
if (this.ShowExpanded)
{
Keyboard.Focus(this);
}
e.Handled = true;
}
}
protected override void OnMouseUp(MouseButtonEventArgs e)
{
// avoid context menu upon right-click when it's collapsed
if (!this.ShowExpanded && e.RightButton == MouseButtonState.Released)
{
e.Handled = true;
}
}
protected override string GetAutomationIdMemberName()
{
return PropertyNames.ExceptionType;
}
void OnAddAnnotationCommandCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if (EditingContextUtilities.GetSingleSelectedModelItem(this.Context) == this.ModelItem)
{
ContextMenuUtilities.OnAddAnnotationCommandCanExecute(e, this.Context, this.FindTryCatch());
}
}
void OnAddAnnotationCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{
ContextMenuUtilities.OnAddAnnotationCommandExecuted(e, this.FindTryCatch());
}
void OnEditAnnotationCommandCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if (EditingContextUtilities.GetSingleSelectedModelItem(this.Context) == this.ModelItem)
{
// call the same method as delete annotation command
ContextMenuUtilities.OnDeleteAnnotationCommandCanExecute(e, this.Context, this.FindTryCatch());
}
}
void OnEditAnnotationCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{
ContextMenuUtilities.OnEditAnnotationCommandExecuted(e, this.FindTryCatch());
}
void OnDeleteAnnotationCommandCanExecute(object sender, CanExecuteRoutedEventArgs e)
{
if (EditingContextUtilities.GetSingleSelectedModelItem(this.Context) == this.ModelItem)
{
ContextMenuUtilities.OnDeleteAnnotationCommandCanExecute(e, this.Context, this.FindTryCatch());
}
}
void OnDeleteAnnotationCommandExecuted(object sender, ExecutedRoutedEventArgs e)
{
ContextMenuUtilities.OnDeleteAnnotationCommandExecuted(e, this.FindTryCatch());
}
private ModelItem FindTryCatch()
{
return this.ModelItem.FindParent((ModelItem item) =>
{
return item.ItemType == typeof(TryCatch);
});
}
}
}

View File

@@ -0,0 +1,29 @@
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System.Windows.Controls;
static class ComboBoxHelper
{
public static bool ShouldFilterUnnecessaryComboBoxEvent(ComboBox comboBox)
{
return comboBox != null && comboBox.IsDropDownOpen;
}
public static void SynchronizeComboBoxSelection(ComboBox comboBox, string value)
{
foreach (string item in comboBox.Items)
{
if (string.Equals(item, value))
{
comboBox.SelectedItem = item;
return;
}
}
comboBox.SelectedIndex = -1;
}
}
}

View File

@@ -0,0 +1,33 @@
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System.Activities.Presentation.Metadata;
using System.Activities.Statements;
using System.ComponentModel;
/// <summary>
/// Interaction logic for TryCatchDesigner.xaml
/// </summary>
partial class CompensableActivityDesigner
{
public CompensableActivityDesigner()
{
InitializeComponent();
}
public static void RegisterMetadata(AttributeTableBuilder builder)
{
Type type = typeof(CompensableActivity);
builder.AddCustomAttributes(type, new DesignerAttribute(typeof(CompensableActivityDesigner)));
builder.AddCustomAttributes(type, type.GetProperty("Body"), BrowsableAttribute.No);
builder.AddCustomAttributes(type, type.GetProperty("CompensationHandler"), BrowsableAttribute.No);
builder.AddCustomAttributes(type, type.GetProperty("ConfirmationHandler"), BrowsableAttribute.No);
builder.AddCustomAttributes(type, type.GetProperty("CancellationHandler"), BrowsableAttribute.No);
builder.AddCustomAttributes(type, type.GetProperty("Variables"), BrowsableAttribute.No);
}
}
}

View File

@@ -0,0 +1,13 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
public enum ConnectionPointType
{
Default,
Incoming,
Outgoing,
}
}

View File

@@ -0,0 +1,34 @@
//----------------------------------------------------------------
// <copyright company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//----------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System.Activities.Core.Presentation.Themes;
using System.Activities.Presentation;
using System.Activities.Presentation.Converters;
using System.Activities.Presentation.Model;
using System.Activities.Presentation.PropertyEditing;
internal class DelegateArgumentsValueEditor : DialogPropertyValueEditor
{
public DelegateArgumentsValueEditor()
{
this.InlineEditorTemplate = EditorCategoryTemplateDictionary.Instance.GetCategoryTemplate("DelegateArguments_InlineTemplate");
}
public override void ShowDialog(PropertyValue propertyValue, Windows.IInputElement commandSource)
{
ModelPropertyEntryToOwnerActivityConverter propertyEntryConverter = new ModelPropertyEntryToOwnerActivityConverter();
ModelItem parentModelItem = (ModelItem)propertyEntryConverter.Convert(propertyValue.ParentProperty, typeof(ModelItem), true, null);
EditingContext context = ((IModelTreeItem)parentModelItem).ModelTreeManager.Context;
ModelItemDictionary inputData = parentModelItem.Properties[propertyValue.ParentProperty.PropertyName].Dictionary;
DynamicArgumentDesignerOptions options = new DynamicArgumentDesignerOptions();
options.Title = propertyValue.ParentProperty.DisplayName;
DynamicArgumentDialog.ShowDialog(parentModelItem, inputData, context, parentModelItem.View, options);
}
}
}

View File

@@ -0,0 +1,154 @@
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System.Activities.Presentation;
using System.Activities.Presentation.Converters;
using System.Activities.Presentation.Metadata;
using System.Activities.Presentation.Model;
using System.Activities.Presentation.PropertyEditing;
using System.Activities.Presentation.View;
using System.Activities.Statements;
using System.Activities.Validation;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ServiceModel;
using System.ServiceModel.Activities;
using System.ServiceModel.Activities.Presentation;
using System.ServiceModel.Activities.Presentation.Converters;
using System.ServiceModel.Presentation;
using System.Xml.Linq;
public class DesignerMetadata : IRegisterMetadata
{
// Called by the designer to register any design-time metadata.
//
// Be aware of the accidential performance impact when adding things into this method.
// In particular, pay attention to calls that will lead to loading extra assemblies.
//
public void Register()
{
AttributeTableBuilder builder = new AttributeTableBuilder();
//shared component
builder.AddCustomAttributes(typeof(Collection<Constraint>), new BrowsableAttribute(false));
builder.AddCustomAttributes(typeof(string), new EditorReuseAttribute(false));
builder.AddCustomAttributes(typeof(ActivityAction), new EditorReuseAttribute(false));
builder.AddCustomAttributes(typeof(XName), new EditorReuseAttribute(false));
//Flowchart activities
FlowchartDesigner.RegisterMetadata(builder);
FlowSwitchDesigner.RegisterMetadata(builder);
FlowDecisionDesigner.RegisterMetadata(builder);
// Messaging activities
ServiceDesigner.RegisterMetadata(builder);
// Registering inline for designers for InitializeCorrelation, Send, Receive, SendReply, ReceiveReply activities to avoid calling
// their static constructors. This will avoid instantiating the ResourceDictionary for their PropertyValueEditors during designer load.
builder.AddCustomAttributes(typeof(Send), new DesignerAttribute(typeof(SendDesigner)));
builder.AddCustomAttributes(typeof(Send), new ActivityDesignerOptionsAttribute { AllowDrillIn = false });
builder.AddCustomAttributes(typeof(Receive), new DesignerAttribute(typeof(ReceiveDesigner)));
builder.AddCustomAttributes(typeof(Receive), new ActivityDesignerOptionsAttribute { AllowDrillIn = false });
builder.AddCustomAttributes(typeof(SendReply), new FeatureAttribute(typeof(SendReplyValidationFeature)));
builder.AddCustomAttributes(typeof(SendReply), new DesignerAttribute(typeof(SendReplyDesigner)));
builder.AddCustomAttributes(typeof(SendReply), new ActivityDesignerOptionsAttribute { AllowDrillIn = false });
CutCopyPasteHelper.AddDisallowedTypeForCopy(typeof(SendReply));
builder.AddCustomAttributes(typeof(ReceiveReply), new FeatureAttribute(typeof(ReceiveReplyValidationFeature)));
builder.AddCustomAttributes(typeof(ReceiveReply), new DesignerAttribute(typeof(ReceiveReplyDesigner)));
builder.AddCustomAttributes(typeof(ReceiveReply), new ActivityDesignerOptionsAttribute { AllowDrillIn = false });
CutCopyPasteHelper.AddDisallowedTypeForCopy(typeof(ReceiveReply));
builder.AddCustomAttributes(typeof(InitializeCorrelation), new DesignerAttribute(typeof(InitializeCorrelationDesigner)));
builder.AddCustomAttributes(typeof(InitializeCorrelation), new ActivityDesignerOptionsAttribute { AllowDrillIn = false });
TransactedReceiveScopeDesigner.RegisterMetadata(builder);
CorrelationScopeDesigner.RegisterMetadata(builder);
//Procedural activities
AssignDesigner.RegisterMetadata(builder);
IfElseDesigner.RegisterMetadata(builder);
InvokeMethodDesigner.RegisterMetadata(builder);
DoWhileDesigner.RegisterMetadata(builder);
WhileDesigner.RegisterMetadata(builder);
ForEachDesigner.RegisterMetadata(builder);
TryCatchDesigner.RegisterMetadata(builder);
CatchDesigner.RegisterMetadata(builder);
ParallelDesigner.RegisterMetadata(builder);
SequenceDesigner.RegisterMetadata(builder);
SwitchDesigner.RegisterMetadata(builder);
CaseDesigner.RegisterMetadata(builder);
//Compensation/Transaction
CancellationScopeDesigner.RegisterMetadata(builder);
CompensableActivityDesigner.RegisterMetadata(builder);
TransactionScopeDesigner.RegisterMetadata(builder);
//Misc activities
PickDesigner.RegisterMetadata(builder);
PickBranchDesigner.RegisterMetadata(builder);
WriteLineDesigner.RegisterMetadata(builder);
NoPersistScopeDesigner.RegisterMetadata(builder);
InvokeDelegateDesigner.RegisterMetadata(builder);
// StateMachine
StateMachineDesigner.RegisterMetadata(builder);
StateDesigner.RegisterMetadata(builder);
TransitionDesigner.RegisterMetadata(builder);
builder.AddCustomAttributes(typeof(AddToCollection<>), new FeatureAttribute(typeof(UpdatableGenericArgumentsFeature)));
builder.AddCustomAttributes(typeof(RemoveFromCollection<>), new FeatureAttribute(typeof(UpdatableGenericArgumentsFeature)));
builder.AddCustomAttributes(typeof(ClearCollection<>), new FeatureAttribute(typeof(UpdatableGenericArgumentsFeature)));
builder.AddCustomAttributes(typeof(ExistsInCollection<>), new FeatureAttribute(typeof(UpdatableGenericArgumentsFeature)));
builder.AddCustomAttributes(typeof(AddToCollection<>), new DefaultTypeArgumentAttribute(typeof(int)));
builder.AddCustomAttributes(typeof(RemoveFromCollection<>), new DefaultTypeArgumentAttribute(typeof(int)));
builder.AddCustomAttributes(typeof(ClearCollection<>), new DefaultTypeArgumentAttribute(typeof(int)));
builder.AddCustomAttributes(typeof(ExistsInCollection<>), new DefaultTypeArgumentAttribute(typeof(int)));
MetadataStore.AddAttributeTable(builder.CreateTable());
MorphHelper.AddPropertyValueMorphHelper(typeof(InArgument<>), MorphHelpers.ArgumentMorphHelper);
MorphHelper.AddPropertyValueMorphHelper(typeof(OutArgument<>), MorphHelpers.ArgumentMorphHelper);
MorphHelper.AddPropertyValueMorphHelper(typeof(InOutArgument<>), MorphHelpers.ArgumentMorphHelper);
MorphHelper.AddPropertyValueMorphHelper(typeof(ActivityAction<>), MorphHelpers.ActivityActionMorphHelper);
MorphHelper.AddPropertyValueMorphHelper(typeof(ActivityFunc<,>), MorphHelpers.ActivityFuncMorphHelper);
// There is no need to keep an reference to this delayed worker since the AppDomain event handler will do it.
RegisterMetadataDelayedWorker delayedWorker = new RegisterMetadataDelayedWorker();
delayedWorker.RegisterMetadataDelayed("System.Workflow.Runtime", InteropDesigner.RegisterMetadata);
delayedWorker.RegisterMetadataDelayed("System.ServiceModel", RegisterMetadataForMessagingActivitiesSearchMetadata);
delayedWorker.RegisterMetadataDelayed("System.ServiceModel", RegisterMetadataForMessagingActivitiesPropertyEditors);
delayedWorker.WorkNowIfApplicable();
}
private static void RegisterMetadataForMessagingActivitiesPropertyEditors(AttributeTableBuilder builder)
{
EndpointDesigner.RegisterMetadata(builder);
builder.AddCustomAttributes(typeof(InArgument<CorrelationHandle>), new EditorReuseAttribute(false));
builder.AddCustomAttributes(typeof(InArgument<Uri>), new EditorReuseAttribute(false));
builder.AddCustomAttributes(typeof(MessageQuerySet), PropertyValueEditor.CreateEditorAttribute(typeof(CorrelatesOnValueEditor)));
}
private static void RegisterMetadataForMessagingActivitiesSearchMetadata(AttributeTableBuilder builder)
{
builder.AddCustomAttributes(typeof(SendMessageContent),
new SearchableStringConverterAttribute(typeof(SendMessageContentSearchableStringConverter)));
builder.AddCustomAttributes(typeof(SendParametersContent),
new SearchableStringConverterAttribute(typeof(SendParametersContentSearchableStringConverter)));
builder.AddCustomAttributes(typeof(ReceiveMessageContent),
new SearchableStringConverterAttribute(typeof(ReceiveMessageContentSearchableStringConverter)));
builder.AddCustomAttributes(typeof(ReceiveParametersContent),
new SearchableStringConverterAttribute(typeof(ReceiveParametersContentSearchableStringConverter)));
builder.AddCustomAttributes(typeof(XPathMessageQuery),
new SearchableStringConverterAttribute(typeof(XPathMessageQuerySearchableStringConverter)));
}
}
}

View File

@@ -0,0 +1,37 @@
//----------------------------------------------------------------
// <copyright company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//----------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Windows.Data;
[SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Used in XAML")]
internal sealed class DisplayNameConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string name = value as string;
if (name == null)
{
return SR.NullName;
}
else if (name == string.Empty)
{
return SR.EmptyName;
}
return name;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw FxTrace.Exception.AsError(new NotImplementedException());
}
}
}

View File

@@ -0,0 +1,29 @@
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System.Activities.Presentation.Metadata;
using System.Activities.Statements;
using System.ComponentModel;
/// <summary>
/// Interaction logic for WhileDesigner.xaml
/// </summary>
partial class DoWhileDesigner
{
public DoWhileDesigner()
{
InitializeComponent();
}
public static void RegisterMetadata(AttributeTableBuilder builder)
{
Type type = typeof(DoWhile);
builder.AddCustomAttributes(type, new DesignerAttribute(typeof(DoWhileDesigner)));
builder.AddCustomAttributes(type, type.GetProperty("Body"), BrowsableAttribute.No);
builder.AddCustomAttributes(type, type.GetProperty("Variables"), BrowsableAttribute.No);
}
}
}

View File

@@ -0,0 +1,103 @@
//----------------------------------------------------------------
// <copyright company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//----------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System;
using System.Activities.Presentation;
using System.Activities.Presentation.Model;
using System.ComponentModel;
using System.Windows.Controls;
internal partial class DynamicActivityPropertyChooser : UserControl
{
private DynamicActivityPropertyChooserViewModel model;
public DynamicActivityPropertyChooser()
{
this.Model = new DynamicActivityPropertyChooserViewModel();
this.InitializeComponent();
this.Model.PropertyChanged += new PropertyChangedEventHandler(this.OnModelPropertyChanged);
this.comboBox.DropDownOpened += new EventHandler(this.OnComboBoxDropDownOpened);
}
public event SelectedPropertyNameChangedEventHandler SelectedPropertyNameChanged;
public DynamicActivityPropertyChooserViewModel Model
{
get
{
return this.model;
}
set
{
this.model = value;
}
}
public ModelItemCollection Properties
{
set
{
this.Model.Properties = value;
}
}
public Predicate<DynamicActivityProperty> Filter
{
set
{
this.Model.Filter = value;
}
}
public string SelectedPropertyName
{
get
{
return this.Model.SelectedPropertyName;
}
set
{
this.Model.SelectedPropertyName = value;
}
}
public bool IsUpdatingDropDownItems
{
get
{
return this.Model.IsUpdatingDropDownItems;
}
}
protected override void OnInitialized(EventArgs e)
{
this.DataContext = this.Model;
base.OnInitialized(e);
}
private void OnComboBoxDropDownOpened(object sender, EventArgs e)
{
this.Model.UpdateDropDownItems();
}
private void OnModelPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "SelectedPropertyName")
{
if (this.SelectedPropertyNameChanged != null)
{
this.SelectedPropertyNameChanged(this, new SelectedPropertyNameChangedEventArgs(this.Model.SelectedPropertyName));
}
}
}
}
}

View File

@@ -0,0 +1,152 @@
//----------------------------------------------------------------
// <copyright company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//----------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System.Activities.Presentation;
using System.Activities.Presentation.Model;
using System.Collections.Generic;
using System.Collections.ObjectModel;
internal class DynamicActivityPropertyChooserViewModel : ViewModel
{
private string selectedPropertyName;
private ModelItemCollection properties;
private Predicate<DynamicActivityProperty> filter;
private ReadOnlyCollection<DynamicActivityProperty> dropDownItems;
public ModelItemCollection Properties
{
private get
{
return this.properties;
}
set
{
this.properties = value;
}
}
public Predicate<DynamicActivityProperty> Filter
{
private get
{
return this.filter;
}
set
{
this.filter = value;
}
}
public ReadOnlyCollection<DynamicActivityProperty> DropDownItems
{
get
{
if (this.dropDownItems == null)
{
this.dropDownItems = new ReadOnlyCollection<DynamicActivityProperty>(new List<DynamicActivityProperty>());
}
return this.dropDownItems;
}
private set
{
if (this.dropDownItems != value)
{
this.dropDownItems = value;
NotifyPropertyChanged("DropDownItems");
}
}
}
public bool IsUpdatingDropDownItems { get; private set; }
public string SelectedPropertyName
{
get
{
return this.selectedPropertyName;
}
set
{
if (this.selectedPropertyName != value)
{
this.selectedPropertyName = value;
this.UpdateDropDownItems();
this.NotifyPropertyChanged("SelectedPropertyName");
}
}
}
public void UpdateDropDownItems()
{
if (this.IsUpdatingDropDownItems)
{
return;
}
List<DynamicActivityProperty> list = new List<DynamicActivityProperty>();
bool currentSelectionFound = false;
if (this.Properties != null)
{
foreach (ModelItem modelItem in this.Properties)
{
DynamicActivityProperty property = modelItem.GetCurrentValue() as DynamicActivityProperty;
if (property != null)
{
if (this.Filter == null || this.Filter(property))
{
DynamicActivityProperty clone = new DynamicActivityProperty();
clone.Name = property.Name;
clone.Type = property.Type;
list.Add(clone);
if (StringComparer.Ordinal.Equals(this.SelectedPropertyName, property.Name))
{
currentSelectionFound = true;
}
}
}
}
}
string savedSelectedPropertyName = this.SelectedPropertyName;
if (!currentSelectionFound)
{
if (!string.IsNullOrEmpty(this.SelectedPropertyName))
{
DynamicActivityProperty unresolvedProperty = new DynamicActivityProperty();
unresolvedProperty.Name = this.SelectedPropertyName;
list.Add(unresolvedProperty);
}
}
list.Sort(new DynamicaActivityPropertyComparer());
this.IsUpdatingDropDownItems = true;
this.DropDownItems = new ReadOnlyCollection<DynamicActivityProperty>(list);
this.SelectedPropertyName = savedSelectedPropertyName;
this.IsUpdatingDropDownItems = false;
}
private class DynamicaActivityPropertyComparer : IComparer<DynamicActivityProperty>
{
public int Compare(DynamicActivityProperty x, DynamicActivityProperty y)
{
return string.CompareOrdinal(x.Name, y.Name);
}
}
}
}

View File

@@ -0,0 +1,40 @@
//----------------------------------------------------------------
// <copyright company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//----------------------------------------------------------------
namespace System.Activities.Core.Presentation
{
using System.Activities.Presentation;
using System.Globalization;
using System.Windows.Data;
using Microsoft.Activities.Presentation;
internal sealed class DynamicActivityPropertyToTooltipConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
DynamicActivityProperty property = value as DynamicActivityProperty;
if (property == null)
{
return null;
}
if (property.Type == null)
{
return string.Format(CultureInfo.CurrentUICulture, SR.PropertyReferenceNotResolved, property.Name);
}
else
{
return TypeNameHelper.GetDisplayName(property.Type, false);
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw FxTrace.Exception.AsError(new NotImplementedException());
}
}
}

Some files were not shown because too many files have changed in this diff Show More