예제 #1
0
		public static void ShowDialog(IServiceProvider serviceProvider, ORMDesignerDocData docData)
		{
			ExtensionManager extensionManager = new ExtensionManager(docData.Store);
			IWin32Window dialogOwner = Utility.GetDialogOwnerWindow(serviceProvider);
			if (extensionManager.ShowDialog(dialogOwner) == DialogResult.OK)
			{
				// TODO: Prompt the user to make sure they really want us to start deleting stuff...

				ListView.CheckedListViewItemCollection checkedItems = extensionManager.lvExtensions.CheckedItems;
				ExtensionLoader extensionLoader = ORMDesignerPackage.ExtensionLoader;
				IDictionary<string, ExtensionModelBinding> availableExtensions = extensionLoader.AvailableCustomExtensions;
				Dictionary<string, ExtensionModelBinding> checkedTypes = new Dictionary<string, ExtensionModelBinding>(availableExtensions.Count);
				foreach (ListViewItem listViewItem in checkedItems)
				{
					string extensionNamespace = (string)listViewItem.Tag;
					checkedTypes.Add(extensionNamespace, availableExtensions[extensionNamespace]);
				}

				// Make sure all required extensions are turned on. This will turn previously ignored
				// secondary extensions back on.
				extensionLoader.VerifyRequiredExtensions(ref checkedTypes);

				Stream currentStream = null;
				Stream newStream = null;
				try
				{
					Object streamObj;
					(docData as EnvDTE.IExtensibleObject).GetAutomationObject("ORMXmlStream", null, out streamObj);
					currentStream = streamObj as Stream;

					Debug.Assert(currentStream != null);

					newStream = ExtensionLoader.CleanupStream(currentStream, extensionLoader.StandardDomainModels, checkedTypes.Values, null);
					docData.ReloadFromStream(newStream, currentStream);
				}
				finally
				{
					if (currentStream != null)
					{
						currentStream.Dispose();
					}
					if (newStream != null)
					{
						newStream.Dispose();
					}
				}
			}
		}
예제 #2
0
        /// <summary>
        /// Loads the SurveyTreeControl from the current document
        /// </summary>
        protected void LoadWindow()
        {
            ToolWindowDiagramView diagramView    = myDiagramView;
            LinkLabel             watermarkLabel = myWatermarkLabel;

            if (diagramView == null)
            {
                ContainerControl container = new ContainerControl();
                myDiagramView = diagramView = new ToolWindowDiagramView(this);
                diagramView.DiagramClientView.DiagramDisassociating += new EventHandler(DiagramDisassociatingEvent);
                myWatermarkLabel                       = watermarkLabel = new SafeLinkLabel();
                watermarkLabel.Dock                    = DockStyle.Fill;
                watermarkLabel.Site                    = diagramView.Site;
                watermarkLabel.TextAlign               = ContentAlignment.MiddleCenter;
                watermarkLabel.BackColor               = SystemColors.ControlLight;
                watermarkLabel.ForeColor               = SystemColors.ControlText;
                watermarkLabel.LinkClicked            += new LinkLabelLinkClickedEventHandler(WatermarkLinkClicked);
                container.Site                         = diagramView.Site;
                diagramView.BackColor                  = SystemColors.Window;
                diagramView.Dock                       = DockStyle.Fill;
                diagramView.ContextMenuRequestedEvent += new EventHandler <DiagramMouseEventArgs>(this.DesignerContextMenuRequested);
                diagramView.Visible                    = false;
                DiagramClientView clientView = diagramView.DiagramClientView;
                clientView.ZoomChanged        += new ZoomChangedEventHandler(this.DesignerZoomChanged);
                clientView.TakeFocusOnDragOver = true;
                container.SuspendLayout();
                container.Controls.Add(diagramView);
                container.Controls.Add(watermarkLabel);
                container.ResumeLayout();
                Guid commandSetId = typeof(ORMDesignerEditorFactory).GUID;
                Frame.SetGuidProperty((int)__VSFPROPID.VSFPROPID_InheritKeyBindings, ref commandSetId);
            }
            ORMDesignerDocData currentDocument = this.CurrentDocument;
            Store newStore = (currentDocument != null) ? currentDocument.Store : null;
            Store oldStore = myStore;

            if (oldStore != newStore)
            {
                myDiagramSetChanged = true;
                myStore             = newStore;
                AdjustVisibility(false, false);
            }
        }
