Base application for .net FieldWorks apps (i.e., replacement for AfApp)
Inheritance: IApp, ISettings, IFWDisposable, IHelpTopicProvider, IMessageFilter, IFeedbackInfoProvider, IProjectSpecificSettingsKeyProvider
Ejemplo n.º 1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Prepares the selected files to be uploaded to REAP using RAMP.
		/// </summary>
		/// <param name="owner">RAMP dialog owner</param>
		/// <param name="dialogFont">RAMP dialog font (for localization and consistency)</param>
		/// <param name="localizationDialogIcon"></param>
		/// <param name="filesToArchive"></param>
		/// <param name="mediator"></param>
		/// <param name="thisapp"></param>
		/// <param name="cache"></param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public bool ArchiveNow(Form owner, Font dialogFont, Icon localizationDialogIcon,
			IEnumerable<string> filesToArchive, Mediator mediator, FwApp thisapp, FdoCache cache)
		{
			var viProvider = new VersionInfoProvider(Assembly.LoadFile(thisapp.ProductExecutableFile), false);
			var wsMgr = cache.ServiceLocator.GetInstance<IWritingSystemManager>();
			var appName = thisapp.ApplicationName;
			var title = cache.LanguageProject.ShortName;
			var uiLocale = wsMgr.Get(cache.DefaultUserWs).IcuLocale;
			var projectId = cache.LanguageProject.ShortName;

			var model = new RampArchivingDlgViewModel(Application.ProductName, title, projectId, /*appSpecificArchivalProcessInfo:*/ string.Empty, SetFilesToArchive(filesToArchive), GetFileDescription);

			// image files should be labeled as Graphic rather than Photograph (the default).
			model.ImagesArePhotographs = false;

			// show the count of media files, not the duration
			model.ShowRecordingCountNotLength = true;

			// set the general description, in each available language
			IMultiString descr = cache.LanguageProject.Description;
			var descriptions = new Dictionary<string, string>();
			foreach (int wsid in descr.AvailableWritingSystemIds)
			{
				var descrText = descr.get_String(wsid).Text;
				if ((!string.IsNullOrEmpty(descrText)) && (descrText != "***"))
					descriptions[wsMgr.Get(wsid).GetIso3Code()] = descrText;
			}

			if (descriptions.Count > 0)
				model.SetDescription(descriptions);

			AddMetsPairs(model, viProvider.ShortNumericAppVersion, cache);

			const string localizationMgrId = "Archiving";

			if (s_localizationMgr == null)
			{
				s_localizationMgr = LocalizationManager.Create(
					uiLocale,
					localizationMgrId, viProvider.ProductName, viProvider.NumericAppVersion,
					FwDirectoryFinder.GetCodeSubDirectory("ArchivingLocalizations"),
					Path.Combine(Application.CompanyName, appName),
					localizationDialogIcon, "*****@*****.**", "SIL.Archiving");
			}
			else
			{
				LocalizationManager.SetUILanguage(uiLocale, true);
			}

			// create the dialog
			using (var dlg = new ArchivingDlg(model, localizationMgrId, dialogFont, new FormSettings()))
			using (var reportingAdapter = new PalasoErrorReportingAdapter(dlg, mediator))
			{
				ErrorReport.SetErrorReporter(reportingAdapter);
				dlg.ShowDialog(owner);
				ErrorReport.SetErrorReporter(null);
			}

			return true;
		}
Ejemplo n.º 2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Perform one-time initialization of a new Scripture project
		/// </summary>
		/// <param name="cache">The database cache</param>
		/// <param name="app">The TE application.</param>
		/// <param name="progressDlg">The progress dialog (can be null).</param>
		/// <returns>
		/// true if data loaded successfully; false, otherwise
		/// </returns>
		/// ------------------------------------------------------------------------------------
		public static bool Initialize(FdoCache cache, FwApp app,
			IThreadedProgress progressDlg)
		{
			TeScrInitializer scrInitializer = new TeScrInitializer(cache);
			scrInitializer.m_app = app;
			return scrInitializer.Initialize(progressDlg);
		}
