ActiveViewHelper attemps to keep track of the active view (i.e. an IRootSite) of a form.
Inheritance: IFWDisposable
Exemplo n.º 1
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing"><c>true</c> to release both managed and unmanaged
		/// resources; <c>false</c> to release only unmanaged resources.
		/// </param>
		/// -----------------------------------------------------------------------------------
		protected override void Dispose( bool disposing )
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			if (disposing)
			{
				if (m_messageFilterInstalled)
				{
					Application.RemoveMessageFilter(this);
					m_messageFilterInstalled = false;
				}
				// We don't want to call Controls.Clear() here, because that causes the controls
				// to change size (and fire the events for it...). It causes CreateMenuAndToolbars()
				// to be called, so we end up with two toolbar adapters, but we dispose only one,
				// so eventually it tries to access the already disposed mediator.
				//Controls.Clear();

				// No, since m_bookMerger owns it.
				// if (m_differences != null)
				//	m_differences.Dispose();
				if (m_viewHelper != null)
					m_viewHelper.Dispose();

				if (m_msgMediator != null)
				{
					m_msgMediator.RemoveColleague(this);
					// m_msgMediator gets disposed from calling components.Dispose() below
				}
				if (m_undoTaskHelper != null)
					m_undoTaskHelper.Dispose();

				if(components != null)
				{
					components.Dispose();
				}
			}

			// Deal with unmanaged stuff here.
			m_viewHelper = null;
			m_differences = null; // Just null it, since m_bookMerger owns it and will dispose it.
			m_msgMediator = null;
			m_bookMerger = null; // Client gave it, so it has to dispose it.
			m_cache = null;
			m_scr = null;
			m_stylesheet = null;
			m_undoTaskHelper = null;

			base.Dispose( disposing );
		}
Exemplo n.º 2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="T:SplitGrid"/> class.
		/// </summary>
		/// <param name="cache">The cache.</param>
		/// <param name="styleSheet">The style sheet.</param>
		/// <param name="columns">The number of columns.</param>
		/// <param name="rows">The number of rows.</param>
		/// ------------------------------------------------------------------------------------
		public SplitGrid(FdoCache cache, IVwStylesheet styleSheet, int rows, int columns)
		{
			m_cache = cache;
			m_StyleSheet = styleSheet;
			m_grid = CreateDataGridView();
			m_defaultGroup = new RootSiteGroup(this);
			m_groups.Add(m_defaultGroup);
			m_activeViewHelper = new ActiveViewHelper(this);
			BorderStyle = BorderStyle.None;

			SuspendLayout();
			m_grid.Dock = DockStyle.Fill;
			m_grid.BackgroundColor = SystemColors.Control;
			m_grid.BorderStyle = BorderStyle.None;
			m_grid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
			m_grid.SelectionMode = DataGridViewSelectionMode.CellSelect;
			m_grid.RowHeadersVisible = false;
			m_grid.ColumnHeadersVisible = false;
			m_grid.AllowUserToAddRows = false;
			m_grid.AllowUserToDeleteRows = false;
			m_grid.AllowUserToOrderColumns = false;
			m_grid.AdvancedCellBorderStyle.All = DataGridViewAdvancedCellBorderStyle.Outset;
			m_grid.AdvancedCellBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None;
			m_grid.ScrollBars = ScrollBars.None;
			m_grid.RowStateChanged += new DataGridViewRowStateChangedEventHandler(OnRowStateChanged);
			m_grid.ColumnStateChanged += new DataGridViewColumnStateChangedEventHandler(OnColumnStateChanged);
			m_grid.MouseDown += new MouseEventHandler(OnGridMouseDown);
			m_grid.MouseUp += new MouseEventHandler(OnGridMouseUp);
			m_grid.RowTemplate = new DataGridViewControlRow();

			for (int i = 0; i < columns; i++)
			{
				DataGridViewControlColumn column = new DataGridViewControlColumn(i == columns - 1);
				m_grid.Columns.Add(column);
			}
			m_MaxRows = rows;
			Controls.Add(m_grid);
			ResumeLayout(true);

			m_grid.BringToFront();
			Visible = false;
		}
