/// <summary>
        /// Helper method for CreateProjectLauncher tests.
        /// </summary>
        private void AssertCreateProjectLauncherWorks(string expectedPath)
        {
            using (var app = new DummyFwApp())
            {
                var dummyWindow = new DummyMainWindowDelegateCallbacks();
                dummyWindow.Cache = Cache;

                var window = new MainWindowDelegate(dummyWindow);
                window.App = app;

                window.CreateShortcut(Path.GetDirectoryName(expectedPath));

                Assert.That(FileUtils.SimilarFileExists(expectedPath), Is.True,
                            String.Format("Expected file does not exist: {0}", expectedPath));

                string actualLauncherData;
                byte[] launcherBuffer;
                using (var launcher = FileUtils.OpenStreamForRead(expectedPath))
                {
                    launcherBuffer = new byte[launcher.Length];
                    launcher.Read(launcherBuffer, 0, launcherBuffer.Length);
                }
                var enc = new UTF8Encoding(false);
                actualLauncherData = enc.GetString(launcherBuffer);

                var description = ResourceHelper.FormatResourceString(
                    "kstidCreateShortcutLinkDescription", Cache.ProjectId.UiName,
                    app.ApplicationName);
                string expectedLauncherData = String.Format(
                    "[Desktop Entry]{1}" +
                    "Version=1.0{1}" +
                    "Terminal=false{1}" +
                    "Exec=fieldworks-flex -db \"{0}\" -s \"\"{1}" +
                    "Icon=fieldworks-flex{1}" +
                    "Type=Application{1}" +
                    "Name={0}{1}" +
                    "Comment=" + description + "{1}",
                    m_projectName, Environment.NewLine);
                Assert.That(actualLauncherData, Is.EqualTo(expectedLauncherData));
            }
        }
        public void CreateShortcut_inNonExistentDirectory_notCreatedAndNoThrow()
        {
            var nonexistentDir = "/nonexistent";
            var path           = Path.Combine(nonexistentDir, m_projectName + m_pathExtension);

            Assert.That(FileUtils.DirectoryExists(nonexistentDir), Is.False,
                        "Unit test error. Should be using a nonexistent directory.");

            using (var app = new DummyFwApp())
            {
                var dummyWindow = new DummyMainWindowDelegateCallbacks();
                dummyWindow.Cache = Cache;

                var window = new MainWindowDelegate(dummyWindow);
                window.App = app;

                Assert.DoesNotThrow(() => {
                    window.CreateShortcut(nonexistentDir);
                });
            }

            Assert.That(FileUtils.DirectoryExists(nonexistentDir), Is.False,
                        "Nonexistent directory should not have been made to hold launcher.");
        }
Пример #3
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing"><c>true</c> to release both managed and unmanaged
		/// resources; <c>false</c> to release only unmanaged resources.
		/// </param>
		/// -----------------------------------------------------------------------------------
		protected override void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			if (disposing)
			{
				if (m_viewHelper != null)
					m_viewHelper.Dispose();
				if (m_app != null)
				{
					// The removing of the window 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);
				}
			}

			// NOTE: base.Dispose() may need the FdoCache which RemoveWindow() wants to delete.
			base.Dispose(disposing);

			m_viewHelper = null;
			m_delegate = null;
		}
Пример #4
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;
		}
Пример #5
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// <param name="disposing"><c>true</c> to release both managed and unmanaged
		/// resources; <c>false</c> to release only unmanaged resources.
		/// </param>
		/// -----------------------------------------------------------------------------------
		protected override void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			FdoCache wndCache = null;
			if (disposing)
			{
				if (m_delegate != null)
					m_delegate.Dispose();
				if (m_viewHelper != null)
					m_viewHelper.Dispose();
				if (FwApp.App != null)
				{
					FwApp.App.OkToCloseApp = false;
					FwApp.App.RemoveWindow(this, out wndCache);
				}
			}

			// NOTE: base.Dispose() may need the FdoCache which RemoveWindow() wants to delete.
			base.Dispose(disposing);

			if (disposing)
			{
				if (FwApp.App != null)
				{
					FwApp.App.OkToCloseApp = true;
					if (wndCache != null)
						FwApp.App.RemoveFdoCache(wndCache);
				}
			}
			m_viewHelper = null;
			m_delegate = null;
			IncomingLinkHandler = null;
		}
Пример #6
0
		private void BasicInit()
		{
			m_delegate = new MainWindowDelegate(this);
			IncomingLinkHandler = new LinkDelegate(OnIncomingLink);
		}