Ejemplo n.º 3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="FwRegistrySettings"/> class.
		/// </summary>
		/// <param name="app">The application.</param>
		/// ------------------------------------------------------------------------------------
		public FwRegistrySettings(FwApp app)
		{
			if (app == null)
				throw new ArgumentNullException("app");
			m_firstTimeAppHasBeenRun = new RegistryBoolSetting(app.SettingsKey, "FirstTime", true);
			m_showSideBar = new RegistryBoolSetting(app.SettingsKey, "ShowSideBar", true);
			m_showStatusBar = new RegistryBoolSetting(app.SettingsKey, "ShowStatusBar", true);
			m_openLastEditedProject = new RegistryBoolSetting(app.SettingsKey, "OpenLastEditedProject", false);
			m_loadingProcessId = new RegistryIntSetting(app.SettingsKey, "LoadingProcessId", 0);
			m_numberOfLaunches = new RegistryIntSetting(app.SettingsKey, "launches", 0);
			m_numberOfSeriousCrashes = new RegistryIntSetting(app.SettingsKey, "NumberOfSeriousCrashes", 0);
			m_numberOfAnnoyingCrashes = new RegistryIntSetting(app.SettingsKey, "NumberOfAnnoyingCrashes", 0);
			m_totalAppRuntime = new RegistryIntSetting(app.SettingsKey, "TotalAppRuntime", 0);
			m_appStartupTime = new RegistryStringSetting(app.SettingsKey, "LatestAppStartupTime", string.Empty);
			m_latestProject = new RegistryStringSetting(app.SettingsKey, "LatestProject", string.Empty);
			m_latestServer = new RegistryStringSetting(app.SettingsKey, "LatestServer", string.Empty);
		}
Ejemplo n.º 4
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="NotesMainWnd"/> class.
		/// </summary>
		/// <param name="app">The app</param>
		/// <param name="stylesheet">The stylesheet</param>
		/// <param name="zoomPercent">The zoom percentage</param>
		/// -----------------------------------------------------------------------------------
		public NotesMainWnd(FwApp app, FwStyleSheet stylesheet, float zoomPercent) : base(app, null)
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			Name = "NotesMainWnd";
			m_zoomPercent = zoomPercent;
			m_scr = m_app.Cache.LangProject.TranslatedScriptureOA;
			m_StyleSheet = stylesheet;

			SetupSideBarInfoBar();
			AddFilters();

			// Save the max. width for the sidebar and set it to the default width.
//			m_maxSideBarWidth = m_sideBarContainer.Width;
			m_sideBarContainer.Width = kDefaultSideBarWidth;
		}
Ejemplo n.º 5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Shows an instance of this dialog on a separate thread.
		/// </summary>
		/// <param name="args">The application arguments</param>
		/// <param name="whatToWaitFor">The condition we're waiting for.</param>
		/// <param name="appToStart">The application to start.</param>
		/// <param name="appToWaitFor">The application to wait for (null if waiting for
		/// WindowToActivate).</param>
		/// ------------------------------------------------------------------------------------
		internal static void ShowOnSeparateThread(FwAppArgs args, WaitFor whatToWaitFor,
			FwApp appToStart, FwApp appToWaitFor)
		{
			if (whatToWaitFor != WaitFor.WindowToActivate && appToWaitFor == null)
				throw new ArgumentNullException("appToWaitFor");
			if (appToStart == null)
				throw new ArgumentNullException("appToStart");

			ApplicationBusyDialog dlg = new ApplicationBusyDialog();
			dlg.m_whatToWaitFor = whatToWaitFor;
			dlg.m_args = args;
			dlg.m_appToStart = appToStart;
			dlg.m_appToWaitFor = appToWaitFor;
			Thread thread = new Thread(dlg.WaitForOtherApp);
			thread.IsBackground = true;
			thread.SetApartmentState(ApartmentState.STA);
			thread.Name = "WaitForOtherBusyApp";
			thread.CurrentUICulture = Thread.CurrentThread.CurrentUICulture;
			thread.Start();
		}
Ejemplo n.º 6
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Perform a Paratext streamlined import
		/// </summary>
		/// <param name="mainWnd">The main window.</param>
		/// <param name="stylesheet">The Scripture stylesheet.</param>
		/// <param name="app">The app.</param>
		/// <returns><c>true</c> if something got imported; <c>false</c> otherwise</returns>
		/// ------------------------------------------------------------------------------------
		public static bool ImportParatext(Form mainWnd, FwStyleSheet stylesheet, FwApp app)
		{
			TeImportManager mgr = new TeImportManager(mainWnd, stylesheet, app, true);
			return mgr.ImportSf();
		}
