/// <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 override void ShowDialog(PropertyValue propertyValue, IInputElement commandSource)
        {
            ModelPropertyEntryToOwnerActivityConverter ownerActivityConverter = new ModelPropertyEntryToOwnerActivityConverter();
            ModelItem activityItem =
                ownerActivityConverter.Convert(propertyValue.ParentProperty, typeof(ModelItem), false, null) as ModelItem;
            EditingContext context = activityItem.GetEditingContext();

            ModelItem parentModelItem =
                ownerActivityConverter.Convert(propertyValue.ParentProperty, typeof(ModelItem), true, null) as ModelItem;
            ModelItemDictionary arguments = parentModelItem.Properties[propertyValue.ParentProperty.PropertyName].Dictionary;

            DynamicArgumentDesignerOptions options = new DynamicArgumentDesignerOptions
            {
                Title = propertyValue.ParentProperty.DisplayName
            };

            using (ModelEditingScope change = arguments.BeginEdit("PowerShellParameterEditing"))
            {
                if (DynamicArgumentDialog.ShowDialog(activityItem, arguments, context, activityItem.View, options))
                {
                    change.Complete();
                }
                else
                {
                    change.Revert();
                }
            }
        }
Beispiel #3
0
        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;
                }
            }
        }
Beispiel #4
0
        public Variable <T> GetVariableOf <T>(string Name)
        {
            if (selectedActivity == null)
            {
                throw new Exception("Cannot get variable when no activity has been selected");
            }
            var seq = GetVariableScope(selectedActivity);

            if (seq == null)
            {
                throw new Exception("Cannot add variables to root activity!");
            }
            Variable <T> result = null;

            result = GetVariableModel <T>(Name, selectedActivity);
            if (result == null)
            {
                ModelService modelService = wfDesigner.Context.Services.GetService <ModelService>();
                using (ModelEditingScope editingScope = modelService.Root.BeginEdit("Implementation"))
                {
                    var Variables = seq.Properties["Variables"].Collection;
                    result = new Variable <T>()
                    {
                        Name = Name
                    };
                    Variables.Add(result);
                    editingScope.Complete();
                }
            }
            return(result);
        }
        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();
                }
            }
        }
        // return true if really something is dropped, otherwise, false.
        bool DoAutoWrapDrop(InsertionPosition insertionPos, IEnumerable <object> droppedObjects)
        {
            List <Activity> activityList = ObjectList2ActivityList(droppedObjects);

            if (activityList.Count == 0)
            {
                return(false);
            }

            AutoWrapEventArgs args = new AutoWrapEventArgs()
            {
                InsertionPosition      = insertionPos,
                ExistingActivity       = this.MyActivity,
                ActivitiesToBeInserted = activityList
            };

            using (ModelEditingScope scope = this.Context.Services.GetService <ModelService>().Root.BeginEdit(SR.WrapInSequenceDescription))
            {
                ModelItem sequenceActivity = WorkflowItemPresenter.AutoWrapInSequenceHandler(this.Context, args);
                if (this.UpdateItem(sequenceActivity, true))
                {
                    scope.Complete();
                    return(true);
                }
                else
                {
                    scope.Revert();
                    return(false);
                }
            }
        }
        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();
            }
        }
        void OnCreateSendReplyExecute(object sender, ExecutedRoutedEventArgs e)
        {
            ModelItem container;
            ModelItem flowStepContainer;

            using (ModelEditingScope scope = this.ModelItem.BeginEdit((string)this.FindResource("createSendReplyDescription")))
            {
                //special case handling for Sequence
                if (this.ModelItem.IsItemInSequence(out container))
                {
                    //get activities collection
                    ModelItemCollection activities = container.Properties["Activities"].Collection;
                    //get index of Send within collection and increment by one
                    int index = activities.IndexOf(this.ModelItem) + 1;
                    //insert created reply just after the Receive
                    activities.Insert(index, ReceiveDesigner.CreateSendReply(container, this.ModelItem));
                }
                //special case handling for Flowchart
                else if (this.ModelItem.IsItemInFlowchart(out container, out flowStepContainer))
                {
                    Activity replyActivity = ReceiveDesigner.CreateSendReply(container, this.ModelItem);
                    FlowchartDesigner.DropActivityBelow(this.ViewStateService, this.ModelItem, replyActivity, 30);
                }
                else
                {
                    ErrorReporting.ShowAlertMessage(string.Format(CultureInfo.CurrentUICulture, System.Activities.Core.Presentation.SR.CannotPasteSendReplyOrReceiveReply, typeof(SendReply).Name));
                }
                scope.Complete();
            }
            //always copy reply to clipboard
            Func <ModelItem, object, object> callback = CreateSendReply;

            CutCopyPasteHelper.PutCallbackOnClipBoard(callback, typeof(SendReply), this.ModelItem);
            e.Handled = true;
        }
 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);
     }
 }
