Example #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.DeSerializeToObject(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;
                    }
                }
            }
        }
Example #2
0
 public void AddTtemplateToPreview(string fileName)
 {
     if (System.IO.File.Exists(fileName))
     {
         // Read the entire template file (stoopid waste of resources, but how else?)
         string      xml            = System.IO.File.ReadAllText(fileName);
         DisplayItem newDisplayItem = PreviewTools.DeSerializeToObject(xml, typeof(DisplayItem));
         if (newDisplayItem != null)
         {
             DeSelectSelectedDisplayItem();
             AddDisplayItem(newDisplayItem);
             _selectedDisplayItem = newDisplayItem;
             OnSelectDisplayItem(this, _selectedDisplayItem);
             _selectedDisplayItem.Shape.MoveTo(10, 10);
             _selectedDisplayItem.Shape.Select(true);
             _selectedDisplayItem.Shape.SetSelectPoint(null);
         }
     }
 }
Example #3
0
        public bool Paste()
        {
            string      xml            = Clipboard.GetText();
            DisplayItem newDisplayItem = (DisplayItem)PreviewTools.DeSerializeToObject(xml, typeof(DisplayItem));

            if (newDisplayItem != null)
            {
                DeSelectSelectedDisplayItem();
                Console.WriteLine("Pasted: " + newDisplayItem.Shape.GetType().ToString());
                AddDisplayItem(newDisplayItem);
                _selectedDisplayItem = newDisplayItem;
                _selectedDisplayItem.Shape.Select(true);
                _selectedDisplayItem.Shape.SetSelectPoint(null);
                OnSelectDisplayItem(this, _selectedDisplayItem);
                return(true);
            }
            else
            {
                return(false);
            }
        }