Exemplo n.º 3
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="DiffDialog"/> class.
		/// </summary>
		/// <param name="bookMerger"></param>
		/// <param name="cache"></param>
		/// <param name="stylesheet"></param>
		/// <param name="zoomFactorDraft">The zoom percentage to be used for the "draft" (i.e.,
		/// main Scripture) view</param>
		/// <param name="zoomFactorFootnote">The zoom percentage to be used for the "footnote"
		/// view</param>
		/// <param name="fDoCollapseUndo">true if we want to collapse to a single Undo item on close.</param>
		/// -----------------------------------------------------------------------------------
		public DiffDialog(BookMerger bookMerger, FdoCache cache, IVwStylesheet stylesheet,
			float zoomFactorDraft, float zoomFactorFootnote,
			bool fDoCollapseUndo)
		{
			Debug.Assert(cache != null);
			m_viewHelper = new ActiveViewHelper(this);
			m_fDoCollapseUndo = fDoCollapseUndo;

			// Required for Windows Form Designer support
			InitializeComponent();

			// just as fallback in case the Designer replaced FwContainer with Container
			// in InitializeComponent()...
			if (!(components is FwContainer))
				components = new FwContainer(components);

			// the last column of the table layout manager in the last row should have the
			// width of the scroll bar
			TableLayoutPanel tablePanel = tableLayoutPanel.GetControlFromPosition(0, 3)
				as TableLayoutPanel;
			tablePanel.ColumnStyles[3].Width = SystemInformation.VerticalScrollBarWidth -
				SystemInformation.FixedFrameBorderSize.Width;
			tablePanel = tableLayoutPanel.GetControlFromPosition(1, 3)
							as TableLayoutPanel;
			tablePanel.ColumnStyles[3].Width = SystemInformation.VerticalScrollBarWidth -
				SystemInformation.FixedFrameBorderSize.Width;

			m_msgMediator = new Mediator();
			m_msgMediator.AddColleague(this);
			components.Add(m_msgMediator);

			m_bookMerger = bookMerger;
			m_differences = bookMerger.Differences;
			m_cache = cache;
			m_scr = m_cache.LangProject.TranslatedScriptureOA;
			m_stylesheet = stylesheet;
			m_zoomFactorDraft = zoomFactorDraft;
			m_zoomFactorFootnote = zoomFactorFootnote;

			// Don't start out in edit mode
			m_editMode = false;

			// If the diff is a comparison of the current against a normal saved version, then
			// change the label text.
			ScrDraft draft = new ScrDraft(m_cache, m_bookMerger.BookRev.OwnerHVO);
			if (draft.Type == ScrDraftType.SavedVersion)
			{
				lblSavedVersion.Text = string.Format(TeDiffViewResources.kstidSavedVersion,
					draft.Description);
			}
			else
				lblSavedVersion.Text = string.Format(lblSavedVersion.Text, draft.Description);

			CreateUndoMark();
		}
Exemplo n.º 4
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing"><c>true</c> to release both managed and unmanaged
		/// resources; <c>false</c> to release only unmanaged resources.
		/// </param>
		/// -----------------------------------------------------------------------------------
		protected override void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			if (disposing)
			{
				if (m_viewHelper != null)
					m_viewHelper.Dispose();
				if (m_app != null)
				{
					// The removing of the window needs to happen later; after this main window is
					// already disposed of. This is needed for side-effects that require a running
					// message loop (such as closing the TE notes view which would normally
					// happen at this call without a running message loop)
					m_app.FwManager.ExecuteAsync(m_app.RemoveWindow, this);
				}
			}

			// NOTE: base.Dispose() may need the FdoCache which RemoveWindow() wants to delete.
			base.Dispose(disposing);

			m_viewHelper = null;
			m_delegate = null;
		}
Exemplo n.º 5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// <param name="disposing"></param>
		/// ------------------------------------------------------------------------------------
		protected override void Dispose(bool disposing)
		{
			System.Diagnostics.Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** ");
			if (disposing)
			{
				if (m_groups != null)
				{
					foreach (RootSiteGroup group in m_groups)
						group.Dispose();
					m_groups.Clear();

					if (Parent != null && Parent is Form)
						((Form)Parent).Shown -= new EventHandler(OnShown);

					// m_grid will be disposed from base class
				}
				if (m_activeViewHelper != null)
					m_activeViewHelper.Dispose();
			}

			m_groups = null;
			m_grid = null;
			m_StyleSheet = null;
			m_cache = null;
			m_activeViewHelper = null;

			base.Dispose(disposing);
		}
