/// <summary>
        /// Pops up a dialog to ask the user how they want to initialize their anthro lists.
        /// Returns a string indicating what file to load, or null if the user selected the custom (make your own) option
        /// </summary>
        public static string PickAnthroList(string description, IHelpTopicProvider helpTopicProvider)
        {
            // Figure out what lists are available (in {FW}/Templates/*.xml).

            var    sFilePattern   = Path.Combine(FwDirectoryFinder.TemplateDirectory, "*.xml");
            var    fHaveOCM       = false;
            var    fHaveFRAME     = false;
            var    rgsAnthroFiles = new List <string>();
            var    rgsXmlFiles    = Directory.GetFiles(FwDirectoryFinder.TemplateDirectory, "*.xml", SearchOption.TopDirectoryOnly);
            string sFile;

            for (var i = 0; i < rgsXmlFiles.Length; ++i)
            {
                sFile = Path.GetFileName(rgsXmlFiles[i]);
                if (Path.GetFileName(sFile) == "OCM.xml")
                {
                    fHaveOCM = true;
                }
                else if (Path.GetFileName(sFile) == "OCM-Frame.xml")
                {
                    fHaveFRAME = true;
                }
                else if (sFile != "NewLangProj.xml" && IsAnthroList(rgsXmlFiles[i]))
                {
                    rgsAnthroFiles.Add(sFile);
                }
            }

            // display a dialog for the user to select a list.

            sFile = null;
            if (fHaveOCM || fHaveFRAME || rgsAnthroFiles.Count > 0)
            {
                using (FwCheckAnthroListDlg dlg = new FwCheckAnthroListDlg())
                {
                    dlg.SetValues(fHaveOCM, fHaveFRAME, rgsAnthroFiles, helpTopicProvider);
                    if (!String.IsNullOrEmpty(description))
                    {
                        dlg.SetDescription(description);
                    }
                    //EnableRelatedWindows(hwnd, false);
                    DialogResult res = dlg.ShowDialog();
                    //EnableRelatedWindows(hwnd, true);
                    if (res == DialogResult.OK)
                    {
                        int nChoice = dlg.GetChoice();
                        switch (nChoice)
                        {
                        case kralUserDef:
                            break;

                        case kralOCM:
                            sFile = Path.Combine(FwDirectoryFinder.TemplateDirectory, "OCM.xml");
                            break;

                        case kralFRAME:
                            sFile = Path.Combine(FwDirectoryFinder.TemplateDirectory, "OCM-Frame.xml");
                            break;

                        default:
                            Debug.Assert(nChoice >= 0 && nChoice < rgsAnthroFiles.Count);
                            sFile = Path.Combine(FwDirectoryFinder.TemplateDirectory, rgsAnthroFiles[nChoice]);
                            break;
                        }
                    }
                }
            }

            return(sFile);
        }
		/// <summary>
		/// Pops up a dialog to ask the user how they want to initialize their anthro lists.
		/// Returns a string indicating what file to load, or null if the user selected the custom (make your own) option
		/// </summary>
		public static string PickAnthroList(string description, IHelpTopicProvider helpTopicProvider)
		{
			// Figure out what lists are available (in {FW}/Templates/*.xml).

			var sFilePattern = Path.Combine(FwDirectoryFinder.TemplateDirectory, "*.xml");
			var fHaveOCM = false;
			var fHaveFRAME = false;
			var rgsAnthroFiles = new List<string>();
			var rgsXmlFiles = Directory.GetFiles(FwDirectoryFinder.TemplateDirectory, "*.xml", SearchOption.TopDirectoryOnly);
			string sFile;
			for (var i = 0; i < rgsXmlFiles.Length; ++i)
			{
				sFile = Path.GetFileName(rgsXmlFiles[i]);
				if (Path.GetFileName(sFile) == "OCM.xml")
					fHaveOCM = true;
				else if (Path.GetFileName(sFile) == "OCM-Frame.xml")
					fHaveFRAME = true;
				else if (sFile != "NewLangProj.xml" && IsAnthroList(rgsXmlFiles[i]))
					rgsAnthroFiles.Add(sFile);
			}

			// display a dialog for the user to select a list.

			sFile = null;
			if (fHaveOCM || fHaveFRAME || rgsAnthroFiles.Count > 0)
			{
				using (FwCheckAnthroListDlg dlg = new FwCheckAnthroListDlg())
				{
					dlg.SetValues(fHaveOCM, fHaveFRAME, rgsAnthroFiles, helpTopicProvider);
					if (!String.IsNullOrEmpty(description))
						dlg.SetDescription(description);
					//EnableRelatedWindows(hwnd, false);
					DialogResult res = dlg.ShowDialog();
					//EnableRelatedWindows(hwnd, true);
					if (res == DialogResult.OK)
					{
						int nChoice = dlg.GetChoice();
						switch (nChoice)
						{
							case kralUserDef:
								break;
							case kralOCM:
								sFile = Path.Combine(FwDirectoryFinder.TemplateDirectory, "OCM.xml");
								break;
							case kralFRAME:
								sFile = Path.Combine(FwDirectoryFinder.TemplateDirectory, "OCM-Frame.xml");
								break;
							default:
								Debug.Assert(nChoice >= 0 && nChoice < rgsAnthroFiles.Count);
								sFile = Path.Combine(FwDirectoryFinder.TemplateDirectory, rgsAnthroFiles[nChoice]);
								break;
						}
					}
				}
			}

			return sFile;
		}
