Inheritance: System.Windows.Forms.Form, IFWDisposable, IMessageFilter
Exemplo n.º 1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		///
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="defaultMsg"></param>
		/// <param name="noMatchFoundType"></param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		private bool FindDlgMatchNotFound(object sender, string defaultMsg,
			FwFindReplaceDlg.MatchType noMatchFoundType)
		{
			m_noMatchFoundType = noMatchFoundType;
			return false;
		}
Exemplo n.º 2
0
		private void m_findReplaceSetupButton_Click(object sender, System.EventArgs e)
		{
			// Ensure that the find and replace strings have the correct writing system.
			int ws = -50;
			try
			{
				// Find the writing system for the selected column (see LT-5491).
				FieldComboItem fci = m_findReplaceTargetCombo.SelectedItem as FieldComboItem;
				if (fci == null)
				{
					MessageBox.Show(XMLViewsStrings.ksChooseEditTarget);
					return;
				}
				XmlNode xnField = m_bv.ColumnSpecs[fci.ColumnIndex];
				string sWs = XmlViewsUtils.FindWsParam(xnField);
				if (String.IsNullOrEmpty(sWs))
				{
					// It's likely a custom field with a ws selector in the field metadata.
					string sTransduce = XmlUtils.GetOptionalAttributeValue(xnField, "transduce");
					if (!String.IsNullOrEmpty(sTransduce))
					{
						string[] parts = sTransduce.Split('.');
						if (parts.Length == 2)
						{
							string className = parts[0];
							string fieldName = parts[1];
							IFwMetaDataCache mdc = m_cache.DomainDataByFlid.MetaDataCache;
							try
							{
								int clid = mdc.GetClassId(className);
								int flid = mdc.GetFieldId2(clid, fieldName, true);
								ws = FieldReadWriter.GetWsFromMetaData(0, flid, m_cache);
								if (ws == 0)
									ws = m_cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem.Handle;
							}
							catch
							{
							}
						}
					}
				}
				else if (!XmlViewsUtils.GetWsRequiresObject(sWs))
				{
					// Try to convert the ws parameter into an int.  Sometimes the parameter
					// cannot be interpreted without an object, such as when the ws is a magic
					// string that will change the actual ws depending on the contents of the
					// object.  In these cases, we give -50 as a known constant to check for.
					// This can possibly throw an exception, so we'll enclose it in a try block.
					ws = WritingSystemServices.InterpretWsLabel(m_cache, sWs, null, 0, 0, null);
				}
			}
			catch
			{
			}
			if (ws == -50)
				ws = m_cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem.Handle;
			ITsStrFactory tsf = m_cache.TsStrFactory;

			if (m_tssReplace == null)
				m_tssReplace = tsf.MakeString("", ws);
			else
			{
				// If we have a replacement TsString, but no pattern, keep the text but
				// no properties.
				if (m_pattern == null)
					m_tssReplace = tsf.MakeString(m_tssReplace.Text, ws);
				else if (!m_pattern.MatchOldWritingSystem)
				{
					// We have both a string and a pattern. We want to clear writing system information
					// on the string unless we are matching on WS. But we don't want to clear any style info.
					ITsStrBldr bldr = m_tssReplace.GetBldr();
					bldr.SetIntPropValues(0, bldr.Length, (int)FwTextPropType.ktptWs,
										  (int)FwTextPropVar.ktpvDefault, ws);
					m_tssReplace = bldr.GetString();
				}
			}
			if (m_pattern != null)
			{
				if (m_pattern.Pattern == null)
					m_pattern.Pattern = tsf.MakeString("", ws);
				else if (!m_pattern.MatchOldWritingSystem)
				{
					// Enforce the expected writing system; but don't clear styles.
					ITsStrBldr bldr = m_pattern.Pattern.GetBldr();
					bldr.SetIntPropValues(0, bldr.Length, (int)FwTextPropType.ktptWs,
										  (int)FwTextPropVar.ktpvDefault, ws);
					m_pattern.Pattern = bldr.GetString();
				}
			}

			using (FwFindReplaceDlg findDlg = new FwFindReplaceDlg())
			{
				//Change the Title from "Find and Replace" to "Bulk Replace Setup"
				findDlg.Text = String.Format(XMLViewsStrings.khtpBulkReplaceTitle);
				IApp app = (IApp)m_mediator.PropertyTable.GetValue("App");
				findDlg.SetDialogValues(m_cache, m_pattern, m_bv.BrowseView.StyleSheet,
					FindForm(), m_mediator.HelpTopicProvider, app);
				findDlg.RestoreAndPersistSettingsIn(m_mediator);
				// Set this AFTER it has the correct WSF!
				findDlg.ReplaceText = m_tssReplace;

				if (findDlg.ShowDialog(this) == DialogResult.OK)
				{
					m_tssReplace = findDlg.ResultReplaceText;
					UpdateFindReplaceSummary();
					EnablePreviewApplyForFindReplace();
				}
			}
		}