Exemplo n.º 6
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing"><c>true</c> to release both managed and unmanaged
		/// resources; <c>false</c> to release only unmanaged resources.
		/// </param>
		/// -----------------------------------------------------------------------------------
		protected override void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			FdoCache wndCache = null;
			if (disposing)
			{
				if (m_delegate != null)
					m_delegate.Dispose();
				if (m_viewHelper != null)
					m_viewHelper.Dispose();
				if (FwApp.App != null)
				{
					FwApp.App.OkToCloseApp = false;
					FwApp.App.RemoveWindow(this, out wndCache);
				}
			}

			// NOTE: base.Dispose() may need the FdoCache which RemoveWindow() wants to delete.
			base.Dispose(disposing);

			if (disposing)
			{
				if (FwApp.App != null)
				{
					FwApp.App.OkToCloseApp = true;
					if (wndCache != null)
						FwApp.App.RemoveFdoCache(wndCache);
				}
			}
			m_viewHelper = null;
			m_delegate = null;
			IncomingLinkHandler = null;
		}
Exemplo n.º 7
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Construct a new form
		/// </summary>
		/// <param name="app">The app.</param>
		/// <param name="wndCopyFrom">Source window to copy from</param>
		/// <param name="iconStream">The icon stream.</param>
		/// <param name="configFile">The config file.</param>
		/// <param name="startupLink">The link to follow once the window is initialized.</param>
		/// <param name="inAutomatedTest">if set to <c>true</c>, (well behaved) code will avoid
		/// bringing up dialogs that we cannot respond to (like confirmation and error dialogs)
		/// and it should cause the system to avoid saving the settings to a file (or at least
		/// saving them in some special way so as not to mess up the user.)</param>
		/// ------------------------------------------------------------------------------------
		public FwXWindow(FwApp app, Form wndCopyFrom, Stream iconStream,
			string configFile, FwLinkArgs startupLink, bool inAutomatedTest)
		{
			BasicInit(app);
			m_startupLink = startupLink;

			Debug.Assert(File.Exists(configFile));
			m_app = app;
			m_configFile = configFile;

			Init(iconStream, wndCopyFrom, app.Cache);
			if(inAutomatedTest)
			{
				Mediator.PropertyTable.SetProperty("DoingAutomatedTest", true);
				Mediator.PropertyTable.SetPropertyPersistence("DoingAutomatedTest", false);
			}

			// The order of the next two lines has been changed because the loading of the UI
			// properly depends on m_viewHelper being initialized.  Why this was not so with DNB
			// I do not know.
			// Here is the orginal order (along with a comment between them that seemed to imply this
			// new order could be a problem, but no obvious ones have appeared in my testing.

		   /*
			* LoadUI(configFile);
			* // Reload additional property settings that depend on knowing the database name.
			* m_viewHelper = new ActiveViewHelper(this);
			*/

			m_viewHelper = new ActiveViewHelper(this);
			LoadUI(configFile);

			m_viewHelper.ActiveViewChanged += new EventHandler<EventArgs>(ActiveViewChanged);
		}
Exemplo n.º 8
0
		/// <summary>
		/// Construct a new form
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="wndCopyFrom">Source window to copy from</param>
		/// <param name="iconStream"></param>
		/// <param name="configFile"></param>
		/// <param name="app"></param>
		/// <param name="inAutomatedTest"></param>
		public FwXWindow(FdoCache cache, Form wndCopyFrom, Stream iconStream,
			string configFile, bool inAutomatedTest)
		{
			BasicInit();

			int dbversion, cobjects, mdfSize, ldfSize;
			DbOps.ReadOneIntFromCommand(cache, "select DbVer from version$", null, out dbversion);
			DbOps.ReadOneIntFromCommand(cache, "select count(id) from CmObject", null, out cobjects);
			DbOps.ReadOneIntFromCommand(cache, "select size from dbo.sysfiles where fileid = 1", null, out mdfSize);
			DbOps.ReadOneIntFromCommand(cache, "select size from dbo.sysfiles where fileid = 2", null, out ldfSize);

			// REVIEW (EberhardB): This doesn't work if you have multiple databases open because
			// the properties are stored in static variables. Opening a second database overwrites
			// the values from the first database!
			// DB: TestLangProj, Ver: 200129, CmObjects: 55105, Mdf size: 5256, Ldf size: 1280
			SIL.Utils.ErrorReporter.AddProperty("DB", cache.DatabaseName + ", Ver: " + dbversion + ", CmObjects: "
				+ cobjects + ", Mdf size: " + (mdfSize * 8) + "K, Ldf size: " + (ldfSize * 8) + "K");
			SIL.Utils.ErrorReporter.AddProperty("LangProject", cache.LangProject.Name.AnalysisDefaultWritingSystem);

			Debug.Assert(File.Exists(configFile));
			m_configFile = configFile;

			Init(iconStream, wndCopyFrom, cache);
			if(inAutomatedTest)
			{
				//this should cause (well behaved) code to avoid bringing up dialogs
				// that we cannot respond to (like confirmation and error dialogs)
				//and it should cause the system to avoid saving the settings to a file (or at least
				//saving them in some special way so as not to mess up the user.)
				Mediator.PropertyTable.SetProperty("DoingAutomatedTest", true);
				Mediator.PropertyTable.SetPropertyPersistence("DoingAutomatedTest", false);
			}

			LoadUI(configFile);
			// Reload additional property settings that depend on knowing the database name.
			m_viewHelper = new ActiveViewHelper(this);
		}
