123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- using System.ComponentModel;
- using System.IO;
- using System.Windows;
- using System.Windows.Controls;
- using InABox.Core;
- using InABox.Wpf;
- namespace InABox.DynamicGrid
- {
- /// <summary>
- /// Interaction logic for PDFViewer.xaml
- /// </summary>
- public partial class DocumentEditor : ThemableWindow
- {
- private IEntityDocument[] _documents;
- private readonly bool bReady;
- public DocumentEditor(params IEntityDocument[] documents)
- {
- PrintAllowed = false;
- SaveAllowed = false;
- InitializeComponent();
- _documents = documents;
- foreach (var doc in documents)
- {
- var tab = new DynamicTabItem();
- tab.Header = Path.GetFileName(doc.DocumentLink.FileName);
- tab.Tag = doc;
- Documents.Items.Add(tab);
- }
- bReady = true;
- Documents.SelectedIndex = -1;
- }
- public bool PrintAllowed { get; set; }
- public bool SaveAllowed { get; set; }
- public string Watermark { get; set; }
- private void Documents_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (!bReady)
- return;
- for (var i = 0; i < e.RemovedItems.Count; i++)
- {
- var item = e.RemovedItems[i] as DynamicTabItem;
- if (item != null)
- {
- var viewer = item.Content as IDocumentEditor;
- if (viewer != null)
- viewer.Document = null;
- item.Content = null;
- }
- }
- for (var i = 0; i < e.AddedItems.Count; i++)
- {
- var item = e.AddedItems[i] as DynamicTabItem;
- if (item != null)
- {
- var doc = item.Tag as IEntityDocument;
- if (doc != null)
- {
- IDocumentEditor editor = null;
- var extension = Path.GetExtension(doc.DocumentLink.FileName).ToLower();
- if (extension.Equals(".pdf"))
- {
- var pdf = new PDFEditorControl();
- pdf.PrintAllowed = PrintAllowed;
- pdf.SaveAllowed = SaveAllowed;
- pdf.Watermark = Watermark;
- editor = pdf;
- }
- else if (extension.Equals(".png") || extension.Equals(".bmp") || extension.Equals(".jpg") || extension.Equals(".jpeg"))
- {
- editor = new ImageEditorControl();
- }
- if (editor != null)
- {
- item.Content = editor;
- editor.Document = doc;
- }
- }
- }
- }
- e.Handled = true;
- }
- protected override void OnClosing(CancelEventArgs e)
- {
- base.OnClosing(e);
- Documents.SelectedIndex = -1;
- }
- private void Window_Loaded(object sender, RoutedEventArgs e)
- {
- //Editor.Document = _documents.FirstOrDefault();
- }
-
- private void OKButton_Click(object sender, RoutedEventArgs e)
- {
- //Editor.Document = null;
- DialogResult = true;
- Close();
- }
- private void CancelButton_Click(object sender, RoutedEventArgs e)
- {
- DialogResult = false;
- Close();
- }
- }
- }
|