Ejemplo n.º 1
0
        void OutlineTreeDataFunc(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter)
        {
            Gtk.CellRendererText txtRenderer = (Gtk.CellRendererText)cell;
            OutlineNode          n           = (OutlineNode)model.GetValue(iter, 0);

            txtRenderer.Text = n.Name;
        }
Ejemplo n.º 2
0
        public void LoadItemsCollection(DesignItem item)
        {
            Debug.Assert(item.View is ItemsControl);
            _item             = item;
            _componentService = item.Services.Component;
            item.Services.Selection.SelectionChanged += delegate { PropertyGridView.SelectedItems = item.Services.Selection.SelectedItems; };
            var control = item.View as ItemsControl;

            if (control != null)
            {
                TypeMappings.TryGetValue(control.GetType(), out _type);
                if (_type != null)
                {
                    OutlineNode node = OutlineNode.Create(item);
                    Outline.Root = node;
                    PropertyGridView.PropertyGrid.SelectedItems = item.Services.Selection.SelectedItems;
                }
                else
                {
                    PropertyGridView.IsEnabled = false;
                    Outline.IsEnabled          = false;
                    AddItem.IsEnabled          = false;
                    RemoveItem.IsEnabled       = false;
                    MoveUpItem.IsEnabled       = false;
                    MoveDownItem.IsEnabled     = false;
                }
            }
        }
