Esempio n. 1
0
        private void ContextMenuNewPageClick(object sender, EventArgs e)
        {
            ToolStripMenuItem menuItem = sender as ToolStripMenuItem;

            if (menuItem != null)
            {
                Store store = base.DocData.Store;
                using (Transaction t = store.TransactionManager.BeginTransaction(menuItem.Text.Replace("&", string.Empty)))
                {
                    object[] itemInfo;
                    if (null != (itemInfo = menuItem.Tag as object[]))
                    {
                        DomainClassInfo             diagramInfo = (DomainClassInfo)itemInfo[1];
                        DiagramMenuDisplayAttribute attribute   = (DiagramMenuDisplayAttribute)itemInfo[0];
                        IDiagramInitialization      initializer = attribute.CreateInitializer(diagramInfo.ImplementationClass);
                        Diagram newDiagram = (Diagram)store.ElementFactory.CreateElement(diagramInfo);
                        if (initializer != null)
                        {
                            initializer.InitializeDiagram(newDiagram);
                        }
                        Diagram        selectedDiagram;
                        DiagramDisplay displayContainer;
                        LinkedElementCollection <Diagram> diagramOrder;
                        int selectedDiagramIndex;
                        if (null != (selectedDiagram = ContextMenuStrip.SelectedDiagram) &&
                            null != store.FindDomainModel(DiagramDisplayDomainModel.DomainModelId) &&
                            null != (displayContainer = DiagramDisplayHasDiagramOrder.GetDiagramDisplay(selectedDiagram)) &&
                            (selectedDiagramIndex = (diagramOrder = displayContainer.OrderedDiagramCollection).IndexOf(selectedDiagram)) < (diagramOrder.Count - 1))
                        {
                            // Add the page immediately after the selected diagram, unless we're already at the end, in which
                            // case we leave it to the rules to add in the correct place
                            diagramOrder.Insert(selectedDiagramIndex + 1, newDiagram);
                        }
                        t.Commit();
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// See <see cref="ModelingDocView.LoadView"/>.
        /// </summary>
        protected override bool LoadView()
        {
            if (base.LoadView())
            {
                ORMDesignerDocData document = (ORMDesignerDocData)this.DocData;
                #region Setup context menu
                ContextMenuStrip contextMenu = base.ContextMenuStrip = new MultiDiagramContextMenuStrip();
                contextMenu.ShowImageMargin = false;
                contextMenu.Opening        += ContextMenuOpening;
                ToolStripMenuItem newPageMenuItem    = new ToolStripMenuItem(ResourceStrings.DiagramCommandNewPage);
                ToolStripMenuItem deletePageMenuItem = new ToolStripMenuItem(ResourceStrings.DiagramCommandDeletePage);
                ToolStripMenuItem renamePageMenuItem = new ToolStripMenuItem(ResourceStrings.DiagramCommandRenamePage);
                newPageMenuItem.DropDown = new ToolStripDropDown();
                ToolStripItemCollection items = newPageMenuItem.DropDownItems;

                ReadOnlyCollection <DomainClassInfo> diagrams = document.Store.DomainDataDirectory.FindDomainClass(Diagram.DomainClassId).AllDescendants;
                int diagramCount = diagrams.Count;
                for (int i = 0; i < diagramCount; ++i)
                {
                    DomainClassInfo diagramInfo = diagrams[i];
                    object[]        attributes  = diagramInfo.ImplementationClass.GetCustomAttributes(typeof(DiagramMenuDisplayAttribute), false);
                    if (attributes.Length > 0)
                    {
                        DiagramMenuDisplayAttribute attribute = (DiagramMenuDisplayAttribute)attributes[0];
                        Image  image = attribute.TabImage;
                        string name  = attribute.DisplayName;
                        if (string.IsNullOrEmpty(name))
                        {
                            name = diagramInfo.DisplayName;
                        }
                        if (image != null)
                        {
                            base.RegisterImageForDiagramType(diagramInfo.ImplementationClass, image);
                        }
                        ToolStripMenuItem newDiagramMenuItem = new ToolStripMenuItem(name, image, ContextMenuNewPageClick);
                        newDiagramMenuItem.Tag = new object[] { attribute, diagramInfo };
                        items.Add(newDiagramMenuItem);
                    }
                }
                newPageMenuItem.Name = ResourceStrings.DiagramCommandNewPage;
                newPageMenuItem.DropDown.ImageScalingSize = DiagramImageSize;

                deletePageMenuItem.Name   = ResourceStrings.DiagramCommandDeletePage;
                deletePageMenuItem.Click += ContextMenuDeletePageClick;
                deletePageMenuItem.Tag    = ContextMenuItemNeedsSelectedTab;

                renamePageMenuItem.Name   = ResourceStrings.DiagramCommandRenamePage;
                renamePageMenuItem.Click += ContextMenuRenamePageClick;
                renamePageMenuItem.Tag    = ContextMenuItemNeedsSelectedTab;

                if (null != Store.FindDomainModel(DiagramDisplayDomainModel.DomainModelId))
                {
                    ToolStripMenuItem reorderPagesMenuItem = new ToolStripMenuItem(ResourceStrings.DiagramCommandReorderPages);
                    reorderPagesMenuItem.Name   = ResourceStrings.DiagramCommandReorderPages;
                    reorderPagesMenuItem.Click += ContextMenuPageOrderClick;

                    contextMenu.Items.AddRange(new ToolStripItem[] { newPageMenuItem, reorderPagesMenuItem, new ToolStripSeparator(), deletePageMenuItem, renamePageMenuItem });
                }
                else
                {
                    contextMenu.Items.AddRange(new ToolStripItem[] { newPageMenuItem, new ToolStripSeparator(), deletePageMenuItem, renamePageMenuItem });
                }
                #endregion                 // Setup context menu

                Store store = document.Store;
                // Add our existing diagrams. If we have the diagram display model extension turned on
                // for this designer, then we will always have an ordered set of diagrams at this point.
                if (null != (store.FindDomainModel(DiagramDisplayDomainModel.DomainModelId)))
                {
                    ReadOnlyCollection <DiagramDisplay> diagramDisplayElements = store.ElementDirectory.FindElements <DiagramDisplay>(false);
                    if (diagramDisplayElements.Count != 0)
                    {
                        IList <DiagramDisplayHasDiagramOrder> existingDiagramLinks = DiagramDisplayHasDiagramOrder.GetLinksToOrderedDiagramCollection(diagramDisplayElements[0]);
                        int existingDiagramsCount = existingDiagramLinks.Count;
                        if (existingDiagramsCount != 0)
                        {
                            Partition defaultPartition = store.DefaultPartition;
                            for (int i = 0; i < existingDiagramsCount; ++i)
                            {
                                DiagramDisplayHasDiagramOrder link = existingDiagramLinks[i];
                                Diagram existingDiagram            = link.Diagram;
                                if (existingDiagram.Partition == defaultPartition)
                                {
                                    // The fixup listeners guarantee that there is exactly one active diagram,
                                    // so we can safely trust the property to get an active diagram
                                    base.AddDiagram(existingDiagram, link.IsActiveDiagram);
                                }
                            }
                        }
                    }
                }
                else
                {
                    // Add our existing diagrams
                    ReadOnlyCollection <Diagram> existingDiagrams = store.ElementDirectory.FindElements <Diagram>(true);
                    int existingDiagramsCount = existingDiagrams.Count;
                    if (existingDiagramsCount != 0)
                    {
                        bool      seenDiagram      = false;
                        Partition defaultPartition = store.DefaultPartition;
                        for (int i = 0; i < existingDiagramsCount; ++i)
                        {
                            Diagram existingDiagram = existingDiagrams[i];
                            if (existingDiagram.Partition == defaultPartition)
                            {
                                // Make the first diagram be selected
                                base.AddDiagram(existingDiagram, !seenDiagram);
                                seenDiagram = true;
                            }
                        }
                    }
                }

                // Make sure we get a closing notification so we can clear the
                // selected components
                document.DocumentClosing += new EventHandler(DocumentClosing);
                return(true);
            }
            return(false);
        }
Esempio n. 3
0
        private void ContextMenuOpening(object sender, EventArgs e)
        {
            MultiDiagramContextMenuStrip contextMenu = ContextMenuStrip;
            ToolStripItemCollection      menuItems   = contextMenu.Items;
            Diagram diagram         = contextMenu.SelectedDiagram;
            bool    haveSelectedTab = diagram != null;

            foreach (ToolStripItem item in menuItems)
            {
                if (item.Tag == ContextMenuItemNeedsSelectedTab)
                {
                    item.Enabled = haveSelectedTab;
                }
            }

            Partition partition = this.DocData.Store.DefaultPartition;

            //Disable/Enable New Diagram Tabs stuff wow
            ToolStripDropDownItem   newPageMenuItem = (ToolStripDropDownItem)menuItems[ResourceStrings.DiagramCommandNewPage];
            ToolStripItemCollection items           = newPageMenuItem.DropDownItems;
            int itemCount = items.Count;

            for (int i = 0; i < itemCount; i++)
            {
                object[]        itemInfo    = (object[])items[i].Tag;
                DomainClassInfo diagramInfo = (DomainClassInfo)itemInfo[1];
                ReadOnlyCollection <ModelElement> modelElements = partition.ElementDirectory.FindElements(diagramInfo);
                DiagramMenuDisplayAttribute       attribute     = (DiagramMenuDisplayAttribute)itemInfo[0];
                if (modelElements.Count > 0 & (attribute.DiagramOption & DiagramMenuDisplayOptions.AllowMultiple) == 0)
                {
                    //DISABLE NEW
                    items[i].Enabled = false;
                }
                else
                {
                    //ENABLE NEW
                    items[i].Enabled = true;
                }
            }

            // Disable page reordering if there is only one page
            string reorderKey = ResourceStrings.DiagramCommandReorderPages;

            if (menuItems.ContainsKey(reorderKey))
            {
                menuItems[reorderKey].Enabled = HasMultiplePages;
            }


            //If a diagram tab is selected
            if (diagram != null)
            {
                //Retrieve all existing diagrams of the same type as the one selected
                ReadOnlyCollection <ModelElement> modelElements = partition.ElementDirectory.FindElements(diagram.GetDomainClass(), true);
                DomainClassInfo diagramInfo = diagram.GetDomainClass();

                //Grab the attribute of the diagram type selected
                object[] attributes = diagramInfo.ImplementationClass.GetCustomAttributes(typeof(DiagramMenuDisplayAttribute), false);
                if (attributes.Length > 0)
                {
                    DiagramMenuDisplayAttribute attribute = (DiagramMenuDisplayAttribute)attributes[0];
                    //If required but you only have 1 then disable delete
                    if ((attribute.DiagramOption & DiagramMenuDisplayOptions.Required) != 0 && modelElements.Count <= 1)
                    {
                        //DISABLE DELETE
                        ToolStripMenuItem deletePageMenuItem = (ToolStripMenuItem)menuItems[ResourceStrings.DiagramCommandDeletePage];
                        deletePageMenuItem.Enabled = false;
                    }
                    else
                    {
                        //ALLOW DELETE
                        ToolStripMenuItem deletePageMenuItem = (ToolStripMenuItem)menuItems[ResourceStrings.DiagramCommandDeletePage];
                        deletePageMenuItem.Enabled = true;
                    }

                    if ((attribute.DiagramOption & DiagramMenuDisplayOptions.BlockRename) != 0)
                    {
                        //DISABLE RENAME
                        ToolStripMenuItem renamePageMenuItem = (ToolStripMenuItem)menuItems[ResourceStrings.DiagramCommandRenamePage];
                        renamePageMenuItem.Enabled = false;
                    }
                    else
                    {
                        //ALLOW RENAME
                        ToolStripMenuItem renamePageMenuItem = (ToolStripMenuItem)menuItems[ResourceStrings.DiagramCommandRenamePage];
                        renamePageMenuItem.Enabled = true;
                    }
                }
            }
        }