-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathMainWindow.xaml.cs
128 lines (120 loc) · 3.29 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Markup;
using PbdViewer.DataModel;
using PbdViewer.Uitils.PbClass;
using PbdViewer.ViewModel;
namespace PbdViewer
{
public partial class MainWindow : Window
{
private readonly WindowViewModel _model;
public MainWindow()
{
this.InitializeComponent();
base.DataContext = (this._model = new WindowViewModel());
base.WindowStartupLocation = WindowStartupLocation.CenterScreen;
base.Loaded += this.MainWindow_Loaded;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
}
private void MainWindow_OnPreviewDragOver(object sender, DragEventArgs e)
{
e.Effects = DragDropEffects.None;
if (!e.Data.GetDataPresent(DataFormats.FileDrop))
{
return;
}
Array array = (Array)e.Data.GetData(DataFormats.FileDrop);
string text = (array != null) ? array.GetValue(0).ToString() : null;
if (string.IsNullOrEmpty(text))
{
return;
}
string a = Path.GetExtension(text).ToLower();
if (a == ".exe" || a == ".dll" || a == ".pbd" || a == ".pbl")
{
e.Effects = DragDropEffects.Move;
}
e.Handled = true;
}
private void MainWindow_OnPreviewDrop(object sender, DragEventArgs e)
{
e.Handled = true;
if (!e.Data.GetDataPresent(DataFormats.FileDrop))
{
return;
}
Array array = (Array)e.Data.GetData(DataFormats.FileDrop);
string text = (array != null) ? array.GetValue(0).ToString() : null;
if (string.IsNullOrEmpty(text))
{
return;
}
this.AddFile(text);
}
private void AddFile(string filename)
{
try
{
using (List<PbFile>.Enumerator enumerator = new PbProject(filename).Files.GetEnumerator())
{
while (enumerator.MoveNext())
{
PbFile pbFile = enumerator.Current;
TreeNode treeNode = this._model.Nodes.FirstOrDefault((TreeNode o) => string.Compare(o.Name, pbFile.FilePath, StringComparison.OrdinalIgnoreCase) == 0);
if (treeNode != null)
{
this._model.Nodes.Remove(treeNode);
}
this._model.Nodes.Add(new FileNode(pbFile));
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void TreeView_OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
TreeNode treeNode = e.NewValue as TreeNode;
this.Image.Visibility = Visibility.Collapsed;
this.RichTextBox.Visibility = Visibility.Collapsed;
if (treeNode != null)
{
if (treeNode.Bitmap != null)
{
this.Image.Source = treeNode.Bitmap;
this.Image.Visibility = Visibility.Visible;
return;
}
this.RichTextBox.Document.Blocks.Clear();
this.RichTextBox.Document.Blocks.Add(new Paragraph(new Run(treeNode.Text)));
this.RichTextBox.Visibility = Visibility.Visible;
}
}
private void UIElement_OnKeyDown(object sender, KeyEventArgs e)
{
TreeView treeView = (TreeView)sender;
if (e.Key == Key.Delete)
{
TreeNode treeNode = treeView.SelectedItem as TreeNode;
if (treeNode != null && treeNode.NodeType == NodeType.File)
{
this._model.Nodes.Remove(treeNode);
}
}
}
}
}