/// <summary>
		/// Override method to handle launching of a chooser for selecting lexical entries or senses.
		/// </summary>
		protected override void HandleChooser()
		{
			Form frm = FindForm();
			WaitCursor wc = null;
			BaseGoDlg dlg = null;
			try
			{
				if (frm != null)
					wc = new WaitCursor(frm);
				if (m_obj is IMoAlloAdhocProhib)
					dlg = new LinkAllomorphDlg();
				else
				{
					Debug.Assert(m_obj is IMoMorphAdhocProhib);
					dlg = new LinkMSADlg();
				}
				Debug.Assert(dlg != null);
				dlg.SetDlgInfo(m_cache, null, m_mediator);
				if (dlg.ShowDialog(frm) == DialogResult.OK)
					AddItem(dlg.SelectedObject);
			}
			finally
			{
				if (wc != null)
					wc.Dispose();
				if (dlg != null)
					dlg.Dispose();
			}
		}
Beispiel #2
0
		/// <summary/>
		public ProgressState(IProgressDisplayer progressBar)
		{
			m_wait = new WaitCursor(Form.ActiveForm);

			m_percentDone = 0;
			m_progressBar = progressBar;
			if (m_progressBar != null)
				m_progressBar.SetStateProvider(this);
		}
Beispiel #3
0
			protected override void DisposeUnmanagedResources()
			{
				m_clerk = null;
				m_waitCursor = null;
			}
Beispiel #4
0
			/// <summary>
			///
			/// </summary>
			/// <param name="clerk"></param>
			/// <param name="parentForWaitCursor">for wait cursor</param>
			public ListUpdateHelper(RecordClerk clerk, Control parentForWaitCursor)
				: this(clerk)
			{
				if (parentForWaitCursor != null)
					m_waitCursor = new WaitCursor(parentForWaitCursor);
			}
