1+ using System . Collections . Generic ;
2+ using Avalonia . Controls ;
3+ using Avalonia . Controls . Models . TreeDataGrid ;
4+ using ColorMC . Core . Objs ;
5+ using ColorMC . Gui . UI . Model . Items ;
6+ using ColorMC . Gui . Utils ;
7+
8+ namespace ColorMC . Gui . UI . Model ;
9+
10+ /// <summary>
11+ /// 文件列表树
12+ /// </summary>
13+ public class ZipPage
14+ {
15+ /// <summary>
16+ /// 根路径
17+ /// </summary>
18+ private readonly FileTreeNodeModel _root ;
19+
20+ public PackType Type ;
21+
22+ /// <summary>
23+ /// 显示内容
24+ /// </summary>
25+ public HierarchicalTreeDataGridSource < FileTreeNodeModel > Source { get ; init ; }
26+
27+ public ZipPage ( string obj , bool check , List < string > ? unselect = null )
28+ {
29+ _root = new FileTreeNodeModel ( null , obj , true , check , true ) ;
30+ Source = new HierarchicalTreeDataGridSource < FileTreeNodeModel > ( _root )
31+ {
32+ Columns =
33+ {
34+ new TemplateColumn < FileTreeNodeModel > (
35+ null ,
36+ cellTemplateResourceKey : "FileNameCell1" ,
37+ options : new TemplateColumnOptions < FileTreeNodeModel >
38+ {
39+ CanUserResizeColumn = false
40+ } ) ,
41+ new HierarchicalExpanderColumn < FileTreeNodeModel > (
42+ new TemplateColumn < FileTreeNodeModel > (
43+ LangUtils . Get ( "Text.FileName" ) ,
44+ "FileNameCell" ,
45+ null ,
46+ new GridLength ( 1 , GridUnitType . Star ) ,
47+ new TemplateColumnOptions < FileTreeNodeModel >
48+ {
49+ CompareAscending = FileTreeNodeModel . SortAscending ( x => x . Name ) ,
50+ CompareDescending = FileTreeNodeModel . SortDescending ( x => x . Name ) ,
51+ IsTextSearchEnabled = true ,
52+ TextSearchValueSelector = x => x . Name
53+ } ) ,
54+ x => x . Children ,
55+ x => x . HasChildren ,
56+ x => x . IsExpanded ) ,
57+ new TextColumn < FileTreeNodeModel , long ? > (
58+ LangUtils . Get ( "Text.Size" ) ,
59+ x => x . Size ,
60+ options : new TextColumnOptions < FileTreeNodeModel >
61+ {
62+ CompareAscending = FileTreeNodeModel . SortAscending ( x => x . Size ) ,
63+ CompareDescending = FileTreeNodeModel . SortDescending ( x => x . Size ) ,
64+ } ) ,
65+ new TextColumn < FileTreeNodeModel , string ? > (
66+ LangUtils . Get ( "GameExportWindow.Text3" ) ,
67+ x => x . Modified ,
68+ options : new TextColumnOptions < FileTreeNodeModel >
69+ {
70+ CompareAscending = FileTreeNodeModel . SortAscending ( x => x . Modified ) ,
71+ CompareDescending = FileTreeNodeModel . SortDescending ( x => x . Modified ) ,
72+ } ) ,
73+ }
74+ } ;
75+
76+ Source . RowSelection ! . SingleSelect = false ;
77+
78+ if ( unselect != null )
79+ {
80+ foreach ( var item in unselect )
81+ {
82+ foreach ( var item1 in _root . Children ! )
83+ {
84+ if ( item1 . Name == item || item1 . Path == item )
85+ {
86+ item1 . IsChecked = false ;
87+ }
88+ }
89+ }
90+ }
91+ }
92+
93+ /// <summary>
94+ /// 设置未选择的文件
95+ /// </summary>
96+ /// <param name="config"></param>
97+ public void SetUnSelectItems ( List < string > config )
98+ {
99+ foreach ( var item in config )
100+ {
101+ _root . UnSelect ( item ) ;
102+ }
103+ }
104+ /// <summary>
105+ /// 获取所有未选择的文件
106+ /// </summary>
107+ /// <returns></returns>
108+ public List < string > GetUnSelectItems ( )
109+ {
110+ return _root . GetUnSelectItems ( ) ;
111+ }
112+ /// <summary>
113+ /// 获取所有选中的文件
114+ /// </summary>
115+ /// <param name="getdir">是否获取目录</param>
116+ /// <returns></returns>
117+ public List < string > GetSelectItems ( bool getdir = false )
118+ {
119+ return _root . GetSelectItems ( getdir ) ;
120+ }
121+ /// <summary>
122+ /// 设置选中的文件
123+ /// </summary>
124+ /// <param name="config"></param>
125+ public void SetSelectItems ( List < string > config )
126+ {
127+ foreach ( var item in config )
128+ {
129+ _root . Select ( item ) ;
130+ }
131+ }
132+ /// <summary>
133+ /// 设置所有文件选中
134+ /// </summary>
135+ public void SetSelectItems ( )
136+ {
137+ _root . Select ( ) ;
138+ }
139+ /// <summary>
140+ /// 设置所有文件不选中
141+ /// </summary>
142+ public void SetUnSelectItems ( )
143+ {
144+ _root . UnSelect ( ) ;
145+ }
146+ }
0 commit comments