private void pasteToolStripMenuItem_Click(object sender, EventArgs e) { if (0 < m_listClipboardElements.Count) { Dictionary <string, ProjectLayoutElement> dictionaryExistingElements = null; if (null != LayoutManager.Instance.ActiveLayout.Element) { dictionaryExistingElements = LayoutManager.Instance.ActiveLayout.Element.ToDictionary(x => x.name); } if (dictionaryExistingElements != null) { if (m_listClipboardElements.Exists( zElement => dictionaryExistingElements.ContainsKey(zElement.name))) { const string ELEMENT_NAMES = "ELEMENT_NAMES"; var zQuery = new QueryPanelDialog("Duplicate Elements Rename", 400, false); zQuery.SetIcon(Properties.Resources.CardMakerIcon); zQuery.AddLabel("Each line has the name of an element to be pasted.", 24); zQuery.AddLabel("Duplicated element names are marked with *", 24); zQuery.AddMultiLineTextBox("Element Name(s)", string.Join(Environment.NewLine, m_listClipboardElements.Select(zElement => { return(zElement.name + (dictionaryExistingElements.ContainsKey(zElement.name) ? "*" : "")); }).ToList()), 200, ELEMENT_NAMES); if (DialogResult.OK == zQuery.ShowDialog(this)) { var arrayNames = zQuery.GetString(ELEMENT_NAMES) .Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); if (arrayNames.Length != m_listClipboardElements.Count) { MessageBox.Show(zQuery.Form, "The number of elements names does not match the clipboard. Cancelling paste.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } for (var nIdx = 0; nIdx < m_listClipboardElements.Count; nIdx++) { AddElements(new string[] { arrayNames [nIdx] }, m_listClipboardElements[nIdx]); } } return; } } m_listClipboardElements.ForEach(x => AddElements(new string[] { x.name }, x)); } }
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); } } } }
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]); } } }
private void removeLayoutTemplatesToolStripMenuItem_Click(object sender, EventArgs e) { const string TEMPLATE = "template"; var listItems = new List <string>(); LayoutTemplateManager.Instance.LayoutTemplates.ForEach(x => listItems.Add(x.ToString())); var zQuery = new QueryPanelDialog("Remove Layout Templates", 450, false); zQuery.SetIcon(Properties.Resources.CardMakerIcon); zQuery.AddLabel("Select the templates to remove.", 20); zQuery.AddListBox("Templates", listItems.ToArray(), null, true, 240, TEMPLATE) .Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; zQuery.AllowResize(); if (DialogResult.OK == zQuery.ShowDialog(this)) { var arrayRemove = zQuery.GetIndices(TEMPLATE); if (0 == arrayRemove.Length) { return; } var trimmedList = new List <LayoutTemplate>(); int removalIdx = 0; List <LayoutTemplate> listOldTemplates = LayoutTemplateManager.Instance.LayoutTemplates; for (int nIdx = 0; nIdx < listOldTemplates.Count; nIdx++) { if (removalIdx < arrayRemove.Length && nIdx == arrayRemove[removalIdx]) { removalIdx++; // delete failures are logged LayoutTemplateManager.Instance.DeleteLayoutTemplate(CardMakerInstance.StartupPath, listOldTemplates[nIdx]); } else { trimmedList.Add(listOldTemplates[nIdx]); } } LayoutTemplateManager.Instance.LayoutTemplates = trimmedList; } }
private void pasteSettingsToolStripMenuItem_Click(object sender, EventArgs e) { if (1 != m_listClipboardElements.Count) { return; } var zSourceElement = m_listClipboardElements[0]; var zQuery = new QueryPanelDialog("Apply Element Settings", 400, false); zQuery.SetIcon(CardMakerInstance.ApplicationIcon); const string SETTINGS_TO_COPY = "settings_to_copy"; // TODO: if this ever expands to more fields just use a dictionary.contains var listProperties = ProjectLayoutElement.SortedPropertyInfos.Where(x => !x.Name.Equals("name")).ToList(); zQuery.AddLabel("Select the settings to apply to the selected Elements.", 40); zQuery.AddListBox("Settings to apply", listProperties.Select(x => x.Name).ToArray(), null, true, 400, SETTINGS_TO_COPY); if (DialogResult.OK == zQuery.ShowDialog(this)) { var dictionaryNewElementValues = new Dictionary <PropertyInfo, object>(); var dictionaryOldElementsValues = new Dictionary <ProjectLayoutElement, Dictionary <PropertyInfo, object> >(); // construct the set of values from the source element foreach (var nIdx in zQuery.GetIndices(SETTINGS_TO_COPY)) { dictionaryNewElementValues.Add(listProperties[nIdx], listProperties[nIdx].GetValue(zSourceElement, null)); } // construct the set of values from the destination element(s) foreach (var zElement in ElementManager.Instance.SelectedElements) { var dictionaryOldValues = new Dictionary <PropertyInfo, object>(); dictionaryOldElementsValues.Add(zElement, dictionaryOldValues); foreach (var zEntry in dictionaryNewElementValues) { dictionaryOldValues.Add(zEntry.Key, zEntry.Key.GetValue(zElement, null)); } } UserAction.PushAction(bRedo => { CardMakerInstance.ProcessingUserAction = true; foreach (var zElementToValue in dictionaryOldElementsValues) { foreach (var zEntry in zElementToValue.Value) { // pull the value from the old element dictionary or the source element var zValue = bRedo ? dictionaryNewElementValues[zEntry.Key] : zEntry.Value; zEntry.Key.SetValue(zElementToValue.Key, zValue, null); } // re-init any translated string values (colors/fonts) // TODO: consider using an event for this kind of thing... zElementToValue.Key.InitializeTranslatedFields(); } CardMakerInstance.ProcessingUserAction = false; // clear the deck cache so element translations are re-processed LayoutManager.Instance.ActiveDeck.ResetDeckCache(); // trigger a re-select (this will cause the element window to update) listViewElements_SelectedIndexChanged(null, null); LayoutManager.Instance.FireLayoutUpdatedEvent(true); }, true); } }
/// <summary> /// Displays the adjust layout dialog (for scaling primarily) /// </summary> /// <param name="bCreateNew">Flag indicating that a copy of the specified layout should be created.</param> /// <param name="zLayout">The base layout to adjust or duplicate</param> public static void ShowAdjustLayoutSettingsDialog(bool bCreateNew, ProjectLayout zLayout, Form zParentForm) { var zQuery = new QueryPanelDialog(bCreateNew ? "Duplicate Layout (Custom)" : "Resize Layout", 450, false); zQuery.SetIcon(CardMakerInstance.ApplicationIcon); const string LAYOUT_NAME = "layoutName"; const string RESIZE_ADJUST_DIMENSIONS = "Dimensions"; const string RESIZE_ADJUST_SCALE = "Scale"; const string RESIZE_ADJUST_DPI = "DPI"; const string RESIZE_ADJUST = "resizeAdjust"; const string ELEMENTS_ADJUST_NOTHING = "Nothing"; const string ELEMENTS_ADJUST_SCALE = "Scale"; const string ELEMENTS_ADJUST_CENTER = "Center"; const string ELEMENTS_ADJUST = "elementAdjust"; const string DPI = "dpi"; const string SCALE = "scale"; const string WIDTH = "width"; const string HEIGHT = "height"; var listMeasureUnits = new List <string>(); listMeasureUnits.AddRange(Enum.GetNames(typeof(MeasurementUnit))); listMeasureUnits.Add(MeasurementUtil.PIXEL); if (bCreateNew) { zQuery.AddTextBox("Layout Name", zLayout.Name + " copy", false, LAYOUT_NAME); } // intentionall start the index as non-zero var comboResizeType = zQuery.AddPullDownBox("Resize Type", new string[] { RESIZE_ADJUST_DIMENSIONS, RESIZE_ADJUST_SCALE, RESIZE_ADJUST_DPI }, 0, RESIZE_ADJUST); zQuery.AddLabel("Note: The DPI is only adjusted if DPI Resize Type is used.", 18); zQuery.AddVerticalSpace(10); var comboUnitMeasure = zQuery.AddPullDownBox("Unit of Measure", listMeasureUnits.ToArray(), (int)CardMakerSettings.PrintPageMeasurementUnit, IniSettings.PrintPageMeasurementUnit); // beware of the minimums as things like measurements definitely can be very small (<1) var numericWidth = zQuery.AddNumericBox("Width", 1, 0.001m, int.MaxValue, 1, 3, WIDTH); var numericHeight = zQuery.AddNumericBox("Height", 1, 0.001m, int.MaxValue, 1, 3, HEIGHT); var numericDPI = zQuery.AddNumericBox("Export DPI (Scales)", zLayout.dpi, 100, int.MaxValue, DPI); var numericScale = zQuery.AddNumericBox("Scale", 1, 0.01m, int.MaxValue, 0.01m, 3, SCALE); EventHandler zComboUnitMeasureAction = (sender, args) => { decimal dWidth, dHeight; MeasurementUtil.GetMeasurement(zLayout.width, zLayout.height, zLayout.dpi, comboUnitMeasure.Text, out dWidth, out dHeight); numericWidth.Value = dWidth; numericHeight.Value = dHeight; }; comboUnitMeasure.SelectedIndexChanged += zComboUnitMeasureAction; zComboUnitMeasureAction.Invoke(null, null); EventHandler zComboResizeTypeAction = (sender, args) => { switch (comboResizeType.Text) { case RESIZE_ADJUST_DIMENSIONS: comboUnitMeasure.Enabled = numericWidth.Enabled = numericHeight.Enabled = true; numericDPI.Enabled = numericScale.Enabled = false; break; case RESIZE_ADJUST_SCALE: comboUnitMeasure.SelectedIndex = listMeasureUnits.Count - 1; // pixel index numericScale.Enabled = true; comboUnitMeasure.Enabled = numericDPI.Enabled = numericWidth.Enabled = numericHeight.Enabled = false; break; case RESIZE_ADJUST_DPI: comboUnitMeasure.SelectedIndex = listMeasureUnits.Count - 1; // pixel index numericDPI.Enabled = true; comboUnitMeasure.Enabled = numericScale.Enabled = numericWidth.Enabled = numericHeight.Enabled = false; break; } }; comboResizeType.SelectedIndexChanged += zComboResizeTypeAction; zComboResizeTypeAction.Invoke(null, null); numericScale.ValueChanged += (sender, e) => { var dScale = numericScale.Value / 1m; numericWidth.Value = (int)Math.Max(numericWidth.Minimum, ((decimal)zLayout.width * dScale)); numericHeight.Value = (int)Math.Max(numericHeight.Minimum, ((decimal)zLayout.height * dScale)); // do not adjust the DPI in any mode but the DPI mode //numericDPI.Value = (int) Math.Max(numericDPI.Minimum, ((decimal) zLayout.dpi * dScale)); }; numericDPI.ValueChanged += (sender, e) => { var dScale = (decimal)numericDPI.Value / (decimal)zLayout.dpi; numericWidth.Value = (int)Math.Max(numericWidth.Minimum, ((decimal)zLayout.width * dScale)); numericHeight.Value = (int)Math.Max(numericHeight.Minimum, ((decimal)zLayout.height * dScale)); numericScale.Value = Math.Max(numericScale.Minimum, (1m * dScale)); }; zQuery.AddVerticalSpace(10); zQuery.AddPullDownBox("Element Adjustment", new string[] { ELEMENTS_ADJUST_NOTHING, ELEMENTS_ADJUST_SCALE, ELEMENTS_ADJUST_CENTER }, 0, ELEMENTS_ADJUST); // remove the accept button so the enter key does not automatically accept/close the dialog zQuery.Form.AcceptButton = null; if (DialogResult.OK == zQuery.ShowDialog(zParentForm)) { var listUserActions = new List <Action <bool> >(); var zLayoutAdjusted = bCreateNew ? new ProjectLayout(zQuery.GetString(LAYOUT_NAME)) : zLayout; var nOriginalWidth = zLayout.width; var nOriginalHeight = zLayout.height; var nOriginalDPI = zLayout.dpi; if (bCreateNew) { zLayoutAdjusted.DeepCopy(zLayout); } int nNewWidth, nNewHeight; var nNewDPI = nOriginalDPI; switch (comboResizeType.Text) { case RESIZE_ADJUST_DIMENSIONS: MeasurementUtil.GetPixelMeasurement(zQuery.GetDecimal(WIDTH), zQuery.GetDecimal(HEIGHT), zLayout.dpi, comboUnitMeasure.Text, out nNewWidth, out nNewHeight); break; case RESIZE_ADJUST_DPI: nNewWidth = (int)zQuery.GetDecimal(WIDTH); nNewHeight = (int)zQuery.GetDecimal(HEIGHT); // this is the only path where the DPI actually changes nNewDPI = (int)zQuery.GetDecimal(DPI); break; default: nNewWidth = (int)zQuery.GetDecimal(WIDTH); nNewHeight = (int)zQuery.GetDecimal(HEIGHT); break; } zLayoutAdjusted.width = nNewWidth; zLayoutAdjusted.height = nNewHeight; zLayoutAdjusted.dpi = nNewDPI; // create the user action for adjusting the layout settings listUserActions.Add((performAction) => { if (performAction) { zLayoutAdjusted.width = nNewWidth; zLayoutAdjusted.height = nNewHeight; zLayoutAdjusted.dpi = nNewDPI; } else { zLayoutAdjusted.width = nOriginalWidth; zLayoutAdjusted.height = nOriginalHeight; zLayoutAdjusted.dpi = nOriginalDPI; } LayoutManager.Instance.FireLayoutUpdatedEvent(true); }); var bProcessedElementChange = false; // create the user action for adjusting the elements if (zLayout.Element != null) { switch (zQuery.GetString(ELEMENTS_ADJUST)) { case ELEMENTS_ADJUST_CENTER: var nXAdjust = (int)(zLayoutAdjusted.width / 2) - (int)(nOriginalWidth / 2); var nYAdjust = (int)(zLayoutAdjusted.height / 2) - (int)(nOriginalHeight / 2); ElementManager.ProcessElementsChange(zLayoutAdjusted.Element, nXAdjust, nYAdjust, 0, 0, 1, 1, true, listUserActions); bProcessedElementChange = true; break; case ELEMENTS_ADJUST_SCALE: var dHorizontalScale = (decimal)zLayoutAdjusted.width / (decimal)nOriginalWidth; var dVerticalScale = (decimal)zLayoutAdjusted.height / (decimal)nOriginalHeight; ElementManager.ProcessElementsChange(zLayoutAdjusted.Element, 0, 0, 0, 0, dHorizontalScale, dVerticalScale, true, listUserActions); bProcessedElementChange = true; break; } } if (!bProcessedElementChange) { UserAction.PushActions(listUserActions); } if (bCreateNew) { ProjectManager.Instance.AddLayout(zLayoutAdjusted); } else { LayoutManager.Instance.FireLayoutUpdatedEvent(true); } } }