public static void createModule(bool isFct) { Module created; bool create = false; if (isFct) { var func = new Function(); created = func; func.Name = "nouvelle_fonction"; func.ReturnType = GenericType.Bool; do { var dialog = new createModule(func); dialog.Owner = MainDialog; if (dialog.ShowDialog() == true) { func.Name = dialog.modName.Text; if (!isNameConventionnal(func.Name)) { MessageBox.Show("nom non conventionnel !", "erreur", MessageBoxButton.OK, MessageBoxImage.Error); } else if (!isNameAvailable(func.Name, CurrentILAcode)) { MessageBox.Show("nom déjà utilisé !", "erreur", MessageBoxButton.OK, MessageBoxImage.Error); } else { create = true; func.ReturnType = ((ToStringOverrider)dialog.returnType.SelectedItem).Content as VarType; var comm = new Comment(); comm.MultiLine = dialog.comments.Text.Contains('\n'); comm.Message = dialog.comments.Text; func.AboveComment = comm; func.InlineComment = dialog.inlineComm.Text; func.Parameters.Clear(); foreach (var item in dialog.paramList.Children) { if (item is Parameter p) { func.Parameters.Add(p.Link as ILANET.Parameter); } } } } else { break; } } while (!(isNameAvailable(func.Name, CurrentILAcode) && isNameConventionnal(func.Name))); } else { var mod = new Module(); created = mod; mod.Name = "nouveau_module"; do { var dialog = new createModule(mod); dialog.Owner = MainDialog; if (dialog.ShowDialog() == true) { mod.Name = dialog.modName.Text; if (!isNameConventionnal(mod.Name)) { MessageBox.Show(dialog, "nom non conventionnel !", "erreur", MessageBoxButton.OK, MessageBoxImage.Error); } else if (!isNameAvailable(mod.Name, CurrentILAcode)) { MessageBox.Show(dialog, "nom déjà utilisé !", "erreur", MessageBoxButton.OK, MessageBoxImage.Error); } else { create = true; var comm = new Comment(); comm.MultiLine = dialog.comments.Text.Contains('\n'); comm.Message = dialog.comments.Text; mod.AboveComment = comm; mod.InlineComment = dialog.inlineComm.Text; mod.Parameters.Clear(); foreach (var item in dialog.paramList.Children) { if (item is Parameter p) { mod.Parameters.Add(p.Link as ILANET.Parameter); } } } } else { break; } } while (!(isNameAvailable(mod.Name, CurrentILAcode) && isNameConventionnal(mod.Name))); } if (create) { CurrentILAcode.Methods.Add(created); CurrentExecutable = created; UpdateTree(); UpdateEditor(); UpdateLexic(); } }
public static void editModule(Module m) { Module copy; Function func; string choosenName = m.Name; if (m is Function f) { copy = new Function(); ((Function)copy).ReturnType = f.ReturnType; } else { copy = new Module(); } copy.Name = m.Name.Clone() as string; copy.AboveComment = m.AboveComment == null ? null : new Comment { MultiLine = m.AboveComment.MultiLine, Message = m.AboveComment.Message.Clone() as string }; copy.InlineComment = m.InlineComment.Clone() as string; foreach (var item in m.Parameters) { var param = new ILANET.Parameter(); var variable = new Variable(); param.ImportedVariable = variable; param.Mode = item.Mode; variable.Name = item.ImportedVariable.Name; variable.Type = item.ImportedVariable.Type; copy.Parameters.Add(param); } m.Name = ""; if (copy is Function fcopy) { func = m as Function; do { var dialog = new createModule(fcopy, true); dialog.Owner = MainDialog; if (dialog.ShowDialog() == true) { fcopy.Name = dialog.modName.Text; if (!isNameConventionnal(dialog.modName.Text)) { MessageBox.Show(dialog, "nom non conventionnel !", "erreur", MessageBoxButton.OK, MessageBoxImage.Error); } else if (!isNameAvailable(dialog.modName.Text, CurrentILAcode)) { MessageBox.Show(dialog, "nom déjà utilisé !", "erreur", MessageBoxButton.OK, MessageBoxImage.Error); } else { choosenName = dialog.modName.Text; func.ReturnType = ((ToStringOverrider)dialog.returnType.SelectedItem).Content as VarType; var comm = new Comment(); comm.MultiLine = dialog.comments.Text.Contains('\n'); comm.Message = dialog.comments.Text; func.AboveComment = comm; func.InlineComment = dialog.inlineComm.Text; func.Parameters.Clear(); foreach (var item in dialog.paramList.Children) { if (item is Parameter p) { func.Parameters.Add(p.Link as ILANET.Parameter); } } } } else { break; } } while (!(isNameAvailable(fcopy.Name, CurrentILAcode) && isNameConventionnal(fcopy.Name))); } else { do { var dialog = new createModule(copy, true); dialog.Owner = MainDialog; if (dialog.ShowDialog() == true) { copy.Name = dialog.modName.Text; if (!isNameConventionnal(dialog.modName.Text)) { MessageBox.Show(dialog, "nom non conventionnel !", "erreur", MessageBoxButton.OK, MessageBoxImage.Error); } else if (!isNameAvailable(dialog.modName.Text, CurrentILAcode)) { MessageBox.Show(dialog, "nom déjà utilisé !", "erreur", MessageBoxButton.OK, MessageBoxImage.Error); } else { choosenName = dialog.modName.Text; var comm = new Comment(); comm.MultiLine = dialog.comments.Text.Contains('\n'); comm.Message = dialog.comments.Text; m.AboveComment = comm; m.InlineComment = dialog.inlineComm.Text; m.Parameters.Clear(); foreach (var item in dialog.paramList.Children) { if (item is Parameter p) { m.Parameters.Add(p.Link as ILANET.Parameter); } } } } else { break; } } while (!(isNameAvailable(copy.Name, CurrentILAcode) && isNameConventionnal(copy.Name))); } m.Name = choosenName; UpdateTree(); UpdateEditor(); }