Ejemplo n.º 7
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="TeImportManager"/> class.
		/// </summary>
		/// <param name="mainWnd">The main window initiating the import</param>
		/// <param name="styleSheet">The stylesheet.</param>
		/// <param name="app">The app.</param>
		/// <param name="fParatextStreamlinedImport">if set to <c>true</c> do a Paratext
		/// streamlined import (minimal UI).</param>
		/// ------------------------------------------------------------------------------------
		internal TeImportManager(Form mainWnd, FwStyleSheet styleSheet, FwApp app,
			bool fParatextStreamlinedImport)
			: this(app.Cache, styleSheet, app, fParatextStreamlinedImport)
		{
			m_mainWnd = mainWnd;
			m_importCallbacks = new DummyImportCallbacks();
		}
Ejemplo n.º 8
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Construct a new form
		/// </summary>
		/// <param name="app">the app.</param>
		/// <param name="wndCopyFrom">Source window to copy from.</param>
		/// <param name="iconStream"></param>
		/// <param name="configStream"></param>
		/// -----------------------------------------------------------------------------------
		public FwXWindow(FwApp app, Form wndCopyFrom, Stream iconStream,
			Stream configStream) : this()
		{
			m_app = app;
			m_configFile = null;
			Init(iconStream, wndCopyFrom, app.Cache);
			LoadUI(configStream);
		}
Ejemplo n.º 9
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Closes all main windows for the specified application ignoring any errors that
		/// occur.
		/// </summary>
		/// <param name="app">The application.</param>
		/// ------------------------------------------------------------------------------------
		private static void CloseAllMainWindowsForApp(FwApp app)
		{
			if (app == null)
				return;
			foreach (Form mainWnd in app.MainWindows.OfType<Form>())
			{
				if (mainWnd.IsDisposed)
					continue;	// This can happen in renaming.
				// This is typically used if an exception happens to gracefully close any
				// open main windows so we need to ignore any errors because we have no
				// idea what state the application is in.
				Form wnd = mainWnd;
				mainWnd.Invoke((Action) (() => ExceptionHelper.LogAndIgnoreErrors(wnd.Close)));
			}
		}
Ejemplo n.º 10
0
		public RestoreDefaultsDlg(FwApp app) : this()
		{
			m_app = app;
		}
Ejemplo n.º 11
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// C'tor for TESTING with MockFwXWindow
		/// </summary>
		/// <param name="app"></param>
		/// <param name="configFile">Only sets the member variable here, does NOT load UI.</param>
		/// ------------------------------------------------------------------------------------
		public FwXWindow(FwApp app, string configFile)
		{
			BasicInit(app);

			Debug.Assert(File.Exists(configFile));
			m_app = app;
			m_configFile = configFile;
		}
Ejemplo n.º 12
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets the status of the previous attempt to startup the specified application.
		/// </summary>
		/// <param name="app">The application.</param>
		/// ------------------------------------------------------------------------------------
		private static StartupStatus GetPreviousStartupStatus(FwApp app)
		{
			int loadingId = app.RegistrySettings.LoadingProcessId;
			if (loadingId > 0)
			{
				// The last attempt to load the application never finished. We need to decide
				// if it didn't finish because of a crash or if its still in the process of
				// loading.
				return ExistingProcesses.Any(process => process.Id == loadingId) ?
					StartupStatus.StillLoading : StartupStatus.Failed;
			}
			return StartupStatus.Successful;
		}
Ejemplo n.º 13
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="IgnoreAppMessageProccessing"/> class.
		/// </summary>
		/// <param name="instance">The FwApp.</param>
		/// ------------------------------------------------------------------------------------
		public IgnoreAppMessageProccessing(FwApp instance)
		{
			if (instance == null)
				return;

			m_app = instance;
			try
			{
				foreach (IFwMainWnd mainWnd in instance.MainWindows)
				{
					if (mainWnd is FwMainWnd)
					{
						m_oldPrsMsgsVals[mainWnd] = ((FwMainWnd)mainWnd).Mediator.ProcessMessages;
						((FwMainWnd)mainWnd).Mediator.ProcessMessages = false;
					}
				}
			}
			catch
			{
				// This is only used when bringing up the error dialog. We don't want to bother
				// with this exception since we have no idea what state the application is in.
			}
		}