Ejemplo n.º 3
0
        private void ListDir(string dir, int level)
        {
            if (string.IsNullOrEmpty(dir))
            {
                return;
            }

            // get files first:
            string[] files = Directory.GetFiles(dir, _mask, SearchOption.TopDirectoryOnly);

            // if there are no matching files - we skip the directory as well:
            if (files.Length > 0)
            {
                C1PrintDocument doc;
                if (_sdoc != null)
                {
                    doc = _sdoc;
                }
                else
                {
                    doc = new C1PrintDocument();
                    SetupDoc(doc);
                }

                // directory header:
                RenderText dirHeader = new RenderText(string.Format("Files in {0}", dir));
                dirHeader.Style.FontSize       = 12;
                dirHeader.Style.FontBold       = true;
                dirHeader.Style.Spacing.Bottom = "3mm";
                dirHeader.Style.BackColor      = Color.LemonChiffon;
                // Add a dir TOC/outline entry, keep outline as files' parent:
                OutlineNode dirOutlineNode = this.DirAdded(doc, dirHeader, dir, level);

                // add files:
                for (int nfile = 0; nfile < files.Length; ++nfile)
                {
                    RenderArea file = ListFile(files[nfile], nfile == 0 ? dirHeader : null);
                    doc.Body.Children.Add(file);
                    // Add a file TOC entry:
                    this.FileAdded(doc, dirOutlineNode, file, files[nfile], level + 1);
                }

                if (_mdoc != null)
                {
                    _mdoc.Items.Add(doc);
                    // Make sure all memory used by the added document is released:
                    doc = null;
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
            }

            // recurse into sub-dirs:
            string[] dirs = Directory.GetDirectories(dir, "*", SearchOption.TopDirectoryOnly);
            for (int ndir = 0; ndir < dirs.Length; ++ndir)
            {
                ListDir(dirs[ndir], level + 1);
            }
        }
Ejemplo n.º 4
0
        protected void assertCurrentNode(ITestPart part, Icon icon, string text)
        {
            OutlineNode outlineNode = treeBuilder.LastNode;

            outlineNode.Part.ShouldBeTheSameAs(part);
            outlineNode.Icon.ShouldEqual(icon);
            outlineNode.HeaderText().ShouldEqual(text);
        }
Ejemplo n.º 5
0
        protected override void theContextIs()
        {
            node = new OutlineNode(theTest, Icon.Test);
            MockFor <IOutlineTreeService>()
            .Expect(x => x.BuildNode(theTest, ClassUnderTest))
            .Return(node);

            ClassUnderTest.Update(null);
        }
Ejemplo n.º 6
0
        protected override void LoadInternal(OpenedFile file, System.IO.Stream stream)
        {
            wasChangedInDesigner = false;
            Debug.Assert(file == this.PrimaryFile);
            SD.AnalyticsMonitor.TrackFeature(typeof(WpfViewContent), "Load");

            _stream = new MemoryStream();
            stream.CopyTo(_stream);
            stream.Position = 0;

            if (designer == null)
            {
                // initialize designer on first load
                designer         = new DesignSurface();
                this.UserContent = designer;
                InitPropertyEditor();
                InitWpfToolbox();
            }
            this.UserContent = designer;
            if (outline != null)
            {
                outline.Root = null;
            }
            using (XmlTextReader r = new XmlTextReader(stream)) {
                XamlLoadSettings settings = new XamlLoadSettings();
                settings.DesignerAssemblies.Add(typeof(WpfViewContent).Assembly);
                settings.CustomServiceRegisterFunctions.Add(
                    delegate(XamlDesignContext context) {
                    context.Services.AddService(typeof(IUriContext), new FileUriContext(this.PrimaryFile));
                    context.Services.AddService(typeof(IPropertyDescriptionService), new PropertyDescriptionService(this.PrimaryFile));
                    context.Services.AddService(typeof(IEventHandlerService), new SharpDevelopEventHandlerService(this));
                    context.Services.AddService(typeof(ITopLevelWindowService), new WpfAndWinFormsTopLevelWindowService());
                    context.Services.AddService(typeof(ChooseClassServiceBase), new IdeChooseClassService());
                });
                settings.TypeFinder = MyTypeFinder.Create(this.PrimaryFile);
                try {
                    settings.ReportErrors = UpdateTasks;
                    designer.LoadDesigner(r, settings);

                    designer.ContextMenuOpening += (sender, e) => MenuService.ShowContextMenu(e.OriginalSource as UIElement, designer, "/AddIns/WpfDesign/Designer/ContextMenu");

                    if (outline != null && designer.DesignContext != null && designer.DesignContext.RootItem != null)
                    {
                        outline.Root = OutlineNode.Create(designer.DesignContext.RootItem);
                    }

                    propertyGridView.PropertyGrid.SelectedItems = null;
                    designer.DesignContext.Services.Selection.SelectionChanged += OnSelectionChanged;
                    designer.DesignContext.Services.GetService <UndoService>().UndoStackChanged += OnUndoStackChanged;
                } catch (Exception e) {
                    this.UserContent = new WpfDocumentError(e);
                }
            }
        }
        public void configure_a_sentence_with_none_of_the_values()
        {
            var sentence = Sentence.For("add {x} to {y}", Cell.For <int>("x"), Cell.For <int>("y"));
            var step     = new Step();

            var node = new OutlineNode(step, Icon.Sentence);

            ClassUnderTest.WriteSentenceText(node, sentence, step);

            node.HeaderText().ShouldEqual("add {x} to {y}");
        }
Ejemplo n.º 8
0
        public void Intialize()
        {
            _grid    = CreateGridContextWithDesignSurface("<Button/><StackPanel><Button/></StackPanel>");
            _outline = OutlineNode.Create(_grid);
            Assert.IsNotNull(_outline);

            var selection        = _grid.Services.Selection;
            var stackPanel       = _grid.ContentProperty.CollectionElements[1];
            var stackPanelButton = stackPanel.ContentProperty.CollectionElements[0];

            selection.SetSelectedComponents(new[] { stackPanel, stackPanelButton });
        }
Ejemplo n.º 9
0
    //まとめて
    void AddElements(object obj, SaveData data, bool setFlag = true)
    {
        OutlineNode outlineNode;

        outlineNode = new OutlineNode(data);

        graphView.AddElement(outlineNode);

        saveData = data;

        dataLoadFlag = (setFlag == true ? true : false);
    }
Ejemplo n.º 10
0
 void UpdateDesign()
 {
     OutlineRoot = null;
     using (var xmlReader = XmlReader.Create(new StringReader(Text))) {
         DesignSurface.LoadDesigner(xmlReader, null);
     }
     if (DesignContext.RootItem != null)
     {
         OutlineRoot = OutlineNode.Create(DesignContext.RootItem);
         UndoService.UndoStackChanged += new EventHandler(UndoService_UndoStackChanged);
     }
     RaisePropertyChanged("SelectionService");
     RaisePropertyChanged("XamlErrorService");
 }
Ejemplo n.º 11
0
        public void Intialize()
        {
            _grid    = CreateGridContextWithDesignSurface("<Button/><StackPanel><Button/></StackPanel>");
            _outline = OutlineNode.Create(_grid);
            Assert.IsNotNull(_outline);

            _gridButton       = _grid.ContentProperty.CollectionElements[0];
            _stackPanel       = _grid.ContentProperty.CollectionElements[1];
            _stackPanelButton = _stackPanel.ContentProperty.CollectionElements[0];

            _gridButtonNode       = _outline.Children[0];
            _stackPanelNode       = _outline.Children[1];
            _stackPanelButtonNode = _stackPanelNode.Children[0];
        }
        void BuildTreeChildren(Gtk.TreeStore store, Gtk.TreeIter parent, ParentNode p, IList <Block> blocks)
        {
            foreach (Node node in p)
            {
                if (!(node is TagNode))
                {
                    var startLoc = new TextLocation(node.Location.BeginLine, node.Location.BeginColumn);
                    var endLoc   = new TextLocation(node.Location.EndLine, node.Location.EndColumn);
                    var doc      = defaultDocument.Editor.Document;

                    var blocksBetween = blocks.Where(n => n.Start.AbsoluteIndex >= doc.GetOffset(startLoc) &&
                                                     n.Start.AbsoluteIndex <= doc.GetOffset(endLoc));

                    foreach (var block in blocksBetween)
                    {
                        var outlineNode = new OutlineNode(block)
                        {
                            Location = new DomRegion(doc.OffsetToLocation(block.Start.AbsoluteIndex),
                                                     doc.OffsetToLocation(block.Start.AbsoluteIndex + block.Length))
                        };
                        if (!parent.Equals(Gtk.TreeIter.Zero))
                        {
                            store.AppendValues(parent, outlineNode);
                        }
                        else
                        {
                            store.AppendValues(outlineNode);
                        }
                    }
                    continue;
                }

                Gtk.TreeIter childIter;
                if (!parent.Equals(Gtk.TreeIter.Zero))
                {
                    childIter = store.AppendValues(parent, new OutlineNode(node as TagNode));
                }
                else
                {
                    childIter = store.AppendValues(new OutlineNode(node as TagNode));
                }

                ParentNode pChild = node as ParentNode;
                if (pChild != null)
                {
                    BuildTreeChildren(store, childIter, pChild, blocks);
                }
            }
        }
Ejemplo n.º 13
0
        void BuildTreeChildren(Gtk.TreeStore store, Gtk.TreeIter parent, XContainer p, IList <Block> blocks)
        {
            foreach (XNode node in p.Nodes)
            {
                var el = node as XElement;
                if (el == null)
                {
                    var startLoc = node.Region.Begin;
                    var endLoc   = node.Region.End;
                    var doc      = defaultDocument.Editor.Document;

                    var blocksBetween = blocks.Where(n => n.Start.AbsoluteIndex >= doc.GetOffset(startLoc) &&
                                                     n.Start.AbsoluteIndex <= doc.GetOffset(endLoc));

                    foreach (var block in blocksBetween)
                    {
                        var outlineNode = new OutlineNode(block)
                        {
                            Location = new DomRegion(doc.OffsetToLocation(block.Start.AbsoluteIndex),
                                                     doc.OffsetToLocation(block.Start.AbsoluteIndex + block.Length))
                        };
                        if (!parent.Equals(Gtk.TreeIter.Zero))
                        {
                            store.AppendValues(parent, outlineNode);
                        }
                        else
                        {
                            store.AppendValues(outlineNode);
                        }
                    }
                    continue;
                }

                Gtk.TreeIter childIter;
                if (!parent.Equals(Gtk.TreeIter.Zero))
                {
                    childIter = store.AppendValues(parent, new OutlineNode(el));
                }
                else
                {
                    childIter = store.AppendValues(new OutlineNode(el));
                }

                BuildTreeChildren(store, childIter, el, blocks);
            }
        }
Ejemplo n.º 14
0
 void NewNovelCB(string filename, string filepath)
 {
     GVL.Instance.NovelFilePath = filepath;
     try
     {
         Novel newNovel = new Novel();
         newNovel.Name         = filename;
         GVL.Instance.CurNovel = newNovel;
         OutlineNode node = new OutlineNode();
         node.Content = filename;
         GVL.Instance.OutlineTree.Add(node);
         SaveToFile(GVL.Instance.NovelFilePath);
         GVL.Instance.UpdateTreeView();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
Ejemplo n.º 15
0
    bool ISearchWindowProvider.OnSelectEntry(SearchTreeEntry searchTreeEntry, SearchWindowContext context)
    {
        var    type     = searchTreeEntry.userData as Type;
        String typeName = type.ToString();
        // マウスの位置にノードを追加
        var worldMousePosition = editorWindow.rootVisualElement.ChangeCoordinatesTo(editorWindow.rootVisualElement.parent, context.screenMousePosition - editorWindow.position.position);
        var localMousePosition = graphView.contentViewContainer.WorldToLocal(worldMousePosition);

        //読み込むノードの分岐
        if (typeName == "ReadNode")
        {
            LoadTextDataFile(localMousePosition);
            return(true);
        }
        if (typeName == "UploadNode")
        {
            var file = new SaveManager();
            file.UploadFile(saveData);

            return(true);
        }

        //呼び出し
        SaveData data = new SaveData();

        data.Init(localMousePosition, "");
        saveData = data;

        OutlineNode outlineNode;

        outlineNode = new OutlineNode(data);

        graphView.AddElement(outlineNode);
        graphView.graphAsset.data.Add(saveData);

        //var node = Activator.CreateInstance(type) as Node;

        //node.SetPosition(new Rect(localMousePosition, new Vector2(100, 100)));
        //graphView.AddElement(node);

        return(true);
    }
Ejemplo n.º 16
0
        void UpdateDesign()
        {
            OutlineRoot = null;
            using (var xmlReader = XmlReader.Create(new StringReader(Text))) {
                XamlLoadSettings settings = new XamlLoadSettings();
                foreach (var assNode in Toolbox.Instance.AssemblyNodes)
                {
                    settings.DesignerAssemblies.Add(assNode.Assembly);
                }
                settings.TypeFinder = MyTypeFinder.Instance;

                DesignSurface.LoadDesigner(xmlReader, settings);
            }
            if (DesignContext.RootItem != null)
            {
                OutlineRoot = OutlineNode.Create(DesignContext.RootItem);
                UndoService.UndoStackChanged += new EventHandler(UndoService_UndoStackChanged);
            }
            RaisePropertyChanged("SelectionService");
            RaisePropertyChanged("XamlErrorService");
        }
Ejemplo n.º 17
0
        // highlight render object selected in the outline view:
        void outline_AfterSelect(object sender, TreeViewEventArgs e)
        {
#if C1REPORT_PRIOR_TO_2011v2
            OutlineNode node = e.Node.Tag as OutlineNode;
            if (node != null)
            {
                RenderObject ro = node.Location as RenderObject;
                if (ro != null)
                {
                    HighlightRenderObject(ro);
                }
            }
#else
            DocumentLocation loc = e.Node.Tag as DocumentLocation;
            if (loc == null)
            {
                return;
            }

            C1PrintDocument doc = this.c1PrintPreviewControl1.Document as C1PrintDocument;
            if (doc == null)
            {
                return;
            }


            _roUnderMouse   = null;
            _outlinePageIdx = loc.PageIndex;
            _outlineRc      = new RectangleD(
                Utils.ConvertUnits(loc.Bounds.X, loc.Units, UnitTypeEnum.Pixel, loc.Dpi, this.c1PrintPreviewControl1.PreviewPane.DpiX),
                Utils.ConvertUnits(loc.Bounds.Y, loc.Units, UnitTypeEnum.Pixel, loc.Dpi, this.c1PrintPreviewControl1.PreviewPane.DpiY),
                Utils.ConvertUnits(loc.Bounds.Width, loc.Units, UnitTypeEnum.Pixel, loc.Dpi, this.c1PrintPreviewControl1.PreviewPane.DpiX),
                Utils.ConvertUnits(loc.Bounds.Height, loc.Units, UnitTypeEnum.Pixel, loc.Dpi, this.c1PrintPreviewControl1.PreviewPane.DpiY));

            this.c1PrintPreviewControl1.PreviewPane.Invalidate();
#endif
        }
Ejemplo n.º 18
0
        public void can_iterate_through_an_outline_node()
        {
            OutlineNode outlineNode = nodeFor("Embedded/Embeds");

            outlineNode.Descendents.Each(x => Debug.WriteLine(x.Description()));
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Fills a C1MultiDocument or a C1PrintDocument passed to it with listings of
        /// all files in the specified directory and its subdirectories matching the specified mask.
        /// </summary>
        /// <param name="theDoc">A C1MultiDocument or a C1PrintDocument.</param>
        /// <param name="dir">Directory containing the files to list.</param>
        /// <param name="mask">The files mask (e.g. "*.cs").</param>
        /// <param name="pf">Progress form.</param>
        public void MakeMultiDocument(object theDoc, string dir, string mask, ProgressForm pf)
        {
            // Find out what kind of document we're creating:
            _mdoc = theDoc as C1MultiDocument;
            _sdoc = theDoc as C1PrintDocument;
            if (_mdoc == null && _sdoc == null)
            {
                throw new Exception("Unsupported document type.");
            }

            _dir  = Path.GetFullPath(dir);
            _mask = mask;

            // Set up the document:
            if (_mdoc != null)
            {
                _mdoc.Clear();
                _mdoc.DoEvents = true;
            }
            else
            {
                _sdoc.Clear();
                _sdoc.DoEvents = true;
                SetupDoc(_sdoc);
            }

            // Show initial progress:
            pf.SetProgress(string.Format("Reading {0}...", _dir), 0);

            // For progress indicator only - get the list of all subdirectories:
            // long allDirsCount = Directory.GetDirectories(_dir, "*", SearchOption.AllDirectories).LongLength;
            // long allDirsIdx = 0;

            // Create TOC render object that will list directories and files:
            RenderToc toc = new RenderToc();

            // Add a TOC directory entry in "directory added" event:
            DirAdded += (doc, dirRo, dirName, level) =>
            {
                C1Anchor aDir = new C1Anchor(string.Format("d{0}", dirName.GetHashCode()));
                dirRo.Anchors.Add(aDir);

                // Add a TOC item for the directory (full name for root dir, own name for subdirs):
                string        tocName = dirName == _dir ? dirName : Path.GetFileName(dirName);
                RenderTocItem rti     = toc.AddItem(tocName, new C1Hyperlink(new C1LinkTargetAnchor(aDir.Name)), level);
                // Bold directory TOC entries:
                rti.Style.FontBold = true;
                // duplicate TOC entry in OUTLINE:
                OutlineNode outlineNode = new OutlineNode(dirName, dirRo);
                doc.Outlines.Add(outlineNode); // in this mode, all directory nodes are top-level

                // update overall progress:
                pf.SetProgress(string.Format("Reading {0}...", dirName));
                if (pf.Cancelled)
                {
                    throw new Exception("Directory scan aborted.");
                }

                return(outlineNode);
            };

            // Add a TOC file entry in "file added" event:
            FileAdded += (doc, dirOutlineNode, fileRo, fileName, level) =>
            {
                C1Anchor aFile = new C1Anchor(string.Format("f{0}", fileName.GetHashCode()));
                fileRo.Anchors.Add(aFile);
                string tocItemName = Path.GetFileName(fileName);
                toc.AddItem(tocItemName, new C1Hyperlink(new C1LinkTargetAnchor(aFile.Name)), level);
                // duplicate TOC entry in OUTLINE:
                if (dirOutlineNode == null)
                {
                    doc.Outlines.Add(tocItemName, fileRo); // top-level entry
                }
                else
                {
                    dirOutlineNode.Children.Add(tocItemName, fileRo); // nested entry
                }
            };

            // Create the common index:
            RenderIndex index = new RenderIndex();
            // Init keywords:
            Dictionary <string, IndexEntry> indexEntries = new Dictionary <string, IndexEntry>();

            // For this sample, we will build an index of all KnownColor names:
            string[] colorNames = Enum.GetNames(typeof(KnownColor));
            foreach (string keyword in colorNames)
            {
                indexEntries.Add(keyword, new IndexEntry(keyword));
            }

            // Add an index entry for each key word in line:
            LineAdded += (lineRo, fileName, line, lineNo) =>
            {
                var      words = line.Split(s_delims, StringSplitOptions.RemoveEmptyEntries);
                C1Anchor a     = null;
                foreach (string word in words)
                {
                    if (indexEntries.ContainsKey(word))
                    {
                        if (a == null)
                        {
                            a = new C1Anchor(string.Format("k{0}{1}", fileName.GetHashCode(), lineNo));
                            lineRo.Anchors.Add(a);
                        }
                        indexEntries[word].Occurrences.Add(new IndexEntryOccurrence(new C1LinkTargetAnchor(a.Name)));
                    }
                }
            };


            // Add listings of files to the document:
            ListDir(_dir, 1);

            // insert TOC at the top:
            RenderText tocHeader = new RenderText("Table of Contents");

            tocHeader.Style.Spacing.Bottom = "3mm";
            tocHeader.Style.TextAlignHorz  = AlignHorzEnum.Center;
            tocHeader.Style.FontSize       = 12;
            tocHeader.Style.FontBold       = true;
            if (_mdoc != null)
            {
                C1PrintDocument docToc = new C1PrintDocument();
                docToc.Body.Children.Add(tocHeader);
                docToc.Body.Children.Add(toc);
                _mdoc.Items.Insert(0, docToc);
                docToc = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            else
            {
                toc.BreakAfter = BreakEnum.Page;
                _sdoc.Body.Children.Insert(0, toc);
                _sdoc.Body.Children.Insert(0, tocHeader);
            }

            // insert word index at the bottom:
            RenderText indexHeader = new RenderText("Index of Known Colors");

            indexHeader.Style.Spacing.Bottom = "3mm";
            indexHeader.Style.TextAlignHorz  = AlignHorzEnum.Center;
            indexHeader.Style.FontSize       = 12;
            indexHeader.Style.FontBold       = true;
            index.HeadingStyle.FontSize     += 1;
            index.HeadingStyle.FontBold      = true;
            index.HeadingStyle.Padding.All   = "2mm";
            // add index entries that have some occurrences:
            foreach (IndexEntry ie in indexEntries.Values)
            {
                if (ie.HasOccurrences)
                {
                    index.Entries.Add(ie);
                }
            }
            if (_mdoc != null)
            {
                C1PrintDocument docIndex = new C1PrintDocument();
                docIndex.Body.Children.Add(indexHeader);
                docIndex.Body.Children.Add(index);
                _mdoc.Items.Add(docIndex);
                docIndex = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
            else
            {
                indexHeader.BreakBefore = BreakEnum.Page;
                _sdoc.Body.Children.Add(indexHeader);
                _sdoc.Body.Children.Add(index);
            }

            // we're done!
            pf.SetProgress(string.Format("Reading {0}...", _dir), 1);
        }
Ejemplo n.º 20
0
        public void CreatePDF(Stream stream)
        {
            var doc = new GcPdfDocument();

            var page1 = doc.NewPage();
            var page2 = doc.NewPage();
            var page3 = doc.NewPage();

            var mainNote = Util.AddNote(
                "This is page 1.\n\n\n" +
                "Demo of various destination types.\n\n" +
                "Destinations attached to nodes in the document's outline tree:\n" +
                "  - Page 1: goes to this page, fits whole page\n" +
                "  - Page 2: goes to page 2, fits whole page\n" +
                "    -- Note 2, zoom 200%: goes to note 2 on page 2, zooms to 200%\n" +
                "    -- Zoom 100%: zooms to whole page 2\n" +
                "    -- Back to page 1: goes back to this page\n" +
                "  - Page 3: goes to page 3, fits whole page\n" +
                "    -- Zoom to note on page 3: zooms to whole note on page 3\n" +
                "    -- Back to page 1: goes back to this page\n" +
                "  - Named destinations: keyed by names in NamedDestinations dictionary:\n" +
                "    -- page1\n" +
                "    -- page2\n" +
                "    -- page3\n\n" +
                "Destinations associated with areas in the document body:",
                page1);

            Util.AddNote(
                "This is page 2.",
                page2);
            var noteOnPage2 = Util.AddNote(
                "Note 2 on page 2.",
                page2, new RectangleF(300, 400, 200, 300));

            Util.AddNote(
                "This is page 3",
                page3);
            var noteOnPage3 = Util.AddNote(
                "This is a somewhat longer\n(even though not really long)\nnote on page 3.",
                page3, new RectangleF(200, 440, 200, 300));

            // Destinations in the outline tree:

            // DestinationFit: fits whole page:
            OutlineNode on1 = new OutlineNode("Page 1", new DestinationFit(0));

            doc.Outlines.Add(on1);

            OutlineNode on2 = new OutlineNode("Page 2", new DestinationFit(1));

            doc.Outlines.Add(on2);
            // DestinationXYZ: allows to specify top/left coordinates and the zoom level (1 is 100%):
            on2.Children.Add(new OutlineNode("Note 2, zoom 200%", new DestinationXYZ(1, noteOnPage2.X, noteOnPage2.Y, 2)));
            on2.Children.Add(new OutlineNode("Zoom 100%", new DestinationXYZ(1, null, null, 1)));
            // Add a link back to page 1:
            on2.Children.Add(new OutlineNode("Back to page 1", new DestinationFit(0)));

            OutlineNode on3 = new OutlineNode("Page 3", new DestinationFit(2));

            doc.Outlines.Add(on3);
            // DestinationFitR: fits a rectangle on page:
            on3.Children.Add(new OutlineNode("Zoom to note on page 3", new DestinationFitR(2, noteOnPage3)));
            // Add links back to page 1 & 2:
            on3.Children.Add(new OutlineNode("Go to page 2", new DestinationFit(1)));
            on3.Children.Add(new OutlineNode("Go to page 1", new DestinationFit(0)));

            // Destinations in the document body (reusing destinations from the outlines):
            // Go to page 2:
            var rc = Util.AddNote("Go to page 2", page1, new RectangleF(72, mainNote.Bottom + 18, 200, 72));

            page1.Annotations.Add(new LinkAnnotation(rc, on2.Dest));
            // Go to page 3:
            rc = Util.AddNote("Go to page 3", page1, new RectangleF(72, rc.Bottom + 18, 200, 72));
            page1.Annotations.Add(new LinkAnnotation(rc, on3.Dest));

            // Destinations can also be named and added to the document's NamedDestinations dictionary.
            doc.NamedDestinations.Add("page1", new DestinationFit(0));
            doc.NamedDestinations.Add("page2", new DestinationFit(1));
            doc.NamedDestinations.Add("page3", new DestinationFit(2));
            // Then they can be referenced using DestinationRef class, here we add them to the outline:
            OutlineNode onNamed = new OutlineNode("Named destinations", (DestinationBase)null);

            doc.Outlines.Add(onNamed);
            onNamed.Children.Add(new OutlineNode("Named: page1", new DestinationRef("page1")));
            onNamed.Children.Add(new OutlineNode("Named: page2", new DestinationRef("page2")));
            onNamed.Children.Add(new OutlineNode("Named: page3", new DestinationRef("page3")));

            // Done:
            doc.Save(stream);
        }
Ejemplo n.º 21
0
        protected override void LoadInternal(OpenedFile file, System.IO.Stream stream)
        {
            wasChangedInDesigner = false;
            Debug.Assert(file == this.PrimaryFile);
            SD.AnalyticsMonitor.TrackFeature(typeof(WpfViewContent), "Load");

            _stream = new MemoryStream();
            stream.CopyTo(_stream);
            stream.Position = 0;

            if (designer == null)
            {
                // initialize designer on first load
                designer         = new DesignSurface();
                this.UserContent = designer;
                InitPropertyEditor();
                InitWpfToolbox();
            }
            this.UserContent = designer;
            if (outline != null)
            {
                outline.Root = null;
            }


            using (XmlTextReader r = new XmlTextReader(stream)) {
                XamlLoadSettings settings = new XamlLoadSettings();
                settings.DesignerAssemblies.Add(typeof(WpfViewContent).Assembly);
                settings.CustomServiceRegisterFunctions.Add(
                    delegate(XamlDesignContext context) {
                    context.Services.AddService(typeof(IUriContext), new FileUriContext(this.PrimaryFile));
                    context.Services.AddService(typeof(IPropertyDescriptionService), new PropertyDescriptionService(this.PrimaryFile));
                    context.Services.AddService(typeof(IEventHandlerService), new SharpDevelopEventHandlerService(this));
                    context.Services.AddService(typeof(ITopLevelWindowService), new WpfAndWinFormsTopLevelWindowService());
                    context.Services.AddService(typeof(ChooseClassServiceBase), new IdeChooseClassService());
                });
                settings.TypeFinder = MyTypeFinder.Create(this.PrimaryFile);
                try {
                    settings.ReportErrors = UpdateTasks;
                    designer.LoadDesigner(r, settings);

                    designer.DesignPanel.ContextMenuHandler = (contextMenu) => {
                        var newContextmenu     = new ContextMenu();
                        var sdContextMenuItems = MenuService.CreateMenuItems(newContextmenu, designer, "/AddIns/WpfDesign/Designer/ContextMenu", "ContextMenu");
                        foreach (var entry in sdContextMenuItems)
                        {
                            newContextmenu.Items.Add(entry);
                        }
                        newContextmenu.Items.Add(new Separator());

                        var items = contextMenu.Items.Cast <Object>().ToList();
                        contextMenu.Items.Clear();
                        foreach (var entry in items)
                        {
                            newContextmenu.Items.Add(entry);
                        }

                        designer.DesignPanel.ContextMenu = newContextmenu;
                    };

                    if (outline != null && designer.DesignContext != null && designer.DesignContext.RootItem != null)
                    {
                        outline.Root = OutlineNode.Create(designer.DesignContext.RootItem);
                    }

                    propertyGridView.PropertyGrid.SelectedItems = null;
                    designer.DesignContext.Services.Selection.SelectionChanged += OnSelectionChanged;
                    designer.DesignContext.Services.GetService <UndoService>().UndoStackChanged += OnUndoStackChanged;
                } catch (Exception e) {
                    this.UserContent = new WpfDocumentError(e);
                }

                try{
                    var appXaml = SD.ProjectService.CurrentProject.Items.FirstOrDefault(x => x.FileName.GetFileName().ToLower() == ("app.xaml"));
                    if (appXaml != null)
                    {
                        var        f = appXaml as FileProjectItem;
                        OpenedFile a = SD.FileService.GetOrCreateOpenedFile(f.FileName);

                        var xml = XmlReader.Create(a.OpenRead());
                        var doc = new XmlDocument();
                        doc.Load(xml);
                        var node = doc.FirstChild.ChildNodes.Cast <XmlNode>().FirstOrDefault(x => x.Name == "Application.Resources");

                        foreach (XmlAttribute att in doc.FirstChild.Attributes.Cast <XmlAttribute>().ToList())
                        {
                            if (att.Name.StartsWith("xmlns"))
                            {
                                node.Attributes.Append(att);
                            }
                        }

                        var appXamlXml = XmlReader.Create(new StringReader(node.InnerXml));
                        var parsed     = XamlParser.Parse(appXamlXml, ((XamlDesignContext)designer.DesignContext).ParserSettings);
                        var dict       = (ResourceDictionary)parsed.RootInstance;
                        designer.DesignPanel.Resources.MergedDictionaries.Add(dict);
                    }
                } catch (Exception ex) {
                    LoggingService.Error("Error in loading app.xaml", ex);
                }
            }
        }
 public void Intialize()
 {
     _grid    = CreateGridContextWithDesignSurface("<Button/><StackPanel><Button/></StackPanel>");
     _outline = OutlineNode.Create(_grid);
     Assert.IsNotNull(_outline);
 }
Ejemplo n.º 23
0
 void SelectNode(OutlineNode n)
 {
     EditorSelect(n.Location);
 }