コード例 #1
0
        public override async Task Execute(params object[] args)
        {
            using (var one = new OneNote(out var page, out _))
            {
                if (!page.ConfirmBodyContext())
                {
                    UIHelper.ShowError(Resx.Error_BodyContext);
                    return;
                }

                _ = one.GetPage().GetPageColor(out _, out black);
            }

            // transform RTF and Xaml data on clipboard to HTML

            var html = PrepareClipboard();

            //logger.WriteLine(html);
#if H
            if (html != null)
            {
                // TODO: find and replace selected region

                logger.WriteLine("Adding HTML blcok");
                using (var manager = new ApplicationManager())
                {
                    var page = new OM.Page(manager.CurrentPage(PageInfo.piBasic));
                    var ns   = page.Namespace;

                    var outline = page.Root.Elements(ns + "Outline").Elements(ns + "OEChildren").FirstOrDefault();

                    outline.Add(new XElement(ns + "HTMLBlock",
                                             new XElement(ns + "Data", new XCData(html))
                                             ));

                    manager.UpdatePageContent(page.Root);
                    return;
                }
            }
#endif
            // paste what's remaining from clipboard, letting OneNote do the
            // heavy lifting of converting the HTML into one:xml schema

            using (var one = new OneNote())
            {
                // since the Hotkey message loop is watching all input, explicitly setting
                // focus on the OneNote main window provides a direct path for SendKeys
                Native.SetForegroundWindow(one.WindowHandle);

                //System.Windows.Forms.SendKeys.SendWait("^(v)");
                new InputSimulator().Keyboard
                .ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_V);
            }

            await Task.Yield();
        }
コード例 #2
0
        public override void Execute(params object[] args)
        {
            // transform RTF and Xaml data on clipboard to HTML

            var html = PrepareClipboard();

            //logger.WriteLine(html);
#if H
            if (html != null)
            {
                // TODO: find and replace selected region

                logger.WriteLine("Adding HTML blcok");
                using (var manager = new ApplicationManager())
                {
                    var page = new OM.Page(manager.CurrentPage(PageInfo.piBasic));
                    var ns   = page.Namespace;

                    var outline = page.Root.Elements(ns + "Outline").Elements(ns + "OEChildren").FirstOrDefault();

                    outline.Add(new XElement(ns + "HTMLBlock",
                                             new XElement(ns + "Data", new XCData(html))
                                             ));

                    manager.UpdatePageContent(page.Root);
                    return;
                }
            }
#endif
            // paste what's remaining from clipboard, letting OneNote do the
            // heavy lifting of converting the HTML into one:xml schema

            using (var one = new OneNote())
            {
                // since the Hotkey message loop is watching all input, explicitly setting
                // focus on the OneNote main window provides a direct path for SendKeys
                Native.SetForegroundWindow(one.WindowHandle);
                System.Windows.Forms.SendKeys.SendWait("^(v)");
            }
        }