예제 #1
0
        /// <summary>
        /// Create a new project
        /// </summary>
        /// <param name="dir"></param>
        /// <param name="projname"></param>
        /// <returns></returns>
        public static EditorProject CreateProject(string dir, string projname)
        {
            char   slash       = Path.DirectorySeparatorChar;
            string projdir     = dir;                                // x:\dir
            string projextname = projname + ".project";
            string projfile    = Path.Combine(projdir, projextname); // x:\dir\projname.project

            //create the project directory
            if (Directory.CreateDirectory(projdir) == null)
            {
                EditorManager.ShowMessageBox("Failed to create project directory", "Failed to create project", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }

            //create the project file
            FileStream fs = File.Create(projfile);

            if (fs == null)
            {
                return(null);
            }

            //We don't store anything in the project file
            fs.Close();

            //Open the project and return it
            //EditorProject proj = new EditorProject();
            EditorProject proj = EditorManager.ProjectFactory.CreateInstance(null) as EditorProject;

            if (proj == null)
            {
                EditorManager.ShowMessageBox("Project must be derived from class 'EditorProject'", "Failed to create project", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }

            proj.FileName = projextname;

            try
            {
                proj.Load(projfile);

                //Add the project file
                ManagedBase.RCS.GetProvider().AddFile(projfile, true /* Binary file - but files are until now empty, should we place text in there this needs to be changed */);
            }
            catch (Exception ex)
            {
                EditorManager.DumpException(ex);
                proj = null;
            }

            return(proj);
        }
        void AddPrefabCreators(string dir, ShapeCreatorTreeNode parent)
        {
            EditorProject project       = EditorApp.Project;
            int           iIcon         = EditorManager.GUI.ShapeTreeImages.AddBitmap(Path.Combine(EditorManager.AppDataDir, @"bitmaps\Shapes\lock_ok.png"), Color.Magenta);
            int           iCategoryIcon = EditorManager.GUI.ShapeTreeImages.AddBitmap(Path.Combine(EditorManager.AppDataDir, @"bitmaps\Shapes\folder_new.png"), Color.Magenta);

            // Create the prefab category, if still missing
            ShapeCreatorTreeNode catParent = null;

            if (parent == null)
            {
                catParent = this.AddCategory(null, "Prefabs", iCategoryIcon);
            }
            else
            {
                catParent = this.AddCategory(parent, dir.Substring(dir.LastIndexOf('\\')), iCategoryIcon);
            }

            // Iterate all subdirectories
            string[] directories = Directory.GetDirectories(dir);
            foreach (string directory in directories)
            {
                AddPrefabCreators(directory, catParent);
            }

            // Iterate all files
            string[] files = Directory.GetFiles(dir, "*.prefab");
            Array.Sort(files, new NaturalFileNameComparer());

            foreach (string filename in files)
            {
                string     relname = project.MakeRelative(filename);
                PrefabDesc desc    = PrefabManager.CreatePrefab(relname);
                if (!desc.Loaded)
                {
                    continue;
                }

                // Get the name of the prefab
                string _name = desc.Name;
                if (_name == null || _name == "")
                {
                    _name = relname;
                }

                // Apply the search filter
                if (!searchPanel.MatchesFilter(_name))
                {
                    continue;
                }

                // Add the category path to the tree
                ShapeCreatorTreeNode cat = catParent;
                string catName           = desc.Category;
                if (catName != null && catName != "")
                {
                    cat = AddCategoryPath(catParent, catName, "\\", -1);
                }

                AddCreator(cat, desc, _name, iIcon);
            }

            // Check whether any prefab creators has been added
            if (catParent.Nodes.Count == 0)
            {
                catParent.Remove();
            }
        }
        /// <summary>
        /// Updates all project related creators, this function is called by the project update event
        /// </summary>
        protected void ProjectUpdate()
        {
            BeginAddCreators();
            StoreCollapsedState();
            ClearTree();
            EditorProject project = EditorApp.Project;

            if (project == null)
            {
                EndAddCreators();
                return;
            }

            int iCategoryIcon = EditorManager.GUI.ShapeTreeImages.AddBitmap(Path.Combine(EditorManager.AppDataDir, @"bitmaps\Shapes\folder_new.png"), Color.Magenta);

            // add all creator plugins in this project
            ShapeCreatorTreeNode catCreators = this.AddCategory(null, "Shape Creators", iCategoryIcon);
            IEditorPluginList    list        = EditorManager.SortedShapeCreatorPlugins;

            foreach (IShapeCreatorPlugin plugin in list)
            {
                if (!plugin.IsVisible())
                {
                    continue;
                }

                // Apply the search filter
                if (!searchPanel.MatchesFilter(plugin.GetPluginName()))
                {
                    continue;
                }

                ShapeCreatorTreeNode catPlugin = catCreators;
                string catName = plugin.GetPluginCategory();
                if (catName != null && catName.Length > 0)
                {
                    catPlugin = AddCategoryPath(catCreators, catName, "\\", -1);
                }

                AddCreator(catPlugin, plugin, plugin.GetPluginName(), plugin.IconIndex);
            }

            string prefabDir = project.MakeAbsolute(EditorManager.Settings.PrefabDirectory);

            if (Directory.Exists(prefabDir))
            {
                // Add prefabs from project directory:
                try
                {
                    AddPrefabCreators(prefabDir, null);
                }
                catch (Exception ex)
                {
                    EditorManager.DumpException(ex);
                }
            }

            // Expand all if no collapsed state was restored before, otherwise restore old one.
            // We can not expand/collapse the TreeNodes at creation time as they have no children
            // assigned when they are created.
            if (nodeState == null || nodeState.Length == 0 || searchPanel.IsActive)
            {
                treeView_Creators.ExpandAll();
            }
            else
            {
                RestoreCollapsedState(treeView_Creators.Nodes);
            }

            EndAddCreators();
        }
예제 #4
0
        public void PlaybackSessionsInProject(string projectDir, string subdir)
        {
            CloseActiveProject();

              string absFilename = projectDir;
              if (!FileHelper.IsAbsolute(absFilename))
            absFilename = Path.Combine(TestDataDir, projectDir);

              string projDir = EditorProject.FindProjectFor(Path.Combine(absFilename, "dummy.xyz"));
              EditorProject proj = new EditorProject();
              if (projDir == null)
            throw new FileNotFoundException("Project file not found for " + absFilename);

              proj.Load(projDir);

              EditorManager.Project = proj;

              DirectoryInfo folder = new DirectoryInfo(proj.MakeAbsolute(subdir));
              FileInfo[] files = folder.GetFiles("*.record");
              foreach (FileInfo file in files)
              {
            RecordSession session = RecordSession.LoadFromFile(Path.Combine(subdir, file.Name));
            if (session == null)
              throw new FileNotFoundException("Session file not found", absFilename);

            TestRecordReport report = new TestRecordReport();
            if (!session.Playback(report, true))
              throw new Exception("Record session '" + session.Filename + "' failed.\nItem '" + report.CurrentItem + "' triggered the following error:\n\n" + report.LastError + "\n\n" + report.LastErrorDetailed);
              }
        }
예제 #5
0
        public void PlaybackSession(string filename)
        {
            CloseActiveProject();

              string absFilename = filename;
              if (!FileHelper.IsAbsolute(absFilename))
            absFilename = Path.Combine(TestDataDir, filename);

              string projDir = EditorProject.FindProjectFor(absFilename);
              EditorProject proj = new EditorProject();
              if (projDir == null)
            throw new FileNotFoundException("Project file not found for " + absFilename);

              proj.Load(projDir);

              EditorManager.Project = proj;

              RecordSession session = RecordSession.LoadFromFile(proj.MakeRelative(absFilename));
              if (session == null)
            throw new FileNotFoundException("Session file not found", absFilename);

              TestRecordReport report = new TestRecordReport();
              if (!session.Playback(report, true))
            throw new Exception("Record session '" + session.Filename + "' failed.\nItem '" + report.CurrentItem + "' triggered the following error:\n\n" + report.LastError + "\n\n" + report.LastErrorDetailed);
        }