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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
using MahApps.Metro.Controls;
using Microsoft.WindowsAPICodePack.Dialogs;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Tango.Core.Commands;
using Tango.Protobuf.Compilers;
namespace Tango.Protobuf.UI
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : MetroWindow
{
private String _sourceFolder;
private CompilerFolderResult _lastFolderResult;
public RelayCommand LoadFileCommand { get; set; }
public RelayCommand LoadFolderCommand { get; set; }
public RelayCommand CompileCommand { get; set; }
public RelayCommand SaveCommand { get; set; }
public List<Item> SourceItems
{
get { return (List<Item>)GetValue(SourceItemsProperty); }
set { SetValue(SourceItemsProperty, value); }
}
public static readonly DependencyProperty SourceItemsProperty =
DependencyProperty.Register("SourceItems", typeof(List<Item>), typeof(MainWindow), new PropertyMetadata(null));
public String CurrentContent
{
get { return (String)GetValue(CurrentContentProperty); }
set { SetValue(CurrentContentProperty, value); }
}
public static readonly DependencyProperty CurrentContentProperty =
DependencyProperty.Register("CurrentContent", typeof(String), typeof(MainWindow), new PropertyMetadata(null));
public List<ICompilerResult> TargetItems
{
get { return (List<ICompilerResult>)GetValue(TargetItemsProperty); }
set { SetValue(TargetItemsProperty, value); }
}
public static readonly DependencyProperty TargetItemsProperty =
DependencyProperty.Register("TargetItems", typeof(List<ICompilerResult>), typeof(MainWindow), new PropertyMetadata(null));
public CompilerLanguage CompilerLanguage
{
get { return (CompilerLanguage)GetValue(CompilerLanguageProperty); }
set { SetValue(CompilerLanguageProperty, value); }
}
public static readonly DependencyProperty CompilerLanguageProperty =
DependencyProperty.Register("CompilerLanguage", typeof(CompilerLanguage), typeof(MainWindow), new PropertyMetadata(CompilerLanguage.CSharp));
public MainWindow()
{
SourceItems = new List<Item>();
TargetItems = new List<ICompilerResult>();
LoadFileCommand = new RelayCommand(LoadFile);
LoadFolderCommand = new RelayCommand(LoadFolder);
CompileCommand = new RelayCommand(Compile);
SaveCommand = new RelayCommand(Save);
InitializeComponent();
}
private void LoadFolder()
{
var dialog = new CommonOpenFileDialog();
dialog.IsFolderPicker = true;
CommonFileDialogResult result = dialog.ShowDialog();
if (result == CommonFileDialogResult.Ok)
{
_sourceFolder = dialog.FileName;
SourceItems = ItemProvider.GetItems(_sourceFolder);
}
}
private void LoadFile()
{
throw new NotImplementedException();
}
private void Source_TreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
if (e.NewValue is FileItem)
{
CurrentContent = File.ReadAllText((e.NewValue as FileItem).Path);
}
else if (e.NewValue is CompilerFileResult)
{
CurrentContent = (e.NewValue as CompilerFileResult).Content;
}
else
{
CurrentContent = String.Empty;
}
}
private void Compile()
{
IProtoCompiler compiler = CompilerFactory.CreateCompiler(CompilerLanguage);
try
{
_lastFolderResult = compiler.CompileFolder(_sourceFolder, txtIncludes.Text.Split(','));
TargetItems = _lastFolderResult.Results.ToList();
}
catch (CompilerException ex)
{
ExceptionWindow exWin = new ExceptionWindow(ex.Issues);
exWin.Owner = this;
exWin.ShowDialog();
}
}
private void Save()
{
if (_lastFolderResult != null)
{
var dialog = new CommonOpenFileDialog();
dialog.IsFolderPicker = true;
CommonFileDialogResult result = dialog.ShowDialog();
if (result == CommonFileDialogResult.Ok)
{
_lastFolderResult.Save(dialog.FileName);
}
}
}
}
}
|