Ejemplo n.º 1
0
        public void Execute()
        {
            using (var manager = new ApplicationManager())
            {
                var section = manager.CurrentSection();
                var ns      = section.GetNamespaceOfPrefix("one");

                // find all level 1 pages not collapsed and immediately followed by level 2 page

                var pages =
                    from e in section.Elements(ns + "Page")
                    let n = e.NextNode
                            where n != null &&
                            e.Attribute("pageLevel").Value.Equals("1") &&
                            !e.Attributes("isCollapsed").Any(x => x.Value.Equals("true")) &&
                            n.NodeType == XmlNodeType.Element && ((XElement)n).Attribute("pageLevel").Value.Equals("2")
                            select e;

                if (pages?.Count() > 0)
                {
                    logger.WriteLine($"found {pages.Count()} expanded pages");

                    foreach (var page in pages)
                    {
                        page.Add(new XAttribute("isCollapsed", "true"));
                    }

                    manager.UpdateHierarchy(section);
                }
                else
                {
                    logger.WriteLine($"found 0 expanded pages");
                }
            }
        }
Ejemplo n.º 2
0
        public void Execute()
        {
            logger.WriteLine("SortCommand.Execute()");

            var result = DialogResult.None;

            using (var dialog = new SortDialog())
            {
                result = dialog.ShowDialog(owner);
                dialog.Focus();

                result    = dialog.DialogResult;
                scope     = dialog.Scope;
                sorting   = dialog.Soring;
                direction = dialog.Direction;
                pinNotes  = dialog.PinNotes;
            }

            if (result == DialogResult.OK)
            {
                logger.WriteLine($"- sort scope [{scope}]");
                logger.WriteLine($"- sort sorting[{sorting}]");
                logger.WriteLine($"- sort direction [{direction}]");

                using (var manager = new ApplicationManager())
                {
                    XElement root;

                    if (scope == HierarchyScope.hsPages)
                    {
                        // get just the current section with all pages as child elements
                        root = manager.CurrentSection();
                        root = SortPages(root, sorting, direction);
                    }
                    else
                    {
                        root = manager.GetHierarchy(scope);

                        if (scope == HierarchyScope.hsNotebooks)
                        {
                            // notebooks is a simple flat list
                            root = SortNotebooks(root, sorting, direction);
                        }
                        else
                        {
                            // sections will include all sections for the current notebook
                            root = SortSections(root, sorting, direction, pinNotes);
                        }
                    }

                    if (root != null)
                    {
                        manager.UpdateHierarchy(root);
                    }
                }
            }
        }