Beispiel #10
0
        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();
                }
            }
        }
        private void EditColumn()
        {
            DataGridColumnModel columnModel = datagridColumnsListBox.SelectedItem as DataGridColumnModel;

            if (columnModel == null)
            {
                return;
            }

            using (ModelEditingScope scope = columnModel.Column.BeginEdit(columnModel.Column.Name + " Changed"))
            {
                EditDataGridColumnsUserInterface ui = new EditDataGridColumnsUserInterface(_context, columnModel, _dataSourceProperties);

                // Use Windows Forms to show the design time because Windows Forms knows about the VS message pump
                System.Windows.Forms.DialogResult result = DesignerDialog.ShowDesignerDialog("Edit Column", ui, 360, 470);
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    scope.Complete();
                    _dataSourcePropertiesCVS.View.Refresh();
                }
                else
                {
                    scope.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;
        }
        // <summary>
        // Basic ctor
        // </summary>
        // <param name="property">Property to display</param>
        // <param name="valueDialogTemplate">Template to use</param>
        public PropertyValueDialogControl(PropertyEntry property, DataTemplate valueDialogTemplate)
        {
            Fx.Assert(property != null, "property parameter is null");
            Fx.Assert(valueDialogTemplate != null, "valueDialogTemplate parameter is null");

            ModelPropertyEntry modelPropertyValue = property as ModelPropertyEntry;

            if (modelPropertyValue != null)
            {
                _rootTransaction = modelPropertyValue.FirstModelProperty.Value.BeginEdit();
            }

            InitializeComponent();

            // Make sure we use PI-specific resources within this control
            this.Resources.MergedDictionaries.Add(PropertyInspectorResources.GetResources());

            // Hook into an opening of nested dialogs.  PropertyInspector class takes care of this for us.
            // However, we are using Blend's collection editor which doesn't do the same thing, so
            // we need to reproduce that behavior manually.
            PropertyValueDialogHost.AttachOpenDialogHandlers(this);

            // Hook into the standard set of Commands
            _defaultCommandHandler = new PropertyValueEditorCommandHandler(this);


            _OKButton.Click                += new RoutedEventHandler(OnOkButtonClicked);
            _cancelButton.Click            += new RoutedEventHandler(OnCancelButtonClicked);
            _contentControl.Content         = property.PropertyValue;
            _contentControl.ContentTemplate = valueDialogTemplate;

            //Handle the commit and cancel keys within the property inspector, that is hosted in the collection editor
            ValueEditorUtils.SetHandlesCommitKeys(this, true);
        }
Beispiel #14
0
        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;
                }
            }
        }
Beispiel #15
0
        /// <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();
                    }
                });
            }
        }
        /// <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();
            }
        }
        bool UpdateItem(object newItem, bool allowReplaceExistingActivity)
        {
            bool      updateSucceeded = false;
            ModelItem newModelItem    = newItem as ModelItem;

            if (this.Item == null || allowReplaceExistingActivity)
            {
                if (newModelItem == null && newItem != null)
                {
                    // try to wrap the droppedObject in  a ModelItem.
                    ModelServiceImpl modelService = (ModelServiceImpl)this.Context.Services.GetService <ModelService>();
                    newModelItem = modelService.WrapAsModelItem(newItem);
                }
                if (this.CanUpdateItem(newModelItem))
                {
                    // In order to allow for model updates that happens during the model item is drop, this is all done in an atomic unit.
                    using (ModelEditingScope editingScope = this.Context.Services.GetService <ModelService>().Root.BeginEdit(SR.PropertyChangeEditingScopeDescription))
                    {
                        this.Item = newModelItem;
                        editingScope.Complete();
                    }
                    updateSucceeded            = true;
                    this.isItemPastedOrDropped = true;
                }
            }
            return(updateSucceeded);
        }
