// These methods are not used, but they are very useful when developing the Design experience #if Development /// <summary> /// Adds a default column for each property in the data source /// </summary> public static void GenerateColumns(ModelItem dataGridModelItem, EditingContext context) { using (ModelEditingScope scope = dataGridModelItem.BeginEdit(Properties.Resources.Generate_Columns)) { // Set databinding related properties DataGridDesignHelper.SparseSetValue(dataGridModelItem.Properties[MyPlatformTypes.DataGrid.AutoGenerateColumnsProperty], false); // Get the datasource object dataSource = dataGridModelItem.Properties[MyPlatformTypes.DataGrid.ItemsSourceProperty].ComputedValue; if (dataSource != null) { foreach (ColumnInfo columnGenerationInfo in DataGridDesignHelper.GetColumnGenerationInfos(dataSource)) { ModelItem dataGridColumn = null; dataGridColumn = DataGridDesignHelper.CreateDefaultDataGridColumn(context, columnGenerationInfo); if (dataGridColumn != null) { dataGridModelItem.Properties[MyPlatformTypes.DataGrid.ColumnsProperty].Collection.Add(dataGridColumn); } } } scope.Complete(); } }
public override void ShowDialog(PropertyValue propertyValue, System.Windows.IInputElement commandSource) { EventActionWin wn = new EventActionWin(); EventActionDefine action = propertyValue.Value as EventActionDefine; wn.action_url = action.url; wn.action_params = action.action_params; wn.event_linkParams = action.event_params; if (wn.ShowDialog().Equals(true)) { var ownerActivityConverter = new ModelPropertyEntryToOwnerActivityConverter(); ModelItem activityItem = ownerActivityConverter.Convert(propertyValue.ParentProperty, typeof(ModelItem), false, null) as ModelItem; using (ModelEditingScope editingScope = activityItem.BeginEdit()) { EventActionDefine newValue = new EventActionDefine(); newValue.url = wn.action_url; newValue.action_params = wn.action_params; newValue.event_params = wn.event_linkParams; propertyValue.Value = newValue; editingScope.Complete(); var control = commandSource as Control; var oldData = control.DataContext; control.DataContext = null; control.DataContext = oldData; } } }
public void BeginEdit() { try { _scope = _modelItem.BeginEdit(); _session = new UaSession { EndpointUrl = Session.EndpointUrl }; if (_session != null) { try { NamespaceItems.Clear(); var root = new ReferenceDescriptionViewModel(new ReferenceDescription { DisplayName = "Objects", NodeId = new NodeId(Objects.ObjectsFolder, 0) }, null, LoadChildren); NamespaceItems.Add(root); root.IsExpanded = true; } catch (Exception ex) { Debug.WriteLine(ex.Message); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
/// <summary> /// Handles the Click event of the DefineArgsButton control to launch a DynamicArgumentDialog instance for argument editing. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void DefineArgsButton_Click(object sender, RoutedEventArgs e) { DynamicArgumentDesignerOptions options = new DynamicArgumentDesignerOptions() { Title = Bot.Activity.ActivityLibrary.Properties.Resources.DynamicArgumentDialogTitle }; this.InitImportDynamicArgumentDialog(); this.ModelItem.Properties["ChildArguments"].SetValue(argumentDictionary); ModelItem modelItem = this.ModelItem.Properties["ChildArguments"].Dictionary; using (ModelEditingScope change = modelItem.BeginEdit("ChildArgumentEditing")) { ThreadInvoker.Instance.RunByUiThread(() => { if (DynamicArgumentDialog.ShowDialog(this.ModelItem, modelItem, Context, this.ModelItem.View, options)) { change.Complete(); } else { change.Revert(); } }); } }
private void Button_Click(object sender, RoutedEventArgs e) { using (var xEditScope = mControlModel.BeginEdit()) { var buttonType = ModelFactory.ResolveType(mControlModel.Context, new TypeIdentifier("System.Windows.Controls.Button")); var modelService = mControlModel.Context.Services.GetRequiredService <ModelService>(); var buttonItem = ModelFactory.CreateItem(mControlModel.Context, buttonType); var allButtons = modelService.Find(buttonItem, t => true); mControlModel.Properties["Height"].ClearValue(); mControlModel.Properties["Width"].ClearValue(); mControlModel.Properties["Margin"].ClearValue(); mControlModel.Properties["HorizontalAlignment"].ClearValue(); mControlModel.Properties["VerticalAlignment"].ClearValue(); xEditScope.Complete(); } if (AfterEdit != null) { AfterEdit(); AfterEdit = null; } }
private static void UpdateTypeArgument(ModelItem modelItem, Int32 argumentIndex, Type newGenericType) { Type itemType = modelItem.ItemType; Type[] genericTypes = itemType.GetGenericArguments(); // Replace the type being changed genericTypes[argumentIndex] = newGenericType; Type newType = itemType.GetGenericTypeDefinition().MakeGenericType(genericTypes); EditingContext editingContext = modelItem.GetEditingContext(); Object instanceOfNewType = Activator.CreateInstance(newType); ModelItem newModelItem = ModelFactory.CreateItem(editingContext, instanceOfNewType); using (ModelEditingScope editingScope = newModelItem.BeginEdit("Change type argument")) { MorphHelper.MorphObject(modelItem, newModelItem); MorphHelper.MorphProperties(modelItem, newModelItem); if (itemType.IsSubclassOf(typeof(Activity)) && newType.IsSubclassOf(typeof(Activity))) { if (DisplayNameRequiresUpdate(modelItem)) { // Update to the new display name String newDisplayName = GetActivityDefaultName(newType); newModelItem.Properties[DisplayName].SetValue(newDisplayName); } } DesignerUpdater.UpdateModelItem(modelItem, newModelItem); editingScope.Complete(); } }
public override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource) { string propertyName = propertyValue.ParentProperty.PropertyName; var ownerActivity = (new ModelPropertyEntryToOwnerActivityConverter()).Convert( propertyValue.ParentProperty, typeof(ModelItem), false, null) as ModelItem; DynamicArgumentDesignerOptions options = new DynamicArgumentDesignerOptions() { Title = propertyName }; ModelItem modelItem = ownerActivity.Properties[propertyName].Dictionary; using (ModelEditingScope change = modelItem.BeginEdit(propertyName + "Editing")) { if (DynamicArgumentDialog.ShowDialog(ownerActivity, modelItem, ownerActivity.GetEditingContext(), ownerActivity.View, options)) { change.Complete(); } else { change.Revert(); } } }
/// <summary> /// Add Columns based on the datasource /// </summary> private void AddColumns(ModelItem selectedDataGrid, EditingContext context) { using (ModelEditingScope scope = selectedDataGrid.BeginEdit("Generate Columns")) { // Set databinding related properties DataGridHelper.SparseSetValue(selectedDataGrid.Properties[DataGrid.AutoGenerateColumnsProperty], false); // Get the datasource object dataSource = selectedDataGrid.Properties[ItemsControl.ItemsSourceProperty].ComputedValue; if (dataSource != null) { // Does WPF expose something like ListBindingHelper? PropertyDescriptorCollection dataSourceProperties = System.Windows.Forms.ListBindingHelper.GetListItemProperties(dataSource); foreach (PropertyDescriptor pd in dataSourceProperties) { ModelItem dataGridColumn = null; dataGridColumn = DataGridHelper.CreateDefaultDataGridColumn(context, pd); if (dataGridColumn != null) { selectedDataGrid.Properties["Columns"].Collection.Add(dataGridColumn); } } } scope.Complete(); } }
/// <summary> /// AddTab menu item action. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event arguments.</param> private void AddTabMenuAction_Execute(object sender, MenuActionEventArgs e) { ModelItem primarySelection = e.Selection.PrimarySelection; ModelItem tabControl = null; if (primarySelection.IsItemOfType(MyPlatformTypes.TabControl.TypeId)) { tabControl = e.Selection.PrimarySelection; } else if (primarySelection.IsItemOfType(MyPlatformTypes.TabItem.TypeId)) { ModelItem parent = e.Selection.PrimarySelection.Parent; if (parent != null && parent.IsItemOfType(MyPlatformTypes.TabControl.TypeId)) { tabControl = parent; } } if (tabControl != null) { using (ModelEditingScope changes = tabControl.BeginEdit(Properties.Resources.TabControl_AddTabMenuItem)) { ModelItem newTabItem = ModelFactory.CreateItem(e.Context, MyPlatformTypes.TabItem.TypeId, CreateOptions.InitializeDefaults); tabControl.Content.Collection.Add(newTabItem); // change selection to newly created TabItem. Selection sel = new Selection(newTabItem); e.Context.Items.SetValue(sel); changes.Complete(); } } }
public void ShowDialog(ModelItem ownerActivity) { using (ModelEditingScope modelEditingScope = ownerActivity.BeginEdit()) { var dlg = new VBNetCodeEditorDialog(ownerActivity); if (!string.IsNullOrEmpty(Title)) { dlg.Title = Title; } if (!string.IsNullOrEmpty(ContentTitle)) { dlg.lblContentTitle.Content = ContentTitle; } if (dlg.ShowOkCancel()) { modelEditingScope.Complete(); } else { modelEditingScope.Revert(); } } }
public static void OnAddAnnotationCommandExecuted(ExecutedRoutedEventArgs e, ModelItem modelItem) { ModelProperty property = modelItem.Properties.Find(Annotation.AnnotationTextPropertyName); if (property != null) { using (ModelEditingScope editingScope = modelItem.BeginEdit(SR.AddAnnotationDescription)) { property.SetValue(string.Empty); ViewStateService viewStateService = modelItem.GetEditingContext().Services.GetService <ViewStateService>(); viewStateService.StoreViewStateWithUndo(modelItem, Annotation.IsAnnotationDockedViewStateName, false); editingScope.Complete(); } if (modelItem.View != null) { WorkflowViewElement element = modelItem.View as WorkflowViewElement; if (element != null) { element.OnEditAnnotation(); } } } e.Handled = true; }
public override void ShowDialog(PropertyValue propertyValue, System.Windows.IInputElement commandSource) { TimeoutWin wn = new TimeoutWin(); Dictionary <string, object> action = propertyValue.Value as Dictionary <string, object>; wn.time_start = action.ContainsKey("start") ? (action["start"] as string) : ""; wn.time_offset = action.ContainsKey("offset") ? (action["offset"] as TimeSpan?) : null; wn.time_exact = action.ContainsKey("exact") ? (action["exact"] as DateTime?) : null; wn.time_callback = action.ContainsKey("callback") ? (action["callback"] as string) : ""; wn.time_action = action.ContainsKey("action") ? (action["action"] as string) : ""; if (wn.ShowDialog().Equals(true)) { var ownerActivityConverter = new ModelPropertyEntryToOwnerActivityConverter(); ModelItem activityItem = ownerActivityConverter.Convert(propertyValue.ParentProperty, typeof(ModelItem), false, null) as ModelItem; using (ModelEditingScope editingScope = activityItem.BeginEdit()) { Dictionary <string, object> newValue = new Dictionary <string, object>(); newValue["start"] = wn.time_start; newValue["offset"] = wn.time_offset; newValue["exact"] = wn.time_exact; newValue["action"] = wn.time_action; newValue["callback"] = wn.time_callback; propertyValue.Value = newValue; editingScope.Complete(); var control = commandSource as Control; var oldData = control.DataContext; control.DataContext = null; control.DataContext = oldData; } } }
/// <summary> /// Removes all columns from the DataGrid /// </summary> public static void RemoveColumns(ModelItem dataGridModelItem, EditingContext editingContext) { using (ModelEditingScope scope = dataGridModelItem.BeginEdit(Properties.Resources.Remove_Columns)) { dataGridModelItem.Properties[MyPlatformTypes.DataGrid.ColumnsProperty].Collection.Clear(); scope.Complete(); } }
internal static void GoToFirstPage(ModelItem wizard) { using (ModelEditingScope changes = wizard.BeginEdit(Resources.FirstPageText)) { SetCurrentPageIndex(wizard, 0); changes.Complete(); } }
internal static void GoToNextPage(ModelItem wizard) { using (ModelEditingScope changes = wizard.BeginEdit(Resources.NextPageText)) { var pageIndex = GetCurrentPageIndex(wizard); SetCurrentPageIndex(wizard, pageIndex + 1); changes.Complete(); } }
internal static void GoToLastPage(ModelItem wizard) { using (ModelEditingScope changes = wizard.BeginEdit(Resources.LastPageText)) { int pageCount = wizard.Content.Collection.Count; SetCurrentPageIndex(wizard, pageCount - 1); changes.Complete(); } }
/// <summary> /// Remove columns /// </summary> private void RemoveColumnsMenuAction_Execute(object sender, MenuActionEventArgs e) { ModelItem selectedDataGrid = e.Selection.PrimarySelection; using (ModelEditingScope scope = selectedDataGrid.BeginEdit("Delete Grid Columns")) { selectedDataGrid.Properties["Columns"].Collection.Clear(); scope.Complete(); } }
public override void InitializeDefaults(ModelItem item) { using (ModelEditingScope batchedChange = item.BeginEdit("Creates Default Items")) { for (int j = 0; j < 2; j++) { ModelItem i = ModelFactory.CreateItem(item.Context, typeof(NavigationPaneItem), CreateOptions.InitializeDefaults, null); item.Properties["Items"].Collection.Add(i); } batchedChange.Complete(); } }
public static void OnDeleteAnnotationCommandExecuted(ExecutedRoutedEventArgs e, ModelItem modelItem) { using (ModelEditingScope editingScope = modelItem.BeginEdit(SR.DeleteAnnotationDescription)) { modelItem.Properties[Annotation.AnnotationTextPropertyName].SetValue(null); ViewStateService viewStateService = modelItem.GetEditingContext().Services.GetService <ViewStateService>(); viewStateService.StoreViewStateWithUndo(modelItem, Annotation.IsAnnotationDockedViewStateName, null); editingScope.Complete(); } e.Handled = true; }
internal static void RemovePage(ModelItem wizard) { using (ModelEditingScope changes = wizard.BeginEdit(Resources.RemovePageText)) { int count = wizard.Content.Collection.Count; int currentPageIndex = (int)wizard.Properties[Types.Designer.PageIndexProperty].ComputedValue; wizard.Content.Collection.RemoveAt(currentPageIndex); wizard.Properties[Types.Designer.PageIndexProperty].SetValue( Math.Min(currentPageIndex, count - 2)); changes.Complete(); } }
internal static void AddPage(ModelItem wizard) { using (ModelEditingScope changes = wizard.BeginEdit(Resources.AddPageText)) { ModelItem newPage = ModelFactory.CreateItem( wizard.Context, Types.WizardPage.TypeId, CreateOptions.None); wizard.Content.Collection.Add(newPage); changes.Complete(); } GoToLastPage(wizard); }
private void SqlButton_Click(object sender, System.Windows.RoutedEventArgs e) { using (ModelEditingScope editingScope = ModelItem.BeginEdit()) { SqlEditorDialog sqlDialog = new SqlEditorDialog(ModelItem); if (sqlDialog.ShowOkCancel()) { editingScope.Complete(); } else { editingScope.Revert(); } } }
/// <summary> /// Opens the Edit Property-Bound Columns dialog for the given DataGrid /// </summary> public static void EditPropertyBoundColumns(ModelItem dataGridModelItem, EditingContext editingContext) { using (ModelEditingScope scope = dataGridModelItem.BeginEdit(Properties.Resources.ColumnsChanged)) { PropertyColumnEditor ui = new PropertyColumnEditor(editingContext, dataGridModelItem); // Use Windows Forms to show the design time because Windows Forms knows about the VS message pump System.Windows.Forms.DialogResult result = DesignerDialog.ShowDesignerDialog(Properties.Resources.Edit_Property_Bound_Columns_Dialog_Title, ui); if (result == System.Windows.Forms.DialogResult.OK) { scope.Complete(); } else { scope.Revert(); } } }
// The following method is called when allowed control is dropped over custom button // from toolbox. It adds the child and changes the text. public override void Parent(ModelItem newParent, ModelItem child) { if (newParent == null) { throw new ArgumentNullException("newParent"); } if (child == null) { throw new ArgumentNullException("child"); } using (ModelEditingScope scope = newParent.BeginEdit()) { child.Properties["Text"].SetValue("Button Child"); newParent.Content.Collection.Add(child); scope.Complete(); } }
private void BeginEdit_Click(object sender, RoutedEventArgs e) { ModelItem mi = workflowDesigner.Context.Services.GetService <ModelService>().Root; // note that editing scopes can nest, so we will keep track of the "top" with a stack. EditingScopes.Insert(0, mi.BeginEdit()); // we know that the root is a sequence // we make multiple changes to the model item tree. // you'll note in the UI, nothing has changed yet, as this has not // yet been committed to the model item tree mi.Properties["Activities"].Collection.Add(new WriteLine { Text = "here is the text" }); mi.Properties["Activities"].Collection.Add(new Persist()); mi.Properties["Activities"].Collection.Add(new Flowchart()); CloseButton.IsEnabled = true; RevertButton.IsEnabled = true; }
private void Button_Click(object sender, RoutedEventArgs e) { using (var xEditScope = mControlModel.BeginEdit()) { mControlModel.Properties["Height"].ClearValue(); mControlModel.Properties["Width"].ClearValue(); mControlModel.Properties["Margin"].ClearValue(); mControlModel.Properties["HorizontalAlignment"].ClearValue(); mControlModel.Properties["VerticalAlignment"].ClearValue(); xEditScope.Complete(); } if (AfterEdit != null) { AfterEdit(); AfterEdit = null; } }
protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e) { if (e != null && !this.Disabled) { ModelItem stateContainerModelItem = this.ParentStateContainerEditor.ModelItem; // Save the new size to view state. using (ModelEditingScope scope = stateContainerModelItem.BeginEdit(SR.Resize)) { ViewStateService viewStateService = this.ParentStateContainerEditor.Context.Services.GetService <ViewStateService>(); viewStateService.StoreViewStateWithUndo(stateContainerModelItem, StateContainerEditor.StateContainerWidthViewStateKey, this.ParentStateContainerEditor.StateContainerWidth); viewStateService.StoreViewStateWithUndo(stateContainerModelItem, StateContainerEditor.StateContainerHeightViewStateKey, this.ParentStateContainerEditor.StateContainerHeight); scope.Complete(); } Mouse.OverrideCursor = null; Mouse.Capture(null); e.Handled = true; } base.OnPreviewMouseLeftButtonUp(e); }
internal static void InsertPage(ModelItem wizard) { if (wizard.Content.Collection.Count == 0) { AddPage(wizard); return; } using (ModelEditingScope changes = wizard.BeginEdit(Resources.InsertPageText)) { ModelItem newPage = ModelFactory.CreateItem( wizard.Context, Types.WizardPage.TypeId, CreateOptions.None); int currentPageIndex = (int)wizard.Properties[Types.Designer.PageIndexProperty].ComputedValue; wizard.Content.Collection.Insert(currentPageIndex, newPage); changes.Complete(); } }
protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e) { if (!this.Disabled) { FlowchartDesigner flowchartDesigner = this.ParentFlowchartDesigner; ModelItem flowchartModelItem = this.ParentFlowchartDesigner.ModelItem; using (ModelEditingScope scope = flowchartModelItem.BeginEdit(SR.FCResizeUndoUnitName)) { TypeDescriptor.GetProperties(flowchartModelItem)[FlowchartSizeFeature.WidthPropertyName].SetValue(flowchartModelItem, flowchartDesigner.FlowchartWidth); TypeDescriptor.GetProperties(flowchartModelItem)[FlowchartSizeFeature.HeightPropertyName].SetValue(flowchartModelItem, flowchartDesigner.FlowchartHeight); scope.Complete(); } Mouse.OverrideCursor = null; Mouse.Capture(null); ParentFlowchartDesigner.IsResizing = false; e.Handled = true; } base.OnPreviewMouseLeftButtonUp(e); }
public override object TranslatePropertyValue(ModelItem item, PropertyIdentifier identifier, object value) { MessageBox.Show($"name: {identifier.Name}\r\n" + $"value: {value}\r\n" + $"type: {value?.GetType()}\r\n" + $"item.View: {item.View}\r\n" + $"item.GetCurrentValue(): {item.GetCurrentValue()}"); if (identifier.DeclaringType == BackgroundPropertyIdentifier.DeclaringType) { using (var editingScope = item.BeginEdit()) { var button = item.GetCurrentValue() as Button; button?.SetValue(Control.BackgroundProperty, value); } return value; } return base.TranslatePropertyValue(item, identifier, value); }
public static void ShowDialog(string propertyName, ModelItem ownerActivity) { DynamicArgumentDesignerOptions options = new DynamicArgumentDesignerOptions() { Title = propertyName }; ModelItem modelItem = ownerActivity.Properties[propertyName].Value; using (ModelEditingScope change = modelItem.BeginEdit(propertyName + "Editing")) { if (DynamicArgumentDialog.ShowDialog(ownerActivity, modelItem, ownerActivity.GetEditingContext(), ownerActivity.View, options)) { change.Complete(); } else { change.Revert(); } } }
public override void InitializeDefaults(ModelItem item) { using (ModelEditingScope batchedChange = item.BeginEdit("Creates Default Items")) { // vs editor defaults some properties values in the control // we must clear those for the NavigationPaneDefaults to work correctly // and because WE DON'T NEED THOSE property values and the template // already put correct values to have a correct diplay of items inside te control item.Properties["Name"].ClearValue(); item.Properties["Height"].ClearValue(); item.Properties["HorizontalAlignment"].ClearValue(); item.Properties["VerticalAlignment"].ClearValue(); item.Properties["Width"].ClearValue(); item.Properties["Header"].SetValue("NavigationPaneItem"); Grid grid = new Grid(); grid.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#FFE5E5E5")); item.Content.SetValue(grid); batchedChange.Complete(); } }