예제 #3
0
 /// <summary>
 /// Refresh all visible diagrams
 /// </summary>
 /// <param name="serviceProvider">Required <see cref="IServiceProvider"/></param>
 /// <param name="docData">A specific <see cref="ORMDesignerDocData"/></param>
 public static void InvalidateAllDiagrams(IServiceProvider serviceProvider, ORMDesignerDocData docData)
 {
     OptionsPage.NotifySettingsChange(
         serviceProvider,
         delegate(ORMDesignerDocData docData2)
     {
         if (docData == docData2)
         {
             foreach (ORMDesignerDocView docView in docData2.DocViews)
             {
                 VSDiagramView view;
                 if (null != (view = docView.CurrentDesigner) &&
                     null != view.DiagramClientView)
                 {
                     view.Invalidate(true);
                 }
             }
         }
     });
 }
        private void LoadWindow()
        {
            ReferenceModeViewForm form = myForm;

            if (form == null)
            {
                return;
            }
            ORMDesignerDocData docData = CurrentDocument;
            Store store;
            ReadOnlyCollection <ORMModel> models;

            if (docData != null &&
                null != (store = docData.Store) &&
                0 != (models = store.ElementDirectory.FindElements <ORMModel>()).Count)
            {
                form.SetModel(models[0]);
            }
            else
            {
                form.SetModel(null);
            }
        }
예제 #5
0
        /// <summary>
        /// This is called by the package base class when our package is loaded. When devenv is run
        /// with the "/setup" command line switch it is not able to do a lot of the normal things,
        /// such as creating output windows and tool windows. Under normal circumstances our package
        /// isn't loaded when run with this switch. However, our package will be loaded when items
        /// are added to the toolbox, even when run with "/setup". To be safe we'll check for "setup"
        /// and we don't do anything interesting in MgdSetSite if we find it.
        /// </summary>
        protected sealed override void Initialize()
        {
            base.Initialize();

            // register the class designer editor factory
            RegisterEditorFactory(new ORMDesignerEditorFactory(this));

            if (!SetupMode)
            {
                ((IServiceContainer)this).AddService(typeof(ORMDesignerFontsAndColors), myFontAndColorService = new ORMDesignerFontsAndColors(this), true);

                FactEditorLanguageService managedLanguageService = new FactEditorLanguageService();
                managedLanguageService.SetSite(this);
                ((IServiceContainer)this).AddService(typeof(FactEditorLanguageService), managedLanguageService, true);

                // setup commands
                (myCommandSet = ORMDesignerDocView.CreateCommandSet(this)).Initialize();
                (vsCommandSet = ORMDesignerDocData.CreateVisualStudioCommandSet(this)).Initialize();

                // Create managed tool windows
                AddToolWindow(typeof(ORMModelBrowserToolWindow));
                AddToolWindow(typeof(ORMReadingEditorToolWindow));
                AddToolWindow(typeof(ORMReferenceModeEditorToolWindow));
                AddToolWindow(typeof(ORMSamplePopulationToolWindow));
                AddToolWindow(typeof(ORMVerbalizationToolWindow));
                AddToolWindow(typeof(ORMDescriptionToolWindow));
                AddToolWindow(typeof(ORMNotesToolWindow));
                AddToolWindow(typeof(ORMContextWindow));
                AddToolWindow(typeof(ORMDiagramSpyWindow));

                // Make sure our options are loaded from the registry
                GetDialogPage(typeof(OptionsPage));

                InitializeToolbox();
            }
        }
예제 #6
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);
        }
예제 #7
0
			/// <summary>
			/// Callback function for modifying a document when font
			/// and color changes are applied.
			/// </summary>
			/// <param name="docData">Currently running docdata</param>
			private static void ChangeDocumentFontAndColors(ORMDesignerDocData docData)
			{
				foreach (ORMDesignerDocView docView in docData.DocViews)
				{
					// UNDONE: This doesn't actually do anything right now. It triggers
					// RefreshResources on all of the loaded style sets, but this does
					// not re-retrieve the resources. The FCF_MUSTRESTART flags can be
					// removed when we find a way to actually trigger a change here.
					// 0x15 == WM_SYSCOLORCHANGE
					SendMessage(docView.CurrentDesigner.DiagramClientView.Handle, 0x15, IntPtr.Zero, IntPtr.Zero);
				}
			}
예제 #8
0
파일: ORMDocData.cs 프로젝트: cjheath/NORMA
			/// <summary>
			/// Create a new <see cref="ORMExtensionManagerAutomationObject"/> for the specific <paramref name="docData"/>
			/// </summary>
			/// <param name="docData">An <see cref="ORMDesignerDocData"/> instance</param>
			public ORMExtensionManagerAutomationObject(ORMDesignerDocData docData)
			{
				myDocData = docData;
			}
