Esempio n. 1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Constructor for FwApp
		/// </summary>
		/// <param name="fwManager">The FieldWorks manager for dealing with FieldWorks-level
		/// stuff.</param>
		/// <param name="helpTopicProvider">An application-specific help topic provider.</param>
		/// ------------------------------------------------------------------------------------
		protected FwApp(IFieldWorksManager fwManager, IHelpTopicProvider helpTopicProvider)
		{
			PictureHolder = new PictureHolder();
			m_fwManager = fwManager;
			m_helpTopicProvider = helpTopicProvider;
#if DEBUG
			m_debugProcs = new DebugProcs();
#endif
			m_registrySettings = new FwRegistrySettings(this);
			m_registrySettings.LatestAppStartupTime = DateTime.Now.ToUniversalTime().Ticks.ToString();
			m_registrySettings.AddErrorReportingInfo();

			Application.EnterThreadModal += Application_EnterThreadModal;
			Application.LeaveThreadModal += Application_LeaveThreadModal;

			Application.AddMessageFilter(this);
		}
Esempio n. 2
0
		/// <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 virtual void Dispose(bool disposing)
		{
			System.Diagnostics.Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** ");
			// Must not be run more than once.
			if (IsDisposed || BeingDisposed)
				return;
			BeingDisposed = true;

			if (disposing)
			{
			UpdateAppRuntimeCounter();

				Logger.WriteEvent("Disposing app: " + GetType().Name);
				RegistrySettings.FirstTimeAppHasBeenRun = false;

				// Dispose managed resources here.
				List<IFwMainWnd> mainWnds = new List<IFwMainWnd>(m_rgMainWindows); // Use another array, since m_rgMainWindows may change.
				m_rgMainWindows.Clear(); // In fact, just clear the main array, so the windows won't have to worry so much.
				foreach (IFwMainWnd mainWnd in mainWnds)
				{
					if (mainWnd is Form)
					{
						Form wnd = (Form)mainWnd;
						wnd.Closing -= OnClosingWindow;
						wnd.Closed -= OnWindowClosed;
						wnd.Activated -= fwMainWindow_Activated;
						wnd.HandleDestroyed -= fwMainWindow_HandleDestroyed;
						wnd.Dispose();
					}
					else if (mainWnd is IDisposable)
						((IDisposable)mainWnd).Dispose();
				}
				if (m_findReplaceDlg != null)
					m_findReplaceDlg.Dispose();
#if DEBUG
				if (m_debugProcs != null)
					m_debugProcs.Dispose();
#endif

				ResourceHelper.ShutdownHelper();

				if (m_registrySettings != null)
					m_registrySettings.Dispose();

				Application.EnterThreadModal -= Application_EnterThreadModal;
				Application.LeaveThreadModal -= Application_LeaveThreadModal;

				Application.RemoveMessageFilter(this);
				PictureHolder.Dispose();
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_rgMainWindows = null;
			m_activeMainWindow = null;
			m_registrySettings = null;
			m_findPattern = null;
			m_findReplaceDlg = null;
			m_suppressedCacheInfo = null;
			m_refreshView = null;
			PictureHolder = null;
#if DEBUG
			m_debugProcs = null;
#endif
			IsDisposed = true;
			BeingDisposed = false;
		}
Esempio n. 3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Handles the Closing event of FieldWorks Main Windows.
		/// </summary>
		/// <param name="sender">The main window that is closing.</param>
		/// <param name="e">The <see cref="T:System.ComponentModel.CancelEventArgs"/> Not used.</param>
		/// ------------------------------------------------------------------------------------
		private static void FwMainWindowClosing(object sender, CancelEventArgs e)
		{
			if (s_activeMainWnd == sender)
			{
				// Remember the settings, so that, if we end up saving some changes
				// related to it, we can record the last saved project.
				s_settingsForLastClosedWindow = s_activeMainWnd.App.RegistrySettings;
				// Make sure the closing main window is not considered the active main window
				s_activeMainWnd = null;
			}
		}