Example #1
0
        public override void Execute(params object[] args)
        {
            using (var one = new OneNote())
            {
                var notebook = one.GetNotebook();
                if (notebook != null)
                {
                    pattern = new Regex(@"^(\(\d+\)\s).+");

                    if (ApplyNumbering(notebook, one.GetNamespace(notebook)) > 0)
                    {
                        one.UpdateHierarchy(notebook);
                    }
                }
            }
        }
Example #2
0
        /*
         * private static void SortPages(SortDialog.Sortings sorting, SortDialog.Directions direction)
         * {
         *      using (var manager = new ApplicationManager())
         *      {
         *              var section = manager.CurrentSection();
         *              var ns = section.GetNamespaceOfPrefix("one");
         *
         *              var tree = new List<PageNode>();
         *              var list = section.Elements(ns + "Page").ToList();
         *              BuildTree(tree, list, 0, 0);
         *      }
         * }
         *
         *
         * private static int BuildTree(List<PageNode> tree, List<XElement> elements, int level, int index)
         * {
         *      if (index >= elements.Count)
         *      {
         *              return index;
         *      }
         *
         *      var element = elements[index];
         *      var pageLevel = int.Parse(element.Attribute("pageLevel").Value);
         *
         *      if (pageLevel < level)
         *      {
         *              return index;
         *      }
         *
         *      if (pageLevel > level)
         *      {
         *              index = BuildTree(tree, elements, pageLevel, index + 1);
         *      }
         *
         *      return index;
         * }
         */


        // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
        // Sections

        private void SortSections(
            SortDialog.Sortings sorting, SortDialog.Directions direction, bool pinNotes)
        {
            #region Notes

            /*
             * <one:Notebook name="Personal" nickname="Personal" ID="">
             *   <one:Section name="Notes" ID="" />
             *   <one:Section name="Automobiles" ID="" />
             *   <one:SectionGroup name="OneNote_RecycleBin" ID="" isRecycleBin="true">
             *     <one:Section name="Deleted Pages" ID="" isInRecycleBin="true" isDeletedPages="true" />
             *   </one:SectionGroup>
             * </one:Notebook>
             *
             * Sort top-level sections only; ignore section groups.
             */
            #endregion Notes

            logger.StartClock();

            using (var one = new OneNote())
            {
                // get the current notebook with its sections
                var notebook = one.GetNotebook();

                if (notebook == null)
                {
                    return;
                }

                var ns = one.GetNamespace(notebook);

                var key = sorting == SortDialog.Sortings.ByName
                                        ? "name"
                                        : "lastModifiedTime";

                SortSection(notebook, ns,
                            key, direction == SortDialog.Directions.Ascending, pinNotes);

                //logger.WriteLine(notebook.ToString());
                one.UpdateHierarchy(notebook);
            }

            logger.WriteTime(nameof(SortSections));
        }
Example #3
0
        // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

        #region InsertSectionsTable
        private void InsertSectionsTable(OneNote one, bool includePages)
        {
            var section   = one.GetSection();
            var sectionId = section.Attribute("ID").Value;

            one.CreatePage(sectionId, out var pageId);

            var page = one.GetPage(pageId);
            var ns   = page.Namespace;

            var scope    = includePages ? OneNote.Scope.Pages : OneNote.Scope.Sections;
            var notebook = one.GetNotebook(scope);

            page.Title = string.Format(Resx.InsertTocCommand_TOCNotebook, notebook.Attribute("name").Value);

            var container = new XElement(ns + "OEChildren");

            BuildSectionTable(one, ns, container, notebook.Elements(), includePages, 1);

            var title = page.Root.Elements(ns + "Title").FirstOrDefault();

            title.AddAfterSelf(new XElement(ns + "Outline", container));
            one.Update(page);

            // move TOC page to top of section...

            // get current section again after new page is created
            section = one.GetSection();

            var entry = section.Elements(ns + "Page")
                        .FirstOrDefault(e => e.Attribute("ID").Value == pageId);

            entry.Remove();
            section.AddFirst(entry);
            one.UpdateHierarchy(section);

            one.NavigateTo(pageId);
        }