protected override bool OpenFormData(string sFileName) { Cursor = Cursors.WaitCursor; try { ProjectManager.Instance.OpenProject(sFileName); } catch (Exception ex) { FormUtils.ShowErrorMessage("Failed to load: " + sFileName + "::" + ex); } Cursor = Cursors.Default; if (null != ProjectManager.Instance.LoadedProject) { UpdateProjectsList(sFileName); bool bHasExternalReference = ProjectManager.Instance.LoadedProject.HasExternalReference(); if (bHasExternalReference) { UpdateGoogleAuth(null, () => { MessageBox.Show(this, "You will be unable to view the layouts for any references that are Google Spreadsheets.", "Reference Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); }); } return(true); } return(false); }
private void btnGenCards_Click(object sender, EventArgs e) { if (LayoutManager.Instance.ActiveDeck.CardLayout.Reference != null && LayoutManager.Instance.ActiveDeck.CardLayout.Reference.Length > 0) { FormUtils.ShowErrorMessage("You cannot assign a default card count to a layout with an associated reference."); return; } const string CARD_COUNT = "CARD_COUNT"; var zQuery = new QueryPanelDialog("Default Card Count", 240, false); zQuery.SetIcon(CardMakerInstance.ApplicationIcon); zQuery.AddNumericBox("Card Count", LayoutManager.Instance.ActiveDeck.CardLayout.defaultCount, 1, int.MaxValue, CARD_COUNT); if (DialogResult.OK == zQuery.ShowDialog(this)) { LayoutManager.Instance.ActiveLayout.defaultCount = (int)zQuery.GetDecimal(CARD_COUNT); LayoutManager.Instance.InitializeActiveLayout(); LayoutManager.Instance.FireLayoutUpdatedEvent(true); } }
private void ExportViaPDFSharp(bool bExportAllLayouts) { var zQuery = new QueryPanelDialog("Export to PDF (via PDFSharp)", 750, false); zQuery.SetIcon(Icon); const string ORIENTATION = "orientation"; const string OUTPUT_FILE = "output_file"; const string OPEN_ON_EXPORT = "open_on_export"; zQuery.AddPullDownBox("Page Orientation", new string[] { PageOrientation.Portrait.ToString(), PageOrientation.Landscape.ToString() }, m_nPdfExportLastOrientationIndex, ORIENTATION); zQuery.AddFileBrowseBox("Output File", m_sPdfExportLastFile, "PDF files (*.pdf)|*.pdf|All files (*.*)|*.*", OUTPUT_FILE); zQuery.AddCheckBox("Open PDF on Export", m_bPdfExportLastOpen, OPEN_ON_EXPORT); if (DialogResult.OK != zQuery.ShowDialog(this)) { return; } var nStartLayoutIdx = 0; var nEndLayoutIdx = ProjectManager.Instance.LoadedProject.Layout.Length; if (!bExportAllLayouts) { int nIdx = ProjectManager.Instance.GetLayoutIndex(LayoutManager.Instance.ActiveLayout); if (-1 == nIdx) { FormUtils.ShowErrorMessage("Unable to determine the current layout. Please select a layout in the tree view and try again."); return; } nStartLayoutIdx = nIdx; nEndLayoutIdx = nIdx + 1; } m_sPdfExportLastFile = zQuery.GetString(OUTPUT_FILE); m_bPdfExportLastOpen = zQuery.GetBool(OPEN_ON_EXPORT); m_nPdfExportLastOrientationIndex = zQuery.GetIndex(ORIENTATION); if (!m_sPdfExportLastFile.EndsWith(".pdf", StringComparison.CurrentCultureIgnoreCase)) { m_sPdfExportLastFile += ".pdf"; } var zFileCardExporter = new PdfSharpExporter(nStartLayoutIdx, nEndLayoutIdx, m_sPdfExportLastFile, zQuery.GetString(ORIENTATION)); var zWait = new WaitDialog( 2, zFileCardExporter.ExportThread, "Export", new string[] { "Layout", "Card" }, 450); #if true zWait.ShowDialog(this); #else zFileCardExporter.ExportThread(); #endif if (zWait.ThreadSuccess && m_bPdfExportLastOpen && File.Exists(m_sPdfExportLastFile)) { Process.Start(m_sPdfExportLastFile); } }
private void ExportImages(bool bExportAllLayouts) { var zQuery = new QueryPanelDialog("Export to Images", 750, false); zQuery.SetIcon(Properties.Resources.CardMakerIcon); const string FORMAT = "FORMAT"; const string NAME_FORMAT = "NAME_FORMAT"; const string NAME_FORMAT_LAYOUT_OVERRIDE = "NAME_FORMAT_LAYOUT_OVERRIDE"; const string FOLDER = "FOLDER"; const string STITCH_SKIP_INDEX = "DUMMY_IDX"; var arrayImageFormats = new ImageFormat[] { ImageFormat.Bmp, ImageFormat.Emf, ImageFormat.Exif, ImageFormat.Gif, ImageFormat.Icon, ImageFormat.Jpeg, ImageFormat.Png, ImageFormat.Tiff, ImageFormat.Wmf }; var arrayImageFormatStrings = new string[arrayImageFormats.Length]; for (int nIdx = 0; nIdx < arrayImageFormats.Length; nIdx++) { arrayImageFormatStrings[nIdx] = arrayImageFormats[nIdx].ToString(); } var nDefaultFormatIndex = 0; var lastImageFormat = CardMakerSettings.IniManager.GetValue(IniSettings.LastImageExportFormat, string.Empty); // TODO: .NET 4.x offers enum.parse... when the project gets to that version if (lastImageFormat != string.Empty) { for (int nIdx = 0; nIdx < arrayImageFormats.Length; nIdx++) { if (arrayImageFormats[nIdx].ToString().Equals(lastImageFormat)) { nDefaultFormatIndex = nIdx; break; } } } zQuery.AddPullDownBox("Format", arrayImageFormatStrings, nDefaultFormatIndex, FORMAT); var sDefinition = ProjectManager.Instance.LoadedProject.exportNameFormat; // default to the project level definition if (!bExportAllLayouts) { sDefinition = LayoutManager.Instance.ActiveLayout.exportNameFormat; } else { zQuery.AddCheckBox("Override Layout File Name Formats", false, NAME_FORMAT_LAYOUT_OVERRIDE); } zQuery.AddNumericBox("Stitch Skip Index", CardMakerSettings.ExportStitchSkipIndex, 0, 65535, 1, 0, STITCH_SKIP_INDEX); zQuery.AddTextBox("File Name Format (optional)", sDefinition ?? string.Empty, false, NAME_FORMAT); if (bExportAllLayouts) { // associated check box and the file format text box zQuery.AddEnableControl(NAME_FORMAT_LAYOUT_OVERRIDE, NAME_FORMAT); } zQuery.AddFolderBrowseBox("Output Folder", Directory.Exists(ProjectManager.Instance.LoadedProject.lastExportPath) ? ProjectManager.Instance.LoadedProject.lastExportPath : string.Empty, FOLDER); zQuery.UpdateEnableStates(); if (DialogResult.OK == zQuery.ShowDialog(this)) { string sFolder = zQuery.GetString(FOLDER); if (!Directory.Exists(sFolder)) { try { Directory.CreateDirectory(sFolder); } catch (Exception e) { Logger.AddLogLine("Error creating folder {0}: {1}".FormatString(sFolder, e.Message)); } } if (Directory.Exists(sFolder)) { ProjectManager.Instance.LoadedProject.lastExportPath = sFolder; var nStartLayoutIdx = 0; var nEndLayoutIdx = ProjectManager.Instance.LoadedProject.Layout.Length; var bOverrideLayout = false; if (!bExportAllLayouts) { int nIdx = ProjectManager.Instance.GetLayoutIndex(LayoutManager.Instance.ActiveLayout); if (-1 == nIdx) { FormUtils.ShowErrorMessage("Unable to determine the current layout. Please select a layout in the tree view and try again."); return; } nStartLayoutIdx = nIdx; nEndLayoutIdx = nIdx + 1; } else { bOverrideLayout = zQuery.GetBool(NAME_FORMAT_LAYOUT_OVERRIDE); } CardMakerSettings.IniManager.SetValue(IniSettings.LastImageExportFormat, arrayImageFormats[zQuery.GetIndex(FORMAT)].ToString()); CardMakerSettings.ExportStitchSkipIndex = (int)zQuery.GetDecimal(STITCH_SKIP_INDEX); ICardExporter zFileCardExporter = new FileCardExporter(nStartLayoutIdx, nEndLayoutIdx, sFolder, bOverrideLayout, zQuery.GetString(NAME_FORMAT), (int)zQuery.GetDecimal(STITCH_SKIP_INDEX), arrayImageFormats[zQuery.GetIndex(FORMAT)]); #if true var zWait = new WaitDialog( 2, zFileCardExporter.ExportThread, "Export", new string[] { "Layout", "Card" }, 450); zWait.ShowDialog(this); #else // non threaded zFileCardExporter.ExportThread(); #endif } else { FormUtils.ShowErrorMessage("The folder specified does not exist!"); } } }