Beispiel #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Create a new language project showing a progress dialog.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected void CreateNewLangProjWithProgress()
        {
            try
            {
                using (var progressDlg = new ProgressDialogWithTask(this))
                {
                    progressDlg.Title = string.Format(FwCoreDlgs.kstidCreateLangProjCaption, ProjectName);
                    string anthroFile = null;
                    if (DisplayUi)                     // Prevents dialogs from showing during unit tests.
                    {
                        anthroFile = FwCheckAnthroListDlg.PickAnthroList(null, m_helpTopicProvider);
                    }
                    using (new WaitCursor())
                    {
                        // Remove primary WritingSystems; remaining WS's will be used as Additional WritingSystems for the new project
                        RemoveWs(m_newVernWss, m_cbVernWrtSys.SelectedItem);
                        RemoveWs(m_newAnalysisWss, m_cbAnalWrtSys.SelectedItem);

                        using (var threadHelper = new ThreadHelper())
                        {
                            m_dbFile = (string)progressDlg.RunTask(DisplayUi, FdoCache.CreateNewLangProj,
                                                                   ProjectName, FwDirectoryFinder.FdoDirectories, threadHelper, m_cbAnalWrtSys.SelectedItem,
                                                                   m_cbVernWrtSys.SelectedItem,
                                                                   ((PalasoWritingSystem)m_wsManager.UserWritingSystem).RFC5646,
                                                                   m_newAnalysisWss, m_newVernWss, anthroFile);
                        }
                    }
                }
            }
            catch (WorkerThreadException wex)
            {
                Exception e = wex.InnerException;
                if (e is UnauthorizedAccessException)
                {
                    if (MiscUtils.IsUnix)
                    {
                        // Tell Mono user he/she needs to logout and log back in
                        MessageBox.Show(ResourceHelper.GetResourceString("ksNeedToJoinFwGroup"));
                    }
                    else
                    {
                        MessageBox.Show(string.Format(FwCoreDlgs.kstidErrorNewDb, e.Message),
                                        FwUtils.ksSuiteName);
                    }
                    m_fIgnoreClose = true;
                    DialogResult   = DialogResult.Cancel;
                }
                else if (e.GetBaseException() is PathTooLongException)
                {
                    Show();
                    m_fIgnoreClose = true;
                    MessageBox.Show(String.Format(FwCoreDlgs.kstidErrorProjectNameTooLong, ProjectName),
                                    FwUtils.ksSuiteName);
                }
                else if (e is ApplicationException)
                {
                    MessageBox.Show(string.Format(FwCoreDlgs.kstidErrorNewDb, e.Message),
                                    FwUtils.ksSuiteName);

                    m_fIgnoreClose = true;
                    DialogResult   = DialogResult.Cancel;
                }
                else if (e is StartupException)
                {
                    MessageBox.Show(string.Format(FwCoreDlgs.kstidErrorNewDb, e.Message),
                                    FwUtils.ksSuiteName);

                    DialogResult = DialogResult.Cancel;
                }
                else
                {
                    // REVIEW Hasso 2013.10: If we don't need to call OnClosing (we shouldn't), instead of using m_fIgnoreClose, we could set
                    // DialogResult = DialogResult.None; and eliminate a redundant flow-control variable
                    m_fIgnoreClose = true;
                    DialogResult   = DialogResult.Cancel;
                    throw new Exception(FwCoreDlgs.kstidErrApp, e);
                }
            }
        }
        /// <summary>
        /// Check whether the anthropology list exists.  If not, initialize it, popping
        /// up a dialog to ask the user how he wants it done.
        /// Returning true indicates an anthro list was actually loaded during first-time initialization.
        /// </summary>
        public bool CheckAnthroList(ILangProject proj, Form parent, int wsDefault, IHelpTopicProvider helpTopicProvider)
        {
            // Don't bother loading the list into a memory-only project.  These are used for
            // testing, and don't want to be slowed down by disk accesses.
            if (proj.Cache.ProjectId.Type == FDOBackendProviderType.kMemoryOnly)
            {
                return(false);
            }

            // 1. Determine whether or not the Anthropology List has been initialized.
            if (proj.AnthroListOA != null && proj.AnthroListOA.Name.StringCount > 0)
            {
                if (proj.AnthroListOA.ItemClsid == 0 || proj.AnthroListOA.Depth == 0)
                {
                    proj.Cache.DomainDataByFlid.BeginNonUndoableTask();
                    proj.AnthroListOA.ItemClsid = CmAnthroItemTags.kClassId;
                    proj.AnthroListOA.Depth     = 127;
                    proj.Cache.DomainDataByFlid.EndNonUndoableTask();
                }
                return(false);
                // The Anthropology List may still be empty, but it's initialized!
            }
            // 2. Figure out what lists are available (in {FW}/Templates/*.xml).

            string        sFilePattern   = Path.Combine(DirectoryFinder.TemplateDirectory, "*.xml");
            bool          fHaveOCM       = false;
            bool          fHaveFRAME     = false;
            List <string> rgsAnthroFiles = new List <string>();

            string[] rgsXmlFiles = Directory.GetFiles(DirectoryFinder.TemplateDirectory, "*.xml", SearchOption.TopDirectoryOnly);
            string   sFile;

            for (int i = 0; i < rgsXmlFiles.Length; ++i)
            {
                sFile = Path.GetFileName(rgsXmlFiles[i]);
                if (Path.GetFileName(sFile) == "OCM.xml")
                {
                    fHaveOCM = true;
                }
                else if (Path.GetFileName(sFile) == "OCM-Frame.xml")
                {
                    fHaveFRAME = true;
                }
                else if (sFile != "NewLangProj.xml" && IsAnthroList(rgsXmlFiles[i]))
                {
                    rgsAnthroFiles.Add(sFile);
                }
            }

            // 3. display a dialog for the user to select a list.

            sFile = null;
            if (fHaveOCM || fHaveFRAME || rgsAnthroFiles.Count > 0)
            {
                using (FwCheckAnthroListDlg dlg = new FwCheckAnthroListDlg())
                {
                    dlg.SetValues(fHaveOCM, fHaveFRAME, rgsAnthroFiles, helpTopicProvider);
                    if (!String.IsNullOrEmpty(m_sDescription))
                    {
                        dlg.SetDescription(m_sDescription);
                    }
                    //EnableRelatedWindows(hwnd, false);
                    DialogResult res = dlg.ShowDialog(parent);
                    //EnableRelatedWindows(hwnd, true);
                    if (res == DialogResult.OK)
                    {
                        int nChoice = dlg.GetChoice();
                        switch (nChoice)
                        {
                        case FwCheckAnthroListDlg.kralUserDef:
                            break;

                        case FwCheckAnthroListDlg.kralOCM:
                            sFile = Path.Combine(DirectoryFinder.TemplateDirectory, "OCM.xml");
                            break;

                        case FwCheckAnthroListDlg.kralFRAME:
                            sFile = Path.Combine(DirectoryFinder.TemplateDirectory, "OCM-Frame.xml");
                            break;

                        default:
                            Debug.Assert(nChoice >= 0 && nChoice < rgsAnthroFiles.Count);
                            sFile = Path.Combine(DirectoryFinder.TemplateDirectory, rgsAnthroFiles[nChoice]);
                            break;
                        }
                    }
                }
            }

            // 4. Load the selected list, or initialize properly for a User-defined (empty) list.

            using (new WaitCursor(parent))
            {
                if (String.IsNullOrEmpty(sFile))
                {
                    proj.Cache.DomainDataByFlid.BeginNonUndoableTask();
                    proj.AnthroListOA.Name.set_String(wsDefault, FwCoreDlgs.ksAnthropologyCategories);
                    proj.AnthroListOA.Abbreviation.set_String(wsDefault, FwCoreDlgs.ksAnth);
                    proj.AnthroListOA.ItemClsid = CmAnthroItemTags.kClassId;
                    proj.AnthroListOA.Depth     = 127;
                    proj.Cache.DomainDataByFlid.EndNonUndoableTask();
                }
                else
                {
                    XmlList xlist = new XmlList();
                    xlist.ImportList(proj, "AnthroList", sFile, null);
                }
            }

            // 5. create the corresponding overlays if the list is not empty.

            ICmOverlay over = null;

            foreach (ICmOverlay x in proj.OverlaysOC)
            {
                if (x.PossListRA == proj.AnthroListOA)
                {
                    over = x;
                    break;
                }
            }
            if (over != null)
            {
                proj.Cache.DomainDataByFlid.BeginNonUndoableTask();
                foreach (ICmPossibility poss in proj.AnthroListOA.PossibilitiesOS)
                {
                    over.PossItemsRC.Add(poss);
                    AddSubPossibilitiesToOverlay(over, poss);
                }
                proj.Cache.DomainDataByFlid.EndNonUndoableTask();
            }
            return(true);
        }