private void AddFunction() { var name = Program.Functions.Select(f => f.Name).CreateUniqueName("Function {0}"); bool wasAccepted = false; var textEditService = new TextEditService(); textEditService.EditText(name, "New Function", "Name", t => { name = t; wasAccepted = true; }, t => !string.IsNullOrWhiteSpace(t)); if (wasAccepted) { var functionHeaderMetadata = new FunctionMetadata() { Name = name, Id = Guid.NewGuid(), Elements = new ElementMetadata[] { }, }; var functionHeaderViewModel = new FunctionHeaderViewModel(functionHeaderMetadata); Program.Functions.Add(functionHeaderViewModel); } }
public void EditFunction(FunctionMetadata metadata, Action<FunctionMetadata> saveAction, bool modal, string displayName) { //Create the function view model var function = CreateRuntimeFunctionInner(metadata); //Create the editor view model var editorViewModel = new FunctionEditorDialogViewModel(_serviceContext, function, saveAction, new TextEditService(), displayName); //Create the view var view = new FunctionEditorDialog(_serviceContext.CustomResources) { DataContext = editorViewModel, Owner = WindowUtil.GetActiveWindow() }; //Show the dialog if (modal) { view.ShowDialog(); } else { view.Show(); } }
public FunctionHeaderViewModel(FunctionMetadata metadata) { if (metadata == null) throw new ArgumentNullException(nameof(metadata)); _metadata = metadata; EditCommand = new RelayCommand(Edit, CanEdit); RenameCommand = new RelayCommand(Rename, CanRename); }
private Function CreateRuntimeFunctionInner(FunctionMetadata metadata) { //Create the view model var functionViewModel = new Function(_serviceContext, metadata.Id) { Name = metadata.Name }; //Create the builder var builder = new ElementBuilder(_serviceContext.ElementFactoryManager, _serviceContext); //Add the elements to the owner (function) builder.LoadFunction(functionViewModel, metadata); return functionViewModel; }
public IFunction LoadFunction(FunctionMetadata functionMetadata) { if (functionMetadata == null) throw new ArgumentNullException(nameof(functionMetadata)); var function = new Function(_context, functionMetadata.Id); LoadFunction(function, functionMetadata); return function; }
#pragma warning restore CS0618 public void LoadFunction(IFunction function, FunctionMetadata functionMetadata) { if (function == null) throw new ArgumentNullException(nameof(function)); if (functionMetadata == null) return; //Fix the bloody metadata FixFunctionMetadata(functionMetadata); //Now get the simple stuff function.Name = functionMetadata.Name; function.ReturnTypeId = functionMetadata.ReturnTypeId; //Add variables if (functionMetadata.Variables != null) { AddToOwner(function, functionMetadata.Variables); } //Add arguments if (functionMetadata.Arguments != null) { AddToOwner(function, functionMetadata.Arguments); } //Add return variable if (functionMetadata.ReturnTypeId != null) { //Get the type for the return variable. var type = function.GetVplTypeOrThrow(functionMetadata.ReturnTypeId.Value); //Add the return variable. function.AddVariable(new ReturnValueVariable(function, type)); } //Add elements if (functionMetadata.Elements != null) { AddToOwner(function, functionMetadata.Elements); } function.MarkClean(); }
private void FixFunctionMetadata(FunctionMetadata functionMetadata) { if (functionMetadata == null) throw new ArgumentNullException(nameof(functionMetadata)); if (functionMetadata.Elements != null) { //Check to see if need to convert if (functionMetadata.Elements.Any(RequiresConversion)) { //This is where we'll put all of the elements. var allElements = new List<ElementMetadata>(); //Consider each of the root elements foreach (var rootElement in functionMetadata.Elements) { //Flatten the element chain var elements = EnumerateElementsWhileFixingBlocks(rootElement); //Add this to the list of all elements allElements.AddRange(elements); } //Set the next element to null allElements.ForEach(e => e.Next = null); functionMetadata.Elements = allElements .ToArray(); } } }
private void Edit() { try { HostViewModelLocator.VplService.EditFunction(_metadata, m => { _metadata = m; RaisePropertyChanged(() => Name); }, false); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }