Пример #1
0
        public string GetStyleGalleryItemScreentip(IRibbonControl control, int itemIndex)
        {
            var name = new StyleProvider().GetName(itemIndex);

            //logger.WriteLine($"GetStyleGalleryItemScreentip({control.Id}, {itemIndex}) = \"{name}\"");
            return(name);
        }
Пример #2
0
        private Style GetStyle()
        {
            Style style = null;

            // use custom Caption style if it exists

            var styles = new StyleProvider().GetStyles();

            if (styles?.Count > 0)
            {
                style = styles.Where(s => s.Name.Equals("Caption")).FirstOrDefault();
            }

            // otherwise use default style

            if (style == null)
            {
                style = new Style
                {
                    Color    = "#5B9BD5",                  // close to CornflowerBlue
                    FontSize = "10pt",
                    IsBold   = true
                };
            }

            return(style);
        }
Пример #3
0
        /*
         * called once, when the ribbon is shown after it is invalidated
         */

        public int GetStyleGalleryItemCount(IRibbonControl control)
        {
            var count = new StyleProvider().Count;

            //logger.WriteLine($"GetStyleGalleryItemCount({control.Id}) = {count}");
            return(count);
        }
Пример #4
0
        public void Execute()
        {
            try
            {
                using (var manager = new ApplicationManager())
                {
                    page = new Page(manager.CurrentPage());
                    if (page != null)
                    {
                        var styles = new StyleProvider().GetStyles();

                        if (ApplyStyles(styles))
                        {
                            ApplyToLists(styles);

                            if (page.GetPageColor(out _, out _).GetBrightness() < 0.5)
                            {
                                ApplyToHyperlinks();
                            }

                            manager.UpdatePageContent(page.Root);
                        }
                    }
                }
            }
            catch (Exception exc)
            {
                logger.WriteLine($"Error executing {nameof(ApplyStylesCommand)}", exc);
            }
        }
Пример #5
0
        /// <summary>
        /// Called by ribbon getItemScreentip, for each item only after invalidation
        /// </summary>
        /// <param name="control"></param>
        /// <param name="itemIndex"></param>
        /// <returns></returns>
        public string GetStyleGalleryItemScreentip(IRibbonControl control, int itemIndex)
        {
            var tip = new StyleProvider().GetName(itemIndex);

            if (itemIndex < 9)
            {
                tip = string.Format(Properties.Resources.CustomStyle_Screentip, tip, itemIndex + 1);
            }

            //logger.WriteLine($"GetStyleGalleryItemScreentip({control.Id}, {itemIndex}) = \"{tip}\"");
            return(tip);
        }
Пример #6
0
        /*
         * When Ribbon button is invalid, first calls:
         *		GetStyleGalleryItemCount(styleGallery)
         *
         * Then for each item, these are called in this order:
         *     GetStyleGalleryItemScreentip(styleGallery, 0) = "Heading 1"
         *     GetStyleGalleryItemImage(styleGallery, 0)
         *     GetStyleGalleryItemId(styleGallery, 0)
         */


        /// <summary>
        /// Called by ribbon getItemCount, once when the ribbon is shown after it is invalidated
        /// </summary>
        /// <param name="control"></param>
        /// <returns></returns>
        public int GetStyleGalleryItemCount(IRibbonControl control)
        {
            using (var one = new OneNote(out var page, out _))
            {
                pageColor = page.GetPageColor(out _, out var black);
                if (black)
                {
                    pageColor = ColorTranslator.FromHtml("#201F1E");
                }
            }

            var count = new StyleProvider().Count;

            //logger.WriteLine($"GetStyleGalleryItemCount() count:{count}");
            return(count);
        }
Пример #7
0
        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);
                    }
                }
            }
        }
Пример #8
0
        public void Execute()
        {
            try
            {
                Color pageColor;
                using (var manager = new ApplicationManager())
                {
                    pageColor = new Page(manager.CurrentPage()).GetPageColor(out _, out var black);
                    if (black)
                    {
                        pageColor = ColorTranslator.FromHtml("#201F1E");
                    }
                }

                var provider = new StyleProvider();

                var          styles = provider.GetStyles();
                DialogResult result;

                using (var dialog = new StyleDialog(styles, pageColor))
                {
                    result = dialog.ShowDialog(owner);

                    if (result == DialogResult.OK)
                    {
                        // save styles to remove delete items and preserve ordering
                        styles = dialog.GetStyles();
                        provider.Save(styles);
                        ribbon.Invalidate();
                    }
                }
            }
            catch (Exception exc)
            {
                logger.WriteLine($"Error executing {nameof(EditStylesCommand)}", exc);
            }
        }
