/// <summary>
		/// Do the bare minimum for use in tests
		/// </summary>
		/// <param name="configuration"></param>
		/// <param name="configurationPath"></param>
		protected override void LoadUIFromXmlDocument(XmlDocument configuration, string configurationPath)
		{
			m_windowConfigurationNode = configuration.SelectSingleNode("window");
			ReplaceControlAssemblies();

			PropertyTable.SetProperty("WindowConfiguration", m_windowConfigurationNode);
			PropertyTable.SetPropertyPersistence("WindowConfiguration", false);

			LoadDefaultProperties(m_windowConfigurationNode.SelectSingleNode("defaultProperties"));

			m_mediator.PropertyTable.SetProperty("window", this);
			m_mediator.PropertyTable.SetPropertyPersistence("window", false);

			CommandSet commandset = new CommandSet(m_mediator);
			commandset.Init(m_windowConfigurationNode);
			m_mediator.Initialize(commandset);

			LoadStringTableIfPresent(configurationPath);

			RestoreWindowSettings(false);
			m_mediator.AddColleague(this);

			m_menusChoiceGroupCollection = new ChoiceGroupCollection(m_mediator, null, m_windowConfigurationNode);
			m_sidebarChoiceGroupCollection = new ChoiceGroupCollection(m_mediator, null, m_windowConfigurationNode);
			m_toolbarsChoiceGroupCollection = new ChoiceGroupCollection(m_mediator, null, m_windowConfigurationNode);

			IntPtr handle = this.Handle; // create's a window handle for this form to allow processing broadcasted items.
		}
		private void SetupTestMediator()
		{
			m_mediator = new Mediator();
			m_mediator.PropertyTable.SetProperty("cache", Cache);
			m_testWindowConfig = SetupMinimalWindowConfig();
			var cmdSet = new CommandSet(m_mediator);
			cmdSet.Init(m_testWindowConfig);
			m_mediator.Initialize(cmdSet);
		}