Exemplo n.º 9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected override void Dispose(bool disposing)
		{
			Debug.WriteLineIf(!disposing, "****************** Missing Dispose() call for " + GetType().Name + ". ******************");

			// Must not be run more than once.
			if (IsDisposed || m_beingDisposed || Disposing)
				return;
			m_beingDisposed = true;
			if (disposing)
			{
				foreach (Control ctrl in m_rgClientViews.Values)
				{
					// Dispose of any views that aren't in the form currently.
					if (ctrl.Parent == null)
						ctrl.Dispose();
				}

				if (m_mediator != null)
				{
					m_mediator.ProcessMessages = false;
					m_mediator.RemoveColleague(this);
				}

				if (m_cboZoomPercent != null)
					m_cboZoomPercent.Dispose();
				if (m_paraStylesComboBox != null)
					m_paraStylesComboBox.Dispose();
				if (m_charStylesComboBox != null)
					m_charStylesComboBox.Dispose();
				if (m_writingSystemSelector != null)
					m_writingSystemSelector.Dispose();

				if (m_progressHandler != null)
					m_progressHandler.Dispose();
				if (m_writingSystemSelector != null)
					m_writingSystemSelector.Dispose();
				if (m_UndoRedoDropDown != null)
					m_UndoRedoDropDown.Dispose();
				if (components != null)
					components.Dispose();
				// no need to explicitly call Dispose on m_persistence - it's part of
				// components collection and gets disposed there.
				if (m_rgClientViews != null)
					m_rgClientViews.Clear();
				if (m_tmAdapter != null)
				{
					m_tmAdapter.LoadControlContainerItem -= LoadCustomToolBarControls;
					m_tmAdapter.InitializeComboItem -= InitializeToolBarCombos;
					m_tmAdapter.Dispose();
				}
				if (m_cache != null)
					m_cache.ProjectNameChanged -= ProjectNameChanged;
				if (m_app != null)
				{
					// The removing of the window from the app's collection needs to happen later, after
					// this main window is already disposed of. This is needed for side-effects
					// that require a running message loop (such as closing the TE notes view
					// which would normally happen at this call without a running message loop)
					m_app.FwManager.ExecuteAsync(m_app.RemoveWindow, this);
				}
			}
			m_cboZoomPercent = null;
			m_paraStylesComboBox = null;
			m_charStylesComboBox = null;
			m_writingSystemSelector = null;
			m_delegate = null;
			m_tmAdapter = null;
			m_UndoRedoDropDown = null;
			m_writingSystemSelector = null;
			m_StyleSheet = null;
			m_selectedView = null;
			m_rgClientViews = null;

#if !__MonoCS__
			base.Dispose(disposing);
#else
			try
			{
				base.Dispose(disposing);
			}
			catch (System.ArgumentOutOfRangeException)
			{
				// TODO-Linux: examine ToolStrip disposal in UIAdapter
				// is ToolStrip (from UIAdapter?) being Disposed multiple times?
			}
#endif

			if (disposing)
			{
				if (m_viewHelper != null)
					m_viewHelper.Dispose();
				if (m_mediator != null)
					m_mediator.Dispose();
			}

			m_cache = null;
			m_viewHelper = null;
			m_mediator = null;
			m_app = null;
			m_beingDisposed = false;
		}