Пример #9
0
        public override void Execute(params object[] args)
        {
            using (var one = new OneNote(out var page, out var ns))
            {
                var elements =
                    (from e in page.Root.Descendants(page.Namespace + "OE")
                     where e.Elements().Count() == 1
                     let t = e.Elements().First()
                             where (t != null) && (t.Name.LocalName == "T") && (t.Value.Length == 0)
                             select e)
                    .ToList();

                if (elements != null)
                {
                    var quickStyles = page.GetQuickStyles()
                                      .Where(s => s.StyleType == StyleType.Heading);

                    var customStyles = new StyleProvider().GetStyles()
                                       .Where(e => e.StyleType == StyleType.Heading)
                                       .ToList();

                    var modified = false;

                    foreach (var element in elements)
                    {
                        // is this a known Heading style?
                        var attr = element.Attribute("quickStyleIndex");
                        if (attr != null)
                        {
                            var index = int.Parse(attr.Value, CultureInfo.InvariantCulture);
                            if (quickStyles.Any(s => s.Index == index))
                            {
                                element.Remove();
                                modified = true;
                                continue;
                            }
                        }

                        // is this a custom Heading style?
                        var style = new Style(element.CollectStyleProperties(true));
                        if (customStyles.Any(s => s.Equals(style)))
                        {
                            element.Remove();
                            modified = true;
                            continue;
                        }

                        // is this an empty paragraph preceded by an empty paragraph?
                        if (element.PreviousNode != null &&
                            element.PreviousNode.NodeType == System.Xml.XmlNodeType.Element)
                        {
                            var prev = element.PreviousNode as XElement;

                            if (prev.Name.LocalName == "OE" &&
                                prev.Elements().Count() == 1)
                            {
                                var t = prev.Elements().First();
                                if (t.Name.LocalName == "T" && t.Value.Length == 0)
                                {
                                    element.Remove();
                                    modified = true;
                                }
                            }
                        }
                    }

                    if (modified)
                    {
                        one.Update(page);
                    }
                }
            }
        }
Пример #10
0
 public GalleryTileFactory() : base()
 {
     provider = new StyleProvider();
 }
Пример #11
0
        private void RemoveSpacing()
        {
            using (var one = new OneNote(out var page, out var ns))
            {
                var elements =
                    (from e in page.Root.Descendants(page.Namespace + "OE")
                     where e.Elements().Count() == 1
                     let t = e.Elements().First()
                             where (t != null) && (t.Name.LocalName == "T") &&
                             ((e.Attribute("spaceBefore") != null) ||
                              (e.Attribute("spaceAfter") != null) ||
                              (e.Attribute("spaceBetween") != null))
                             select e)
                    .ToList();

                if (elements != null)
                {
                    var quickStyles = page.GetQuickStyles()
                                      .Where(s => s.StyleType == StyleType.Heading);

                    var customStyles = new StyleProvider().GetStyles()
                                       .Where(e => e.StyleType == StyleType.Heading)
                                       .ToList();

                    var modified = false;

                    foreach (var element in elements)
                    {
                        // is this a known Heading style?
                        var attr = element.Attribute("quickStyleIndex");
                        if (attr != null)
                        {
                            var index = int.Parse(attr.Value, CultureInfo.InvariantCulture);
                            if (quickStyles.Any(s => s.Index == index))
                            {
                                if (includeHeadings)
                                {
                                    modified |= CleanElement(element);
                                }

                                continue;
                            }
                        }

                        // is this a custom Heading style?
                        var style = new Style(element.CollectStyleProperties(true));
                        if (customStyles.Any(s => s.Equals(style)))
                        {
                            if (includeHeadings)
                            {
                                modified |= CleanElement(element);
                            }

                            continue;
                        }

                        // normal paragraph
                        modified |= CleanElement(element);
                    }

                    if (modified)
                    {
                        one.Update(page);
                    }
                }
            }
        }