예제 #9
0
파일: ORMDocView.cs 프로젝트: cjheath/NORMA
		/// <summary>
		/// Refresh all visible diagrams
		/// </summary>
		/// <param name="serviceProvider">Required <see cref="IServiceProvider"/></param>
		/// <param name="docData">A specific <see cref="ORMDesignerDocData"/></param>
		public static void InvalidateAllDiagrams(IServiceProvider serviceProvider, ORMDesignerDocData docData)
		{
			OptionsPage.NotifySettingsChange(
				serviceProvider,
				delegate(ORMDesignerDocData docData2)
				{
					if (docData == docData2)
					{
						foreach (ORMDesignerDocView docView in docData2.DocViews)
						{
							VSDiagramView view;
							if (null != (view = docView.CurrentDesigner) &&
								null != view.DiagramClientView)
							{
								view.Invalidate(true);
							}
						}
					}
				});
		}
예제 #10
0
        public static void ShowDialog(IServiceProvider serviceProvider, ORMDesignerDocData docData)
        {
            ExtensionManager extensionManager = new ExtensionManager(docData.Store);
            IWin32Window     dialogOwner      = Utility.GetDialogOwnerWindow(serviceProvider);

            if (extensionManager.ShowDialog(dialogOwner) == DialogResult.OK)
            {
                // TODO: Prompt the user to make sure they really want us to start deleting stuff...

                ListView.CheckedListViewItemCollection checkedItems = extensionManager.lvExtensions.CheckedItems;
                ExtensionLoader extensionLoader = ORMDesignerPackage.ExtensionLoader;
                IDictionary <string, ExtensionModelBinding> availableExtensions = extensionLoader.AvailableCustomExtensions;
                Dictionary <string, ExtensionModelBinding>  checkedTypes        = new Dictionary <string, ExtensionModelBinding>(availableExtensions.Count);
                foreach (ListViewItem listViewItem in checkedItems)
                {
                    string extensionNamespace = (string)listViewItem.Tag;
                    checkedTypes.Add(extensionNamespace, availableExtensions[extensionNamespace]);
                }

                // Make sure all required extensions are turned on. This will turn previously ignored
                // secondary extensions back on.
                extensionLoader.VerifyRequiredExtensions(ref checkedTypes);

                Stream currentStream  = null;
                Stream newStream      = null;
                Stream modifiedStream = null;
                try
                {
                    Object streamObj;
                    EnvDTE.IExtensibleObject docDataExtender = (EnvDTE.IExtensibleObject)docData;
                    docDataExtender.GetAutomationObject("ORMXmlStream", null, out streamObj);
                    currentStream = streamObj as Stream;

                    Debug.Assert(currentStream != null);

                    // Allow each domain model that is being removed to run custom code immediately before the
                    // unload process.
                    Transaction customUnloadTransaction = null;
                    Store       store = docData.Store;
                    try
                    {
                        IDomainModelUnloading[] unloadingModels = ((IFrameworkServices)store).GetTypedDomainModelProviders <IDomainModelUnloading>();
                        if (unloadingModels != null)
                        {
                            for (int i = 0; i < unloadingModels.Length; ++i)
                            {
                                IDomainModelUnloading        unloadingModel = unloadingModels[i];
                                ICustomSerializedDomainModel serializedModel;
                                if (null != (serializedModel = unloadingModel as ICustomSerializedDomainModel))
                                {
                                    string[,] namespaceInfo = serializedModel.GetCustomElementNamespaces();
                                    int namespaceCount = namespaceInfo.GetLength(0);
                                    int j = 0;
                                    for (; j < namespaceCount; ++j)
                                    {
                                        if (checkedTypes.ContainsKey(namespaceInfo[j, 1]))
                                        {
                                            break;
                                        }
                                    }
                                    if (j == namespaceCount)
                                    {
                                        // Extension domain model is not in the pending set, go ahead and run
                                        // the custom code to unload it cleanly.
                                        if (customUnloadTransaction == null)
                                        {
                                            customUnloadTransaction = store.TransactionManager.BeginTransaction("Domain Models Unloading");                                             // String not localized, won't be displayed on either success or failure
                                        }
                                        unloadingModel.DomainModelUnloading(store);
                                    }
                                }
                            }
                        }
                    }
                    finally
                    {
                        if (customUnloadTransaction != null)
                        {
                            if (customUnloadTransaction.HasPendingChanges)
                            {
                                customUnloadTransaction.Commit();

                                // Get the modified stream
                                docDataExtender.GetAutomationObject("ORMXmlStream", null, out streamObj);
                                modifiedStream = streamObj as Stream;
                            }
                            customUnloadTransaction.Dispose();
                        }
                    }

                    newStream = ExtensionLoader.CleanupStream(modifiedStream ?? currentStream, extensionLoader.StandardDomainModels, checkedTypes.Values, null);
                    docData.ReloadFromStream(newStream, currentStream);
                }
                finally
                {
                    if (currentStream != null)
                    {
                        currentStream.Dispose();
                    }
                    if (modifiedStream != null)
                    {
                        currentStream.Dispose();
                    }
                    if (newStream != null)
                    {
                        newStream.Dispose();
                    }
                }
            }
        }