Ejemplo n.º 14
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Shutdowns the specified application. The application will be disposed of immediately.
		/// If no other applications are running, then FieldWorks will also be shutdown.
		/// </summary>
		/// <param name="app">The application to shut down.</param>
		/// <param name="fSaveSettings">True to have the application save its settings,
		/// false otherwise</param>
		/// ------------------------------------------------------------------------------------
		internal static void ShutdownApp(FwApp app, bool fSaveSettings)
		{
			if (app != s_teApp && app != s_flexApp)
				throw new ArgumentException("Application must belong to this FieldWorks", "app");

			if (fSaveSettings)
				app.SaveSettings();

			if (s_activeMainWnd != null && app.MainWindows.Contains(s_activeMainWnd))
			{
				// The application that owns the active main window is being disposed. This
				// means that the window is, most likely, already disposed.
				s_activeMainWnd = null;
			}

			RecordLastAppForProject();

			if (app == s_teApp)
				s_teApp = null;
			else if (app == s_flexApp)
				s_flexApp = null;

			// Make sure we do this after we set the variables to null to keep a race condition
			// from happening where we want to GetOrCreateApplication() for the app that is
			// being disposed.
			try
			{
				app.Dispose();
			}
			catch
			{
				// continue shutdown even with an exception. It's possible we're shutting down because
				// of a crash and we don't know what state the application is in.
			}

			ExitIfNoAppsRunning();
		}
Ejemplo n.º 15
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Attempts to shut down the specified application as nicely as possible ignoring any
		/// errors that occur.
		/// </summary>
		/// <param name="app">The application.</param>
		/// ------------------------------------------------------------------------------------
		private static void GracefullyShutDownApp(FwApp app)
		{
			if (app == null)
				return;
			// This is typically used if an exception happens so we need to ignore any errors
			// because we have no idea what state the application is in.
			ExceptionHelper.LogAndIgnoreErrors(() => ShutdownApp(app, false));
		}
Ejemplo n.º 16
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes the specified application and creates a new main window for it. Also
		/// does application-specific cache initialization.
		/// </summary>
		/// <param name="app">The application</param>
		/// <param name="progressDlg">The progress dialog.</param>
		/// <returns>True if the application was started successfully, false otherwise</returns>
		/// ------------------------------------------------------------------------------------
		private static bool InitializeApp(FwApp app, IThreadedProgress progressDlg)
		{
			using (new DataUpdateMonitor(null, "Application Initialization"))
				app.DoApplicationInitialization(progressDlg);
			using (new DataUpdateMonitor(null, "Loading Application Settings"))
				app.LoadSettings();

			using (NonUndoableUnitOfWorkHelper undoHelper = new NonUndoableUnitOfWorkHelper(
				s_cache.ServiceLocator.GetInstance<IActionHandler>()))
			using (new DataUpdateMonitor(null, "Application Cache Initialization"))
			{
				try
				{
					if (!app.InitCacheForApp(progressDlg))
						throw new StartupException(Properties.Resources.kstidCacheInitFailure);
				}
				catch (Exception e)
				{
					if (e is StartupException)
						throw;
					throw new StartupException(Properties.Resources.kstidCacheInitFailure, e, true);
				}
				undoHelper.RollBack = false;
			}

			if (s_cache.ServiceLocator.GetInstance<IUndoStackManager>().HasUnsavedChanges)
			{
				if (progressDlg != null)
				{
					progressDlg.Message = String.Format(Properties.Resources.kstidSaving, s_cache.ProjectId.UiName);
					progressDlg.IsIndeterminate = true;
				}
				s_cache.ServiceLocator.GetInstance<IUndoStackManager>().Save();
				if (progressDlg != null)
					progressDlg.IsIndeterminate = false;
			}

			return CreateAndInitNewMainWindow(app, true, null, false);
		}
