Summary description for FwXWindow.
Inheritance: XCore.XWindow, IFwMainWnd, ISettings, IRecordListOwner, IMainWindowDelegatedFunctions, IMainWindowDelegateCallbacks
		/// <summary>non-undoable task because setting up an StText must be done in a Unit of Work</summary>
		private void DoSetupFixture()
		{
			m_application = new MockFwXApp(new MockFwManager { Cache = Cache }, null, null);
			var configFilePath = Path.Combine(FwDirectoryFinder.CodeDirectory, m_application.DefaultConfigurationPathname);
			m_window = new MockFwXWindow(m_application, configFilePath);
			((MockFwXWindow)m_window).Init(Cache); // initializes Mediator values
			m_mediator = m_window.Mediator;

			// set up default vernacular ws.
			m_wsDefaultVern = Cache.ServiceLocator.WritingSystemManager.Get("fr");
			m_wsOtherVern = Cache.ServiceLocator.WritingSystemManager.Get("es");
			m_wsEn = Cache.ServiceLocator.WritingSystemManager.Get("en");
			Cache.ServiceLocator.WritingSystems.VernacularWritingSystems.Add(m_wsOtherVern);
			Cache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems.Add(m_wsOtherVern);
			Cache.ServiceLocator.WritingSystems.VernacularWritingSystems.Add(m_wsDefaultVern);
			Cache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems.Insert(0, m_wsDefaultVern);

			// set up an StText with an empty paragraph with default Contents (empty English TsString)
			m_sttNoExplicitWs = Cache.ServiceLocator.GetInstance<IStTextFactory>().Create();
			Cache.ServiceLocator.GetInstance<ITextFactory>().Create().ContentsOA = m_sttNoExplicitWs;
			m_sttNoExplicitWs.AddNewTextPara(null);
			Assert.AreEqual(m_wsEn.Handle, m_sttNoExplicitWs.MainWritingSystem, "Our code counts on English being the defualt WS for very empty texts");

			// set up an StText with an empty paragraph with an empty TsString in a non-default vernacular
			m_sttEmptyButWithWs = Cache.ServiceLocator.GetInstance<IStTextFactory>().Create();
			Cache.ServiceLocator.GetInstance<ITextFactory>().Create().ContentsOA = m_sttEmptyButWithWs;
			m_sttEmptyButWithWs.AddNewTextPara(null);
			((IStTxtPara)m_sttEmptyButWithWs.ParagraphsOS[0]).Contents = TsStringUtils.MakeTss(string.Empty, m_wsOtherVern.Handle);
		}
Beispiel #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Creates a new instance of the main X window
        /// </summary>
        /// <param name="progressDlg">The progress dialog to use, if needed (can be null).</param>
        /// <param name="isNewCache">Flag indicating whether one-time, application-specific
        /// initialization should be done for this cache.</param>
        /// <param name="wndCopyFrom">Must be null for creating the original app window.
        /// Otherwise, a reference to the main window whose settings we are copying.</param>
        /// <param name="fOpeningNewProject"><c>true</c> if opening a brand spankin' new
        /// project</param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public override Form NewMainAppWnd(IProgress progressDlg, bool isNewCache,
			Form wndCopyFrom, bool fOpeningNewProject)
        {
            if (isNewCache)
            {
                // TODO: Do any needed initialization here.
            }
            Stream iconStream = ApplicationIconStream;
            Debug.Assert(iconStream != null, "Couldn't find the specified application icon as a resource.");
            string configFile;
            if (m_appArgs.ConfigFile != string.Empty)
                configFile = m_appArgs.ConfigFile;
            else
            {
                configFile = FwDirectoryFinder.GetCodeFile(DefaultConfigurationPathname);
                //					configFile = (string)SettingsKey.GetValue("LatestConfigurationFile",
                //						Path.Combine(FwDirectoryFinder.CodeDirectory,
                //						DefaultConfigurationPathname));
                if (!File.Exists(configFile))
                    configFile = null;
            }
            if (configFile == null) // try to load from stream
                return new FwXWindow(this, wndCopyFrom, iconStream, ConfigurationStream);

            // We pass a copy of the link information because it doesn't get used until after the following line
            // removes the information we need.
            FwXWindow result = new FwXWindow(this, wndCopyFrom, iconStream, configFile,
                m_appArgs.HasLinkInformation ? m_appArgs.CopyLinkArgs() : null, false);
            m_appArgs.ClearLinkInformation(); // Make sure the next window that is opened doesn't default to the same place
            return result;
        }
