Beispiel #1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Display the project properties dialog
		/// </summary>
		/// <param name="args"></param>
		/// ------------------------------------------------------------------------------------
		protected virtual bool OnFileProjectProperties(object args)
		{
			// Disabling the main window circumvents the usual mechanisms for switching keyboards,
			// so we manually switch to the default keyboard here so that the Project Properties
			// dialog displays the default keyboard. When we're all done we switch back to the
			// keyboard we had recently. (TE-4683)
			var oldWsd = Keyboard.Controller.ActiveKeyboard;
			Keyboard.Controller.ActivateDefaultKeyboard();
			// Disable windows on cache to prevent painting when fonts for writing system are changed
			m_app.EnableMainWindows(false);
			bool fDbRenamed = false;
			bool fFilesMoved = false;
			string sProject = m_cache.ProjectId.Name;
			string sOrigLinkedFilesRootDir = m_cache.LangProject.LinkedFilesRootDir;
			try
			{
				using (var dlg = new FwProjPropertiesDlg(m_cache, m_app, m_app, m_StyleSheet))
				{
					if (dlg.ShowDialog(this) != DialogResult.OK)
						return true;
					using (new WaitCursor(this))
					{
						fDbRenamed = dlg.ProjectNameChanged();
						if (fDbRenamed)
							sProject = dlg.ProjectName;
						if (dlg.LinkedFilesChanged())
							fFilesMoved = m_app.UpdateExternalLinks(sOrigLinkedFilesRootDir);
						if (!fDbRenamed)
						{
							// rename works only if other programs (like Flex) are not
							// running.  In which case, the Sync operation isn't needed.
							// Note: We handle this here since Flex does full refresh and we don't want
							// this happening first.
							if (dlg.WritingSystemsChanged())
							{
								using (var undoHelper = new UndoTaskHelper(m_cache.ActionHandlerAccessor, null,
									"kstidUndoRedoProjectProperties"))
								{
									var undoAction = new SyncUndoAction(m_app, SyncMsg.ksyncWs);
									undoAction.Do();
									m_cache.DomainDataByFlid.GetActionHandler().AddAction(undoAction);
									undoHelper.RollBack = false;
								}
							}
						}
					}
				}
			}
			finally
			{
				m_app.EnableMainWindows(true);
				if (!fDbRenamed && !fFilesMoved)	// no need for refresh when total shutdown & reopen
				{
					// Make sure windows for this cache are now enabled.
					// if the dialog merged two writing systems it will close/dispose this FwMainWnd.
					// if so, don't try to access any properties like EditingHelper or we'll crash (TE-7297).
					if (!IsDisposed)
					{
						// Restore the previous keyboard
						if (oldWsd != null)
							oldWsd.Activate();
					}
				}
			}
			if (fDbRenamed)
				m_app.FwManager.RenameProject(sProject, m_app);

			return true;
		}
Beispiel #2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Display the project properties dialog
		/// </summary>
		/// <param name="args"></param>
		/// ------------------------------------------------------------------------------------
		protected virtual bool OnFileProjectProperties(object args)
		{
			// Disabling the main window circumvents the usual mechanisms for switching keyboards,
			// so we manually switch to the default keyboard here so that the Project Properties
			// dialog displays the default keyboard. When we're all done we switch back to the
			// keyboard we had recently. (TE-4683)
			int oldWs = 0;
			if (EditingHelper != null) // JohnT: guard against e.g. TE-6543.
				oldWs = EditingHelper.SetKeyboardForWs(-1);
			// Disable windows on cache to prevent painting when fonts for writing system are
			// changed
			FwApp.App.EnableSameProjectWindows(m_cache, false);
			bool fDbRenamed = false;
			bool fFilesMoved = false;
			string sServer = m_cache.ServerName;
			string sDatabase = m_cache.DatabaseName;
			string sProject = m_cache.LangProject.Name.UserDefaultWritingSystem;
			string sOrigExtLinkRootDir = m_cache.LangProject.ExternalLinkRootDir;
			try
			{
				using (FwProjPropertiesDlg dlg = new FwProjPropertiesDlg(m_cache, FwApp.App,
					FwApp.App, FwApp.App, Logger.Stream, m_cache.LangProject.Hvo,
					HvoAppRootObject, m_cache.DefaultUserWs, FontHeightAdjuster.StyleSheetFromMediator(Mediator)))
				{
					using (new UndoTaskHelper(m_cache.MainCacheAccessor, null, "kstidUndoRedoProjectProperties"))
					{
						if (dlg.ShowDialog(this) != DialogResult.OK)
							return true;

						using (new WaitCursor(this))
						{
							fDbRenamed = dlg.ProjectNameChanged();
							if (fDbRenamed)
								sProject = m_cache.LangProject.Name.UserDefaultWritingSystem;
							if (dlg.ExternalLinkChanged())
								fFilesMoved = FwApp.UpdateExternalLinks(sOrigExtLinkRootDir, m_cache.LangProject);
							if (!fDbRenamed)
							{
								// rename works only if other programs (like Flex) are not
								// running.  In which case, the Sync operation isn't needed.
								// Note: We handle this here since Flex does full refresh and we don't want
								// this happening first.
								if (dlg.WritingSystemsChanged())
								{
									SyncUndoAction undoAction = new SyncUndoAction(m_cache, FwApp.App,
										new SyncInfo(SyncMsg.ksyncWs, 0, 0));
									undoAction.Do();
									m_cache.ActionHandlerAccessor.AddAction(undoAction);
								}
							}
						}
					}
				}
			}
			finally
			{
				if (!fDbRenamed && !fFilesMoved)	// no need for refresh when total shutdown & reopen
				{
					// Make sure windows for this cache are now enabled.
					FwApp.App.EnableSameProjectWindows(m_cache, true);
					// if the dialog merged two writing systems it will close/dispose this FwMainWnd.
					// if so, don't try to access any properties like EditingHelper or we'll crash (TE-7297).
					if (!this.IsDisposed)
					{
						// Restore the previous keyboard
						if (oldWs != 0 && EditingHelper != null)
							EditingHelper.SetKeyboardForWs(oldWs);
					}
				}
			}
			if (fDbRenamed)
				FwApp.App.RenameProject(sServer, sDatabase, sProject);
			return true;
		}