예제 #1
0
        private void PopulateTemplateList()
        {
            TemplateComboBoxItem selectedTemplateItem = comboBoxTemplates.SelectedItem as TemplateComboBoxItem;

            comboBoxTemplates.Items.Clear();

            IEnumerable <string> files = System.IO.Directory.EnumerateFiles(PreviewTools.TemplateFolder, "*.xml");

            foreach (string file in files)
            {
                string fileName = PreviewTools.TemplateWithFolder(file);
                try {
                    // Read the entire template file (stoopid waste of resources, but how else?)
                    string               xml             = System.IO.File.ReadAllText(fileName);
                    DisplayItem          newDisplayItem  = (DisplayItem)PreviewTools.DeSerializeToDisplayItem(xml, typeof(DisplayItem));
                    TemplateComboBoxItem newTemplateItem = new TemplateComboBoxItem(newDisplayItem.Shape.Name, fileName);
                    comboBoxTemplates.Items.Add(newTemplateItem);
                }
                catch (Exception ex) {
                    MessageBox.Show("There was an error loading the template file (" + file + "): " + ex.Message,
                                    "Error Loading Template", MessageBoxButtons.OKCancel);
                }
                finally {
                    if (selectedTemplateItem != null && comboBoxTemplates.Items.IndexOf(selectedTemplateItem) >= 0)
                    {
                        comboBoxTemplates.SelectedItem = selectedTemplateItem;
                    }
                    if (comboBoxTemplates.SelectedItem == null && comboBoxTemplates.Items.Count > 0)
                    {
                        comboBoxTemplates.SelectedIndex = 0;
                    }
                }
            }
        }
예제 #2
0
        public void GroupItems()
        {
            DisplayItem newDisplayItem;

            newDisplayItem       = new DisplayItem();
            newDisplayItem.Shape = new PreviewCustom(new PreviewPoint(100, 100), SelectedShapes());
            AddDisplayItem(newDisplayItem);
            Console.Write("Grouped");
            foreach (DisplayItem item in SelectedDisplayItems)
            {
                DisplayItems.Remove(item);
            }

            _selectedDisplayItem = newDisplayItem;
            if (_selectedDisplayItem != null)
            {
                PreviewCustomCreateForm f = new PreviewCustomCreateForm();
                if (f.ShowDialog() == DialogResult.OK)
                {
                    _selectedDisplayItem.Shape.Name = f.TemplateName;
                    _selectedDisplayItem.Shape.Select(true);

                    string xml          = PreviewTools.SerializeToString(_selectedDisplayItem);
                    string destFileName = PreviewTools.TemplateWithFolder(f.TemplateName + ".xml");
                    System.IO.File.WriteAllText(destFileName, xml);

                    OnSelectDisplayItem(this, _selectedDisplayItem);
                }
            }
        }
예제 #3
0
        private void PopulateTemplateList()
        {
            TemplateComboBoxItem selectedTemplateItem = comboBoxTemplates.SelectedItem as TemplateComboBoxItem;

            comboBoxTemplates.Items.Clear();

            IEnumerable <string> files = System.IO.Directory.EnumerateFiles(PreviewTools.TemplateFolder, "*.xml");

            foreach (string file in files)
            {
                string fileName = PreviewTools.TemplateWithFolder(file);
                try
                {
                    // Read the entire template file (stoopid waste of resources, but how else?)
                    string               xml             = System.IO.File.ReadAllText(fileName);
                    DisplayItem          newDisplayItem  = PreviewTools.DeSerializeToDisplayItem(xml, typeof(DisplayItem));
                    TemplateComboBoxItem newTemplateItem = new TemplateComboBoxItem(newDisplayItem.Shape.Name, fileName);
                    comboBoxTemplates.Items.Add(newTemplateItem);
                }
                catch (Exception ex)
                {
                    //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
                    MessageBoxForm.msgIcon = SystemIcons.Error;                     //this is used if you want to add a system icon to the message form.
                    var messageBox = new MessageBoxForm("There was an error loading the template file (" + file + "): " + ex.Message,
                                                        "Error Loading Template", false, true);
                    messageBox.ShowDialog();
                }
                finally
                {
                    if (selectedTemplateItem != null && comboBoxTemplates.Items.IndexOf(selectedTemplateItem) >= 0)
                    {
                        comboBoxTemplates.SelectedItem = selectedTemplateItem;
                    }
                    if (comboBoxTemplates.SelectedItem == null && comboBoxTemplates.Items.Count > 0)
                    {
                        comboBoxTemplates.SelectedIndex = 0;
                    }
                }
            }
        }