public override void Execute(params object[] args) { var builder = new StringBuilder(); builder.AppendLine("Diagnostics.Execute()"); builder.AppendLine(new string('-', 80)); builder.AppendLine($"ONENOTE...: {Process.GetProcessesByName("ONENOTE")[0].MainModule.FileName}"); builder.AppendLine($"Addin path: {Assembly.GetExecutingAssembly().Location}"); builder.AppendLine($"Data path.: {PathFactory.GetAppDataPath()}"); builder.AppendLine($"Log path..: {logger.LogPath}"); builder.AppendLine(); using (var one = new OneNote()) { var(backupFolder, defaultFolder, unfiledFolder) = one.GetFolders(); builder.AppendLine($"Default path: {defaultFolder}"); builder.AppendLine($"Backup path: {backupFolder}"); builder.AppendLine($"Unfiled path: {unfiledFolder}"); builder.AppendLine(); var(Name, Path, Link) = one.GetPageInfo(); builder.AppendLine($"Page name: {Name}"); builder.AppendLine($"Page path: {Path}"); builder.AppendLine($"Page link: {Link}"); builder.AppendLine(); one.ReportWindowDiagnostics(builder); builder.AppendLine(); var page = one.GetPage(); var pageColor = page.GetPageColor(out _, out _); var pageBrightness = pageColor.GetBrightness(); builder.AppendLine($"Page background: {pageColor.ToRGBHtml()}"); builder.AppendLine($"Page brightness: {pageBrightness}"); builder.AppendLine($"Page is dark...: {pageBrightness < 0.5}"); (float dpiX, float dpiY) = UIHelper.GetDpiValues(); builder.AppendLine($"Screen DPI.....: horizontal/X:{dpiX} vertical/Y:{dpiY}"); (float scalingX, float scalingY) = UIHelper.GetScalingFactors(); builder.AppendLine($"Scaling factors: horizontal/X:{scalingX} vertical/Y:{scalingY}"); builder.AppendLine(new string('-', 80)); logger.WriteLine(builder.ToString()); UIHelper.ShowInfo($"Diagnostics written to {logger.LogPath}"); } }
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)); }
private void LoadTheme(object sender, EventArgs e) { using (var dialog = new OpenFileDialog()) { dialog.DefaultExt = "xml"; dialog.Filter = "Theme files (*.xml)|*.xml|All files (*.*)|*.*"; dialog.Multiselect = false; dialog.Title = "Open Style Theme"; dialog.ShowHelp = true; // stupid, but this is needed to avoid hang var path = PathFactory.GetAppDataPath(); if (Directory.Exists(path)) { dialog.InitialDirectory = path; } else { dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); } var result = dialog.ShowDialog(); if (result == DialogResult.OK) { var styles = new StyleProvider().LoadTheme(dialog.FileName); if (styles?.Count > 0) { LoadStyles(styles); } else { MessageBox.Show(this, "Could not load this theme file?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void LoadCustomColors() { var path = Path.Combine(PathFactory.GetAppDataPath(), Properties.Resources.CustomColorsFilesname); if (File.Exists(path)) { var doc = XElement.Load(path, LoadOptions.None); var ns = doc.GetDefaultNamespace(); var colors = doc.Elements(ns + "color").Select(e => e.Value); if (colors?.Count() > 0) { var list = new List <int>(); foreach (var color in colors) { list.Add(int.Parse(color[0] == '#' ? color.Substring(1) : color, NumberStyles.HexNumber)); } CustomColors = list.ToArray(); } } }
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); } }
/* * <menu xmlns="http://schemas.microsoft.com/office/2006/01/customui"> * <button id="favoriteAddButton" label="Add current page" * imageMso="AddToFavorites" onAction="AddFavoritePage" /> * * <!-- separator present only when there are favorites available --> * <menuSeparator id="favotiteSeparator" /> * * <!-- one or more favorites as split buttons --> * <splitButton id="favorite1"> * <button id="favoriteLink1" imageMso="FileLinksToFiles" * label="Some fancy page" screentip="Notebook/Section/Some fancy page long name..." /> * <menu id="favoriteMenu1" label="Some fancy menu" > * <button id="favoriteRemove1" label="Remove this link" imageMso="HyperlinkRemove" /> * </menu> * </splitButton> * * ... * * </menu> */ public FavoritesProvider(IRibbonUI ribbon) { logger = Logger.Current; path = Path.Combine(PathFactory.GetAppDataPath(), Resx.FavoritesFilename); this.ribbon = ribbon; }
public void Execute() { var builder = new StringBuilder(); builder.AppendLine("Diagnostics.Execute()"); builder.AppendLine(new string('-', 80)); builder.AppendLine($"Addin path: {Assembly.GetExecutingAssembly().Location}"); builder.AppendLine($"Data path.: {PathFactory.GetAppDataPath()}"); builder.AppendLine($"Log path..: {(logger as Logger).LogPath}"); builder.AppendLine(); using (var manager = new ApplicationManager()) { var(backupPath, defaultPath, unfiledPath) = manager.GetLocations(); builder.AppendLine($"Default path: {defaultPath}"); builder.AppendLine($"Backup path: {backupPath}"); builder.AppendLine($"Unfiled path: {unfiledPath}"); builder.AppendLine(); var(pageName, pagePath, pageLink) = manager.GetCurrentPageInfo(); builder.AppendLine($"Page name: {pageName}"); builder.AppendLine($"Page path: {pagePath}"); builder.AppendLine($"Page link: {pageLink}"); builder.AppendLine(); var app = manager.Application; var win = app.Windows.CurrentWindow; builder.AppendLine($"CurrentNotebookId: {win.CurrentNotebookId}"); builder.AppendLine($"CurrentPageId....: {win.CurrentPageId}"); builder.AppendLine($"CurrentSectionId.: {win.CurrentSectionId}"); builder.AppendLine($"CurrentSecGrpId..: {win.CurrentSectionGroupId}"); builder.AppendLine($"DockedLocation...: {win.DockedLocation}"); builder.AppendLine($"IsFullPageView...: {win.FullPageView}"); builder.AppendLine($"IsSideNote.......: {win.SideNote}"); builder.AppendLine(); builder.AppendLine($"Windows ({app.Windows.Count})"); var currentHandle = manager.Application.Windows.CurrentWindow.WindowHandle; var e = app.Windows.GetEnumerator(); while (e.MoveNext()) { var window = e.Current as One.Window; var threadId = Native.GetWindowThreadProcessId( (IntPtr)window.WindowHandle, out var processId); builder.Append($"- window [processId:{processId}, threadId:{threadId}]"); builder.Append($" handle:{window.WindowHandle:x} active:{window.Active}"); if (window.WindowHandle == currentHandle) { builder.AppendLine(" (current)"); } } builder.AppendLine(); var page = new Page(manager.CurrentPage()); var pageColor = page.GetPageColor(out _, out _); var pageBrightness = pageColor.GetBrightness(); builder.AppendLine($"Page background: {pageColor.ToRGBHtml()}"); builder.AppendLine($"Page brightness: {pageBrightness}"); builder.AppendLine($"Page is dark...: {pageBrightness < 0.5}"); builder.AppendLine(new string('-', 80)); logger.WriteLine(builder.ToString()); } }
public void Save() { PathFactory.EnsurePathExists(Path.GetDirectoryName(path)); root.Save(path, SaveOptions.None); }