Ejemplo n.º 1
0
        public void NewCategory(object o, EventArgs e)
        {
            SnippetCategory s = new SnippetCategory();

            s.Name = "New Category";
            SnippetCategories.Add(s);
        }
Ejemplo n.º 2
0
 public Snippet(string name, string shortcut, string text, SnippetCategory category)
 {
     Name     = name;
     Shortcut = shortcut;
     Text     = text;
     Category = category;
 }
Ejemplo n.º 3
0
        public void DoGridDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.Text))
            {
                // create a new category
                SnippetCategory sc = new SnippetCategory();
                sc.Name = "New Category";
                SnippetCategories.Add(sc);

                string Text = (string)e.Data.GetData(DataFormats.Text);
                sc.AddSnippet("New Snippet", "", Text);

                TabItem ti = (TabItem)SnippetCategoriesTabControl.ItemContainerGenerator.ContainerFromItem(sc);
                if (ti != null)
                {
                    ti.IsSelected = true;
                }

                // write the xaml file
                WriteValues();

                // don't allow drops here anymore
                MainGrid.AllowDrop = false;
                MainGrid.Drop     -= new DragEventHandler(DoGridDrop);
            }
        }
Ejemplo n.º 4
0
 public Snippet(string name, string shortcut, string text, SnippetCategory category)
 {
     Name = name;
     Shortcut = shortcut;
     Text = text;
     Category = category;
 }
