/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Provide the information needed to merge one writing system into another, just in
		/// case the user decides to do so.
		/// </summary>
		/// <param name="fwt">IFwTool object used to open/close application window</param>
		/// <param name="strmLog">optional log file stream</param>
		/// <param name="hvoProj">Hvo of the Language Project</param>
		/// <param name="hvoRootObj">Hvo of the root object</param>
		/// <param name="wsUser">user interface writing system id</param>
		/// ------------------------------------------------------------------------------------
		public void SetupForWsMerges(IFwTool fwt, IStream strmLog, int hvoProj, int hvoRootObj, int wsUser)
		{
			CheckDisposed();

			string strServer = m_cache.ServerName;
			string strDatabase = m_cache.DatabaseName;
			CheckServerAndDatabaseInfo(strServer, strDatabase);

			m_fwt = fwt;
			m_strServer = strServer;
			m_strDatabase = strDatabase;
			m_strmLog = strmLog;
			m_hvoProj = hvoProj;
			m_hvoRootObj = hvoRootObj;
			m_wsUser = wsUser;
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Sets the initial values for the dialog controls, prior to displaying the dialog.
		/// This method should be called after creating, but prior to calling DoModeless. This
		/// overload is meant to be called from managed code.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="vwPattern">Find/replace values</param>
		/// <param name="rootSite">view</param>
		/// <param name="fReplace"><c>true</c> to initially display replace dialog page</param>
		/// <param name="fOverlays">ignored for now</param>
		/// <param name="sUserWs">UI writing system</param>
		/// <param name="hwnd">The window handle of the main window that owns the rootsite
		/// </param>
		/// <param name="tool">The app (needed to be able to disable all main windows)</param>
		/// <param name="helpTopicProvider">help topic provider allows the dialog box class
		/// to specify the appropriate help topic path for this dialog
		/// </param>
		/// <param name="wsEdit">writing system for the find and replace edit boxes</param>
		/// <remarks>ENHANCE JohnT: it may need more arguments, for example, the name of the
		/// kind of object we can restrict the search to, a list of fields.</remarks>
		/// <returns>true if the dialog was initialized properly, otherwise false.
		/// False indicates some problem and the find/replace dialog should not be
		/// shown at this time.</returns>
		/// ------------------------------------------------------------------------------------
		public bool SetDialogValues(FdoCache cache, IVwPattern vwPattern, IVwRootSite rootSite,
			bool fReplace, bool fOverlays, string sUserWs, IntPtr hwnd, IFwTool tool,
			IHelpTopicProvider helpTopicProvider, int wsEdit)
		{
			CheckDisposed();

			if (!SetDialogValues(cache, vwPattern, rootSite, fReplace, fOverlays, sUserWs, hwnd, helpTopicProvider, wsEdit))
				return false;

			m_tool = tool;

			// get the current selection text to fill in the find pattern.
			IVwSelection sel = rootSite.RootBox.Selection;
			if (sel == null)
			{
				// Set the TSS of the edit box to an empty string if it isn't set.
				if (FindText == null)
				{
					FindText = TsStrFactoryClass.Create().MakeString(
						string.Empty, cache.DefaultVernWs);
				}
			}
			else
			{
				// Get the selected text as the initial contents of the find box. Make a new TS String without
				// any character style so the character style from the selection will not be used. Also, if the
				// selection ends with a paragraph end sequence (CR/LF) then remove it.
				ITsString tssSel;
				bool fGotItAll;
				sel.GetFirstParaString(out tssSel, " ", out fGotItAll);
				if (tssSel == null)
				{
					// Not able to get ITsString from selection (e.g. if it is a picture)...
					SetFormatLabels();
					return true;
				}
				ITsStrBldr bldr = tssSel.GetBldr();
				bldr.SetStrPropValue(0, bldr.Length, (int)FwTextPropType.ktptNamedStyle, null);
				RemoveEndOfPara(bldr);
				// Set the TSS of the edit box if there is any text to set, or if there is no
				// TSS for the box, or if there is no text in the find box AND the selection is not a user prompt.
				// If the current selection is an IP AND we have a previous find text, we want to use that
				// instead of the current selection (TE-5127 and TE-5126).
				int nVar; //dummy for out params
				if (bldr.Length == 0 && vwPattern != null && vwPattern.Pattern != null)
				{
					FindText = vwPattern.Pattern;
				}
				else if ((bldr.Length != 0 || FindText == null || FindText.Length == 0)
					&& tssSel.get_Properties(0).GetIntPropValues(SimpleRootSite.ktptUserPrompt, out nVar) != 1)
				{
					FindText = bldr.GetString();
				}
				if (FindText != null)
				{
					// Set the replace text box properties to be the same as the find text box.
					// The best we can do is take the properties of the first run which should
					// be fine for most cases.
					ITsTextProps props = FindText.get_Properties(0);
					ITsStrBldr replaceBldr = TsStrBldrClass.Create();
					replaceBldr.Replace(0, 0, "", props);
					ReplaceText = replaceBldr.GetString();
				}
			}

			SetFormatLabels();
			return true;
		}
		/// ------------------------------------------------------------------------------------
		/// <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)
			{
				// release managed objects
				if (components != null)
					components.Dispose();
				if (m_fwTextBoxTestWs != null)
					m_fwTextBoxTestWs.Dispose();
				// We may have made the cache from COM objects given to us by a COM client.
				// In that case, we have to dispose it.
				if (m_cacheMadeLocally && m_cache != null)
					m_cache.Dispose();
				if (m_langDefCurrent != null)
					m_langDefCurrent.ReleaseRootRb();
				if (cbDictionaries != null)
					cbDictionaries.Dispose();
			}

			// release unmanaged objects regardless of disposing flag
			if (m_fwt != null && Marshal.IsComObject(m_fwt))
			{
				System.Runtime.InteropServices.Marshal.ReleaseComObject(m_fwt);
				m_fwt = null;
			}

			if (m_strmLog != null && Marshal.IsComObject(m_strmLog))
			{
				System.Runtime.InteropServices.Marshal.ReleaseComObject(m_strmLog);
				m_strmLog = null;
			}

			PUACharacter.ReleaseTheCom();

			// Garbage collect the cached ICU
			m_cachedIcu = null;
			// GC.Collect(); Can't be deterministic about when it happens, even by calling for a collection.
			m_langDefCurrent = null;
			m_fwTextBoxTestWs = null;
			cbDictionaries = null;

			base.Dispose(disposing);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Sets the initial values for the dialog controls, prior to displaying the dialog.
		/// This method should be called after creating, but prior to calling DoModeless. This
		/// overload is meant to be called from unmanaged code.
		/// </summary>
		/// <param name="mdc"></param>
		/// <param name="ode"></param>
		/// <param name="oleDbAccess"></param>
		/// <param name="vwPattern">Find/replace values</param>
		/// <param name="rootSite">view</param>
		/// <param name="fReplace"><c>true</c> to initially display replace dialog page</param>
		/// <param name="fOverlays">ignored for now</param>
		/// <param name="sUserWs">UI writing system</param>
		/// <param name="hwnd">The window handle of the main window that owns the rootsite
		/// </param>
		/// <param name="tool">The app (needed to be able to disable all main windows)</param>
		/// <param name="helpTopicProvider">help topic provider allows the dialog box class
		/// to specify the appropriate help topic path for this dialog
		/// </param>
		/// <param name="wsEdit">writing system for the find and replace edit boxes</param>
		/// <returns>true if the dialog was initialized properly, otherwise false.
		/// False indicates some problem and the find/replace dialog should not be
		/// shown at this time.</returns>
		/// <remarks>ENHANCE JohnT: it may need more arguments, for example, the name of the
		/// kind of object we can restrict the search to, a list of fields.</remarks>
		/// ------------------------------------------------------------------------------------
		public bool SetDialogValues(IOleDbEncap ode, IFwMetaDataCache mdc, IVwOleDbDa oleDbAccess,
			IVwPattern vwPattern, IVwRootSite rootSite, bool fReplace, bool fOverlays,
			string sUserWs, IntPtr hwnd, IFwTool tool, IHelpTopicProvider helpTopicProvider,
			int wsEdit)
		{
			CheckDisposed();

			m_cacheMadeLocally = true;
			return SetDialogValues(new FdoCache(ode, mdc, oleDbAccess), vwPattern, rootSite,
				fReplace, fOverlays, sUserWs, hwnd, tool, helpTopicProvider, wsEdit);
		}
		/// <summary>
		/// Set the initial values for the dialog controls, assuming that the find and replace
		/// edit boxes use the default vernacular writing system.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="vwPattern"></param>
		/// <param name="rootSite"></param>
		/// <param name="fReplace"></param>
		/// <param name="fOverlays"></param>
		/// <param name="sUserWs"></param>
		/// <param name="hwnd"></param>
		/// <param name="tool"></param>
		/// <param name="helpTopicProvider"></param>
		/// <returns></returns>
		public bool SetDialogValues(FdoCache cache, IVwPattern vwPattern, IVwRootSite rootSite,
			bool fReplace, bool fOverlays, string sUserWs, IntPtr hwnd, IFwTool tool,
			IHelpTopicProvider helpTopicProvider)
		{
			return SetDialogValues(cache, vwPattern, rootSite, fReplace, fOverlays, sUserWs,
				hwnd, tool, helpTopicProvider, cache.DefaultVernWs);
		}
Exemple #6
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="T:DummyFwProjPropertiesDlg"/> class.
 /// </summary>
 /// <param name="cache">The cache.</param>
 /// <param name="tool">The tool.</param>
 /// <param name="strmLog">The STRM log.</param>
 /// <param name="hvoProj">The hvo proj.</param>
 /// <param name="hvoRoot">The hvo root.</param>
 /// <param name="wsUser">The ws user.</param>
 /// ------------------------------------------------------------------------------------
 public DummyFwProjPropertiesDlg(FdoCache cache, IFwTool tool, IStream strmLog,
                                 int hvoProj, int hvoRoot, int wsUser)
     : base(cache, null, tool, null, strmLog, hvoProj, hvoRoot, wsUser, null)
 {
 }
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="T:DummyFwProjPropertiesDlg"/> class.
		/// </summary>
		/// <param name="cache">The cache.</param>
		/// <param name="tool">The tool.</param>
		/// <param name="strmLog">The STRM log.</param>
		/// <param name="hvoProj">The hvo proj.</param>
		/// <param name="hvoRoot">The hvo root.</param>
		/// <param name="wsUser">The ws user.</param>
		/// ------------------------------------------------------------------------------------
		public DummyFwProjPropertiesDlg(FdoCache cache, IFwTool tool, IStream strmLog,
			int hvoProj, int hvoRoot, int wsUser)
			: base(cache, null, tool, null, strmLog, hvoProj, hvoRoot, wsUser, null)
		{
		}
		/// ------------------------------------------------------------------------------------
		/// <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)
				return;

			// release unmanaged COM objects regardless of disposing flag
			if (m_tool != null)
			{
				if (Marshal.IsComObject(m_tool))
					Marshal.ReleaseComObject(m_tool);
				m_tool = null;
			}
			if (m_strmLog != null)
			{
				if (Marshal.IsComObject(m_strmLog))
					Marshal.ReleaseComObject(m_strmLog);
				m_strmLog = null;
			}

			if (disposing)
			{
				// release managed objects
				// We may have made the cache from COM objects given to us by a COM client.
				// In that case, we have to dispose it.
				if (m_cacheMadeLocally && m_cache != null)
					m_cache.Dispose();

				//if (m_helpTopicProvider != null && m_helpTopicProvider is IDisposable) // No, since the client provides it.
				//	(m_helpTopicProvider as IDisposable).Dispose();

				if (components != null)
					components.Dispose();
			}
			m_helpTopicProvider = null;
			m_cache = null;

			base.Dispose(disposing);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes the FwProjProperties class. Clients written in .Net with an FdoCache
		/// should use the version of the constructor that accepts an FdoCache. COM clients that
		/// do not have an FdoCache should use the default constructor and then call this method
		/// to initialize the object.
		/// </summary>
		/// <param name="ode"></param>
		/// <param name="mdc"></param>
		/// <param name="oleDbAccess"></param>
		/// <param name="tool">IFwTool object used to open/close application window</param>
		/// <param name="helpTopicProvider">IHelpTopicProvider object used to get help
		/// information</param>
		/// <param name="strmLog">optional log file stream</param>
		/// <param name="hvoProj">Hvo of the Language Project</param>
		/// <param name="hvoRoot">Hvo of the root object</param>
		/// <param name="wsUser">user interface writing system id</param>
		/// <param name="stylesheet">stylesheet for FwTextBox</param>
		/// ------------------------------------------------------------------------------------
		public void Initialize(IOleDbEncap ode, IFwMetaDataCache mdc, IVwOleDbDa oleDbAccess,
			IFwTool tool, IHelpTopicProvider helpTopicProvider, IStream strmLog, int hvoProj,
			int hvoRoot, int wsUser, IVwStylesheet stylesheet)
		{
			CheckDisposed();

			m_cache = new FdoCache(ode, mdc, oleDbAccess);
			m_cacheMadeLocally = true;
			m_tool = tool;
			m_helpTopicProvider = helpTopicProvider;
			m_strmLog = strmLog;
			m_hvoProj = hvoProj;
			m_hvoRoot = hvoRoot;
			m_wsUser = wsUser;
			m_stylesheet = stylesheet;

			Initialize();
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates and initializes a new instance of the FwProjProperties class. Accepts an
		/// FdoCache that encapsulates a DB connection.
		/// </summary>
		/// <param name="cache">Accessor for data cache and DB connection</param>
		/// <param name="app">The application (can be <c>null</c>)</param>
		/// <param name="tool">IFwTool object used to open/close application window</param>
		/// <param name="helpTopicProvider">IHelpTopicProvider object used to get help
		/// information</param>
		/// <param name="strmLog">optional log file stream</param>
		/// <param name="hvoProj">Hvo of the Language Project</param>
		/// <param name="hvoRoot">Hvo of the root object</param>
		/// <param name="wsUser">user interface writing system id</param>
		/// <param name="stylesheet">this is used for the FwTextBox</param>
		/// ------------------------------------------------------------------------------------
		public FwProjPropertiesDlg(FdoCache cache, IApp app,
			IFwTool tool, IHelpTopicProvider helpTopicProvider, IStream strmLog, int hvoProj,
			int hvoRoot, int wsUser, IVwStylesheet stylesheet): this()
		{
			if (cache == null)
				throw new ArgumentNullException("cache", "Null Cache passed to FwProjProperties");

			m_cache = cache;
			m_app = app;
			m_tool = tool;
			m_helpTopicProvider = helpTopicProvider;
			m_strmLog = strmLog;
			m_hvoProj = hvoProj;
			m_hvoRoot = hvoRoot;
			m_wsUser = wsUser;
			m_stylesheet = stylesheet;

			Initialize();
		}