public bool BindToClass() { if (SourceCodeFile != FilePath.Null) { return(true); } // Find the classes that could be bound to this design var ctx = fproject.GetParserContext(); ArrayList list = new ArrayList(); foreach (var cls in ctx.MainAssembly.GetAllTypeDefinitions()) { if (IsValidClass(cls)) { list.Add(cls.FullName); } } // Ask what to do try { using (BindDesignDialog dialog = new BindDesignDialog(Name, list, Project.Project.BaseDirectory)) { if (!dialog.Run()) { return(false); } if (dialog.CreateNew) { CreateClass(dialog.ClassName, dialog.Namespace, dialog.Folder); } string fullName = dialog.Namespace.Length > 0 ? dialog.Namespace + "." + dialog.ClassName : dialog.ClassName; rootWidget.Name = fullName; fproject.Save(true); } return(true); } catch (Exception ex) { MessageService.ShowException(ex); return(false); } }
public override void Save(string fileName) { base.Save(fileName); if (designer == null) { return; } string oldBuildFile = GuiBuilderService.GetBuildCodeFileName(gproject.Project, window.RootWidget.Name); codeBinder.UpdateBindings(fileName); if (!ErrorMode) { if (designer != null) { designer.Save(); } if (actionsBox != null) { actionsBox.Save(); } } string newBuildFile = GuiBuilderService.GetBuildCodeFileName(gproject.Project, window.RootWidget.Name); if (oldBuildFile != newBuildFile && oldBuildFile != null && newBuildFile != null) { if (System.IO.File.Exists(newBuildFile)) { FileService.DeleteFile(newBuildFile); } if (System.IO.File.Exists(oldBuildFile)) { FileService.MoveFile(oldBuildFile, newBuildFile); } } gproject.Save(true); OnDirtyChanged(EventArgs.Empty); }
public override void Save(string fileName) { string oldBuildFile = GuiBuilderService.GetBuildCodeFileName(project.Project, groupInfo.Name); base.Save(fileName); if (designer == null) { return; } codeBinder.UpdateBindings(fileName); designer.Save(); string newBuildFile = GuiBuilderService.GetBuildCodeFileName(project.Project, groupInfo.Name); if (oldBuildFile != newBuildFile) { FileService.MoveFile(oldBuildFile, newBuildFile); } project.Save(true); }
public IType GetClass(bool getUserClass) { if (targetObject == null) { return(null); } IType cls = gproject.FindClass(className, getUserClass); if (cls != null) { return(cls); } // The class name may have changed. Try to guess the new name. ArrayList matches = new ArrayList(); ICompilationUnit unit = null; ProjectDom ctx = gproject.GetParserContext(); ParsedDocument doc = ProjectDomService.Parse(project, classFile, null); if (doc != null && doc.CompilationUnit != null) { unit = doc.CompilationUnit; foreach (IType fcls in unit.Types) { if (IsValidClass(ctx, fcls, targetObject)) { matches.Add(fcls); } } } // If found the class, just return it if (matches.Count == 1) { cls = (IType)matches [0]; className = cls.FullName; targetObject.Name = className; gproject.Save(true); return(cls); } // If not found, warn the user. if (unit != null && unit.Types.Count > 0) { using (SelectRenamedClassDialog dialog = new SelectRenamedClassDialog(unit.Types)) { if (dialog.Run()) { className = dialog.SelectedClass; if (className == null) { return(null); } else { targetObject.Name = className; gproject.Save(true); return(gproject.FindClass(className)); } } } } else { MessageService.ShowError(GettextCatalog.GetString("The class bound to the component '{0}' could not be found. This may be due to syntax errors in the source code file.", GetObjectName(targetObject))); } return(null); }
public IUnresolvedTypeDefinition GetClass(bool getUserClass) { if (targetObject == null) { return(null); } var cls = gproject.FindClass(className, getUserClass); if (cls != null) { return(cls); } // The class name may have changed. Try to guess the new name. var matches = new List <IUnresolvedTypeDefinition> (); ParsedDocument unit = null; var ctx = gproject.GetParserContext(); var doc = TypeSystemService.ParseFile(project, classFile); if (doc != null) { unit = doc; foreach (var fcls in unit.TopLevelTypeDefinitions) { if (IsValidClass(fcls.Resolve(project), targetObject)) { matches.Add(fcls); } } } // If found the class, just return it if (matches.Count == 1) { cls = matches [0]; className = cls.FullName; targetObject.Name = className; gproject.Save(true); return(cls); } // If not found, warn the user. if (unit != null && unit.TopLevelTypeDefinitions.Count > 0) { using (SelectRenamedClassDialog dialog = new SelectRenamedClassDialog(unit.TopLevelTypeDefinitions.Select(c => c.Resolve(project)))) { if (dialog.Run()) { className = dialog.SelectedClass; if (className == null) { return(null); } else { targetObject.Name = className; gproject.Save(true); return(gproject.FindClass(className)); } } } } else { MessageService.ShowError(GettextCatalog.GetString("The class bound to the component '{0}' could not be found. This may be due to syntax errors in the source code file.", GetObjectName(targetObject))); } return(null); }