예제 #1
0
        /// <summary>
        /// Collects the items of Spectrum Code Discovery project
        /// </summary>
        public override void CollectItems()
        {
            HierarchyItems.Clear();
            foreach (ProjectItem item in Root.ProjectItems)
            {
                ProcessProjectItem(item);
            }
            LoadSpectrumModelInfo();
            LoadProjectSettings();

            // --- Mark the default items
            SetVisuals(DefaultAnnotationItem, AnnotationProjectItems);
            SetVisuals(DefaultTapeItem, TapeFileProjectItems);
            SetVisuals(DefaultZ80CodeItem, Z80CodeProjectItems);
        }
 /// <summary>
 /// Scans the solution for Spectrum Code Discovery projects
 /// </summary>
 public void CollectProjects()
 {
     HierarchyItems.Clear();
     foreach (Project project in Root.Projects)
     {
         if (project.Kind == VsHierarchyTypes.SolutionFolder)
         {
             Traverse(project);
         }
         else if (project.Kind == VsHierarchyTypes.CodeDiscoveryProject)
         {
             _solutionService.GetProjectOfUniqueName(project.UniqueName, out var projectHierarchy);
             HierarchyItems.Add(new DiscoveryProject(project, projectHierarchy));
         }
     }
 }
예제 #3
0
        /// <summary>
        /// Respond to the event when an item within the hierarchy has been renamed
        /// </summary>
        /// <param name="oldItem">Old name</param>
        /// <param name="newItem">New name</param>
        public override void OnRenameItem(string oldItem, string newItem)
        {
            try
            {
                var contents = File.ReadAllText(Path.Combine(ProjectDir, SETTINGS_FILE));
                var settings = JsonConvert.DeserializeObject <SpectrumProjectSettings>(contents);

                // --- Adjust default code item
                if (oldItem.EndsWith(settings.DefaultCodeFile))
                {
                    DefaultProgramItem = HierarchyItems.OfType <Z80CodeProjectItem>()
                                         .FirstOrDefault(i => i.Filename == newItem);
                    if (DefaultProgramItem != null)
                    {
                        SetVisuals(DefaultProgramItem, Z80CodeProjectItems);
                    }
                }

                // --- Adjust default tape item
                if (oldItem.EndsWith(settings.DefaultTapeFile))
                {
                    DefaultTapeItem = HierarchyItems.OfType <TapeProjectItemBase>()
                                      .FirstOrDefault(i => i.Filename == newItem);
                    if (DefaultTapeItem != null)
                    {
                        SetVisuals(DefaultTapeItem, TapeFileProjectItems);
                    }
                }

                // --- Adjust default annotation item
                if (oldItem.EndsWith(settings.DefaultAnnotationFile))
                {
                    DefaultAnnotationItem = HierarchyItems.OfType <AnnotationProjectItem>()
                                            .FirstOrDefault(i => i.Filename == newItem);
                    if (DefaultAnnotationItem != null)
                    {
                        SetVisuals(DefaultAnnotationItem, AnnotationProjectItems);
                    }
                }

                SaveProjectSettings();
            }
            catch
            {
                // --- This exception in intentionally ignored
            }
        }
        /// <summary>
        /// Traverses the specified project for ZX Spectrum projects
        /// </summary>
        /// <param name="projectToTraverse"></param>
        private void Traverse(Project projectToTraverse)
        {
            foreach (ProjectItem item in projectToTraverse.ProjectItems)
            {
                var project = item.SubProject;
                if (project == null)
                {
                    continue;
                }

                if (project.Kind == VsHierarchyTypes.SolutionFolder)
                {
                    Traverse(project);
                }
                else if (project.Kind == VsHierarchyTypes.CodeDiscoveryProject)
                {
                    _solutionService.GetProjectOfUniqueName(project.UniqueName, out var projectHierarchy);
                    HierarchyItems.Add(new DiscoveryProject(project, projectHierarchy));
                }
            }
        }
예제 #5
0
 /// <summary>
 /// Obtains the hierarchy information for the item specified by its identity
 /// </summary>
 /// <param name="fullName">Identity information</param>
 /// <returns>The full file name, if found; otherwise, null</returns>
 public string GetIdentityByFullName(string fullName)
 {
     return(HierarchyItems.FirstOrDefault(item => item.Filename == fullName)?.Identity);
 }
예제 #6
0
 /// <summary>
 /// Obtains the hierarchy information for the item specified by its identity
 /// </summary>
 /// <param name="identity">Identity information</param>
 /// <returns>The full file name, if found; otherwise, null</returns>
 public string GetFullNameByIdentity(string identity)
 {
     return(HierarchyItems.FirstOrDefault(item => item.Identity == identity)?.Filename);
 }