Exemplo n.º 3
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;
		}
Exemplo n.º 4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Display the Find/Replace modeless dialog
		/// </summary>
		/// <param name="fReplace"><c>true</c> to make the replace tab active</param>
		/// <param name="rootsite">The view where the find will be conducted</param>
		/// <returns><c>true</c> if the dialog is successfully displayed</returns>
		/// ------------------------------------------------------------------------------------
		public bool ShowFindReplaceDialog(bool fReplace, RootSite rootsite)
		{
			CheckDisposed();

			if (rootsite == null || rootsite.RootBox == null)
				return false;

			int hvoRoot, frag;
			IVwViewConstructor vc;
			IVwStylesheet ss;
			rootsite.RootBox.GetRootObject(out hvoRoot, out vc, out frag, out ss);
			if (hvoRoot == 0)
				return false;

			if (FindReplaceDialog == null)
			{
				m_findReplaceDlg = new FwFindReplaceDlg();
				ConfigureFindReplacedialog();
			}

			bool fOverlay = (rootsite.RootBox.Overlay != null);

			if (m_findReplaceDlg.SetDialogValues(rootsite.Cache, FindPattern,
				rootsite, fReplace, fOverlay, rootsite.FindForm(), this, this))
			{
				m_findReplaceDlg.Show();
				return true;
			}
			return false;
		}
Exemplo n.º 5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Close and remove the Find/Replace modeless dialog (result of LT-5702)
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public void RemoveFindReplaceDialog()
		{
			if (m_findReplaceDlg != null)
			{
				// Closing doesn't work as it tries to hide the dlg ..
				// so go for the .. dispose.  It will do it 'base.Dispose()'!
				m_findReplaceDlg.Close();
				m_findReplaceDlg.Dispose();
				m_findReplaceDlg = null;
			}
		}
Exemplo n.º 6
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)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (m_isDisposed || m_beingDisposed)
				return;
			m_beingDisposed = true;

			UpdateAppRuntimeCounter();

			if (disposing)
			{
				FwRegistrySettings.FirstTimeAppHasBeenRun = false;

				// Dispose managed resources here.
				Logger.ShutDown();
				Application.ThreadException -= new ThreadExceptionEventHandler(HandleTopLevelError);

				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 -= new CancelEventHandler(OnClosingWindow);
						wnd.Closed -= new EventHandler(OnWindowClosed);
						wnd.Activated -= new EventHandler(fwMainWindow_Activated);
						wnd.HandleDestroyed -= new EventHandler(fwMainWindow_HandleDestroyed);
						wnd.Dispose();
					}
					else if (mainWnd is IDisposable)
						((IDisposable)mainWnd).Dispose();
				}
				if (m_caches != null)
				{
					foreach (FdoCache cache in m_caches.Values)
						cache.Dispose();
					m_caches.Clear();
				}
				if (m_findReplaceDlg != null)
					m_findReplaceDlg.Dispose();
#if DEBUG
				if (m_debugProcs != null)
					m_debugProcs.Dispose();
#endif
				// Close the splash screen if, for some reason, it's still hanging around. It
				// really shouldn't still be around by this time, except when some testing code
				// instantiates FwApp objects. This will make sure the splash screen goes away
				// when the FwApp object goes out of scope.
				CloseSplashScreen();
				ResourceHelper.ShutdownHelper();
				if (m_rgMainWindows != null)
					m_rgMainWindows.Clear();
				if (m_commandLineArgs != null)
					m_commandLineArgs.Clear();
				if (m_suppressedCaches != null)
					m_suppressedCaches.Clear();
				if (m_refreshViewCaches != null)
					m_refreshViewCaches.Clear();
				if (m_findPatterns != null)
					m_findPatterns.Clear();

				Application.RemoveMessageFilter(this);
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_rgMainWindows = null;
			m_activeMainWindow = null;
			m_commandLineArgs = null;
			m_SplashScreenWnd = null;
			m_findPatterns = null;
			m_findReplaceDlg = null;
			m_suppressedCaches = null;
			m_refreshViewCaches = null;
#if DEBUG
			m_debugProcs = null;
#endif
			m_caches = null;
			s_app = null;

			m_isDisposed = true;
			m_beingDisposed = false;
		}