From 6f6488fb8e1c3b1574aed8c2043a0386148ae1e2 Mon Sep 17 00:00:00 2001 From: Michael Becker Date: Sat, 20 Feb 2021 22:25:59 -0500 Subject: [PATCH] playing around with printing stuff - nothing production ready yet --- .../Controls/PrintDialogOptionsTabPage.cs | 69 ++++++++++++++ .../Controls/PrintDialogOptionsTabPage.glade | 95 +++++++++++++++++++ .../MainWindow.cs | 54 ++++++++++- .../UniversalEditor.UserInterface.csproj | 2 + 4 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 Libraries/UniversalEditor.UserInterface/Controls/PrintDialogOptionsTabPage.cs create mode 100644 Libraries/UniversalEditor.UserInterface/Controls/PrintDialogOptionsTabPage.glade diff --git a/Libraries/UniversalEditor.UserInterface/Controls/PrintDialogOptionsTabPage.cs b/Libraries/UniversalEditor.UserInterface/Controls/PrintDialogOptionsTabPage.cs new file mode 100644 index 00000000..1913cc38 --- /dev/null +++ b/Libraries/UniversalEditor.UserInterface/Controls/PrintDialogOptionsTabPage.cs @@ -0,0 +1,69 @@ +// +// PrintDialogOptionsTab.cs +// +// Author: +// Michael Becker +// +// Copyright (c) 2021 Mike Becker's Software +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +using System; +using MBS.Framework.UserInterface; +using MBS.Framework.UserInterface.Controls; +using UniversalEditor.Printing; + +namespace UniversalEditor.UserInterface.Controls +{ + [ContainerLayout(typeof(PrintDialogOptionsTabPage), "UniversalEditor.UserInterface.Controls.PrintDialogOptionsTabPage.glade")] + public class PrintDialogOptionsTabPage : TabPage + { + private GroupBox fraCustomOptions; + private ComboBox cboPrintHandler; + + public PrintHandlerReference[] PrintHandlers { get; set; } = null; + public PrintHandlerReference SelectedPrintHandler { get; set; } = null; + + public PrintDialogOptionsTabPage() + { + Text = "Options"; + } + + [EventHandler(nameof(cboPrintHandler), "Changed")] + private void cboPrintHandler_Changed(object sender, EventArgs e) + { + fraCustomOptions.Controls.Clear(); + } + + protected override void OnCreated(EventArgs e) + { + base.OnCreated(e); + + if (PrintHandlers != null) + { + for (int i = 0; i < PrintHandlers.Length; i++) + { + (cboPrintHandler.Model as DefaultTreeModel).Rows.Add(new TreeModelRow(new TreeModelRowColumn[] + { + new TreeModelRowColumn(cboPrintHandler.Model.Columns[0], PrintHandlers[i].TypeName) + })); + } + + if (SelectedPrintHandler != null) + { + cboPrintHandler.SelectedItem = (cboPrintHandler.Model as DefaultTreeModel).Rows[Array.IndexOf(PrintHandlers, SelectedPrintHandler)]; + } + } + } + } +} diff --git a/Libraries/UniversalEditor.UserInterface/Controls/PrintDialogOptionsTabPage.glade b/Libraries/UniversalEditor.UserInterface/Controls/PrintDialogOptionsTabPage.glade new file mode 100644 index 00000000..6d586709 --- /dev/null +++ b/Libraries/UniversalEditor.UserInterface/Controls/PrintDialogOptionsTabPage.glade @@ -0,0 +1,95 @@ + + + + + + + + + + + + False + + + + + + True + False + vertical + + + True + False + + + True + False + Print _handler + True + 0 + + + 0 + 0 + + + + + True + False + tmPrintHandler + + + + 0 + + + + + 1 + 0 + + + + + True + True + 0 + + + + + True + False + 0 + none + + + True + False + 12 + + + + + + + + True + False + Custom options + + + + + True + True + 1 + + + + + + diff --git a/Libraries/UniversalEditor.UserInterface/MainWindow.cs b/Libraries/UniversalEditor.UserInterface/MainWindow.cs index d7c1febb..654d13b9 100644 --- a/Libraries/UniversalEditor.UserInterface/MainWindow.cs +++ b/Libraries/UniversalEditor.UserInterface/MainWindow.cs @@ -31,6 +31,8 @@ using System.Collections.Generic; using System.Text; using MBS.Framework.UserInterface.Controls.ListView; using MBS.Framework; +using UniversalEditor.UserInterface.Controls; +using UniversalEditor.ObjectModels.PropertyList; namespace UniversalEditor.UserInterface { @@ -1317,7 +1319,52 @@ namespace UniversalEditor.UserInterface if (phrs.Length > 0) { PrintDialog dlg = new PrintDialog(); - if (dlg.ShowDialog(this) == DialogResult.OK) + dlg.EnablePreview = true; + + PrintDialogOptionsTabPage tab1 = new PrintDialogOptionsTabPage(); + tab1.SelectedPrintHandler = phrs[0]; + tab1.PrintHandlers = phrs; + + dlg.TabPages.Add(tab1); + + DialogResult result = dlg.ShowDialog(this); + + switch (result) + { + case DialogResult.Apply: + { + // do print preview + + FileAccessor faINI = new FileAccessor(TemporaryFileManager.GetTemporaryFileName(), true, true, true); + PropertyListObjectModel omINI = new PropertyListObjectModel(); + DataFormats.PropertyList.WindowsConfigurationDataFormat dfINI = new DataFormats.PropertyList.WindowsConfigurationDataFormat(); + + omINI.Items.Add(new Group("Print Settings", new PropertyListItem[] + { + })); + omINI.Items.Add(new Group("Page Setup", new PropertyListItem[] + { + new Property("PPDName", "Letter") + })); + omINI.Items.Add(new Group("Print Job", new PropertyListItem[] + { + new Property("title", "Universal Editor Print Preview Test") + })); + + // we do not need to quote property values here + dfINI.PropertyValuePrefix = String.Empty; + dfINI.PropertyValueSuffix = String.Empty; + + Document.Save(omINI, dfINI, faINI); + + string pdfFileName = TemporaryFileManager.GetTemporaryFileName(); + System.IO.File.Copy("/tmp/1940.pdf", pdfFileName); + + (Application.Instance as UIApplication).Launch("evince-previewer", String.Format("--print-settings {0} --unlink-tempfile {1}", faINI.FileName, pdfFileName)); + break; + } + } + if (result == DialogResult.OK) { PrintHandler ph = phrs[0].Create(); if (ph != null) @@ -1339,6 +1386,11 @@ namespace UniversalEditor.UserInterface } } + void Job_Preview(object sender, PrintPreviewEventArgs e) + { + e.Handled = true; + } + void Job_DrawPage(object sender, PrintEventArgs e) { PrintJob job = (sender as PrintJob); diff --git a/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj b/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj index bb0d0638..025307ab 100644 --- a/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj +++ b/Libraries/UniversalEditor.UserInterface/UniversalEditor.UserInterface.csproj @@ -134,6 +134,7 @@ + @@ -197,6 +198,7 @@ +