Пример #1
0
        private void initProject(bool updateProjectItems = true)
        {
            ProjectItemsTemp.Clear();

            ProjectPath = Path.GetDirectoryName(CurrentProjectJsonFile);

            var json_cfg = ProcessProjectJsonConfig();

            ProjectName        = json_cfg.name;
            ProjectDescription = json_cfg.description;
            ProjectMain        = ProjectPath + @"\" + json_cfg.main;

            var projectItem = new ProjectTreeItem(this);

            RootProjectTreeItem         = projectItem;
            projectItem.IsRoot          = true;
            projectItem.IsExpanded      = true;
            projectItem.Name            = json_cfg.name;
            projectItem.Path            = ProjectPath;
            projectItem.ToolTip         = ProjectPath;
            projectItem.Icon            = "pack://application:,,,/Resources/Image/Project/project.png";
            projectItem.ContextMenuName = "ProjectRootContextMenu";

            ProjectItemsTemp.Add(projectItem);

            InitDependencies(projectItem);
            InitDirectory(new DirectoryInfo(ProjectPath), projectItem);

            if (updateProjectItems)
            {
                ProjectItems = new ObservableCollection <ProjectTreeItem>(ProjectItemsTemp);
            }
        }
Пример #2
0
 private void ProjectTreeItemSetAllIsMatch(ProjectTreeItem item, bool IsMatch)
 {
     item.IsMatch = IsMatch;
     foreach (var child in item.Children)
     {
         ProjectTreeItemSetAllIsMatch(child, IsMatch);
     }
 }
Пример #3
0
 private void ProjectTreeItemSetAllSearchText(ProjectTreeItem item, string SearchText)
 {
     item.SearchText = SearchText;
     foreach (var child in item.Children)
     {
         ProjectTreeItemSetAllSearchText(child, SearchText);
     }
 }
Пример #4
0
 private void ProjectTreeItemSetAllIsSearching(ProjectTreeItem item, bool IsSearching)
 {
     item.IsSearching = IsSearching;
     foreach (var child in item.Children)
     {
         ProjectTreeItemSetAllIsSearching(child, IsSearching);
     }
 }
Пример #5
0
 private void ProjectTreeItemSetAllIsExpanded(ProjectTreeItem item, bool IsExpanded)
 {
     item.IsExpanded = IsExpanded;
     foreach (var child in item.Children)
     {
         ProjectTreeItemSetAllIsExpanded(child, IsExpanded);
     }
 }
Пример #6
0
 private void Delete(ProjectTreeItem obj)
 {
     //有文件被删除,检查下当前文档对应的xamlPath是否还存在,不存在的话强制关闭即可
     if (!File.Exists(XamlPath))
     {
         Messenger.Default.Send(this, "Close");
         Messenger.Default.Unregister(this);//取消注册
     }
 }
Пример #7
0
        private void InitDependencies(ProjectTreeItem projectItem)
        {
            var dependRootItem = new ProjectTreeItem(this);

            dependRootItem.IsDependRoot = true;
            dependRootItem.IsExpanded   = true;
            //dependRootItem.Name = "依赖包";
            dependRootItem.Name = ResxIF.GetString("DependencyText");
            dependRootItem.Icon = "pack://application:,,,/Resources/Image/Project/dependencies.png";
            projectItem.Children.Add(dependRootItem);

            string json     = File.ReadAllText(CurrentProjectJsonFile);
            var    json_cfg = Newtonsoft.Json.JsonConvert.DeserializeObject <ProjectJsonConfig>(json);

            foreach (JProperty jp in (JToken)json_cfg.dependencies)
            {
                var ver_range = VersionRange.Parse((string)jp.Value);

                string ver_desc = "";

                //目前只考虑等于和大于等于两种情况
                if (ver_range.MinVersion == ver_range.MaxVersion)
                {
                    ver_desc = $" = {ver_range.MinVersion}";
                }
                else
                {
                    if (ver_range.MinVersion != null && ver_range.IsMinInclusive)
                    {
                        ver_desc = $" >= {ver_range.MinVersion}";
                    }
                }

                var desc = jp.Name + ver_desc;

                var dependItem = new ProjectTreeItem(this);
                dependItem.IsDependItem = true;
                dependItem.Name         = desc;
                dependItem.Icon         = "pack://application:,,,/Resources/Image/Project/depend-item.png";
                dependRootItem.Children.Add(dependItem);
            }
        }
