fasdfsa commited on
Commit
f985a6e
·
1 Parent(s): 6aabcf5

目录拆解显示目录树

Browse files
src/WpfEditor/MainWindow.xaml CHANGED
@@ -90,6 +90,8 @@
90
  <Grid.RowDefinitions>
91
  <RowDefinition Height="Auto"/>
92
  <RowDefinition Height="*"/>
 
 
93
  </Grid.RowDefinitions>
94
 
95
  <!-- 标题栏 -->
@@ -151,6 +153,41 @@
151
  </DataTemplate>
152
  </ListBox.ItemTemplate>
153
  </ListBox>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  </Grid>
155
  </Border>
156
 
 
90
  <Grid.RowDefinitions>
91
  <RowDefinition Height="Auto"/>
92
  <RowDefinition Height="*"/>
93
+ <RowDefinition Height="Auto"/>
94
+ <RowDefinition Height="*"/>
95
  </Grid.RowDefinitions>
96
 
97
  <!-- 标题栏 -->
 
153
  </DataTemplate>
154
  </ListBox.ItemTemplate>
155
  </ListBox>
156
+
157
+ <!-- 树形目录标题栏 -->
158
+ <Border x:Name="BorderDirectoryTreeView"
159
+ Grid.Row="2"
160
+ Background="#E8E8E8"
161
+ BorderBrush="#DDDDDD"
162
+ BorderThickness="0,1,0,0"
163
+ Visibility="Hidden"
164
+ Padding="8,4">
165
+ <TextBlock Text="目录"
166
+ FontWeight="Bold"
167
+ VerticalAlignment="Center"/>
168
+ </Border>
169
+
170
+ <!-- 树形目录 -->
171
+ <TreeView x:Name="DirectoryTreeView"
172
+ Grid.Row="3"
173
+ Background="Transparent"
174
+ BorderThickness="0"
175
+ Visibility="Hidden"
176
+ SelectedItemChanged="DirectoryTreeView_SelectedItemChanged">
177
+ <TreeView.ItemTemplate>
178
+ <HierarchicalDataTemplate ItemsSource="{Binding Children}">
179
+ <StackPanel Orientation="Horizontal" Margin="2">
180
+ <TextBlock Text="{Binding Icon}"
181
+ FontSize="14"
182
+ Margin="0,0,6,0"
183
+ VerticalAlignment="Center"/>
184
+ <TextBlock Text="{Binding Name}"
185
+ VerticalAlignment="Center"
186
+ ToolTip="{Binding FullPath}"/>
187
+ </StackPanel>
188
+ </HierarchicalDataTemplate>
189
+ </TreeView.ItemTemplate>
190
+ </TreeView>
191
  </Grid>
192
  </Border>
193
 
src/WpfEditor/MainWindow.xaml.cs CHANGED
@@ -43,6 +43,32 @@ namespace WpfEditor
43
  }
44
  }
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  public enum EditorMode
47
  {
48
  ImageOCR,
@@ -149,6 +175,7 @@ namespace WpfEditor
149
  else if (this._mode == EditorMode.MenuSplit)
150
  {
151
  this.Title = "目录拆解";
 
152
  }
153
  }
154
 
@@ -2540,6 +2567,27 @@ namespace WpfEditor
2540
  {
2541
  On_Rectangle_adjust(rectangle);
2542
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2543
  }
2544
 
2545
 
 
43
  }
44
  }
45
 
46
+ // 添加树形目录节点信息类
47
+ public class DirectoryTreeNode
48
+ {
49
+ public string Name { get; set; }
50
+ public string FullPath { get; set; }
51
+ public string Icon { get; set; }
52
+ public bool IsDirectory { get; set; }
53
+ public List<DirectoryTreeNode> Children { get; set; }
54
+
55
+ public DirectoryTreeNode(string fullPath, bool isDirectory = true)
56
+ {
57
+ FullPath = fullPath;
58
+ Name = Path.GetFileName(fullPath);
59
+ if (string.IsNullOrEmpty(Name))
60
+ Name = fullPath; // 对于根目录
61
+ IsDirectory = isDirectory;
62
+ Icon = isDirectory ? "📁" : "📄";
63
+ Children = new List<DirectoryTreeNode>();
64
+ }
65
+
66
+ public override string ToString()
67
+ {
68
+ return Name;
69
+ }
70
+ }
71
+
72
  public enum EditorMode
73
  {
74
  ImageOCR,
 
175
  else if (this._mode == EditorMode.MenuSplit)
176
  {
177
  this.Title = "目录拆解";
178
+ this.BorderDirectoryTreeView.Visibility = Visibility.Visible;
179
  }
180
  }
181
 
 
2567
  {
2568
  On_Rectangle_adjust(rectangle);
2569
  }
2570
+
2571
+ // 树形目录选择变化事件
2572
+ private void DirectoryTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
2573
+ {
2574
+ if (e.NewValue is DirectoryTreeNode selectedNode)
2575
+ {
2576
+ // 处理目录或文件选择
2577
+ if (selectedNode.IsDirectory)
2578
+ {
2579
+ StatusText.Text = $"选中目录: {selectedNode.FullPath}";
2580
+ // 这里可以添加目录选择时的处理逻辑
2581
+ // 例如:加载目录下的图片文件到图片列表
2582
+ }
2583
+ else
2584
+ {
2585
+ StatusText.Text = $"选中文件: {selectedNode.FullPath}";
2586
+ // 这里可以添加文件选择时的处理逻辑
2587
+ // 例如:如果是图片文件,直接打开显示
2588
+ }
2589
+ }
2590
+ }
2591
  }
2592
 
2593