/// <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); }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Can be called more than once, but not run more than once. if (m_isDisposed) return; if (disposing) { // Dispose managed resources here. // Use a copy of the m_colleagues Set, // since the Dispose methods on the colleague should remove itself from m_colleagues, // which will cause an exception to be throw (list changed while spinning through it. Set<IxCoreColleague> copyOfColleagues = new Set<IxCoreColleague>(m_colleagues.ToArray()); m_colleagues.Clear(); // Just get rid of them now. foreach (IxCoreColleague icc in copyOfColleagues) { if (icc is IDisposable) { // Is the class marked with [XCore.MediatorDispose], // or is it in the temporary colleague holder? object[] attrs = icc.GetType().GetCustomAttributes(typeof(MediatorDisposeAttribute), true); if ((attrs != null && attrs.Length > 0) || m_temporaryColleague == icc) { (icc as IDisposable).Dispose(); } } } copyOfColleagues.Clear(); if (m_propertyTable != null) m_propertyTable.Dispose(); if (m_commandSet != null) m_commandSet.Dispose(); if (m_pathVariables != null) m_pathVariables.Clear(); if (m_disposedColleagues != null) m_disposedColleagues.Clear(); if (m_jobs != null) m_jobs.Clear(); if (m_pendingjobs != null) m_pendingjobs.Clear(); if (m_MethodsOnAnyColleague != null) m_MethodsOnAnyColleague.Clear(); m_idleQueue.Dispose(); } // Dispose unmanaged resources here, whether disposing is true or false. m_mainWndPtr = IntPtr.Zero; m_MethodsOnAnyColleague = null; m_pendingjobs = null; m_jobs = null; m_disposedColleagues = null; m_temporaryColleague = null; m_propertyTable = null; m_commandSet = null; m_colleagues = null; m_pathVariables = null; /* It is illegal to try to access managed stuff in this part of the Dispose method. #if DEBUG //DebugMsg("-- Number of calls to the InvokeRecursively method = " + m_invokeCount.ToString()); DebugMsg("-- Number of saved calls to Type.GetMethod = " + m_SavedCalls.ToString()); DebugMsg("-- Mediator MsgHash info: count=" + m_MethodsNOTonColleagues.Count + " mx depth=" + m_MethodsCount); DebugMsg("-- Mediator - Calls to check for method on colleague: " + m_MethodChecks); #endif */ m_isDisposed = true; base.Dispose(disposing); }
/// <summary> /// /// </summary> /// <remarks> this needs to be done separately from construction because the mediator is /// handed to the CommandSet when it is constructed.</remarks> /// <param name="commandset"></param> public void Initialize(CommandSet commandset) { CheckDisposed(); m_commandSet = commandset; }
/// ------------------------------------------------------------------------------------ /// <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(); }