Пример #8
0
        public ProjectTreeItem GetProjectTreeItemIsSelected(ProjectTreeItem parent = null)
        {
            if (parent == null)
            {
                foreach (var item in ProjectItems)
                {
                    if (item.IsSelected)
                    {
                        return(item);
                    }

                    var ret = GetProjectTreeItemIsSelected(item);
                    if (ret != null)
                    {
                        return(ret);
                    }
                }
            }
            else
            {
                foreach (var child in parent.Children)
                {
                    if (child.IsSelected)
                    {
                        return(child);
                    }

                    var ret = GetProjectTreeItemIsSelected(child);
                    if (ret != null)
                    {
                        return(ret);
                    }
                }
            }

            return(null);
        }
Пример #9
0
        public ProjectTreeItem GetProjectTreeItemByFullPath(string fullPath, ProjectTreeItem parent = null)
        {
            if (parent == null)
            {
                foreach (var item in ProjectItems)
                {
                    if (item.IsXaml && item.Path.EqualsIgnoreCase(fullPath))
                    {
                        return(item);
                    }

                    var ret = GetProjectTreeItemByFullPath(fullPath, item);
                    if (ret != null)
                    {
                        return(ret);
                    }
                }
            }
            else
            {
                foreach (var child in parent.Children)
                {
                    if (child.IsXaml && child.Path.EqualsIgnoreCase(fullPath))
                    {
                        return(child);
                    }

                    var ret = GetProjectTreeItemByFullPath(fullPath, child);
                    if (ret != null)
                    {
                        return(ret);
                    }
                }
            }

            return(null);
        }
Пример #10
0
        private void InitDirectory(DirectoryInfo di, ProjectTreeItem parent)
        {
            //当前目录文件夹遍历
            DirectoryInfo[] dis = di.GetDirectories();
            for (int j = 0; j < dis.Length; j++)
            {
                var item = new ProjectTreeItem(this);
                item.Path            = dis[j].FullName;
                item.Name            = dis[j].Name;
                item.IsDirectory     = true;
                item.ContextMenuName = "ProjectDirectoryContextMenu";

                if (item.Name != ".local")
                {
                    parent.Children.Add(item);

                    InitDirectory(dis[j], item);
                }
            }

            //当前目录文件遍历
            FileInfo[] fis = di.GetFiles();
            for (int i = 0; i < fis.Length; i++)
            {
                var item = new ProjectTreeItem(this);
                item.Path   = fis[i].FullName;
                item.Name   = fis[i].Name;
                item.IsFile = true;

                if (item.Path.EqualsIgnoreCase(CurrentProjectJsonFile))
                {
                    item.IsProjectJson = true;
                }

                if (fis[i].Extension.ToLower() == ".xaml")
                {
                    item.IsXaml = true;
                    item.Icon   = "pack://application:,,,/Resources/Image/Project/xaml.png";

                    if (item.Path == ProjectMain)
                    {
                        item.IsMain          = true;
                        item.ContextMenuName = "ProjectMainXamlContextMenu";

                        MainProjectTreeItem = item;
                    }
                    else
                    {
                        item.ContextMenuName = "ProjectXamlContextMenu";
                    }

                    parent.Children.Add(item);
                }
                else
                {
                    var icon = System.Drawing.Icon.ExtractAssociatedIcon(item.Path);
                    item.IconSource = Common.ToImageSource(icon);

                    if (fis[i].Extension.ToLower() == ".py")
                    {
                        item.IsPython = true;
                    }

                    if (item.IsProjectJson)
                    {
                    }
                    else
                    {
                        item.ContextMenuName = "ProjectFileContextMenu";
                    }


                    if (IsShowAllFiles)
                    {
                        parent.Children.Add(item);
                    }
                }
            }
        }