Inheritance: System.Windows.Forms.Form, IFWDisposable, ICreateLangProject
示例#1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Lets the user create a new project
		/// </summary>
		/// <param name="dialogOwner">The owner of the dialog (and any message boxes shown)</param>
		/// <param name="app">This is needed for opening an existing project.</param>
		/// <param name="helpTopicProvider">The help topic provider.</param>
		/// <returns>
		/// The project that was created (and needs to be loaded), or null if the user
		/// canceled.
		/// </returns>
		/// ------------------------------------------------------------------------------------
		internal static ProjectId CreateNewProject(Form dialogOwner, FwApp app, IHelpTopicProvider helpTopicProvider)
		{
			using (var dlg = new FwNewLangProject())
			{
				dlg.SetDialogProperties(helpTopicProvider);
				switch (dlg.DisplayDialog(dialogOwner))
				{
					case DialogResult.OK:
						if (dlg.IsProjectNew)
							return new ProjectId(dlg.GetDatabaseFile(), null);
						else
						{
							// The user tried to create a new project which already exists and
							// then choose to open the project. Therefore open the project and return
							// null for the ProjectId so the caller of this method does not try to
							// create a new project.
							ProjectId projectId = new ProjectId(dlg.GetDatabaseFile(), null);
							OpenExistingProject(projectId, app, dialogOwner);
							return null;
						}
					case DialogResult.Abort:
						// If we get an Abort it means that we got an exception in the dialog (e.g.
						// in the OnLoad method). We can't just catch that exception here (probably
						// because of the extra message loop the dialog has), so we close the dialog
						// and return Abort.
						MessageBox.Show(dialogOwner,
							ResourceHelper.GetResourceString("kstidNewProjError"),
							ResourceHelper.GetResourceString("kstidMiscError"));
						break;
				}
			}
			return null;
		}
示例#2
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Opens the New Project dialog
		/// </summary>
		/// <param name="newWindowToAdjustFrom"></param>
		/// <returns>The result from FwNewLangProject dialog.</returns>
		/// ------------------------------------------------------------------------------------
		public DialogResult NewProjectDialog(Form newWindowToAdjustFrom)
		{
			bool fAssignedOkToCloseApp = newWindowToAdjustFrom != null;
			try
			{
				if (fAssignedOkToCloseApp)
					OkToCloseApp = false;
				DialogResult result;

				using (FwNewLangProject dlg = new FwNewLangProject())
				{
					dlg.SetDialogProperties(this);
					result = dlg.DisplayDialog(newWindowToAdjustFrom);

					// Make sure we don't pass in a window that isn't a main window.
					// This can happen from the Welcome to Fieldworks dialog.
					if (!(newWindowToAdjustFrom is IFwMainWnd))
						newWindowToAdjustFrom = null;

					if (result == DialogResult.OK)
					{
						if (dlg.IsProjectNew)
						{
							ReplaceCommandLine(new string[] { "-db", dlg.DatabaseName });
							Form wnd = NewMainWindow(null, true);
							if (wnd != null && newWindowToAdjustFrom != null)
								AdjustNewWindowPosition(wnd, newWindowToAdjustFrom);
						}
						else
						{
							// Only attempt to open the project if it isn't already open.
							if (dlg.Project != null && !dlg.Project.InUse)
							{
								try
								{
									string serverName = (newWindowToAdjustFrom is FwMainWnd ?
										((FwMainWnd)newWindowToAdjustFrom).Cache.ServerName :
										MiscUtils.LocalServerName);
									CreateProjectWindow(serverName, dlg.Project.DatabaseName);
								}
								catch (ApplicationException e)
								{
									ErrorReporter.ReportException(e, newWindowToAdjustFrom, false);
								}
							}
						}
					}
					else if (result == DialogResult.Abort)
					{
						// If we get an Abort it means that we got an exception in the dialog (e.g.
						// in the OnLoad method). We can't just catch that exception here (probably
						// because of the extra message loop the dialog has), so we close the dialog
						// and return Abort.
						MessageBox.Show(newWindowToAdjustFrom,
							GetResourceString("kstidNewProjError"),
							GetResourceString("kstidMiscError"));
					}
				}
				return result;
			}
			finally
			{
				if (fAssignedOkToCloseApp)
					OkToCloseApp = true;
			}
		}