public void NewCategory(object o, EventArgs e) { SnippetCategory s = new SnippetCategory(); s.Name = "New Category"; SnippetCategories.Add(s); }
public Snippet(string name, string shortcut, string text, SnippetCategory category) { Name = name; Shortcut = shortcut; Text = text; Category = category; }
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); } }
public Snippet(string name, string shortcut, string text, SnippetCategory category) { Name = name; Shortcut = shortcut; Text = text; Category = category; }
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); } } } }
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(); }
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(); } }
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); } }
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; }
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(); }
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(); }
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; } }
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); } } } }
public void NewCategory(object o, EventArgs e) { SnippetCategory s = new SnippetCategory(); s.Name = "New Category"; SnippetCategories.Add(s); }
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); } }