コード例 #1
0
ファイル: MDILayoutControl.cs プロジェクト: nhmkdev/cardmaker
        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.InitializeCache();
                    }

                    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);
            }
        }
コード例 #2
0
ファイル: MDILayoutControl.cs プロジェクト: nhmkdev/cardmaker
        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]);
                }
            }
        }
コード例 #3
0
ファイル: MDILayoutControl.cs プロジェクト: nhmkdev/cardmaker
        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);
                    }
                }
            }
        }
コード例 #4
0
ファイル: CardMakerMDI.cs プロジェクト: ksuquix/cardmaker
        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, 120, TEMPLATE);
            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;
            }
        }