Exemple #3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Load UI from an XML document
		/// </summary>
		/// <param name="configuration"></param>
		/// <param name="configurationPath"></param>
		/// ------------------------------------------------------------------------------------
		protected virtual void LoadUIFromXmlDocument(XmlDocument configuration, string configurationPath)
		{
			SuspendLayoutAll();

			bool wasCrashDuringPreviousStartup = File.Exists(CrashOnStartupDetectorPathName);
			if (!wasCrashDuringPreviousStartup)
			{
				// Create the crash detector file for next time.
				// Make sure the folder exists first.
				System.IO.Directory.CreateDirectory(CrashOnStartupDetectorPathName.Substring(0, CrashOnStartupDetectorPathName.LastIndexOf(Path.DirectorySeparatorChar)));
				using (System.IO.StreamWriter writer = System.IO.File.CreateText(CrashOnStartupDetectorPathName))
					writer.Close();
			}

			ErrorReporter.OkToInteractWithUser = !m_mediator.PropertyTable.GetBoolProperty("DoingAutomatedTest", false);
			m_windowConfigurationNode = configuration.SelectSingleNode("window");

			PropertyTable.SetProperty("WindowConfiguration", m_windowConfigurationNode);
			PropertyTable.SetPropertyPersistence("WindowConfiguration", false);

			SetApplicationName();

			//nb:some things might be sensitive to when this actually happens
			LoadDefaultProperties(m_windowConfigurationNode.SelectSingleNode("defaultProperties"));

			m_mediator.PropertyTable.SetProperty("window", this);
			m_mediator.PropertyTable.SetPropertyPersistence("window", false);

			LoadStringTableIfPresent(configurationPath);
			LoadResources(m_windowConfigurationNode.SelectSingleNode("resources"));

			//make the command set
			CommandSet commandset = new CommandSet(m_mediator);
			commandset.Init(m_windowConfigurationNode);
			m_mediator.Initialize(commandset);
			RestoreWindowSettings(wasCrashDuringPreviousStartup);
			Size restoreSize = Size;

			// Some of the listener initialization depends on PropertyTable initialization which
			// occurs in RestoreWindowSettings() above (e.g. LT-14150 re: 'sticky' spell checking).
			LoadListeners(m_windowConfigurationNode.SelectSingleNode("listeners"));

			// Note: This will throw an exception, if the Init method has already been called.
			// It is 'poor form' to try and add a colleague more than once,
			// even though we could cope with it.
			m_mediator.AddColleague(this);
			Assembly adaptorAssembly = GetAdapterAssembly();

			m_mediator.PropertyTable.SetProperty("uiAdapter", adaptorAssembly);
			m_mediator.PropertyTable.SetPropertyPersistence("uiAdapter", false);

			//add the menubar
			Control menubar;
			m_menusChoiceGroupCollection = MakeMajorUIPortion(
				adaptorAssembly,
				m_windowConfigurationNode,
				"menubar",
				"XCore.MenuAdapter",
				out menubar,
				out m_menuBarAdapter);

			if (menubar != null && menubar.Parent != null)
			{
				System.Windows.Forms.Control parent = menubar.Parent;
				if (parent.AccessibleName == null)
					parent.AccessibleName = "ParentOf" + menubar.AccessibleName;
			}

			//add the toolbar
			System.Windows.Forms.Control rebar;
			m_toolbarsChoiceGroupCollection = MakeMajorUIPortion(
				adaptorAssembly,
				m_windowConfigurationNode,
				"toolbars",
				"XCore.ReBarAdapter",
				out rebar,
				out m_rebarAdapter);

			if (rebar != null && rebar.Parent != null)
			{
				if (rebar.Parent.AccessibleName == null)
					rebar.Parent.AccessibleName = "ParentOf" + rebar.AccessibleName;
			}

			// Start of main layout.
			// Add the sidebar.
			m_sidebarChoiceGroupCollection = MakeMajorUIPortion(
				adaptorAssembly,
				m_windowConfigurationNode,
				"sidebar",
				"XCore.SidebarAdapter",
				out m_sidebar,
				out m_sidebarAdapter);
			m_sidebar.AccessibleName = "SideBar";
			// Remove m_sideBarPlaceholderPanel (a placeholder) and replace it with the real m_sidebar.
			m_sidebar.Dock = DockStyle.Fill;
			m_sidebar.TabStop = true;
			m_sidebar.TabIndex = 0;
			m_mainSplitContainer.FirstControl = m_sidebar;
			m_mainSplitContainer.Tag = "SidebarWidthGlobal";
			m_mainSplitContainer.Panel1MinSize = CollapsingSplitContainer.kCollapsedSize;
			m_mainSplitContainer.Panel1Collapsed = !Mediator.PropertyTable.GetBoolProperty("ShowSidebar", false); // Andy Black wants to collapse it for one of his XCore apps.
			m_mainSplitContainer.Panel2Collapsed = false; // Never collapse the main content control, plus optional record list.
			int sd = Mediator.PropertyTable.GetIntProperty("SidebarWidthGlobal", 140);
			if (!m_mainSplitContainer.Panel1Collapsed)
				SetSplitContainerDistance(m_mainSplitContainer, sd);
			if (m_sideBarPlaceholderPanel != null)
			{
				m_sideBarPlaceholderPanel.Dispose();
				m_sideBarPlaceholderPanel = null;
			}
			m_mainSplitContainer.FirstLabel = (string)Mediator.PropertyTable.GetValue("SidebarLabel");
			m_mainSplitContainer.SecondLabel = (string)Mediator.PropertyTable.GetValue("AllButSidebarLabel");

			// Maybe show the record list.
			m_recordBar.Dock = DockStyle.Fill;
			m_recordBar.TabStop = true;
			m_recordBar.TabIndex = 1;
			m_secondarySplitContainer.Panel1Collapsed = !Mediator.PropertyTable.GetBoolProperty("ShowRecordList", false);
			// Always show the main content control.
			m_secondarySplitContainer.Panel1MinSize = CollapsingSplitContainer.kCollapsedSize;
			m_secondarySplitContainer.Panel2Collapsed = false;
			m_secondarySplitContainer.Tag = "RecordListWidthGlobal";
			sd = Mediator.PropertyTable.GetIntProperty("RecordListWidthGlobal", 200);
			SetSplitContainerDistance(m_secondarySplitContainer, sd);
			m_secondarySplitContainer.FirstLabel = (string)Mediator.PropertyTable.GetValue("RecordListLabel");
			m_secondarySplitContainer.SecondLabel = (string)Mediator.PropertyTable.GetValue("MainContentLabel");
			// End of main layout.

			CreateStatusBar(m_windowConfigurationNode);

			// Add the content control
			// Note: We should be able to do it directly, since everything needed is in the default properties.
			SetInitialContentObject(m_windowConfigurationNode);
			m_sidebarAdapter.FinishInit();
			m_menuBarAdapter.FinishInit();

			// Some adapters modify the window size, so reset it to what was in the XML file.
			// Technically, this should assert that they are the same,
			// as it should now never call this code.
			if (restoreSize != Size)
			{
				// It will be the same as what is now in the file and the prop table,
				// so skip updating the table.
				m_persistWindowSize = false;
				Size = restoreSize;
				m_persistWindowSize = true;
			}

			if (File.Exists(CrashOnStartupDetectorPathName)) // Have to check again, because unit test check deletes it in the RestoreWindowSettings method.
				File.Delete(CrashOnStartupDetectorPathName);

			// this.ResumeLayout(); // Don't resume until after the maio content control is added.

			ClearRecordBarList();//sets up event handling
			ResumeLayoutAll();
		}