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.SaveWindow(true, fullName);
                }
                return(true);
            }
            catch (Exception ex)
            {
                MessageService.ShowException(ex);
                return(false);
            }
        }
示例#2
0
        protected override async Task OnSave()
        {
            await base.OnSave();

            if (designer == null)
            {
                return;
            }

            string oldBuildFile = GuiBuilderService.GetBuildCodeFileName(gproject.Project, window.RootWidget.Name);

            codeBinder.UpdateBindings(FilePath);
            if (!ErrorMode)
            {
                if (designer != null)
                {
                    designer.Save();
                }
                if (actionsBox != null)
                {
                    actionsBox.Save();
                }
            }

            string newBuildFile = GuiBuilderService.GetBuildCodeFileName(gproject.Project, window.RootWidget.Name);

            if (oldBuildFile != newBuildFile)
            {
                if (System.IO.File.Exists(newBuildFile))
                {
                    FileService.DeleteFile(newBuildFile);
                }
                FileService.MoveFile(oldBuildFile, newBuildFile);
            }

            gproject.SaveWindow(true, window.RootWidget.Name);
        }
示例#3
0
        public override void Save(FileSaveInformation fileSaveInformation)
        {
            base.Save(fileSaveInformation);

            if (designer == null)
            {
                return;
            }

            string oldBuildFile = GuiBuilderService.GetBuildCodeFileName(gproject.Project, window.RootWidget.Name);

            codeBinder.UpdateBindings(fileSaveInformation.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)
            {
                if (System.IO.File.Exists(newBuildFile))
                {
                    FileService.DeleteFile(newBuildFile);
                }
                FileService.MoveFile(oldBuildFile, newBuildFile);
            }

            gproject.SaveWindow(true, window.RootWidget.Name);
        }
示例#4
0
        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.SaveWindow(true, targetObject.Name);
                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.SaveWindow(true, targetObject.Name);
                            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);
        }