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);
            }
        }
Beispiel #2
0
        internal static string BindToClass(Project project, Stetic.ActionGroupInfo group)
        {
            GuiBuilderProject gproject = GtkDesignInfo.FromProject(project).GuiBuilderProject;
            string            file     = gproject.GetSourceCodeFile(group);

            if (file != null)
            {
                return(file);
            }

            // Find the classes that could be bound to this design

            ArrayList list = new ArrayList();
            var       ctx  = gproject.GetParserContext();

            foreach (var cls in ctx.MainAssembly.GetAllTypeDefinitions())
            {
                if (IsValidClass(cls))
                {
                    list.Add(cls.FullName);
                }
            }

            // Ask what to do

            using (BindDesignDialog dialog = new BindDesignDialog(group.Name, list, project.BaseDirectory))
            {
                if (!dialog.Run())
                {
                    return(null);
                }

                if (dialog.CreateNew)
                {
                    CreateClass(project, (Stetic.ActionGroupComponent)group.Component, dialog.ClassName, dialog.Namespace, dialog.Folder);
                }

                string fullName = dialog.Namespace.Length > 0 ? dialog.Namespace + "." + dialog.ClassName : dialog.ClassName;
                group.Name = fullName;
            }
            return(gproject.GetSourceCodeFile(group));
        }
Beispiel #3
0
        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);
        }
Beispiel #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.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);
        }