Beispiel #1
0
        private void btnElementRename_Click(object sender, EventArgs e)
        {
            if (1 != listViewElements.SelectedItems.Count)
            {
                return;
            }
            const string NAME = "NAME";
            var zElement = (ProjectLayoutElement)listViewElements.SelectedItems[0].Tag;
            var zQuery = new QueryPanelDialog("Rename", 350, false);
            zQuery.SetIcon(Properties.Resources.CardMakerIcon);
            zQuery.AddTextBox("Name: ", zElement.name, false, NAME);
            if (DialogResult.OK == zQuery.ShowDialog(this))
            {
                string sName = zQuery.GetString(NAME).Trim();
                if (!m_dictionaryItems.ContainsKey(sName))
                {
                    // UserAction
                    var lvItem = listViewElements.SelectedItems[0];
                    var sRedoName = sName;
                    var sUndoName = zElement.name;
                    UserAction.PushAction(bRedo =>
                    {
                        string sOldName = bRedo ? sUndoName : sRedoName;
                        string sNewName = bRedo ? sRedoName : sUndoName;

                        RenameElement(zElement, lvItem, sOldName, sNewName);
                    });

                    RenameElement(zElement, lvItem, zElement.name, sName);

                    LayoutManager.Instance.FireLayoutUpdatedEvent(true);
                }
                else
                {
                    MessageBox.Show(this, "The new name already exists!", "Duplicate Name", MessageBoxButtons.OK);
                }
            }
        }
Beispiel #2
0
        private void btnAddElement_Click(object sender, EventArgs e)
        {
            const string ELEMNAME = "ELEMNAME";
            var zQuery = new QueryPanelDialog("Add Element", 400, false);
            zQuery.SetIcon(Properties.Resources.CardMakerIcon);
            zQuery.AddLabel("Element Names are broken up by a line.", 24);
            zQuery.AddMultiLineTextBox("Element Name(s)", string.Empty, 200, ELEMNAME);

            if (DialogResult.OK == zQuery.ShowDialog(this))
            {
                var arrayNames = zQuery.GetString(ELEMNAME).Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                if (0 < arrayNames.Length)
                {
                    AddElements(arrayNames, null);
                    ChangeSelectedElement(arrayNames[0]);
                }
            }
        }
Beispiel #3
0
        private void btnDuplicate_Click(object sender, EventArgs e)
        {
            if (0 == listViewElements.SelectedItems.Count)
            {
                return;
            }

            const string ELEMNAME = "ELEMNAME";
            var zQuery = new QueryPanelDialog("Duplicate Element", 400, false);
            zQuery.SetIcon(Properties.Resources.CardMakerIcon);
            zQuery.AddLabel("Duplicate Element Names are broken up by a line.", 24);
            zQuery.AddMultiLineTextBox("Element Name(s)", string.Empty, 200, ELEMNAME);
            if (1 < listViewElements.SelectedItems.Count)
            {
                zQuery.Form.Closing += (o, args) =>
                {
                    if (zQuery.Form.DialogResult == DialogResult.Cancel)
                    {
                        return;
                    }
                    var arrayNames = zQuery.GetString(ELEMNAME)
                                        .Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                    if (arrayNames.Length != listViewElements.SelectedItems.Count)
                    {
                        MessageBox.Show(zQuery.Form,
                            $"Please specify {listViewElements.SelectedItems.Count} element names.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        args.Cancel = true;
                    }
                };
            }

            if (DialogResult.OK == zQuery.ShowDialog(this))
            {
                string[] arrayNames = zQuery.GetString(ELEMNAME)
                    .Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
                if (1 == listViewElements.SelectedItems.Count)
                {
                    AddElements(arrayNames, (ProjectLayoutElement) listViewElements.SelectedItems[0].Tag);
                }
                else if (arrayNames.Length == listViewElements.SelectedIndices.Count)
                {
                    var listIndicies = new List<int>();
                    foreach (int nIdx in listViewElements.SelectedIndices)
                    {
                        listIndicies.Add(nIdx);
                    }
                    listIndicies.Sort();
                    for (var nIdx = 0; nIdx < arrayNames.Length; nIdx++)
                    {
                        AddElements(new string[] { arrayNames[nIdx] }, (ProjectLayoutElement)listViewElements.Items[listIndicies[nIdx]].Tag);
                    }
                }
            }
        }
Beispiel #4
0
        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);
            }
        }