Beispiel #18
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            var options = new DynamicArgumentDesignerOptions
            {
                Title = string.Format("Параметры метода {0}", _methodInfo.Name)
            };

            var modelParameters = GetParametersProperty();

            foreach (var p in _methodParameters)
            {
                if (modelParameters.ContainsKey(p.Name ?? ResultParamName))
                {
                    continue;
                }

                var direction = (p.IsOut || p.IsRetval || string.IsNullOrEmpty(p.Name)) ? ArgumentDirection.Out : ArgumentDirection.In;
                modelParameters.Add(p.Name ?? ResultParamName, ActivityHelpers.CreateDefaultValue(p.ParameterType, direction));
            }

            using (ModelEditingScope change = modelParameters.BeginEdit("ObjectEditing"))
            {
                if (DynamicArgumentDialog.ShowDialog(ModelItem, modelParameters, Context, ModelItem.View, options))
                {
                    change.Complete();
                }
                else
                {
                    change.Revert();
                }
            }
        }
Beispiel #19
0
        public void Complete()
        {
            if (this._activeTool == null)
            {
                throw new InvalidOperationException(Resources.Error_ObjectNotActive);
            }
            ModelEditingScope modelEditingScope = this._editingScope;

            try
            {
                this.OnCompleted(EventArgs.Empty);
                if (modelEditingScope == null)
                {
                    return;
                }
                if (this.Description.Length > 0)
                {
                    modelEditingScope.Description = this.Description;
                }
                modelEditingScope.Complete();
                modelEditingScope = (ModelEditingScope)null;
            }
            finally
            {
                this._activeTool.ClearFocusedTask();
                this._activeTool   = (Tool)null;
                this._editingScope = (ModelEditingScope)null;
                if (modelEditingScope != null)
                {
                    modelEditingScope.Revert();
                }
                this.OnFocusDeactivated(EventArgs.Empty);
            }
        }
        // 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();
            }
        }