Ejemplo n.º 17
0
		private static bool InitializeFirstApp(FwApp app, ProjectId projectId)
		{
			Debug.Assert(s_cache == null && s_projectId == null, "This should only get called once");
			Debug.Assert(projectId != null, "Should have exited the program");

			using (var process = Process.GetCurrentProcess())
			{
				app.RegistrySettings.LoadingProcessId = process.Id;
			}
			if (String.IsNullOrEmpty(app.RegistrySettings.LatestProject))
			{
				// Until something gets saved, we will keep track of the first project opened.
				app.RegistrySettings.LatestProject = projectId.Handle;
				app.RegistrySettings.LatestServer = projectId.ServerName ?? string.Empty;
			}

			UsageEmailDialog.IncrementLaunchCount(app.SettingsKey); // count launches for bug reporting

			ShowSplashScreen(app);

			try
			{
				// Create the cache and let the application init the cache for what it needs
				s_cache = CreateCache(projectId);
				Debug.Assert(s_cache != null, "At this point we should know which project to load and have loaded it!");

				if (s_noUserInterface || InitializeApp(app, s_splashScreen))
				{
					app.RegistrySettings.LoadingProcessId = 0;
#if !__MonoCS__
					if (!WindowsInstallerQuery.IsThisInstalled() || app.ActiveMainWindow == null)
						return true;

					// Initialize NetSparkle to check for updates:
					Settings.Default.IsBTE = WindowsInstallerQuery.IsThisBTE();

					var appCastUrl = Settings.Default.IsBTE
						? (Settings.Default.CheckForBetaUpdates
							? CoreImpl.Properties.Resources.ResourceManager.GetString("kstidAppcastBteBetasUrl")
							: CoreImpl.Properties.Resources.ResourceManager.GetString("kstidAppcastBteUrl"))
						: (Settings.Default.CheckForBetaUpdates
							? CoreImpl.Properties.Resources.ResourceManager.GetString("kstidAppcastSeBetasUrl")
							: CoreImpl.Properties.Resources.ResourceManager.GetString("kstidAppcastSeUrl"));

					var sparkle = SingletonsContainer.Get("Sparkle", () => new Sparkle(appCastUrl, app.ActiveMainWindow.Icon));
					sparkle.AboutToExitForInstallerRun += delegate(object sender, CancelEventArgs args)
						{
							CloseAllMainWindows();
							if(app.ActiveMainWindow != null)
							{
								args.Cancel = true;
							}
						};
					if (Settings.Default.AutoCheckForUpdates)
						sparkle.CheckOnFirstApplicationIdle();
#endif
					return true;
				}
			}
			catch (UnauthorizedAccessException uae)
			{
				if (MiscUtils.IsUnix)
				{
					// Tell Mono user he/she needs to logout and log back in
					MessageBox.Show(ResourceHelper.GetResourceString("ksNeedToJoinFwGroup"));
				}
				throw;
			}
			catch (FdoDataMigrationForbiddenException)
			{
				// tell the user to close all other applications using this project
				MessageBox.Show(ResourceHelper.GetResourceString("kstidDataMigrationProhibitedText"),
					ResourceHelper.GetResourceString("kstidDataMigrationProhibitedCaption"), MessageBoxButtons.OK, MessageBoxIcon.Error);
			}
			finally
			{
				CloseSplashScreen();
			}

			return false;
		}
Ejemplo n.º 18
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Gets an existing app or creates a new one for the application type specified on
		/// the command line.
		/// </summary>
		/// <param name="args">The application arguments.</param>
		/// <returns>An app to use (can be null if no valid app was specified)</returns>
		/// ------------------------------------------------------------------------------------
		private static FwApp GetOrCreateApplication(FwAppArgs args)
		{
			var appAbbrev = args.AppAbbrev;
			if (String.IsNullOrEmpty(appAbbrev))
			{
				// Probably a double-click of the data file. See if we can figure out who last had it open.
				appAbbrev = GetDefaultApp(args);
			}
			if (appAbbrev.Equals(FwUtils.ksTeAbbrev, StringComparison.InvariantCultureIgnoreCase))
			{
				if (FwUtils.IsTEInstalled)
				{
					if (s_teApp == null)
					{
						s_teApp = (FwApp)DynamicLoader.CreateObject(FwDirectoryFinder.TeDll,
							FwUtils.ksFullTeAppObjectName, s_fwManager, GetHelpTopicProvider(appAbbrev), args);
						s_teAppKey = s_teApp.SettingsKey;
					}
					return s_teApp;
				}
			}
			else if (appAbbrev.Equals(FwUtils.ksFlexAbbrev, StringComparison.InvariantCultureIgnoreCase))
			{
				if (FwUtils.IsFlexInstalled)
				{
					if (s_flexApp == null)
					{
						s_flexApp = (FwApp)DynamicLoader.CreateObject(FwDirectoryFinder.FlexDll,
							FwUtils.ksFullFlexAppObjectName, s_fwManager, GetHelpTopicProvider(appAbbrev), args);
						s_flexAppKey = s_flexApp.SettingsKey;
					}
					return s_flexApp;
				}
			}

			ShowCommandLineHelp();
			return null;
		}