Ejemplo n.º 5
0
        public void ReadValues()
        {
            SnippetCategories = new ObservableCollection <SnippetCategory>();

            XmlDocument xml = new XmlDocument();

            try
            {
                xml.Load(_SnippetsFullPath);
            }
            catch (System.IO.FileNotFoundException)
            {
                return;
            }

            XmlNode root = xml.DocumentElement;

            foreach (XmlNode CategoryNode in root.ChildNodes)
            {
                if (CategoryNode.Name == "Category")
                {
                    // look for a matching categor
                    SnippetCategory c = null;

                    foreach (SnippetCategory sc in SnippetCategories)
                    {
                        if (sc.Name.CompareTo(CategoryNode.Attributes["Name"].Value) == 0)
                        {
                            c = sc;
                        }
                    }

                    if (c == null)
                    {
                        c      = new SnippetCategory();
                        c.Name = CategoryNode.Attributes["Name"].Value;
                        SnippetCategories.Add(c);
                    }

                    foreach (XmlNode SnippetNode in CategoryNode.ChildNodes)
                    {
                        string name     = "";
                        string shortcut = "";

                        if (SnippetNode.Attributes["Name"] != null)
                        {
                            name = SnippetNode.Attributes["Name"].Value;
                        }
                        if (SnippetNode.Attributes["Shortcut"] != null)
                        {
                            shortcut = SnippetNode.Attributes["Shortcut"].Value;
                        }

                        c.AddSnippet(name, shortcut, SnippetNode.InnerText);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void DeleteSnippet(object o, EventArgs e)
        {
            ContextMenu     cm  = (ContextMenu)ItemsControl.ItemsControlFromItemContainer(o as MenuItem);
            ListBoxItem     lbi = (ListBoxItem)cm.PlacementTarget;
            Snippet         s   = (Snippet)lbi.DataContext;
            SnippetCategory c   = s.Category;

            c.Snippets.Remove(s);
            WriteValues();
        }
Ejemplo n.º 7
0
        public void DeleteCategory(object o, EventArgs e)
        {
            ContextMenu     cm = (ContextMenu)ItemsControl.ItemsControlFromItemContainer(o as MenuItem);
            TabItem         t  = (TabItem)cm.PlacementTarget;
            SnippetCategory s  = (SnippetCategory)t.DataContext;

            if (MessageBox.Show("Are you sure you want to delete the category " + s.Name + " and all associated snippets?", "Delete Category?", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                SnippetCategories.Remove(s);
                WriteValues();
            }
        }
Ejemplo n.º 8
0
        public void MoveCategoryUp(object o, EventArgs e)
        {
            ContextMenu     cm = (ContextMenu)ItemsControl.ItemsControlFromItemContainer(o as MenuItem);
            TabItem         t  = (TabItem)cm.PlacementTarget;
            SnippetCategory s  = (SnippetCategory)t.DataContext;

            int index = SnippetCategories.IndexOf(s);

            if (index > 0)
            {
                SnippetCategories.Move(index, index - 1);
            }
        }
Ejemplo n.º 9
0
        public void DoCategoryHidden(object o, TextBoxOverlayHideEventArgs e)
        {
            TabItem         ti = (TabItem)o;
            SnippetCategory c  = (SnippetCategory)ti.DataContext;

            if (e.Result == TextBoxOverlayResult.Accept)
            {
                c.Name = e.ResultText;
                WriteValues();
            }

            _TextBoxOverlay.Hidden -= CategoryHidden;
        }
Ejemplo n.º 10
0
        private void MoveSnippetUp(object o, EventArgs e)
        {
            ContextMenu     cm  = (ContextMenu)ItemsControl.ItemsControlFromItemContainer(o as MenuItem);
            ListBoxItem     lbi = (ListBoxItem)cm.PlacementTarget;
            Snippet         s   = (Snippet)lbi.DataContext;
            SnippetCategory c   = s.Category;

            int index = c.Snippets.IndexOf(s);

            if (index > 0)
            {
                c.Snippets.Move(index, index - 1);
            }

            WriteValues();
        }
Ejemplo n.º 11
0
        public void RenameCategory(object o, EventArgs e)
        {
            ContextMenu     cm = (ContextMenu)ItemsControl.ItemsControlFromItemContainer(o as MenuItem);
            TabItem         ti = (TabItem)cm.PlacementTarget;
            SnippetCategory c  = (SnippetCategory)ti.DataContext;

            if (CategoryHidden == null)
            {
                CategoryHidden = DoCategoryHidden;
            }
            _TextBoxOverlay.Hidden += CategoryHidden;

            _TextBoxOverlay.Hidden += DoCategoryHidden;
            _TextBoxOverlay.Show((ti as FrameworkElement), new Rect(new Point(14, 2), new Size(ti.ActualWidth - 20, 20)), c.Name);

            WriteValues();
        }
Ejemplo n.º 12
0
        public void DoDrop(object o, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(typeof(Snippet)))
            {
                SnippetCategory sc = (SnippetCategory)(o as FrameworkElement).DataContext;
                Snippet         s  = (Snippet)(e.Data.GetData(typeof(Snippet)));

                // make sure we're not dragging into the same category
                if (s.Category == sc)
                {
                    return;
                }

                // otherwise, consider this a move so remove from the previous category
                // and add to the new one

                // remove from old category
                s.Category.Snippets.Remove(s);

                // add to the new one
                sc.Snippets.Add(s);

                // update the category
                s.Category = sc;

                // save the changes
                WriteValues();
            }
            else if (e.Data.GetDataPresent(DataFormats.Text))
            {
                string          Text = (string)e.Data.GetData(DataFormats.Text);
                SnippetCategory sc   = (SnippetCategory)(o as FrameworkElement).DataContext;
                sc.AddSnippet("New Snippet", "", Text);

                // write the xaml file
                WriteValues();
            }

            // if the drop target is a TabItem, then expand it
            if (o.GetType() == typeof(TabItem))
            {
                TabItem ti = (TabItem)o;
                ti.IsSelected = true;
            }
        }
Ejemplo n.º 13
0
        public void ReadValues()
        {
            SnippetCategories = new ObservableCollection<SnippetCategory>();

            XmlDocument xml = new XmlDocument();

            try
            {
                xml.Load(_SnippetsFullPath);
            }
            catch (System.IO.FileNotFoundException)
            {
                return;
            }

            XmlNode root = xml.DocumentElement;

            foreach (XmlNode CategoryNode in root.ChildNodes)
            {
                if (CategoryNode.Name == "Category")
                {
                    // look for a matching categor
                    SnippetCategory c = null;

                    foreach (SnippetCategory sc in SnippetCategories)
                    {
                        if (sc.Name.CompareTo(CategoryNode.Attributes["Name"].Value) == 0) c = sc;
                    }

                    if (c == null)
                    {
                        c = new SnippetCategory();
                        c.Name = CategoryNode.Attributes["Name"].Value;
                        SnippetCategories.Add(c);
                    }

                    foreach (XmlNode SnippetNode in CategoryNode.ChildNodes)
                    {
                        string name = "";
                        string shortcut = "";

                        if (SnippetNode.Attributes["Name"] != null) name = SnippetNode.Attributes["Name"].Value;
                        if (SnippetNode.Attributes["Shortcut"] != null) shortcut = SnippetNode.Attributes["Shortcut"].Value;

                        c.AddSnippet(name, shortcut, SnippetNode.InnerText);
                    }
                }
            }
        }
Ejemplo n.º 14
0
 public void NewCategory(object o, EventArgs e)
 {
     SnippetCategory s = new SnippetCategory();
     s.Name = "New Category";
     SnippetCategories.Add(s);
 }
Ejemplo n.º 15
0
        public void DoGridDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.Text))
            {
                // create a new category
                SnippetCategory sc = new SnippetCategory();
                sc.Name = "New Category";
                SnippetCategories.Add(sc);

                string Text = (string)e.Data.GetData(DataFormats.Text);
                sc.AddSnippet("New Snippet", "", Text);

                TabItem ti = (TabItem)SnippetCategoriesTabControl.ItemContainerGenerator.ContainerFromItem(sc);
                if (ti != null) ti.IsSelected = true;

                // write the xaml file
                WriteValues();

                // don't allow drops here anymore
                MainGrid.AllowDrop = false;
                MainGrid.Drop -= new DragEventHandler(DoGridDrop);
            }
        }