Beispiel #5
0
        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!");
                }
            }
        }
Beispiel #6
0
        private void setNameFormatToolStripMenuItem_Click(object sender, EventArgs e)
        {
            const string NAME = "NAME";
            const string ROTATION = "ROTATION";
            const string EXPORT_WIDTH = "EXPORT_WIDTH";
            const string EXPORT_HEIGHT = "EXPORT_HEIGHT";
            const string EXPORT_TRANSPARENT = "EXPORT_TRANSPARENT";

            Type typeObj = treeView.SelectedNode.Tag.GetType();
            string sExistingFormat = String.Empty;
            var zQuery = new QueryPanelDialog("Configure Layout Export", 450, 200, false);
            zQuery.SetIcon(Resources.CardMakerIcon);

            if (typeof(Project) == typeObj)
            {
                sExistingFormat = ((Project)treeView.SelectedNode.Tag).exportNameFormat;
            }
            else if (typeof(ProjectLayout) == typeObj)
            {
                var zProjectLayout = ((ProjectLayout) treeView.SelectedNode.Tag);

                sExistingFormat = zProjectLayout.exportNameFormat;
                var nDefaultRotationIndex =
                    Math.Max(0, ProjectLayout.AllowedExportRotations.ToList()
                        .IndexOf(zProjectLayout.exportRotation.ToString()));
                zQuery.AddPullDownBox("Export Rotation (Print/PDF/Export)", ProjectLayout.AllowedExportRotations,
                    nDefaultRotationIndex, ROTATION);
                zQuery.AddNumericBox("Export Width", zProjectLayout.exportWidth,
                    0, 65536, EXPORT_WIDTH);
                zQuery.AddNumericBox("Export Height", zProjectLayout.exportHeight,
                    0, 65536, EXPORT_HEIGHT);
                zQuery.AddCheckBox("Export Transparent Background", zProjectLayout.exportTransparentBackground,
                    EXPORT_TRANSPARENT);
            }

            zQuery.AddTextBox("Name Format", sExistingFormat ?? String.Empty, false, NAME);

            if(DialogResult.OK == zQuery.ShowDialog(this))
            {
                if (typeof(Project) == typeObj)
                {
                    ((Project)treeView.SelectedNode.Tag).exportNameFormat = zQuery.GetString(NAME);
                }
                else if (typeof(ProjectLayout) == typeObj)
                {
                    var zProjectLayout = ((ProjectLayout)treeView.SelectedNode.Tag);
                    zProjectLayout.exportNameFormat = zQuery.GetString(NAME);
                    zProjectLayout.exportRotation = Int32.Parse(zQuery.GetString(ROTATION));
                    zProjectLayout.exportWidth = Int32.Parse(zQuery.GetString(EXPORT_WIDTH));
                    zProjectLayout.exportHeight = Int32.Parse(zQuery.GetString(EXPORT_HEIGHT));
                    zProjectLayout.exportTransparentBackground = zQuery.GetBool(EXPORT_TRANSPARENT);
                }
                CardMakerMDI.Instance.MarkDirty();
            }
        }
Beispiel #7
0
 private void illegalFilenameCharacterReplacementToolStripMenuItem_Click(object sender, EventArgs e)
 {
     var zQuery = new QueryPanelDialog("Illegal File Name Character Replacement", 350, false);
     zQuery.SetIcon(Properties.Resources.CardMakerIcon);
     var arrayBadChars = FilenameTranslator.DISALLOWED_FILE_CHARS_ARRAY;
     var arrayReplacementChars = CardMakerSettings.IniManager.GetValue(IniSettings.ReplacementChars, string.Empty).Split(new char[] { CardMakerConstants.CHAR_FILE_SPLIT });
     if (arrayReplacementChars.Length == FilenameTranslator.DISALLOWED_FILE_CHARS_ARRAY.Length)
     {
         // from ini
         for (int nIdx = 0; nIdx < arrayBadChars.Length; nIdx++)
         {
             zQuery.AddTextBox(arrayBadChars[nIdx].ToString(CultureInfo.InvariantCulture), arrayReplacementChars[nIdx], false, nIdx.ToString(CultureInfo.InvariantCulture));
         }
     }
     else
     {
         // default
         for (int nIdx = 0; nIdx < arrayBadChars.Length; nIdx++)
         {
             zQuery.AddTextBox(arrayBadChars[nIdx].ToString(CultureInfo.InvariantCulture), string.Empty, false, nIdx.ToString(CultureInfo.InvariantCulture));
         }
     }
     if (DialogResult.OK == zQuery.ShowDialog(this))
     {
         var zBuilder = new StringBuilder();
         for (int nIdx = 0; nIdx < arrayBadChars.Length; nIdx++)
         {
             zBuilder.Append(zQuery.GetString(nIdx.ToString(CultureInfo.InvariantCulture)) + CardMakerConstants.CHAR_FILE_SPLIT);
         }
         zBuilder.Remove(zBuilder.Length - 1, 1); // remove last char
         CardMakerSettings.IniManager.SetValue(IniSettings.ReplacementChars, zBuilder.ToString());
         RestoreReplacementChars();
     }
 }