Ejemplo n.º 19
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Import an OXES (Open XML for Editing Scripture) file.
		/// </summary>
		/// <param name="mainWnd">The main WND.</param>
		/// <param name="importCallbacks">The import callbacks.</param>
		/// <param name="app">The app.</param>
		/// ------------------------------------------------------------------------------------
		public static void ImportXml(FwMainWnd mainWnd, ITeImportCallbacks importCallbacks,
			FwApp app)
		{
			TeImportManager mgr = new TeImportManager(mainWnd, importCallbacks, app, false);
			mgr.ImportXml();
		}
Ejemplo n.º 20
0
		private static void WarnUserAboutFailedLiftImportIfNecessary(FwApp fwApp)
		{
			var mainWindow = fwApp.ActiveMainWindow as IFwMainWnd;
			if(mainWindow != null)
			{
				mainWindow.Mediator.SendMessage("WarnUserAboutFailedLiftImportIfNecessary", null);
			}
		}
Ejemplo n.º 21
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="TeImportManager"/> class.
		/// </summary>
		/// <param name="mainWnd">The main window initiating the import</param>
		/// <param name="importCallbacks">The import callbacks.</param>
		/// <param name="app">The app.</param>
		/// <param name="fParatextStreamlinedImport">if set to <c>true</c> do a Paratext
		/// streamlined import (minimal UI).</param>
		/// ------------------------------------------------------------------------------------
		internal TeImportManager(FwMainWnd mainWnd, ITeImportCallbacks importCallbacks,
			FwApp app, bool fParatextStreamlinedImport)
			: this(app.Cache, mainWnd.StyleSheet, app, fParatextStreamlinedImport)
		{
			m_mainWnd = mainWnd;
			m_importCallbacks = importCallbacks;
		}
Ejemplo n.º 22
0
		public void SetUp()
		{
			CheckDisposed();

			m_inMemoryCache = InMemoryFdoCache.CreateInMemoryFdoCache();
			m_mainWnd = new DynamicMock(typeof(IFwMainWnd));
			m_mainWnd.SetupResult("Cache", Cache);
			m_app = new DummyFwApp();
		}
Ejemplo n.º 23
0
		private void BasicInit(FwApp app)
		{
			m_delegate = new MainWindowDelegate(this);
			m_delegate.App = app;
			m_mediator.HelpTopicProvider = app;
			m_mediator.FeedbackInfoProvider = app;
			m_mediator.PropertyTable.SetProperty("App", app);
			m_mediator.PropertyTable.SetPropertyPersistence("App", false);

			string path = null;
			if (app != null) // if configFile in FwXApp == null
			{
				path = FdoFileHelper.GetConfigSettingsDir(app.Cache.ProjectId.ProjectFolder);
				Directory.CreateDirectory(path);
			}
			m_mediator.PropertyTable.UserSettingDirectory = path;
		}
Ejemplo n.º 24
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Moves the external link directory and files to the new FW 7.0 or later location.
		/// </summary>
		/// <param name="app">The application.</param>
		/// ------------------------------------------------------------------------------------
		private static void MoveExternalLinkDirectoryAndFiles(FwApp app)
		{
			var sLinkedFilesRootDir = app.Cache.LangProject.LinkedFilesRootDir;
			NonUndoableUnitOfWorkHelper.Do(app.Cache.ActionHandlerAccessor, () =>
			{
				app.Cache.LangProject.LinkedFilesRootDir = FdoFileHelper.GetDefaultLinkedFilesDir(
					app.Cache.ProjectId.ProjectFolder);
			});
			app.UpdateExternalLinks(sLinkedFilesRootDir);
		}
Ejemplo n.º 25
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Construct a new form
		/// </summary>
		/// <param name="app">The app.</param>
		/// <param name="wndCopyFrom">Source window to copy from</param>
		/// <param name="iconStream">The icon stream.</param>
		/// <param name="configFile">The config file.</param>
		/// <param name="startupLink">The link to follow once the window is initialized.</param>
		/// <param name="inAutomatedTest">if set to <c>true</c>, (well behaved) code will avoid
		/// bringing up dialogs that we cannot respond to (like confirmation and error dialogs)
		/// and it should cause the system to avoid saving the settings to a file (or at least
		/// saving them in some special way so as not to mess up the user.)</param>
		/// ------------------------------------------------------------------------------------
		public FwXWindow(FwApp app, Form wndCopyFrom, Stream iconStream,
			string configFile, FwLinkArgs startupLink, bool inAutomatedTest)
		{
			BasicInit(app);
			m_startupLink = startupLink;

			Debug.Assert(File.Exists(configFile));
			m_app = app;
			m_configFile = configFile;

			Init(iconStream, wndCopyFrom, app.Cache);
			if(inAutomatedTest)
			{
				Mediator.PropertyTable.SetProperty("DoingAutomatedTest", true);
				Mediator.PropertyTable.SetPropertyPersistence("DoingAutomatedTest", false);
			}

			// The order of the next two lines has been changed because the loading of the UI
			// properly depends on m_viewHelper being initialized.  Why this was not so with DNB
			// I do not know.
			// Here is the orginal order (along with a comment between them that seemed to imply this
			// new order could be a problem, but no obvious ones have appeared in my testing.

		   /*
			* LoadUI(configFile);
			* // Reload additional property settings that depend on knowing the database name.
			* m_viewHelper = new ActiveViewHelper(this);
			*/

			m_viewHelper = new ActiveViewHelper(this);
			LoadUI(configFile);

			m_viewHelper.ActiveViewChanged += new EventHandler<EventArgs>(ActiveViewChanged);
		}
Ejemplo n.º 26
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected override void Dispose(bool disposing)
		{
			Debug.WriteLineIf(!disposing, "****************** Missing Dispose() call for " + GetType().Name + ". ******************");

			// Must not be run more than once.
			if (IsDisposed || m_beingDisposed || Disposing)
				return;
			m_beingDisposed = true;
			if (disposing)
			{
				foreach (Control ctrl in m_rgClientViews.Values)
				{
					// Dispose of any views that aren't in the form currently.
					if (ctrl.Parent == null)
						ctrl.Dispose();
				}

				if (m_mediator != null)
				{
					m_mediator.ProcessMessages = false;
					m_mediator.RemoveColleague(this);
				}

				if (m_cboZoomPercent != null)
					m_cboZoomPercent.Dispose();
				if (m_paraStylesComboBox != null)
					m_paraStylesComboBox.Dispose();
				if (m_charStylesComboBox != null)
					m_charStylesComboBox.Dispose();
				if (m_writingSystemSelector != null)
					m_writingSystemSelector.Dispose();

				if (m_progressHandler != null)
					m_progressHandler.Dispose();
				if (m_writingSystemSelector != null)
					m_writingSystemSelector.Dispose();
				if (m_UndoRedoDropDown != null)
					m_UndoRedoDropDown.Dispose();
				if (components != null)
					components.Dispose();
				// no need to explicitly call Dispose on m_persistence - it's part of
				// components collection and gets disposed there.
				if (m_rgClientViews != null)
					m_rgClientViews.Clear();
				if (m_tmAdapter != null)
				{
					m_tmAdapter.LoadControlContainerItem -= LoadCustomToolBarControls;
					m_tmAdapter.InitializeComboItem -= InitializeToolBarCombos;
					m_tmAdapter.Dispose();
				}
				if (m_cache != null)
					m_cache.ProjectNameChanged -= ProjectNameChanged;
				if (m_app != null)
				{
					// The removing of the window from the app's collection needs to happen later, after
					// this main window is already disposed of. This is needed for side-effects
					// that require a running message loop (such as closing the TE notes view
					// which would normally happen at this call without a running message loop)
					m_app.FwManager.ExecuteAsync(m_app.RemoveWindow, this);
				}
			}
			m_cboZoomPercent = null;
			m_paraStylesComboBox = null;
			m_charStylesComboBox = null;
			m_writingSystemSelector = null;
			m_delegate = null;
			m_tmAdapter = null;
			m_UndoRedoDropDown = null;
			m_writingSystemSelector = null;
			m_StyleSheet = null;
			m_selectedView = null;
			m_rgClientViews = null;

#if !__MonoCS__
			base.Dispose(disposing);
#else
			try
			{
				base.Dispose(disposing);
			}
			catch (System.ArgumentOutOfRangeException)
			{
				// TODO-Linux: examine ToolStrip disposal in UIAdapter
				// is ToolStrip (from UIAdapter?) being Disposed multiple times?
			}
#endif

			if (disposing)
			{
				if (m_viewHelper != null)
					m_viewHelper.Dispose();
				if (m_mediator != null)
					m_mediator.Dispose();
			}

			m_cache = null;
			m_viewHelper = null;
			m_mediator = null;
			m_app = null;
			m_beingDisposed = false;
		}
Ejemplo n.º 27
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)
				return;

			if (disposing)
			{
				// Dispose managed resources here.
				if (m_app != null)
					m_app.Dispose(); // Ensure cache disposed and WSF shutdown.
				if (m_inMemoryCache != null)
					m_inMemoryCache.Dispose();
			}

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

			m_isDisposed = true;
		}
Ejemplo n.º 28
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Creates a new main window and initializes it. The specified App is responsible for
		/// creating the proper main window type.
		/// </summary>
		/// <param name="app">The app</param>
		/// <param name="fNewCache"><c>true</c> if we didn't reuse an existing cache</param>
		/// <param name="wndCopyFrom">The window to copy from (optional).</param>
		/// <param name="fOpeningNewProject"><c>true</c> if opening a new project</param>
		/// <returns>True if the main window was create and initialized successfully</returns>
		/// ------------------------------------------------------------------------------------
		internal static bool CreateAndInitNewMainWindow(FwApp app, bool fNewCache, Form wndCopyFrom,
			bool fOpeningNewProject)
		{
			Debug.Assert(app == s_flexApp || app == s_teApp);

			WriteSplashScreen(app.GetResourceString("kstidInitWindow"));

			Form fwMainWindow;
			try
			{
				// Construct the new window, of the proper derived type
				fwMainWindow = app.NewMainAppWnd(s_splashScreen, fNewCache, wndCopyFrom, fOpeningNewProject);

				// Let the application do its initialization of the new window
				using (new DataUpdateMonitor(fwMainWindow, "Creating new main window"))
					app.InitAndShowMainWindow(fwMainWindow, wndCopyFrom);
				// It seems to get activated before we connect the Activate event. But it IS active by now;
				// so just record it now as the active one.
				s_activeMainWnd = (IFwMainWnd)fwMainWindow;
			}
			catch (StartupException ex)
			{
				// REVIEW: Can this actually happen when just creating a new main window?
				CloseSplashScreen();
				MessageBox.Show(ex.Message, Properties.Resources.ksErrorCaption,
					MessageBoxButtons.OK, MessageBoxIcon.Error);
				return false;
			}

			CloseSplashScreen();

			if (!((IFwMainWnd)fwMainWindow).OnFinishedInit())
				return false;	// did not initialize properly!

			fwMainWindow.Activated += FwMainWindowActivated;
			fwMainWindow.Closing += FwMainWindowClosing;
			return true;
		}
Ejemplo n.º 29
0
		public void TearDown()
		{
			CheckDisposed();

			// Note: m_inMemoryCache has to be dispsoed first,
			// and then the app can be disposed.
			// Otherwise, m_inMemoryCache can't do waht it wants with
			// its NewFdoCache object, as it will already have been disposed.
			if (m_inMemoryCache != null)
			{
				m_inMemoryCache.Dispose();
				m_inMemoryCache = null;
			}
			if (m_app != null)
			{
				m_app.Dispose(); // Ensure cache disposed and WSF shutdown.
				m_app = null;
			}
			m_mainWnd = null;
		}
Ejemplo n.º 30
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initializes a new instance of the <see cref="FwMainWnd"/> class.
		/// </summary>
		/// <param name="app">The app.</param>
		/// <param name="wndCopyFrom">The Window to copy from.</param>
		/// ------------------------------------------------------------------------------------
		public FwMainWnd(FwApp app, Form wndCopyFrom) : this(app.Cache)
		{
			m_app = app;
			m_delegate.App = app;
			m_fWindowIsCopy = (wndCopyFrom != null);

			CreateMenusAndToolBars();
			CreateSideBarInfoBarAdapter();

			m_mediator.HelpTopicProvider = app;
			m_mediator.FeedbackInfoProvider = app;
			m_mediator.PropertyTable.SetProperty("App", app);
			m_mediator.PropertyTable.SetPropertyPersistence("App", false);
		}