Exemplo n.º 10
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Default constructor for FwMainWnd.
		/// </summary>
		/// -----------------------------------------------------------------------------------
		protected FwMainWnd()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			m_mediator = new Mediator();
			m_delegate = new MainWindowDelegate(this);
//			m_Resources = new System.Resources.ResourceManager(typeof(FwMainWnd));

			m_rgClientViews = new Dictionary<string, IRootSite>();
			m_viewHelper = new ActiveViewHelper(this);

			m_progressHandler = new StatusBarProgressHandler(statusBarFwPanel1, ProgressPanel);

			// Set the width of the side bar
			splitContainer.MaxFirstPanePercentage = 0.5f;
			splitContainer.SplitterDistance = kDefaultSideBarWidth;
			splitContainer.SettingsKey = SettingsKey;

			Debug.Assert(components is FwContainer, "Member variable components should be of " +
				"type FwContainer. If the Designer changed it, please change it back!");
			if (!(components is FwContainer))
				components = new FwContainer(components);

			// Add this as a component so that children can retrieve services
			components.Add(this);
		}
Exemplo n.º 11
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 override void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			if (disposing)
			{
				// Dispose managed resources here.
				Debug.Assert(m_scrollingController == null ||
					Controls.Contains(m_scrollingController as Control));
				if (m_slaves != null)
				{
					// We need to close all of the rootboxes because when controls are
					// destroyed they cause the other controls still on the parent to
					// resize. If the rootbox is sync'd with other views then the other
					// views will try to layout their rootboxes. This is BAD!!! :)
					foreach (RootSite site in m_slaves)
						site.CloseRootBox();

					foreach (Control ctrl in m_slaves)
					{
						if (!Controls.Contains(ctrl))
							ctrl.Dispose();
					}
				}
				if (m_slaves != null)
					m_slaves.Clear();
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_slaves = null;
			if (m_sync != null)
			{
				Marshal.ReleaseComObject(m_sync);
				m_sync = null;
			}
			m_activeViewHelper = null;
			m_scrollingController = null;

			base.Dispose(disposing);
		}
Exemplo n.º 12
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected override void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed || m_beingDisposed || Disposing)
				return;
			m_beingDisposed = true;

			FdoCache wndCache = null;
			if (disposing)
			{
				foreach (Control ctrl in m_rgClientWindows.Values)
				{
					// Dispose of any views that aren't in the form currently.
					if (ctrl.Parent == null)
						ctrl.Dispose();
				}

				if (m_mediator != null)
				{
					m_mediator.ProcessMessages = false;
					m_mediator.RemoveColleague(this);
				}

				if (m_writingSystemSelector != null)
					m_writingSystemSelector.Dispose();
				if (m_UndoRedoDropDown != null)
					m_UndoRedoDropDown.Dispose();
				if (components != null)
					components.Dispose();
				// no need to explicitly call Dispose on m_persistence - it's part of
				// components collection and gets disposed there.
				if (m_delegate != null)
					m_delegate.Dispose();
				if (m_rgClientWindows != null)
					m_rgClientWindows.Clear();

				if (m_cache != null && m_cache.ProgressBar == m_progressHandler)
					m_cache.ProgressBar = null;

				if (FwApp.App != null)
				{
					FwApp.App.OkToCloseApp = false; // Make sure we don't shutdown too soon
					FwApp.App.RemoveWindow(this, out wndCache);
				}
			}
			m_delegate = null;
			m_UndoRedoDropDown = null;
			m_writingSystemSelector = null;
			m_StyleSheet = null;
			m_selectedView = null;
			m_rgClientWindows = null;

			base.Dispose(disposing);

			if (disposing)
			{
				if (m_viewHelper != null)
					m_viewHelper.Dispose();
				if (m_mediator != null)
					m_mediator.Dispose();

				if (FwApp.App != null)
				{
					// Remove the cache as the last step. Hopefully this will fix some
					// ObjectDisposed exceptions we get but can't reproduce. (TE-8340)
					FwApp.App.OkToCloseApp = true;
					if (wndCache != null)
						FwApp.App.RemoveFdoCache(wndCache);
				}
			}

			m_cache = null;
			m_viewHelper = null;
			m_mediator = null;
			m_beingDisposed = false;
		}