Beispiel #5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Import an Open XML for Exchanging Scripture Annotations (OXESA) file.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public bool OnFileImportOXESA(object args)
		{
			CheckDisposed();
			using (TeImportExportFileDialog dlg = new TeImportExportFileDialog(m_cache.ProjectId.Name, FileType.OXESA))
			{
				if (dlg.ShowOpenDialog(null, this) == DialogResult.OK)
				{
					string sUndo, sRedo;
					TeResourceHelper.MakeUndoRedoLabels("kstidImportAnnotations", out sUndo, out sRedo);

					using (UndoTaskHelper undoHelper = new UndoTaskHelper(Cache.ActionHandlerAccessor,
					   null, sUndo, sRedo))
					{
						using (WaitCursor waitCursor = new WaitCursor(this))
						{

							Exception e;
							XmlScrAnnotationsList.LoadFromFile(dlg.FileName, m_cache, m_StyleSheet, out e);
							if (e != null)
							{
								// Something went wrong while importing so let the user know.
								MessageBox.Show(string.Format(Properties.Resources.kstidOxesaImportFailedMsg, e.Message),
												Properties.Resources.kstidOxesaImportFailedTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
							}
							undoHelper.RollBack = false;
						}
					}
				}
			}
			return true;
		}
Beispiel #6
0
		public virtual bool OnRecordNavigation(object argument)
		{
			CheckDisposed();

			if (!m_fullyInitialized
				|| RecordNavigationInfo.GetSendingClerk(argument) != Clerk) // Don't pretend to have handled it if it isn't our clerk.
				return false;

			// persist Clerk's CurrentIndex in a db specific way
			string propName = Clerk.PersistedIndexProperty;
			m_mediator.PropertyTable.SetProperty(propName, Clerk.CurrentIndex, PropertyTable.SettingsGroup.LocalSettings);
			m_mediator.PropertyTable.SetPropertyPersistence(propName, true, PropertyTable.SettingsGroup.LocalSettings);

			Clerk.SuppressSaveOnChangeRecord = (argument as RecordNavigationInfo).SuppressSaveOnChangeRecord;
			using (WaitCursor wc = new WaitCursor(this))
			{
				//DateTime dt0 = DateTime.Now;
				try
				{
					ShowRecord();
				}
				finally
				{
					Clerk.SuppressSaveOnChangeRecord = false;
				}
				//DateTime dt1 = DateTime.Now;
				//TimeSpan ts = TimeSpan.FromTicks(dt1.Ticks - dt0.Ticks);
				//Debug.WriteLine("XmlDocView.OnRecordNavigation(): ShowRecord() took " + ts.ToString() + " at " + dt1.ToString());
			}
			return true;	//we handled this.
		}
Beispiel #7
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Makes a backup (saved version) of the current version of the book in the given
		/// BookMerger if we don't already have it backed up.
		/// </summary>
		/// <remarks>This is called when the user clicks the Compare and Merge button as well as
		/// before auto-merging.</remarks>
		/// <param name="bookMerger">The book merger.</param>
		/// ------------------------------------------------------------------------------------
		public void MakeBackupIfNeeded(BookMerger bookMerger)
		{
			// Copy original to backup
			using (WaitCursor wc = new WaitCursor(this))
			{
				ReplaceBookInBackup(bookMerger.BookCurr, false);
			}
		}
			/// <summary>
			/// Connect to the real data, when the control has lost focus.
			/// </summary>
			/// <param name="e"></param>
			protected override void OnLostFocus(EventArgs e)
			{
				WaitCursor wc = null;
				Form window = FindForm();
				if (window != null)
					wc = new WaitCursor(window);
				try
				{
					ConvertDummiesToReal(0);
					base.OnLostFocus(e);
				}
				finally
				{
					if (wc != null)
					{
						wc.Dispose();
						wc = null;
					}
				}
			}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="DataUpdateMonitor"/> class.
		/// </summary>
		/// <param name="owner">An optional owner (A wait cursor will be put on it if not null).
		/// </param>
		/// <param name="updateDescription">A simple description of what is being done.</param>
		/// ------------------------------------------------------------------------------------
		public DataUpdateMonitor(Control owner, string updateDescription)
		{
			if (s_updateSemaphore == null)
				s_updateSemaphore = new UpdateSemaphore(true, updateDescription);
			else
			{
				if (s_updateSemaphore.fDataUpdateInProgress)
					throw new Exception("Concurrent access on Database detected. Previous access: " + s_updateSemaphore.sDescr);
				// Set ((static semaphore) members) for this data update
				s_updateSemaphore.fDataUpdateInProgress = true;
				s_updateSemaphore.sDescr = updateDescription;
			}

			// Set wait cursor
			if (owner != null)
			{
				m_wait = new WaitCursor(owner);
			}
		}
Beispiel #10
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">if set to <c>true</c> [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, "****************** Missing Dispose() call for " + GetType().Name + "******************");
			// Must not be run more than once.
			if (m_isDisposed)
				return;

			if (disposing)
			{
				try
				{
					// Dispose managed resources here.
					UpdateSemaphore semaphore = s_updateSemaphore;
					Debug.Assert(semaphore.fDataUpdateInProgress);
					semaphore.fDataUpdateInProgress = false;
					semaphore.sDescr = string.Empty;
				}
				finally
				{
					// end Wait Cursor
					// Since it needs m_wait, this must be done when 'disposing' is true,
					// as that is a disposable object, which may be gone in
					// Finalizer mode.
					if (m_wait != null)
						m_wait.Dispose();
				}
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_wait = null;

			m_isDisposed = true;
		}
Beispiel #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 virtual void Dispose(bool disposing)
		{
			System.Diagnostics.Debug.WriteLineIf(!disposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** ");
			// Must not be run more than once.
			if (m_isDisposed)
				return;

			if (disposing)
			{
				// Dispose managed resources here.
				if (m_progressBar != null)
				{
					m_progressBar.ClearStateProvider();
					//m_progressBar.Dispose(); // We don't own this!! (JohnT)
				}
				if (m_wait != null)
				{
					m_wait.Dispose();
					m_wait = null;
				}
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_progressBar = null;
			m_status = null;

			m_isDisposed = true;
		}
			private void DoValidation(bool refresh)
			{
				Form frm = FindForm();
				// frm may be null, if the record has been switched
				WaitCursor wc = null;
				try
				{
					if (frm != null)
						wc = new WaitCursor(frm);
					ConstraintFailure failure;
					m_env.CheckConstraints(PhEnvironmentTags.kflidStringRepresentation, true, out failure, /* adjust the squiggly line */ true);
					// This will make the record list update to the new value.
					if(refresh)
						Mediator.BroadcastMessage("Refresh", null);
				}
				finally
				{
					if (wc != null)
						wc.Dispose();
				}
			}
Beispiel #13
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Refresh your contents. We try to re-use as many slices as possible,
		/// both to improve performance,
		/// and so as to preserve expansion state as much as possible.
		/// </summary>
		/// <param name="differentObject">
		/// True to not recycle any slices.
		/// False to try and recycle them.
		/// </param>
		/// <remarks>
		/// If the DataTree's slices call this method, they should use 'false',
		/// or they will be disposed when this call returns to them.
		/// </remarks>
		/// ------------------------------------------------------------------------------------
		public virtual void RefreshList(bool differentObject)
		{
			CheckDisposed();
			if (m_fDoNotRefresh)
			{
				RefreshListNeeded = true;
				m_fPostponedClearAllSlices |= differentObject;
				return;
			}
			Form myWindow = FindForm();
			WaitCursor wc = null;
			if (myWindow != null)
				wc = new WaitCursor(myWindow);
			try
			{
				Slice oldCurrent = m_currentSlice;
				DeepSuspendLayout();
				int scrollbarPosition = this.VerticalScroll.Value;

				m_currentSlicePartName = String.Empty;
				m_currentSliceObjGuid = Guid.Empty;
				m_fSetCurrentSliceNew = false;
				m_currentSliceNew = null;
				XmlNode xnConfig = null;
				XmlNode xnCaller = null;
				string sLabel = null;
				Type oldType = null;
				if (m_currentSlice != null)
				{
					if (m_currentSlice.ConfigurationNode != null &&
						m_currentSlice.ConfigurationNode.ParentNode != null)
					{
						m_currentSlicePartName = XmlUtils.GetAttributeValue(
							m_currentSlice.ConfigurationNode.ParentNode, "id", String.Empty);
					}
					if (m_currentSlice.Object != null)
						m_currentSliceObjGuid = m_currentSlice.Object.Guid;
					xnConfig = m_currentSlice.ConfigurationNode;
					xnCaller = m_currentSlice.CallerNode;
					sLabel = m_currentSlice.Label;
					oldType = m_currentSlice.GetType();
				}

				// Make sure we invalidate the root object if it's been deleted.
				if (m_root != null && !m_root.IsValidObject)
				{
					Reset();
				}

				// Make a new root object...just in case it changed class.
				if (m_root != null)
					m_root = m_root.Cache.ServiceLocator.GetInstance<ICmObjectRepository>().GetObject(m_root.Hvo);

				Invalidate(true); // forces all children to invalidate also
				CreateSlices(differentObject);
				PerformLayout();

				if (Slices.Contains(oldCurrent))
				{
					CurrentSlice = oldCurrent;
					m_currentSliceNew = CurrentSlice != oldCurrent ? oldCurrent : null;
				}
				else if (oldCurrent != null)
				{
					foreach (Control ctl in Slices)
					{
						var slice = ctl as Slice;
						if (slice == null)
							continue;
						Guid guidSlice = Guid.Empty;
						if (slice.Object != null)
							guidSlice = slice.Object.Guid;
						if (slice.GetType() == oldType &&
							slice.CallerNode == xnCaller &&
							slice.ConfigurationNode == xnConfig &&
							guidSlice == m_currentSliceObjGuid &&
							slice.Label == sLabel)
						{
							CurrentSlice = slice;
							m_currentSliceNew = CurrentSlice != slice ? slice : null;
							break;
						}
					}
				}

				// FWNX-590
				if (MiscUtils.IsMono)
					this.VerticalScroll.Value = scrollbarPosition;

				if (m_currentSlice != null)
				{
					ScrollControlIntoView(m_currentSlice);
				}
			}
			finally
			{
				DeepResumeLayout();
				RefreshListNeeded = false;  // reset our flag.
				if (wc != null)
				{
					wc.Dispose();
					wc = null;
				}
				m_currentSlicePartName = null;
				m_currentSliceObjGuid = Guid.Empty;
				m_fSetCurrentSliceNew = false;
				if (m_currentSliceNew != null)
				{
					m_mediator.IdleQueue.Add(IdleQueuePriority.High, OnReadyToSetCurrentSlice, (object)false);
					// prevent setting focus in slice until we're all setup (cf.
					m_fSuspendSettingCurrentSlice = true;
				}
			}
		}
		/// <summary>
		/// Integrate changes in dummy cache to real cache and DB.
		/// </summary>
		public void ConnectToRealCache()
		{
			// (FLEx) Review use of ISilDataAccess and other C++ cache related classes
			CheckDisposed();
			// If an Undo or Redo is in progress, we CAN'T save the changes. Ideally it wouldn't be necessary because making
			// any savable change in the slice would discard any pending Redo, and Undo would undo any changes in the slice
			// before undoing anything else. Currently Undo within the slice is not this well integrated. However, doing some editing
			// in the slice and then Undoing or Redoing a previous command DOES save the changes in the slice; I think OnLeave() must
			// be called somewhere in the process of invoking Undo before it is too late. This is not ideal behavior, but it
			// beats crashing.
			if (m_fdoCache.ActionHandlerAccessor.IsUndoOrRedoInProgress)
				return;
			Form frm = FindForm();
			WaitCursor wc = null;
			try
			{
				// frm will be null, if the record has been switched
				if (frm != null)
					wc = new WaitCursor(frm);
				// We're saving any changes to the real cache, so can no longer Undo/Redo local edits.
				CommitLocalEdits();
				// [NB: m_silCache is the same cache as m_vwCache, but is is a different cache than
				// m_fdoCache.  m_fdoCache has access to the database, and updates it, but
				// m_silCache does not.]
				if (DesignMode || m_rootb == null
					// It may not be valid by now, since it may have been deleted.
					|| !m_rootObj.IsValidObject)
				{
					if (frm != null)
						frm.Cursor = Cursors.Default;
					return;
				}
				string fieldname =
					(m_rootFlid == MoAffixAllomorphTags.kflidPhoneEnv) ? "PhoneEnv" : "Position";
				m_fdoCache.DomainDataByFlid.BeginUndoTask(
					String.Format(DetailControlsStrings.ksUndoSet, fieldname),
					String.Format(DetailControlsStrings.ksRedoSet, fieldname));
				IPhEnvironmentFactory environmentFactory = m_fdoCache.ServiceLocator.GetInstance<IPhEnvironmentFactory>();
				IFdoOwningSequence<IPhEnvironment> allAvailablePhoneEnvironmentsInProject =
					m_fdoCache.LanguageProject.PhonologicalDataOA.EnvironmentsOS;

				var envsBeingRequestedForThisEntry = EnvsBeingRequestedForThisEntry();

				// Environments just typed into slice that are not already used for
				// this entry or known about in the project.
				var newEnvsJustTyped =
					envsBeingRequestedForThisEntry.Where(localDummyHvoOfAnEnvInEntry =>
						!allAvailablePhoneEnvironmentsInProject
							.Select(projectEnv => RemoveSpaces(projectEnv.StringRepresentation.Text))
							.Contains(RemoveSpaces(GetStringOfEnvironment(localDummyHvoOfAnEnvInEntry))));
				// Add the unknown/new environments to project
				foreach (var localDummyHvoOfAnEnvironmentInEntry in
					newEnvsJustTyped)
				{
					ITsString envTssRep = GetTsStringOfEnvironment(
						localDummyHvoOfAnEnvironmentInEntry);
					IPhEnvironment newEnv = environmentFactory.Create();
					allAvailablePhoneEnvironmentsInProject.Add(newEnv);
					newEnv.StringRepresentation = envTssRep;
				}

				var countOfExistingEnvironmentsInDatabaseForEntry =
					m_fdoCache.DomainDataByFlid.get_VecSize(m_rootObj.Hvo, m_rootFlid);
				// Contains environments already in entry or recently selected in
				// dialog, but not ones just typed
				int[] existingListOfEnvironmentHvosInDatabaseForEntry;
				int chvoMax = m_fdoCache.DomainDataByFlid.get_VecSize(
					m_rootObj.Hvo, m_rootFlid);
				using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative<int>(chvoMax))
				{
					m_fdoCache.DomainDataByFlid.VecProp(m_rootObj.Hvo, m_rootFlid, chvoMax, out chvoMax, arrayPtr);
					existingListOfEnvironmentHvosInDatabaseForEntry = MarshalEx.NativeToArray<int>(arrayPtr, chvoMax);
				}

				// Build up a list of real hvos used in database for the
				// environments in the entry
				var newListOfEnvironmentHvosForEntry = new List<int>();
				foreach (var localDummyHvoOfAnEnvironmentInEntry in
					envsBeingRequestedForThisEntry)
				{
					ITsString envTssRep = GetTsStringOfEnvironment(
						localDummyHvoOfAnEnvironmentInEntry);
					string envStringRep = envTssRep.Text;

					// Pick a sensible environment from the known environments in
					// the project, by string
					IPhEnvironment anEnvironmentInEntry = FindPhoneEnv(
						allAvailablePhoneEnvironmentsInProject, envStringRep,
						newListOfEnvironmentHvosForEntry.ToArray(),
						existingListOfEnvironmentHvosInDatabaseForEntry);

					// Maybe the ws has changed, so change the real env in database,
					// in case.
					anEnvironmentInEntry.StringRepresentation = envTssRep;

					ITsStrBldr bldr = envTssRep.GetBldr();
					ConstraintFailure failure;
					if (anEnvironmentInEntry.CheckConstraints(PhEnvironmentTags.kflidStringRepresentation, false, out failure, true))
						ClearSquigglyLine(localDummyHvoOfAnEnvironmentInEntry, ref envTssRep, ref bldr);
					else
						MakeSquigglyLine(localDummyHvoOfAnEnvironmentInEntry, failure.XmlDescription, ref envTssRep, ref bldr);

					newListOfEnvironmentHvosForEntry.Add(anEnvironmentInEntry.Hvo);

					// Refresh
					m_sda.SetString(localDummyHvoOfAnEnvironmentInEntry, kEnvStringRep, bldr.GetString());
					m_rootb.PropChanged(localDummyHvoOfAnEnvironmentInEntry, kEnvStringRep, 0,
						envTssRep.Length, envTssRep.Length);
				}

				// Only reset the main property, if it has changed.
				// Otherwise, the parser gets too excited about needing to reload.
				if ((countOfExistingEnvironmentsInDatabaseForEntry !=
					newListOfEnvironmentHvosForEntry.Count()) ||
					!equalArrays(existingListOfEnvironmentHvosInDatabaseForEntry,
						newListOfEnvironmentHvosForEntry.ToArray()))
				{
					m_fdoCache.DomainDataByFlid.Replace(m_rootObj.Hvo, m_rootFlid, 0,
						countOfExistingEnvironmentsInDatabaseForEntry,
						newListOfEnvironmentHvosForEntry.ToArray(),
						newListOfEnvironmentHvosForEntry.Count());
				}
				m_fdoCache.DomainDataByFlid.EndUndoTask();
			}
			finally
			{
				if (wc != null)
				{
					wc.Dispose();
					wc = null;
				}
			}
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Import Key Terms menu handler
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected bool OnFileImportKeyTerms(object args)
		{
			CheckDisposed();
			using (TeImportExportFileDialog dlg = new TeImportExportFileDialog(m_cache.ProjectId.Name, FileType.OXEKT))
			{
				if (dlg.ShowOpenDialog(null, this) == DialogResult.OK)
				{
					string sUndo, sRedo;
					TeResourceHelper.MakeUndoRedoLabels("kstidImportKeyTerms", out sUndo, out sRedo);

					using (UndoTaskHelper undoHelper = new UndoTaskHelper(m_cache.ActionHandlerAccessor,
					   null, sUndo, sRedo))
					{
						using (WaitCursor waitCursor = new WaitCursor(this))
						{

							Exception e;
							XmlTermRenderingsList.LoadFromFile(dlg.FileName, m_cache,
								(occurrence, existingRendering, importedRendering) =>
								{
									using (ResolveKeyTermRenderingImportConflictDlg resolver =
										new ResolveKeyTermRenderingImportConflictDlg(this, occurrence, existingRendering, importedRendering, m_stylesheet))
									{
										return resolver.UseImportedRendering;
									}
								},
								out e);
							if (e != null)
							{
								// Something went wrong while importing so let the user know.
								MessageBox.Show(string.Format(Properties.Resources.kstidOxektImportFailedMsg, e.Message),
												Properties.Resources.kstidOxektImportTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
								return true;
							}
							undoHelper.RollBack = false;
							MessageBox.Show(Properties.Resources.kstidOxektImportCompleteMsg,
								Properties.Resources.kstidOxektImportTitle, MessageBoxButtons.OK);
						}
					}
				}
			}
			return true;
		}