protected override void Dispose(bool disposing) { if (CustomColors?.Length > 0) { var doc = new XElement("CustomColors"); foreach (int color in CustomColors) { if (!BasicColors.IsKnown(color)) { var hex = color.ToString("X6"); if (hex.Length > 6) { hex = hex.Substring(hex.Length - 6); } doc.Add(new XElement("color", "#" + hex)); } } var path = PathFactory.GetAppDataPath(); if (PathFactory.EnsurePathExists(path)) { path = Path.Combine(path, Properties.Resources.CustomColorsFilesname); doc.Save(path, SaveOptions.None); } } base.Dispose(disposing); }
public void SaveStyles(List <CustomStyle> styles) { var all = new XElement("Styles"); foreach (var style in styles) { all.Add(MakeElement(style)); } root = new XElement(new XElement("CustomStyles", all)); string path = PathFactory.GetAppDataPath(); PathFactory.EnsurePathExists(path); Save(root, Path.Combine(path, Resx.CustomStylesFilename)); }
private static void Save(IEnumerable <StyleRecord> styles, string path = null) { if (path == null) { path = Path.Combine(PathFactory.GetAppDataPath(), Properties.Resources.CustomStylesFilename); } PathFactory.EnsurePathExists(Path.GetDirectoryName(path)); var root = new XElement("CustomStyles"); foreach (var style in styles) { root.Add(style.ToXElement()); } root.Save(path, SaveOptions.None); }
public void SaveFavorites(XElement root) { try { PathFactory.EnsurePathExists(PathFactory.GetAppDataPath()); root.Save(path, SaveOptions.None); if (ribbon != null) { ribbon.InvalidateControl("ribFavoritesMenu"); } } catch (Exception exc) { logger.WriteLine($"cannot save {path}"); logger.WriteLine(exc); } }
public void RemoveFavorite(string favoriteId) { if (File.Exists(path)) { var root = XElement.Load(path, LoadOptions.None); var element = (from e in root.Elements(ns + "splitButton") where e.Attribute("id").Value == favoriteId select e).FirstOrDefault(); if (element != null) { var label = element.Element(ns + "button")?.Attribute("label").Value; var result = MessageBox.Show( $"Remove {label}?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2, MessageBoxOptions.DefaultDesktopOnly ); if (result == DialogResult.Yes) { element.Remove(); try { PathFactory.EnsurePathExists(PathFactory.GetAppDataPath()); root.Save(path, SaveOptions.None); ribbon.InvalidateControl("ribFavoritesMenu"); } catch (Exception exc) { logger.WriteLine($"Cannot save {path}"); logger.WriteLine(exc); } } } } }
public void SaveStyle(CustomStyle style) { var candidate = (from e in root.Elements(ns + "Styles").Elements(ns + "Style") where e.Attribute("name").Value.Equals(style.Name) select e).FirstOrDefault(); if (candidate != null) { candidate.ReplaceWith(MakeElement(style)); } else { root.Element(ns + "Styles")?.Add(MakeElement(style)); } string path = PathFactory.GetAppDataPath(); PathFactory.EnsurePathExists(path); Save(root, Path.Combine(path, Resx.CustomStylesFilename)); }
public void AddFavorite() { XElement root; if (File.Exists(path)) { root = XElement.Load(path, LoadOptions.None); } else { root = MakeMenuRoot(); } using (var one = new OneNote()) { var info = one.GetPageInfo(); var name = EmojiDialog.RemoveEmojis(info.Name); if (name.Length > 50) { name = name.Substring(0, 50) + "..."; } // similar to mongo ObjectId, a random-enough identifier for our needs var id = ((DateTimeOffset.Now.ToUnixTimeSeconds() << 32) + new Random().Next()).ToString("x"); root.Add(new XElement(ns + "splitButton", new XAttribute("id", $"omFavorite{id}"), new XElement(ns + "button", new XAttribute("id", $"omFavoriteLink{id}"), new XAttribute("onAction", "NavigateToFavorite"), new XAttribute("imageMso", "FileLinksToFiles"), new XAttribute("label", name), new XAttribute("tag", info.Link), new XAttribute("screentip", info.Path) ), new XElement(ns + "menu", new XAttribute("id", $"omFavoriteMenu{id}"), new XElement(ns + "button", new XAttribute("id", $"omFavoriteRemoveButton{id}"), new XAttribute("onAction", "RemoveFavorite"), new XAttribute("label", "Remove this item"), new XAttribute("imageMso", "HyperlinkRemove"), new XAttribute("tag", $"omFavorite{id}") ) ) )); // sort by name/label var items = from e in root.Elements(ns + "splitButton") let key = e.Element(ns + "button").Attribute("label").Value orderby key select e; root = MakeMenuRoot(); foreach (var item in items) { root.Add(item); } logger.WriteLine($"Saving favorite '{info.Path}' ({info.Link})"); } try { PathFactory.EnsurePathExists(PathFactory.GetAppDataPath()); root.Save(path, SaveOptions.None); ribbon.InvalidateControl("ribFavoritesMenu"); } catch (Exception exc) { logger.WriteLine($"Cannot save {path}"); logger.WriteLine(exc); } }
public void Save() { PathFactory.EnsurePathExists(Path.GetDirectoryName(path)); root.Save(path, SaveOptions.None); }