Beispiel #8
0
        private void addLayoutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            const string NAME = "name";
            const string WIDTH = "width";
            const string HEIGHT = "height";
            const string DPI = "dpi";

            var zQuery = new QueryPanelDialog("New Layout", 450, false);
            zQuery.SetIcon(Resources.CardMakerIcon);
            zQuery.AddTextBox("Name", "New Layout", false, NAME);
            zQuery.AddNumericBox("Width", 300, 1, Int32.MaxValue, WIDTH);
            zQuery.AddNumericBox("Height", 300, 1, Int32.MaxValue, HEIGHT);
            zQuery.AddNumericBox("DPI", 300, 100, 9600, DPI);
            if (DialogResult.OK == zQuery.ShowDialog(this))
            {
                var zLayout = new ProjectLayout(zQuery.GetString(NAME))
                {
                    width = (int)zQuery.GetDecimal(WIDTH),
                    height = (int)zQuery.GetDecimal(HEIGHT),
                    dpi = (int)zQuery.GetDecimal(DPI)
                };
                AddProjectLayout(zLayout, CardMakerMDI.Instance.LoadedProject);
                CardMakerMDI.Instance.MarkDirty();
            }
        }
Beispiel #9
0
 private void defineAsTemplateLayoutToolStripMenuItem_Click(object sender, EventArgs e)
 {
     const string NAME = "name";
     //const string COPY_REFS = "copy_refs";
     var zQuery = new QueryPanelDialog("Template Name", 450, 80, false);
     zQuery.SetIcon(Resources.CardMakerIcon);
     zQuery.AddTextBox("Name", "New Template", false, NAME);
     // TODO: is there really a case where the refs should be copied?
     //zQuery.AddCheckBox("Copy References", false, COPY_REFS);
     if (DialogResult.OK == zQuery.ShowDialog(this))
     {
         var zLayout = new ProjectLayout();
         zLayout.DeepCopy((ProjectLayout)treeView.SelectedNode.Tag, /*zQuery.GetBool(COPY_REFS)*/ false);
         var zTemplate = new LayoutTemplate(zQuery.GetString(NAME), zLayout);
         if (LayoutTemplateManager.Instance.SaveLayoutTemplate(CardMakerMDI.StartupPath, zTemplate))
         {
             LayoutTemplateManager.Instance.LayoutTemplates.Add(zTemplate);
         }
     }
 }
Beispiel #10
0
        private void addCardLayoutFromTemplateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            const string TEMPLATE = "template";
            const string NAME = "name";
            const string COUNT = "count";
            var listItems = new List<string>();
            LayoutTemplateManager.Instance.LayoutTemplates.ForEach(x => listItems.Add(x.ToString()));

            var zQuery = new QueryPanelDialog("Select Layout Template", 450, false);
            zQuery.SetIcon(Resources.CardMakerIcon);
            zQuery.AddTextBox("New Layout Name", "New Layout", false, NAME);
            zQuery.AddNumericBox("Number to create", 1, 1, 256, COUNT);
            zQuery.AddListBox("Template", listItems.ToArray(), null, false, 120, TEMPLATE);
            zQuery.AllowResize();
            while(DialogResult.OK == zQuery.ShowDialog(this))
            {
                int nSelectedIndex = zQuery.GetIndex(TEMPLATE);
                if(-1 == nSelectedIndex)
                {
                    MessageBox.Show("Please select a layout template");
                    continue;
                }

                ProjectLayout zSelectedLayout = LayoutTemplateManager.Instance.LayoutTemplates[nSelectedIndex].Layout;

                for (int nCount = 0; nCount < zQuery.GetDecimal(COUNT); nCount++)
                {
                    var zLayout = new ProjectLayout(zQuery.GetString(NAME));
                    zLayout.DeepCopy(zSelectedLayout);
                    AddProjectLayout(zLayout, CardMakerMDI.Instance.LoadedProject);
                }
                break;
            }
        }
