-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDocumentBinder.cs
50 lines (41 loc) · 1.58 KB
/
DocumentBinder.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
namespace pocketmodise {
using System.IO;
using System.Windows.Input;
using PdfSharp;
internal class DocumentBinder {
public NullaryCommand OpenInputCommand { get; set; }
public NullaryCommand RenderCommand { get; set; }
public NullaryCommand WriteOutputCommand { get; set; }
private PocketModDocument document;
public DocumentBinder() {
OpenInputCommand = new NullaryCommand(ReadInputFile, CanSelectInputFile);
RenderCommand = new NullaryCommand(RenderDocument, CanRender);
WriteOutputCommand = new NullaryCommand(WriteOutputFile, CanSave);
}
private static bool CanSelectInputFile() {
return true;
}
private bool CanRender() {
return document != null;
}
private bool CanSave() {
return document != null && document.IsRendered;
}
private void ReadInputFile() {
try {
document = new PocketModDocument(DialogService.ChooseFileToOpen(), new Superpage4x2());
RenderCommand.RaiseCanExecuteChanged();
WriteOutputCommand.RaiseCanExecuteChanged();
} catch (IOException) {
// burp
}
}
private void RenderDocument() {
document.Render(PageSize.A4);
WriteOutputCommand.RaiseCanExecuteChanged();
}
private void WriteOutputFile() {
document.WriteToFile(DialogService.ChooseFileToSave());
}
}
}