Example #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;
                }

                OneNote.Scope scope;
                bool          addTopLinks;
                bool          rightAlignTopLinks;
                bool          includePages;

                using (var dialog = new InsertTocDialog())
                {
                    if (dialog.ShowDialog(owner) == DialogResult.Cancel)
                    {
                        return;
                    }

                    scope              = dialog.Scope;
                    addTopLinks        = dialog.TopLinks;
                    rightAlignTopLinks = dialog.RightAlignTopLinks;
                    includePages       = dialog.SectionPages;
                }

                try
                {
                    switch (scope)
                    {
                    case OneNote.Scope.Self:
                        await InsertHeadingsTable(one, addTopLinks, rightAlignTopLinks);

                        break;

                    case OneNote.Scope.Pages:
                        await InsertPagesTable(one);

                        break;

                    case OneNote.Scope.Sections:
                        await InsertSectionsTable(one, includePages);

                        break;
                    }
                }
                catch (Exception exc)
                {
                    logger.WriteLine($"error executing {nameof(InsertTocCommand)}", exc);
                }
            }
        }
Example #2
0
        public override async Task Execute(params object[] args)
        {
            OneNote.Scope scope;
            bool          addTopLinks;
            bool          includePages;

            using (var dialog = new InsertTocDialog())
            {
                if (dialog.ShowDialog(owner) == DialogResult.Cancel)
                {
                    return;
                }

                scope        = dialog.Scope;
                addTopLinks  = dialog.TopLinks;
                includePages = dialog.SectionPages;
            }

            try
            {
                using (var one = new OneNote())
                {
                    switch (scope)
                    {
                    case OneNote.Scope.Self:
                        await InsertHeadingsTable(one, addTopLinks);

                        break;

                    case OneNote.Scope.Pages:
                        await InsertPagesTable(one);

                        break;

                    case OneNote.Scope.Sections:
                        await InsertSectionsTable(one, includePages);

                        break;
                    }
                }
            }
            catch (Exception exc)
            {
                logger.WriteLine($"error executing {nameof(InsertTocCommand)}", exc);
            }
        }
Example #3
0
        public override async Task Execute(params object[] args)
        {
            bool jumplinks;
            bool alignlinks;

            if (args.Length > 0 && args[0] is string refresh && refresh == "refresh")
            {
                jumplinks  = args.Any(a => a as string == "links");
                alignlinks = args.Any(a => a as string == "align");

                if (await RefreshToc(jumplinks, alignlinks))
                {
                    // successfully updated
                    return;
                }
            }

            OneNote.Scope scope;
            bool          withPreviews;
            bool          withPages;

            using (var dialog = new InsertTocDialog())
            {
                if (dialog.ShowDialog(owner) == DialogResult.Cancel)
                {
                    return;
                }

                scope        = dialog.Scope;
                jumplinks    = dialog.TopLinks;
                alignlinks   = dialog.RightAlignTopLinks;
                withPreviews = dialog.PreviewPages;
                withPages    = dialog.SectionPages;
            }

            try
            {
                using (one = new OneNote())
                {
                    switch (scope)
                    {
                    case OneNote.Scope.Self:
                        await InsertToc(one.GetPage(), jumplinks, alignlinks);

                        break;

                    case OneNote.Scope.Pages:
                        await InsertPagesTable(withPreviews);

                        break;

                    case OneNote.Scope.Sections:
                        await InsertSectionsTable(withPages, withPreviews);

                        break;
                    }
                }
            }
            catch (Exception exc)
            {
                logger.WriteLine($"error executing {nameof(InsertTocCommand)}", exc);
            }
        }