private int GetWsForNewText()
        {
            int wsText = PrevTextWs;

            if (wsText != 0)
            {
                if (Cache.ServiceLocator.WritingSystems.CurrentVernacularWritingSystems.Count == 1)
                {
                    wsText = Cache.DefaultVernWs;
                }
                else
                {
                    using (var dlg = new ChooseTextWritingSystemDlg())
                    {
                        dlg.Initialize(Cache, m_mediator.HelpTopicProvider, wsText);
                        dlg.ShowDialog(Form.ActiveForm);
                        wsText = dlg.TextWs;
                    }
                }
                PrevTextWs = 0;
            }
            else
            {
                wsText = Cache.DefaultVernWs;
            }
            return(wsText);
        }
Пример #2
0
		protected override void ShowRecord()
		{
			base.ShowRecord ();
			if (Clerk.SuspendLoadingRecordUntilOnJumpToRecord)
				return;
			if (m_bookmark == null)
				m_bookmark = new InterAreaBookmark(this, m_mediator, Cache);
			if (IsPersistedForAnInterlinearTabPage) // can be true from work in another instance
				MakeInterlinPane(); // does nothing if already made.
			// It's important not to do this if there is a filter, as there's a good chance the new
			// record doesn't pass the filter and we get into an infinite loop. Also, if the user
			// is filtering, he probably just wants to see that there are no matching texts, not
			// make a new one.
			if (Clerk.CurrentObject == null && !m_fSuppressAutoCreate && !Clerk.ShouldNotModifyList
				&& Clerk.Filter == null)
			{
				// first clear the views of their knowledge of the previous text.
				// otherwise they could crash trying to access information that is no longer valid. (LT-10024)
				SwitchText(0);

				// Presumably because there are none..make one.
				// This is invisible to the user so it should not be undoable; that is particularly
				// important if the most recent action was to delete the last text, which will
				// not be undoable if we are now showing 'Undo insert text'.
				using (new SuppressSubTasks(Cache))
				{
					bool fWasSuppressed = Clerk.SuppressSaveOnChangeRecord;
					try
					{
						// We don't want to force a Save here if we just deleted the last text;
						// we want to be able to Undo deleting it!
						Clerk.SuppressSaveOnChangeRecord = true;
						Clerk.InsertItemInVector("StText");
					}
					finally
					{
						Clerk.SuppressSaveOnChangeRecord = fWasSuppressed;
					}
				}
			}
			if (Clerk.CurrentObject == null)
			{
				SwitchText(0);		// We no longer have a text.
				return;				// We get another call when there is one.
			}
			int hvoRoot = Clerk.CurrentObject.Hvo;
			int clsid = Cache.GetClassOfObject(hvoRoot);
			int hvoStText = 0;
			if (clsid == CmBaseAnnotation.kClassId)	// RecordClerk is tracking the annotation
			{
				// This pane, as well as knowing how to work with a record list of Texts, knows
				// how to work with one of CmBaseAnnotations, that is, a list of occurrences of
				// a word.
				int annHvo = hvoRoot;
				if (!m_fRefreshOccurred)
					m_bookmark.Save(annHvo, false);
				int hvoPara = Cache.MainCacheAccessor.get_ObjectProp(annHvo, kflidBeginObject);
				hvoStText = hvoRoot = Cache.GetOwnerOfObject(hvoPara);
				if (m_rtPane != null)
					m_rtPane.SetRoot(hvoRoot);
				if (m_constChartPane != null)
					SetConstChartRoot(hvoRoot);
			}
			else
			{
				//FDO.IText text = new Text(Cache, hvoRoot);
				//// If the text is empty...typically newly created...make it an StText and an
				//// empty paragraph in the right WS.
				//if (text.ContentsOA == null)
				//    text.ContentsOA = new StText();
				IStText stText = new StText(Cache, hvoRoot);
				if (stText.ParagraphsOS.Count == 0)
				{
					IStTxtPara txtPara = new StTxtPara();
					stText.ParagraphsOS.Append(txtPara);
					int wsText = (Clerk as InterlinearTextsRecordClerk).PrevTextWs;
					if (wsText != 0)
					{
						// Establish the writing system of the new text by filling its first paragraph with
						// an empty string in the proper writing system.
						if (Cache.LangProject.VernWssRC.Count > 1 && !Cache.AddAllActionsForTests)
						{
							using (ChooseTextWritingSystemDlg dlg = new ChooseTextWritingSystemDlg())
							{
								dlg.Initialize(Cache, wsText);
								dlg.ShowDialog();
								wsText = dlg.TextWs;
							}
						}
						(Clerk as InterlinearTextsRecordClerk).PrevTextWs = 0;
					}
					else
					{
						wsText = Cache.DefaultVernWs;
					}
					ITsStrFactory tsf = TsStrFactoryClass.Create();
					Cache.MainCacheAccessor.SetString(txtPara.Hvo,
						(int)StTxtPara.StTxtParaTags.kflidContents,
						tsf.MakeString("", wsText));
					// since we have a new text, we should switch to the Baseline tab.
					// ShowMainView() will adjust the tab control appropriately.
					this.InterlinearTab = TabPageSelection.RawText;
				}

				if (m_tcPane != null)
					m_tcPane.SetRoot(hvoRoot);
				if (m_rtPane != null)
					m_rtPane.SetRoot(hvoRoot);

				if (m_hvoStText == 0)
				{
					// we've just now entered the area, so try to restore a bookmark.
					m_bookmark.Restore();
				}
				else if (m_hvoStText != hvoRoot)
				{
					// we've switched texts, so reset our bookmark.
					m_bookmark.Reset();
				}
			}

			if (m_hvoStText != hvoRoot)
			{
				SwitchText(hvoRoot);
			}
			else
				SelectAnnotation(); // select an annotation in the current text.

			// This takes a lot of time, and the view is never visible by now, and it gets done
			// again when made visible! So don't do it!
			//m_idcPane.SetRoot(hvoRoot);

			// If we're showing the raw text pane make sure it has a selection.
			if (Controls.IndexOf(m_rtPane) >= 0 && m_rtPane.RootBox.Selection == null)
				m_rtPane.RootBox.MakeSimpleSel(true, false, false, true);

			UpdateContextHistory();
			m_fRefreshOccurred = false;	// reset our flag that a refresh occurred.
		}