Beispiel #11
0
        private void setNameFormatToolStripMenuItem_Click(object sender, EventArgs e)
        {
            const string NAME = "NAME";
            const string ROTATION = "ROTATION";
            const string EXPORT_WIDTH = "EXPORT_WIDTH";
            const string EXPORT_HEIGHT = "EXPORT_HEIGHT";
            const string EXPORT_TRANSPARENT = "EXPORT_TRANSPARENT";
            const string EXPORT_PDF_AS_PAGE_BACK = "EXPORT_PDF_AS_PAGE_BACK";

            Type typeObj = treeView.SelectedNode.Tag.GetType();
            string sExistingFormat = string.Empty;
            var zQuery = new QueryPanelDialog("Configure Layout Export", 550, 300, false);
            zQuery.SetIcon(Resources.CardMakerIcon);

            if (typeof(Project) == typeObj)
            {
                sExistingFormat = ((Project)treeView.SelectedNode.Tag).exportNameFormat;
            }
            else if (typeof(ProjectLayout) == typeObj)
            {
                var zProjectLayout = ((ProjectLayout) treeView.SelectedNode.Tag);

                sExistingFormat = zProjectLayout.exportNameFormat;
                var nDefaultRotationIndex =
                    Math.Max(0, ProjectLayout.AllowedExportRotations.ToList()
                        .IndexOf(zProjectLayout.exportRotation.ToString()));
                zQuery.AddPullDownBox("Export Rotation (PDF/Export)", ProjectLayout.AllowedExportRotations,
                    nDefaultRotationIndex, ROTATION);

                zQuery.AddCheckBox("Export PDF Layout Page as Back", zProjectLayout.exportPDFAsPageBack, EXPORT_PDF_AS_PAGE_BACK);

                var nColumns = 0;
                var nRows = 0;

                if (zProjectLayout.exportWidth > 0)
                {
                    var nWidth = zProjectLayout.width + zProjectLayout.buffer;
                    nColumns = zProjectLayout.exportWidth / nWidth;
                }

                if (zProjectLayout.exportHeight > 0)
                {
                    var nHeight = zProjectLayout.width + zProjectLayout.buffer;
                    nRows = zProjectLayout.exportHeight / nHeight;
                }

                var numericColumns = zQuery.AddNumericBox("Stitched Columns (changes export width)", nColumns, 0, 100, "COLUMNS");

                var numericRows = zQuery.AddNumericBox("Stitched Rows (changes export height)", nRows, 0, 100, "ROWS");

                var numericExportWidth = zQuery.AddNumericBox("Export Width", zProjectLayout.exportWidth,
                    0, 65536, EXPORT_WIDTH);
                var numericExportHeight = zQuery.AddNumericBox("Export Height", zProjectLayout.exportHeight,
                    0, 65536, EXPORT_HEIGHT);
                zQuery.AddCheckBox("Export Transparent Background", zProjectLayout.exportTransparentBackground,
                    EXPORT_TRANSPARENT);

                numericColumns.ValueChanged += (o, args) =>
                {
                    numericExportWidth.Value = (zProjectLayout.width * numericColumns.Value) +
                        Math.Max(0, (numericColumns.Value - 1) * zProjectLayout.buffer);
                };

                numericRows.ValueChanged += (o, args) =>
                {
                    numericExportHeight.Value = (zProjectLayout.height * numericRows.Value) +
                        Math.Max(0, (numericRows.Value - 1) * zProjectLayout.buffer);
                };
            }

            zQuery.AddTextBox("Name Format", sExistingFormat ?? string.Empty, false, NAME);

            if(DialogResult.OK == zQuery.ShowDialog(this))
            {
                if (typeof(Project) == typeObj)
                {
                    ((Project)treeView.SelectedNode.Tag).exportNameFormat = zQuery.GetString(NAME);
                }
                else if (typeof(ProjectLayout) == typeObj)
                {
                    var zProjectLayout = ((ProjectLayout)treeView.SelectedNode.Tag);
                    zProjectLayout.exportNameFormat = zQuery.GetString(NAME);
                    zProjectLayout.exportRotation = int.Parse(zQuery.GetString(ROTATION));
                    zProjectLayout.exportWidth = int.Parse(zQuery.GetString(EXPORT_WIDTH));
                    zProjectLayout.exportHeight = int.Parse(zQuery.GetString(EXPORT_HEIGHT));
                    zProjectLayout.exportTransparentBackground = zQuery.GetBool(EXPORT_TRANSPARENT);
                    zProjectLayout.exportPDFAsPageBack = zQuery.GetBool(EXPORT_PDF_AS_PAGE_BACK);
                }
                ProjectManager.Instance.FireProjectUpdated(true);
            }
        }