예제 #7
0
 /// <summary>
 /// Obtain the names of items within the hierarchy
 /// </summary>
 /// <returns></returns>
 public override List <string> GetCurrentItemNames()
 {
     return(HierarchyItems.Select(i => i.Filename).ToList());
 }
예제 #8
0
        /// <summary>
        /// Processes the specified item, and its sub items, provided it is a folder
        /// </summary>
        /// <param name="item">Item to process</param>
        public void ProcessProjectItem(ProjectItem item)
        {
            string extension;

            try
            {
                if (item.Properties.Item("Extension") == null)
                {
                    return;
                }
                extension = (item.Properties.Item("Extension").Value?.ToString() ?? string.Empty).ToLower();
            }
            catch
            {
                // --- The freshly deleted item cannot be found, and it results in exception.
                return;
            }

            if (extension == string.Empty && item.ProjectItems.Count > 0)
            {
                // --- This is a folder
                foreach (ProjectItem subItem in item.ProjectItems)
                {
                    ProcessProjectItem(subItem);
                }
            }
            else if (string.Compare(extension, VsHierarchyTypes.DISANN_ITEM,
                                    StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                HierarchyItems.Add(new AnnotationProjectItem(item));
            }
            else if (string.Compare(extension, VsHierarchyTypes.ROM_ITEM,
                                    StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                HierarchyItems.Add(new SpectrumRomProjectItem(item));
            }
            else if (string.Compare(extension, VsHierarchyTypes.TZX_ITEM,
                                    StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                HierarchyItems.Add(new TzxProjectItem(item));
            }
            else if (string.Compare(extension, VsHierarchyTypes.TAP_ITEM,
                                    StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                HierarchyItems.Add(new TapProjectItem(item));
            }
            else if (string.Compare(extension, VsHierarchyTypes.Z80_ITEM,
                                    StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                HierarchyItems.Add(new Z80CodeProjectItem(item));
            }
            else if (string.Compare(extension, VsHierarchyTypes.ZX_BASIC_ITEM,
                                    StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                HierarchyItems.Add(new ZxBasicProjectItem(item));
            }
            else if (string.Compare(extension, VsHierarchyTypes.TEST_ITEM,
                                    StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                HierarchyItems.Add(new Z80TestProjectItem(item));
            }
            else if (string.Compare(extension, VsHierarchyTypes.SP_CONF_ITEM,
                                    StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                HierarchyItems.Add(new SpectrumProjectConfigItem(item));
            }
            else
            {
                HierarchyItems.Add(new UnusedProjectItem(item));
            }
        }
        /// <summary>
        /// Processes the specified item, and its sub items, provided it is a folder
        /// </summary>
        /// <param name="item">Item to process</param>
        public void ProcessProjectItem(ProjectItem item)
        {
            string extension;
            try
            {
                if (item.Properties.Item("Extension") == null) return;
                extension = (item.Properties.Item("Extension").Value?.ToString() ?? string.Empty).ToLower();
            }
            catch 
            {
                // --- The freshly deleted item cannot be found, and it results in exception.
                return;
            }

            if (extension == string.Empty && item.ProjectItems.Count > 0)
            {
                // --- This is a folder
                foreach (ProjectItem subItem in item.ProjectItems)
                {
                    ProcessProjectItem(subItem);
                }
            }
            else if (string.Compare(extension, VsHierarchyTypes.DisannItem, 
                StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                HierarchyItems.Add(new AnnotationProjectItem(item));
            }
            else if (string.Compare(extension, VsHierarchyTypes.RomItem,
                         StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                HierarchyItems.Add(new RomProjectItem(item));
            }
            else if (string.Compare(extension, VsHierarchyTypes.TzxItem,
                         StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                HierarchyItems.Add(new TzxProjectItem(item));
            }
            else if (string.Compare(extension, VsHierarchyTypes.TapItem,
                         StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                HierarchyItems.Add(new TapProjectItem(item));
            }
            else if (string.Compare(extension, VsHierarchyTypes.Z80Item,
                         StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                HierarchyItems.Add(new Z80CodeProjectItem(item));
            }
            else if (string.Compare(extension, VsHierarchyTypes.TestItem,
                         StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                HierarchyItems.Add(new Z80TestProjectItem(item));
            }
            else if (string.Compare(extension, VsHierarchyTypes.SpConfItem,
                         StringComparison.InvariantCultureIgnoreCase) == 0)
            {
                HierarchyItems.Add(new SpConfProjectItem(item));
            }
            else
            {
                HierarchyItems.Add(new UnusedProjectItem(item));
            }
        }
예제 #10
0
 /// <summary>
 /// Obtain the names of items within the hierarchy
 /// </summary>
 /// <returns></returns>
 public override List<string> GetCurrentItemNames()
 {
     return HierarchyItems.Select(i => i.Root.FullName).ToList();
 }