Ejemplo n.º 1
0
        private void addCardLayoutFromTemplateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            const string TEMPLATE          = "template";
            const string NAME              = "name";
            const string COUNT             = "count";
            var          listTemplateNames = new List <string>();

            LayoutTemplateManager.Instance.LayoutTemplates.ForEach(x => listTemplateNames.Add(x.ToString()));

            var zQuery = new QueryPanelDialog("Select Layout Template", 600, false);

            zQuery.SetIcon(Resources.CardMakerIcon);
            zQuery.AddTextBox("New Layout Name", "New Layout", false, NAME);
            zQuery.AddNumericBox("Number to create", 1, 1, 256, COUNT);
            var zTxtFilter        = zQuery.AddTextBox("Template Filter", string.Empty, false, TEMPLATE + NAME);
            var zListBoxTemplates = zQuery.AddListBox("Template", listTemplateNames.ToArray(), null, false, 240, TEMPLATE);

            zListBoxTemplates.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Left;
            zTxtFilter.TextChanged  += (o, args) =>
            {
                var txtBox = (TextBox)o;
                zListBoxTemplates.Items.Clear();
                if (string.IsNullOrWhiteSpace(txtBox.Text))
                {
                    listTemplateNames.ForEach(zTemplate => zListBoxTemplates.Items.Add(zTemplate));
                }
                else
                {
                    listTemplateNames.Where(sTemplateName => sTemplateName.ToLower().Contains(txtBox.Text.ToLower())).ToList().ForEach(zTemplate => zListBoxTemplates.Items.Add(zTemplate));
                }
            };

            zQuery.AllowResize();
            while (DialogResult.OK == zQuery.ShowDialog(this))
            {
                var nSelectedIndex = listTemplateNames.IndexOf(zQuery.GetString(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);
                    ProjectManager.Instance.AddLayout(zLayout);
                }
                break;
            }
        }
Ejemplo n.º 2
0
        private void importLayoutsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var ofd = new OpenFileDialog
            {
                Filter          = m_sFileOpenFilter,
                CheckFileExists = true
            };

            if (DialogResult.OK != ofd.ShowDialog(this))
            {
                return;
            }

            Project zProject = null;

            try
            {
                zProject = ProjectManager.LoadProject(ofd.FileName);
            }
            catch (Exception ex)
            {
                Logger.AddLogLine("Error Loading Project File: " + ex.Message);
            }

            if (null == zProject)
            {
                return;
            }

            var          zQuery           = new QueryPanelDialog("Select Layouts To Import", 500, false);
            const string LAYOUT_QUERY_KEY = "layoutquerykey";

            zQuery.AddListBox("Layouts", zProject.Layout.ToList().Select(projectLayout => projectLayout.Name).ToArray(), null, true, 400, LAYOUT_QUERY_KEY);
            if (DialogResult.OK == zQuery.ShowDialog(this))
            {
                var listIndices = zQuery.GetIndices(LAYOUT_QUERY_KEY).ToList();
                listIndices.ForEach(nIdx =>
                {
                    ProjectManager.Instance.AddLayout(zProject.Layout[nIdx]);
                });
            }
        }
Ejemplo n.º 3
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;
            }
        }
Ejemplo n.º 4
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);
                    ProjectManager.Instance.AddLayout(zLayout);
                }
                break;
            }
        }
Ejemplo n.º 5
0
        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);
            }
        }