Пример #7
0
		/// <summary>
		/// Helper method for CreateProjectLauncher tests.
		/// </summary>
		private void AssertCreateProjectLauncherWorks(string expectedPath)
		{
			using (var app = new DummyFwApp())
			{
				var dummyWindow = new DummyMainWindowDelegateCallbacks();
				dummyWindow.Cache = Cache;

				var window = new MainWindowDelegate(dummyWindow);
				window.App = app;

				window.CreateShortcut(Path.GetDirectoryName(expectedPath));

				Assert.That(FileUtils.SimilarFileExists(expectedPath), Is.True,
					String.Format("Expected file does not exist: {0}", expectedPath));

				string actualLauncherData;
				byte[] launcherBuffer;
				using (var launcher = FileUtils.OpenStreamForRead(expectedPath))
				{
					launcherBuffer = new byte[launcher.Length];
					launcher.Read(launcherBuffer, 0, launcherBuffer.Length);
				}
				var enc = new UTF8Encoding(false);
				actualLauncherData = enc.GetString(launcherBuffer);

				var description = ResourceHelper.FormatResourceString(
					"kstidCreateShortcutLinkDescription", Cache.ProjectId.UiName,
					app.ApplicationName);
				string expectedLauncherData = String.Format(
					"[Desktop Entry]{1}" +
					"Version=1.0{1}" +
					"Terminal=false{1}" +
					"Exec=fieldworks-flex -db \"{0}\" -s \"\"{1}" +
					"Icon=fieldworks-flex{1}" +
					"Type=Application{1}" +
					"Name={0}{1}" +
					"Comment=" + description + "{1}",
					m_projectName, Environment.NewLine);
				Assert.That(actualLauncherData, Is.EqualTo(expectedLauncherData));
			}
		}
Пример #8
0
		public void CreateShortcut_inNonExistentDirectory_notCreatedAndNoThrow()
		{
			var nonexistentDir = "/nonexistent";
			var path = Path.Combine(nonexistentDir, m_projectName + m_pathExtension);

			Assert.That(FileUtils.DirectoryExists(nonexistentDir), Is.False,
				"Unit test error. Should be using a nonexistent directory.");

			using (var app = new DummyFwApp())
			{
				var dummyWindow = new DummyMainWindowDelegateCallbacks();
				dummyWindow.Cache = Cache;

				var window = new MainWindowDelegate(dummyWindow);
				window.App = app;

				Assert.DoesNotThrow(() => {
					window.CreateShortcut(nonexistentDir);
				});
			}

			Assert.That(FileUtils.DirectoryExists(nonexistentDir), Is.False,
				"Nonexistent directory should not have been made to hold launcher.");
		}
Пример #9
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;
		}
Пример #10
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Default constructor for FwMainWnd.
		/// </summary>
		/// -----------------------------------------------------------------------------------
		protected FwMainWnd()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			m_mediator = new Mediator();
			m_delegate = new MainWindowDelegate(this);
//			m_Resources = new System.Resources.ResourceManager(typeof(FwMainWnd));

			m_rgClientViews = new Dictionary<string, IRootSite>();
			m_viewHelper = new ActiveViewHelper(this);

			m_progressHandler = new StatusBarProgressHandler(statusBarFwPanel1, ProgressPanel);

			// Set the width of the side bar
			splitContainer.MaxFirstPanePercentage = 0.5f;
			splitContainer.SplitterDistance = kDefaultSideBarWidth;
			splitContainer.SettingsKey = SettingsKey;

			Debug.Assert(components is FwContainer, "Member variable components should be of " +
				"type FwContainer. If the Designer changed it, please change it back!");
			if (!(components is FwContainer))
				components = new FwContainer(components);

			// Add this as a component so that children can retrieve services
			components.Add(this);
		}
Пример #11
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected override void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed || m_beingDisposed || Disposing)
				return;
			m_beingDisposed = true;

			FdoCache wndCache = null;
			if (disposing)
			{
				foreach (Control ctrl in m_rgClientWindows.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_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_delegate != null)
					m_delegate.Dispose();
				if (m_rgClientWindows != null)
					m_rgClientWindows.Clear();

				if (m_cache != null && m_cache.ProgressBar == m_progressHandler)
					m_cache.ProgressBar = null;

				if (FwApp.App != null)
				{
					FwApp.App.OkToCloseApp = false; // Make sure we don't shutdown too soon
					FwApp.App.RemoveWindow(this, out wndCache);
				}
			}
			m_delegate = null;
			m_UndoRedoDropDown = null;
			m_writingSystemSelector = null;
			m_StyleSheet = null;
			m_selectedView = null;
			m_rgClientWindows = null;

			base.Dispose(disposing);

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

				if (FwApp.App != null)
				{
					// Remove the cache as the last step. Hopefully this will fix some
					// ObjectDisposed exceptions we get but can't reproduce. (TE-8340)
					FwApp.App.OkToCloseApp = true;
					if (wndCache != null)
						FwApp.App.RemoveFdoCache(wndCache);
				}
			}

			m_cache = null;
			m_viewHelper = null;
			m_mediator = null;
			m_beingDisposed = false;
		}