Exemple #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");
                }
            }
        }
Exemple #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);
                    }
                }
            }
        }
Exemple #3
0
        private void currSectionButton_CheckedChanged(object sender, EventArgs e)
        {
            var element = manager.CurrentSection();

            if (element != null)
            {
                var xml = element.ToString(SaveOptions.None);
                hierBox.Text = xml;
            }
            else
            {
                hierBox.Text = "Cannot get current section hierarchy";
            }
        }
Exemple #4
0
        /// <summary>
        /// Analyze the current page selections and determined if at least two pages are selected.
        /// </summary>
        /// <param name="control">The menu item invoking the action.</param>
        /// <returns>True if two or more pages are selected.</returns>
        public bool GetMultiPageContext(IRibbonControl control)
        {
            //Logger.Current.WriteLine($"GetMultiPageContext {control.Id}");

            using (var manager = new ApplicationManager())
            {
                var section = manager.CurrentSection();
                var ns      = section.GetNamespaceOfPrefix("one");

                var count =
                    section.Elements(ns + "Page")
                    .Count(e => e.Attributes("selected").Any(a => a.Value.Equals("all")));

                return(count > 1);
            }
        }
Exemple #5
0
        public void Execute()
        {
            using (var manager = new ApplicationManager())
            {
                var section = manager.CurrentSection();
                ns = section.GetNamespaceOfPrefix("one");

                // find first selected - active page

                var active =
                    section.Elements(ns + "Page")
                    .Where(e => e.Attributes("isCurrentlyViewed").Any(a => a.Value.Equals("true")))
                    .FirstOrDefault();

                if (active == null)
                {
                    UIHelper.ShowMessage(manager.Window, "At least two pages must be selected to merge");
                    return;
                }

                var selections =
                    section.Elements(ns + "Page")
                    .Where(e =>
                           e.Attributes("isCurrentlyViewed").Count() == 0 &&
                           e.Attributes("selected").Any(a => a.Value.Equals("all")));

                if (active == null)
                {
                    UIHelper.ShowMessage(manager.Window, "At least two pages must be selected to merge");
                    return;
                }


                // get first selected (active) page and reference its quick styles, outline, size

                page = manager.GetPage(active.Attribute("ID").Value);

                quickies = page.Elements(ns + "QuickStyleDef")
                           .Select(p => new QuickRef(p))
                           .ToList();

                var offset = GetPageBottomOffset();

                // track running bottom as we add new outlines
                var maxOffset = offset;

                // find maximum z-offset
                var z = page.Elements(ns + "Outline").Elements(ns + "Position")
                        .Attributes("z").Max(a => int.Parse(a.Value)) + 1;

                // merge each of the subsequently selected pages into the active page

                foreach (var selection in selections.ToList())
                {
                    var childPage = manager.GetPage(selection.Attribute("ID").Value);

                    var styles = MergeQuickStyles(childPage);

                    var topOffset = childPage.Elements(ns + "Outline")
                                    .Elements(ns + "Position").Min(p => double.Parse(p.Attribute("y").Value));

                    foreach (var childOutline in childPage.Elements(ns + "Outline"))
                    {
                        // adjust position relative to new parent page outlines
                        var position = childOutline.Elements(ns + "Position").FirstOrDefault();
                        var y        = double.Parse(position.Attribute("y").Value) - topOffset + offset + OutlineMargin;
                        position.Attribute("y").Value = y.ToString("#0.0");

                        // keep track of lowest bottom
                        var size   = childOutline.Elements(ns + "Size").FirstOrDefault();
                        var bottom = y + double.Parse(size.Attribute("height").Value);
                        if (bottom > maxOffset)
                        {
                            maxOffset = bottom;
                        }

                        position.Attribute("z").Value = z.ToString();
                        z++;

                        // remove its IDs so the page can apply its own
                        childOutline.Attributes("objectID").Remove();
                        childOutline.Descendants().Attributes("objectID").Remove();

                        AdjustQuickStyles(styles, childOutline);

                        page.Add(childOutline);
                    }

                    if (maxOffset > offset)
                    {
                        offset = maxOffset;
                    }
                }

                // update page and section hierarchy

                manager.UpdatePageContent(page);

                foreach (var selection in selections)
                {
                    manager.DeleteHierarchy(selection.Attribute("ID").Value);
                }
            }
        }