Ejemplo n.º 1
0
        private async Task SetGeneralOptions()
        {
            var provider = new SettingsProvider();
            var settings = provider.GetCollection("GeneralSheet");

            EnablersEnabled = settings.Get("enablers", true);

            if (settings.Get("checkUpdates", false))
            {
                try
                {
                    await factory.Run <Commands.UpdateCommand>();
                }
                catch (Exception exc)
                {
                    logger.WriteLine("error checking for updates", exc);
                }
            }
        }
Ejemplo n.º 2
0
        private uint clockSpeed;                            // Mhz of CPU


        // Lifecycle...

        /// <summary>
        /// Initializes the addin
        /// </summary>
        public AddIn()
        {
            //System.Diagnostics.Debugger.Launch();

            logger  = Logger.Current;
            trash   = new List <IDisposable>();
            process = Process.GetCurrentProcess();

            UIHelper.PrepareUI();

            var thread = System.Threading.Thread.CurrentThread;

            var settings = new SettingsProvider().GetCollection("GeneralSheet");
            var lang     = settings.Get("language", thread.CurrentUICulture.Name);

            Culture = CultureInfo.GetCultureInfo(lang);
            thread.CurrentCulture   = Culture;
            thread.CurrentUICulture = Culture;

            GetCurrentClockSpeed();

            logger.WriteLine();
            logger.Start(
                $"Starting {process.ProcessName} {process.Id}, CPU={clockSpeed}Mhz, " +
                $"{thread.CurrentCulture.Name}/{thread.CurrentUICulture.Name}, " +
                $"v{AssemblyInfo.Version}, OneNote {Office.GetOneNoteVersion()}, " +
                $"Office {Office.GetOfficeVersion()}");

            var hostproc = Process.GetProcessesByName("ONENOTE");

            if (hostproc.Length > 0)
            {
                var module = hostproc[0].MainModule;
                logger.WriteLine($"{module.FileName} ({module.FileVersionInfo.ProductVersion})");
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// IRibbonExtensibility method, returns XML describing the Ribbon customizations.
        /// Called directly by OneNote when initializing the addin.
        /// </summary>
        /// <param name="RibbonID">The ID of the ribbon</param>
        /// <returns>XML starting at the customUI root element</returns>
        public string GetCustomUI(string RibbonID)
        {
            logger.WriteLine("building ribbon");

            try
            {
                var root = XElement.Parse(Resx.Ribbon);
                ns = root.GetDefaultNamespace();

                AddColorizerCommands(root);

                var contextMenus = root.Element(ns + "contextMenus");
                if (contextMenus == null)
                {
                    contextMenus = new XElement(ns + "contextMenus");
                    root.Add(contextMenus);
                }

                AddSectionGroupContextMenuCommands(contextMenus);

                var provider = new SettingsProvider();

                var ribbonbar = provider.GetCollection("RibbonBarSheet");
                if (ribbonbar.Count > 0)
                {
                    AddRibbonBarCommands(ribbonbar, root);
                }

                var ccommands = provider.GetCollection("ContextMenuSheet");
                var searchers = provider.GetCollection("SearchEngineSheet");

                if (ccommands.Count == 0 && searchers.Count == 0)
                {
                    return(root.ToString(SaveOptions.DisableFormatting));
                }

                // construct context menu UI...

                var menu = new XElement(ns + "contextMenu",
                                        new XAttribute("idMso", "ContextMenuText"));

                if (ccommands.Count > 0)
                {
                    AddContextMenuCommands(ccommands, root, menu);
                }

                if (searchers.Count > 0)
                {
                    AddContextMenuSearchers(searchers, menu);
                }

                // add separator before Cut
                menu.Add(new XElement(ns + "menuSeparator",
                                      new XAttribute("id", "omContextMenuSeparator"),
                                      new XAttribute("insertBeforeMso", "Cut")
                                      ));

                //logger.WriteLine(menu);

                contextMenus.Add(menu);

                return(root.ToString(SaveOptions.DisableFormatting));
            }
            catch (Exception exc)
            {
                logger.WriteLine("error building custom UI", exc);
                return(XElement.Parse(Resx.Ribbon).ToString(SaveOptions.DisableFormatting));
            }
        }
Ejemplo n.º 4
0
        private string GetColor(int index, bool dark)
        {
            if (dark)
            {
                switch (index)
                {
                case 1: return("#008000");                          // Dark Green

                case 2: return("#00B0F0");                          // Turquoise

                case 3: return("#800080");                          // Dark Purple

                case 4: return("#0000FF");                          // Blue

                default: return("#808000");                         // Dark Yellow
                }
            }

            var theme = new SettingsProvider()
                        .GetCollection("HighlightsSheet")?.Get <string>("theme");

            if (theme == "Faded")
            {
                switch (index)
                {
                case 1: return("#CCFFCC");                          // Light Green

                case 2: return("#CCFFFF");                          // Sky Blue

                case 3: return("#FF99CC");                          // Pink

                case 4: return("#99CCFF");                          // Light Blue

                default: return("#FFFF99");                         // Light Yellow
                }
            }

            if (theme == "Deep")
            {
                switch (index)
                {
                case 1: return("#92D050");                          // Lime

                case 2: return("#33CCCC");                          // Teal

                case 3: return("#CC99FF");                          // Lavender

                case 4: return("#00B0F0");                          // Turquoise

                default: return("#FFC000");                         // Gold
                }
            }

            // default theme "Normal"
            switch (index)
            {
            case 1: return("#00FF00");                      // Light Green

            case 2: return("#00FFFF");                      // Sky Blue

            case 3: return("#FF00CC");                      // Pink

            case 4: return("#0000FF");                      // Light Blue

            default: return("#FFFF00");                     // Light Yellow
            }
        }