Beispiel #12
0
        private void AdjustLayoutSettings(bool bCreateNew, ProjectLayout zLayout)
        {
            var zQuery = new QueryPanelDialog("Resize Layout", 450, false);
            zQuery.SetIcon(CardMakerInstance.ApplicationIcon);
            const string LAYOUT_NAME = "layoutName";
            const string CENTER_ELEMENTS = "centerElements";
            const string WIDTH = "width";
            const string HEIGHT = "height";

            if (bCreateNew)
            {
                zQuery.AddTextBox("Layout Name", zLayout.Name + " copy", false, LAYOUT_NAME);
            }
            zQuery.AddNumericBox("Width", zLayout.width, 1, int.MaxValue, WIDTH);
            zQuery.AddNumericBox("Height", zLayout.height, 1, int.MaxValue, HEIGHT);
            zQuery.AddCheckBox("Center Elements", false, CENTER_ELEMENTS);

            if (DialogResult.OK == zQuery.ShowDialog(this))
            {
                var zLayoutAdjusted = bCreateNew ? new ProjectLayout(zQuery.GetString(LAYOUT_NAME)) : zLayout;

                var nOriginalWidth = zLayout.width;
                var nOriginalHeight = zLayout.height;

                if (bCreateNew)
                {
                    zLayoutAdjusted.DeepCopy(zLayout);
                }

                zLayoutAdjusted.width = (int)zQuery.GetDecimal(WIDTH);
                zLayoutAdjusted.height = (int)zQuery.GetDecimal(HEIGHT);

                if (zQuery.GetBool(CENTER_ELEMENTS) && null != zLayoutAdjusted.Element)
                {
                    var pointOldCenter = new Point(nOriginalWidth / 2, nOriginalHeight / 2);
                    var pointNewCenter = new Point(zLayoutAdjusted.width / 2, zLayoutAdjusted.height / 2);
                    var nXAdjust = pointNewCenter.X - pointOldCenter.X;
                    var nYAdjust = pointNewCenter.Y - pointOldCenter.Y;
                    foreach (var zElement in zLayoutAdjusted.Element)
                    {
                        zElement.x += nXAdjust;
                        zElement.y += nYAdjust;
                    }
                }

                UserAction.ClearUndoRedoStacks();

                if (bCreateNew)
                {
                    ProjectManager.Instance.AddLayout(zLayoutAdjusted);
                }
                else
                {
                    LayoutManager.Instance.FireLayoutUpdatedEvent(true);
                }
            }
        }
        private static FileCardExporter BuildLayoutExporter()
        {
            var zQuery = new QueryPanelDialog("Export to Images", 750, false);
            zQuery.SetIcon(Properties.Resources.CardMakerIcon);

            var sDefinition = LayoutManager.Instance.ActiveLayout.exportNameFormat;
            var nDefaultFormatIndex = GetLastFormatIndex();

            zQuery.AddPullDownBox("Format", s_arrayAllowedFormatNames, nDefaultFormatIndex, ExportOptionKey.Format);
            zQuery.AddNumericBox("Stitch Skip Index", CardMakerSettings.ExportStitchSkipIndex, 0, 65535, 1, 0, ExportOptionKey.StitchSkipIndex);
            zQuery.AddTextBox("File Name Format (optional)", sDefinition ?? string.Empty, false, ExportOptionKey.NameFormat);
            zQuery.AddFolderBrowseBox("Output Folder",
                Directory.Exists(ProjectManager.Instance.LoadedProject.lastExportPath) ? ProjectManager.Instance.LoadedProject.lastExportPath : string.Empty,
                ExportOptionKey.Folder);

            zQuery.UpdateEnableStates();

            if (DialogResult.OK != zQuery.ShowDialog(CardMakerInstance.ApplicationForm))
            {
                return null;
            }
            var sFolder = zQuery.GetString(ExportOptionKey.Folder);
            SetupExportFolder(sFolder);

            if (!Directory.Exists(sFolder))
            {
                FormUtils.ShowErrorMessage("The folder specified does not exist!");
                return null;
            }

            ProjectManager.Instance.LoadedProject.lastExportPath = sFolder;
            var nLayoutIndex = ProjectManager.Instance.GetLayoutIndex(LayoutManager.Instance.ActiveLayout);
            if (-1 == nLayoutIndex)
            {
                FormUtils.ShowErrorMessage("Unable to determine the current layout. Please select a layout in the tree view and try again.");
                return null;
            }

            CardMakerSettings.IniManager.SetValue(IniSettings.LastImageExportFormat, s_arrayAllowedFormatNames[zQuery.GetIndex(ExportOptionKey.Format)]);
            CardMakerSettings.ExportStitchSkipIndex = (int)zQuery.GetDecimal(ExportOptionKey.StitchSkipIndex);

            return new FileCardExporter(nLayoutIndex, nLayoutIndex + 1, sFolder, zQuery.GetString(ExportOptionKey.NameFormat),
                CardMakerSettings.ExportStitchSkipIndex, s_arrayAllowedFormats[zQuery.GetIndex(ExportOptionKey.Format)]);
        }
        private static FileCardExporter BuildProjectExporter()
        {
            var zQuery = new QueryPanelDialog("Export to Images", 750, false);
            zQuery.SetIcon(Properties.Resources.CardMakerIcon);

            var sDefinition = ProjectManager.Instance.LoadedProject.exportNameFormat; // default to the project level definition
            var nDefaultFormatIndex = GetLastFormatIndex();

            zQuery.AddPullDownBox("Format", s_arrayAllowedFormatNames, nDefaultFormatIndex, ExportOptionKey.Format);
            zQuery.AddCheckBox("Override Layout File Name Formats", false, ExportOptionKey.NameFormatOverride);
            zQuery.AddNumericBox("Stitch Skip Index", CardMakerSettings.ExportStitchSkipIndex, 0, 65535, 1, 0, ExportOptionKey.StitchSkipIndex);
            zQuery.AddTextBox("File Name Format (optional)", sDefinition ?? string.Empty, false, ExportOptionKey.NameFormat);
                // associated check box and the file format override text box
            zQuery.AddEnableControl(ExportOptionKey.NameFormatOverride, ExportOptionKey.NameFormat);
            zQuery.AddFolderBrowseBox("Output Folder",
                Directory.Exists(ProjectManager.Instance.LoadedProject.lastExportPath) ? ProjectManager.Instance.LoadedProject.lastExportPath : string.Empty,
                ExportOptionKey.Folder);
            zQuery.UpdateEnableStates();

            if (DialogResult.OK != zQuery.ShowDialog(CardMakerInstance.ApplicationForm))
            {
                return null;
            }
            var sFolder = zQuery.GetString(ExportOptionKey.Folder);
            SetupExportFolder(sFolder);

            if (!Directory.Exists(sFolder))
            {
                FormUtils.ShowErrorMessage("The folder specified does not exist!");
                return null;
            }

            ProjectManager.Instance.LoadedProject.lastExportPath = sFolder;
            var nStartLayoutIdx = 0;
            var nEndLayoutIdx = ProjectManager.Instance.LoadedProject.Layout.Length;
            var bOverrideLayout = false;
            bOverrideLayout = zQuery.GetBool(ExportOptionKey.NameFormatOverride);

            CardMakerSettings.IniManager.SetValue(IniSettings.LastImageExportFormat, s_arrayAllowedFormatNames[zQuery.GetIndex(ExportOptionKey.Format)]);
            CardMakerSettings.ExportStitchSkipIndex = (int)zQuery.GetDecimal(ExportOptionKey.StitchSkipIndex);

            return new FileCardExporter(nStartLayoutIdx, nEndLayoutIdx, sFolder, bOverrideLayout ? zQuery.GetString(ExportOptionKey.NameFormat) : null,
                CardMakerSettings.ExportStitchSkipIndex, s_arrayAllowedFormats[zQuery.GetIndex(ExportOptionKey.Format)]);
        }