Beispiel #21
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            ModelItemDictionary dictionary = base.ModelItem.Properties["Arguments"].Dictionary;

            try
            {
                string form       = ModelItem.GetValue <string>("Form");
                var    definition = Forge.Forms.FormBuilding.FormBuilder.Default.GetDefinition(form, freeze: false);
                foreach (DataFormField f in definition.GetElements().Where(x => x is DataFormField))
                {
                    bool exists = false;
                    foreach (var key in dictionary.Keys)
                    {
                        if (key.ToString() == f.Key)
                        {
                            exists = true;
                        }
                        if (key.GetValue <string>("AnnotationText") == f.Key)
                        {
                            exists = true;
                        }
                        if (key.GetValue <string>("Name") == f.Key)
                        {
                            exists = true;
                        }
                    }
                    if (!exists)
                    {
                        Type   t           = f.PropertyType;
                        Type   atype       = typeof(VisualBasicValue <>);
                        Type   constructed = atype.MakeGenericType(t);
                        object o           = Activator.CreateInstance(constructed, f.Key);

                        Argument a = null;
                        a = Argument.Create(t, ArgumentDirection.InOut);
                        dictionary.Add(f.Key, a);
                    }
                }
            }
            catch (Exception)
            {
            }
            var options = new System.Activities.Presentation.DynamicArgumentDesignerOptions()
            {
                Title = "Map Arguments"
            };

            using (ModelEditingScope modelEditingScope = dictionary.BeginEdit())
            {
                if (System.Activities.Presentation.DynamicArgumentDialog.ShowDialog(base.ModelItem, dictionary, base.Context, base.ModelItem.View, options))
                {
                    modelEditingScope.Complete();
                }
                else
                {
                    modelEditingScope.Revert();
                }
            }
        }
 /// <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();
     }
 }
        private void GenerateExpression()
        {
            //TODO: Enhance the type infering logic
            if (ExpressionType == null)
            {
                // Get the variables in scope
                List <ModelItem> declaredVariables = CSharpExpressionHelper.GetVariablesInScope(OwnerActivity);

                if (declaredVariables.Count > 0)
                {
                    InferredType = ((LocationReference)declaredVariables[0].GetCurrentValue()).Type;
                }
            }

            Type resultType = ExpressionType != null ? ExpressionType : InferredType;

            ////This could happen when:
            ////1) No ExpressionType is specified and
            ////2) The expression is invalid so that the inferred type equals to null
            if (resultType == null)
            {
                resultType = typeof(object);
            }

            // If the text is null we don't need to bother generating the expression (this would be the case the
            // first time you enter an ETB. We still need to generate the expression when it is EMPTY however - otherwise
            // the case where you had an expression (valid or invalid), then deleted the whole thing will not be evaluated.
            if (Text != null)
            {
                using (ModelEditingScope scope = OwnerActivity.BeginEdit("Property Change"))
                    if (OwnerActivity != null)
                    {
                        EditingState = EditingState.Validating;
                        // we set the expression to null
                        // a) when the expressionText is empty AND it's a reference expression or
                        // b) when the expressionText is empty AND the DefaultValue property is null
                        if (Text.Length == 0 &&
                            (UseLocationExpression || DefaultValue == null))
                        {
                            Expression = null;
                        }
                        else
                        {
                            if (Text.Length == 0)
                            {
                                Text = DefaultValue;
                            }

                            ModelTreeManager   modelTreeManager = Context.Services.GetService <ModelTreeManager>();
                            ActivityWithResult newExpression    = CSharpExpressionHelper.CreateExpressionFromString(Text, UseLocationExpression, resultType);
                            ModelItem          expressionItem   = modelTreeManager.CreateModelItem(null, newExpression);

                            Expression = expressionItem;
                        }
                        scope.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();
     }
 }
Beispiel #27
0
        public ModelItem addActivity(Activity a)
        {
            ModelItem    newItem      = null;
            ModelService modelService = wfDesigner.Context.Services.GetService <ModelService>();

            using (ModelEditingScope editingScope = modelService.Root.BeginEdit("Implementation"))
            {
                var lastSequence = GetSequence(selectedActivity);
                if (lastSequence == null && selectedActivity != null)
                {
                    lastSequence = GetActivitiesScope(selectedActivity.Parent);
                }
                if (lastSequence != null)
                {
                    ModelItemCollection Activities = null;
                    if (lastSequence.Properties["Activities"] != null)
                    {
                        Activities = lastSequence.Properties["Activities"].Collection;
                    }
                    else
                    {
                        Activities = lastSequence.Properties["Nodes"].Collection;
                    }

                    var insertAt = Activities.Count;
                    for (var i = 0; i < Activities.Count; i++)
                    {
                        if (Activities[i].Equals(selectedActivity))
                        {
                            insertAt = (i + 1);
                        }
                    }
                    if (lastSequence.Properties["Activities"] != null)
                    {
                        newItem = Activities.Insert(insertAt, a);
                    }
                    else
                    {
                        FlowStep step = new FlowStep();
                        step.Action = a;
                        newItem     = Activities.Insert(insertAt, step);
                    }
                    //Selection.Select(wfDesigner.Context, selectedActivity);
                    //ModelItemExtensions.Focus(selectedActivity);
                }
                editingScope.Complete();
                //WorkflowInspectionServices.CacheMetadata(a);
            }
            if (newItem != null)
            {
                selectedActivity = newItem;
                newItem.Focus(20);
                Selection.SelectOnly(wfDesigner.Context, newItem);
            }
            return(newItem);
        }
Beispiel #28
0
        void OnModelItemPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            if (e.PropertyName == "Expression")
            {
                Update();
            }
            else if (e.PropertyName == "DefaultCaseDisplayName")
            {
                // To fix 218600 without losing PropertyGrid focus (Bug 210326), the only workaround is to
                // update the connector label manually, because FlowSwitchLink.ModelItem["DefaultCaseDisplayName"]
                // is a FakeModelPropertyImpl, and would not generate a Undo unit
                // (FakeModelNotifyPropertyChange.GetInverse() returns null).
                // However, there is a known issue with PropertyGrid bound to a fake ModelItem.  The workaround is
                // to shift the focus to the FlowchartDesigner IF the keyboard focus is on the connector when the user
                // calls Undo/Redo, to avoid the problem of PropertyGrid not refreshable.
                FlowchartDesigner flowchartDesigner = VisualTreeUtils.FindVisualAncestor <FlowchartDesigner>(this);
                Fx.Assert(null != flowchartDesigner, "flowchart designer cannot be null because FlowswitchDesigner must exist within the same visual tree ofthe parent Flowchart.");

                if (null != flowchartDesigner &&
                    null != this.ModelItem.Properties["Default"].Value &&
                    this.Context.Services.GetService <UndoEngine>().IsUndoRedoInProgress)
                {
                    // the designer is available
                    Connector connector = flowchartDesigner.GetLinkOnCanvas(this.ModelItem, this.ModelItem.Properties["Default"].Value, "Default");
                    Fx.Assert(null != connector, "Connector should not be null.");
                    ModelItem linkModelItem = FlowchartDesigner.GetLinkModelItem(connector);
                    Fx.Assert(linkModelItem is FakeModelItemImpl, "ModelItem of FlowSwitch link is fake.");
                    IFlowSwitchDefaultLink link = (IFlowSwitchDefaultLink)linkModelItem.GetCurrentValue();
                    string defaultDisplayName   =
                        (string)this.ModelItem.Properties[FlowSwitchLabelFeature.DefaultCaseDisplayNamePropertyName].Value.GetCurrentValue();

                    if (link.DefaultCaseDisplayName != defaultDisplayName)
                    {
                        // the purpose of re-setting the link value during Undo/Redo is to update the FlowSwitch label
                        using (ModelEditingScope scope = this.ModelItem.BeginEdit(SR.FlowSwitchDefaultCaseDisplayNameEditingScopeDesc))
                        {
                            linkModelItem.Properties[FlowSwitchLabelFeature.DefaultCaseDisplayNamePropertyName].SetValue(defaultDisplayName);
                            link.DefaultCaseDisplayName = defaultDisplayName;
                            scope.Complete();
                        }

                        if (Selection.IsSelection(linkModelItem))
                        {
                            // cause the connector to lose focus, because the PropertyGrid would not have focus.
                            // this scenario only happens if the user explicitly selects the FlowSwitch link after
                            // editing the DefaultDisplayName.  This behavior is only a workaround due to the fact
                            // that PropertyGrid does not receive update from change in a FakeModelPropertyImpl
                            // (i.e. FlowSwitchLink).
                            Keyboard.ClearFocus();
                            Selection.SelectOnly(this.Context, this.ModelItem);
                            linkModelItem.Highlight();
                        }
                    }
                }
            }
        }
        private void AbortRootTransaction()
        {
            if (_rootTransaction == null)
            {
                return;
            }

            _rootTransaction.Revert();
            _rootTransaction = null;
        }
        /// <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();
            }
        }
 // The following method handles the MouseLeftButtonDown event.
 // It calls the BeginEdit method on the ModelItem which represents
 // the adorned control.
 void slider_MouseLeftButtonDown(
     object sender,
     System.Windows.Input.MouseButtonEventArgs e)
 {
     batchedChange = adornedControlModel.BeginEdit();
 }
 // The following method handles the MouseLeftButtonUp event.
 // It commits any changes made to the ModelItem which represents the
 // the adorned control.
 void slider_MouseLeftButtonUp(
     object sender,
     System.Windows.Input.MouseButtonEventArgs e)
 {
     if (batchedChange != null)
     {
         batchedChange.Complete();
         batchedChange.Dispose();
         batchedChange = null;
     }
 }