Beispiel #3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates a new instance of the main X window
		/// </summary>
		///
		/// <param name="cache">Instance of the FW Data Objects cache that the new main window
		/// will use for accessing the database.</param>
		/// <param name="isNewCache">Flag indicating whether one-time, application-specific
		/// initialization should be done for this cache.</param>
		/// <param name="wndCopyFrom"> Must be null for creating the original app window.
		/// Otherwise, a reference to the main window whose settings we are copying.</param>
		/// <param name="fOpeningNewProject"><c>true</c> if opening a brand spankin' new
		/// project</param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		protected override Form NewMainAppWnd(FdoCache cache, bool isNewCache, Form wndCopyFrom,
			bool fOpeningNewProject)
		{
			// Review: I put in this exception catching block because
			// the exception handler is not been invoked...until we figure out why
			// not, this is better than just having the raw exception in the users face.
			try
			{
				if (isNewCache)
				{
					// TODO: Do any needed initialization here.
				}
				Stream iconStream = ApplicationIconStream;
				Debug.Assert(iconStream != null, "Couldn't find the specified application icon as a resource.");
				string configFile;
				if (m_commandLineArgs.ContainsKey("x"))
				{
					configFile = m_commandLineArgs["x"][0];
				}
				else
				{
					configFile = DirectoryFinder.GetFWCodeFile(DefaultConfigurationPathname);
					//					configFile = (string)SettingsKey.GetValue("LatestConfigurationFile",
					//						Path.Combine(DirectoryFinder.FWCodeDirectory,
					//						DefaultConfigurationPathname));
					if (!File.Exists(configFile))
						configFile = null;
				}
				FwXWindow result;
				if (configFile != null)
					result = new FwXWindow(cache, wndCopyFrom, iconStream, configFile, false);
				else
				{
					// try to load from stream
					return new FwXWindow(cache, wndCopyFrom, iconStream, ConfigurationStream);
				}
				if (isNewCache)
				{
					// Must be done after reading properties from init table.
					if (result.PropertyTable.GetBoolProperty("SendSync", false) && SyncGuid != Guid.Empty)
						cache.MakeDbSyncRecords(SyncGuid);
				}

				if (m_commandLineArgs.ContainsKey("link"))
					result.StartupAtURL(m_commandLineArgs["link"][0]);

				return result;
			}
			catch (Exception error)
			{
				HandleTopLevelError(this, new System.Threading.ThreadExceptionEventArgs(error));
				return null;
			}
		}
Beispiel #4
0
		/// <summary>
		/// Select an existing language project.
		/// </summary>
		/// <param name="activeWindow"></param>
		public void ChooseLangProject(FwXWindow activeWindow)
		{
			CheckDisposed();

			Debug.Assert(activeWindow != null);
			FdoCache cache = activeWindow.Cache;
			Debug.Assert(cache != null);

			// Results parms for the dlg.
			bool fHaveProject;
			int hvoProj;
			string sProject;
			Guid guid;
			bool fHaveSubitem;
			int hvoSubitem;
			string sUserWs = cache.LanguageWritingSystemFactoryAccessor.GetStrFromWs(cache.DefaultUserWs);	//"en";
			string sName;
			string sServer = (cache != null) ? cache.ServerName : MiscUtils.LocalServerName;
			string sDatabase;

			IOpenFWProjectDlg dlg = OpenFWProjectDlgClass.Create();
			dlg.WritingSystemFactory = cache.LanguageWritingSystemFactoryAccessor;
			uint hwnd = activeWindow == null ? 0 : (uint)activeWindow.Handle.ToInt32();
			dlg.Show(Logger.Stream, sServer, MiscUtils.LocalServerName, sUserWs, hwnd, false, 0,
				FwApp.App.HelpFile + "::/" + FwApp.App.GetHelpString("khtpFWOpenProject", 0));
			dlg.GetResults(out fHaveProject, out hvoProj, out sProject,
				out sDatabase, out sServer, out guid, out fHaveSubitem, out hvoSubitem, out sName);
			System.Runtime.InteropServices.Marshal.ReleaseComObject(dlg);

			if (fHaveProject)
			{
				// make sure the server ends in "\\SILFW"
				// Note lowercase of SILFW in Turkish is not silfw.
				if (sServer !=null && sServer.ToLowerInvariant().EndsWith("\\silfw") == false)
					sServer += "\\SILFW";	// append it

				// The GetCache call will switch the 'cache' var to an extant FdoCache,
				// if the app already has a connection on open on that server and DB.

				if (CheckDbVerCompatibility(sServer, sDatabase))
				{
					bool isNewCache = GetCache(sServer, sDatabase, out cache);
					// save the local and global settings for windows sharing this cache.
					if (!isNewCache)
					{
						foreach (IFwMainWnd mainWindow in m_rgMainWindows)
						{
							if (mainWindow.Cache == cache &&
								mainWindow is FwXWindow &&
								mainWindow != activeWindow)
							{
								(mainWindow as FwXWindow).SaveSettings();
							}
						}
					}
					// save the settings for activeWindow last.
					activeWindow.SaveSettings();
					Form fwMainWindow = NewMainAppWnd(cache, isNewCache, null, false);
					m_rgMainWindows.Add((IFwMainWnd)fwMainWindow);
					AdjustNewWindowPosition(fwMainWindow, activeWindow);
					fwMainWindow.Show();
					((IFwMainWnd)fwMainWindow).InitAndShowClient();
				}
			}
		}
Beispiel #5
0
		public virtual void FixtureInit()
		{
			TestManager.ApproveFixture ("WW", "UI");
			//TestManager.ApproveFixture ("WW", "5Min");

			Init();

			//FwXApp app = MakeApplication();
			string configPath = System.IO.Path.Combine(SIL.FieldWorks.Common.Utils.DirectoryFinder.FWCodeDirectory, m_application.DefaultConfigurationPathname);
			FwApp.App = m_application;

			//review: this seems weird to me (JH); one would think that the application would deliver the window
			//instead, here, we are passing the application to the new window.
			m_window = new FwXWindow(LoadCache("TestLangProj"), null, null, configPath, true);// (FwXApp)app.MockInstance);

			/* note that someday, when we write a test to test the persistence function,
			 * set "TestRestoringFromTestSettings" the second time the application has run in order to pick up
			 * the settings from the first run. The code for this is already in xWindow.
			 */

			m_window.Show();
			Application.DoEvents();//without this, tests may fail non-deterministically

		}