/// <summary> /// /// </summary> /// <param name="commandObject"></param> /// <param name="display"></param> /// <returns></returns> public virtual bool OnDisplayJumpToTool(object commandObject, ref UIItemDisplayProperties display) { FdoCache cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache"); XCore.Command cmd = (XCore.Command)commandObject; string className = SIL.Utils.XmlUtils.GetManditoryAttributeValue(cmd.Parameters[0], "className"); uint specifiedClsid = cache.MetaDataCacheAccessor.GetClassId(className); IWfiAnalysis anal = Analysis; if (anal != null) { if (anal.ClassID == (int)specifiedClsid) { display.Enabled = display.Visible = true; return(true); } else if (specifiedClsid == (uint)WfiGloss.kclsidWfiGloss) { if (m_dataEntryForm != null && m_dataEntryForm.CurrentSlice != null && CurrentSliceObject != null && CurrentSliceObject.ClassID == specifiedClsid) { display.Enabled = display.Visible = true; return(true); } } } return(false); }
/// <summary> /// Used to launch various import dialogs, but could do other things /// </summary> /// <param name="commandObject"></param> /// <returns></returns> public bool OnLaunchConnectedDialog(object commandObject) { CheckDisposed(); XCore.Command command = (XCore.Command)commandObject; System.Xml.XmlNode first = command.Parameters[0]; System.Xml.XmlNode classInfo = first.SelectSingleNode("dynamicloaderinfo"); Form formActive = ActiveForm; FwXWindow wndActive = formActive as FwXWindow; IFwExtension dlg = null; try { try { dlg = (IFwExtension)DynamicLoader.CreateObject(classInfo); } catch (Exception error) { string message = XmlUtils.GetOptionalAttributeValue(classInfo, "notFoundMessage", null); // Make this localizable! if (message != null) { throw new ApplicationException(message, error); } } var oldWsUser = Cache.WritingSystemFactory.UserWs; dlg.Init(Cache, wndActive.Mediator); DialogResult dr = ((Form)dlg).ShowDialog(ActiveForm); if (dr == DialogResult.OK) { if (dlg is LexOptionsDlg) { LexOptionsDlg loDlg = dlg as LexOptionsDlg; if ((oldWsUser != Cache.WritingSystemFactory.UserWs) || loDlg.PluginsUpdated) { ReplaceMainWindow(wndActive); } } else if (dlg is LinguaLinksImportDlg || dlg is InterlinearImportDlg || dlg is LexImportWizard || dlg is NotebookImportWiz || dlg is LiftImportDlg) { // Make everything we've imported visible. wndActive.Mediator.SendMessage("MasterRefresh", wndActive); } } } finally { if (dlg != null && dlg is IDisposable) { (dlg as IDisposable).Dispose(); } } return(true); }
/// <summary> /// Display the import commands only while in the appropriate area. /// </summary> public bool OnDisplayLaunchConnectedDialog(object parameters, ref UIItemDisplayProperties display) { display.Enabled = false; display.Visible = false; XCore.Command command = parameters as XCore.Command; if (command == null) { return(true); } Form formActive = ActiveForm; FwXWindow wndActive = formActive as FwXWindow; if (wndActive == null) { return(true); } Mediator mediator = wndActive.Mediator; if (mediator == null) { return(true); } string area = wndActive.PropTable.GetValue <string>("areaChoice"); bool fEnabled = true; switch (command.Id) { case "CmdImportSFMLexicon": fEnabled = area == "lexicon"; break; case "CmdImportLinguaLinksData": fEnabled = area == "lexicon"; break; case "CmdImportLiftData": fEnabled = area == "lexicon"; break; case "CmdImportInterlinearSfm": case "CmdImportWordsAndGlossesSfm": case "CmdImportInterlinearData": // LT-11998: importing texts in the Concordance tool can crash fEnabled = area == "textsWords" && wndActive.PropTable.GetStringProperty("currentContentControl", null) != "concordance"; break; case "CmdImportSFMNotebook": fEnabled = area == "notebook"; break; default: break; } display.Enabled = fEnabled; display.Visible = fEnabled; return(true); }
/// <summary> /// Display a file given a path relative to the FieldWorks/Helps directory. /// </summary> /// <param name="commandObject"></param> /// <returns></returns> public bool OnHelpHelpsFile(object commandObject) { CheckDisposed(); XCore.Command command = (XCore.Command)commandObject; string fileName = SIL.Utils.XmlUtils.GetManditoryAttributeValue(command.Parameters[0], "file"); fileName = fileName.Replace('\\', Path.DirectorySeparatorChar); string path = String.Format(DirectoryFinder.FWCodeDirectory + "{0}Helps{0}" + fileName, Path.DirectorySeparatorChar); OpenDocument(path, (e) => { MessageBox.Show(null, String.Format(LexTextStrings.ksCannotShowX, path), LexTextStrings.ksError); }); return(true); }
/// <summary> /// Override to handle case of improper menu in the reversal cat list tool. /// </summary> /// <param name="commandObject"></param> /// <param name="display"></param> /// <returns></returns> public override bool OnDisplayJumpToTool(object commandObject, ref XCore.UIItemDisplayProperties display) { CheckDisposed(); XCore.Command command = (XCore.Command)commandObject; string tool = SIL.Utils.XmlUtils.GetManditoryAttributeValue(command.Parameters[0], "tool"); string toolChoice = m_mediator.PropertyTable.GetStringProperty("currentContentControl", null); if (tool == "posEdit" && toolChoice == "reversalToolReversalIndexPOS") { display.Visible = display.Enabled = false; // we're already there! return(true); } else { return(base.OnDisplayJumpToTool(commandObject, ref display)); } }
/// <summary> /// Display a file given a path relative to the FieldWorks/Helps directory. /// </summary> /// <param name="commandObject"></param> /// <returns></returns> public bool OnHelpHelpsFile(object commandObject) { CheckDisposed(); XCore.Command command = (XCore.Command)commandObject; string fileName = SIL.Utils.XmlUtils.GetManditoryAttributeValue(command.Parameters[0], "file"); string path = Path.Combine(DirectoryFinder.FWCodeDirectory, @"Helps\" + fileName); try { System.Diagnostics.Process.Start(path); } catch (Exception) { MessageBox.Show(null, String.Format(LexTextStrings.ksCannotShowX, path), LexTextStrings.ksError); } return(true); }
internal virtual void HandleFwMenuSelection(object sender, EventArgs ea) { CheckDisposed(); if (m_fConstructingMenu) { return; } int iSel = m_clb.SelectedIndex; m_clb.HideForm(); FwMenuItem fmi = FindEnabledItem(iSel); if (fmi == null) { return; } var command = new XCore.Command(m_mediator, fmi.ConfigurationNode); m_mediator.SendMessage(fmi.Message, command); }
/// <summary> /// /// </summary> /// <param name="commandObject"></param> /// <returns></returns> public virtual bool OnJumpToTool(object commandObject) { FdoCache cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache"); XCore.Command cmd = (XCore.Command)commandObject; string className = SIL.Utils.XmlUtils.GetManditoryAttributeValue(cmd.Parameters[0], "className"); int hvo = 0; if (className == "WfiAnalysis") { IWfiAnalysis anal = Analysis; if (anal != null) { hvo = anal.Hvo; } } else if (className == "WfiGloss") { if (m_dataEntryForm != null && m_dataEntryForm.CurrentSlice != null && CurrentSliceObject != null && CurrentSliceObject.ClassID == WfiGloss.kclsidWfiGloss) { hvo = CurrentSliceObject.Hvo; } } if (hvo != 0) { string tool = SIL.Utils.XmlUtils.GetManditoryAttributeValue(cmd.Parameters[0], "tool"); m_mediator.PostMessage("FollowLink", SIL.FieldWorks.FdoUi.FwLink.Create(tool, cache.GetGuidFromId(hvo), cache.ServerName, cache.DatabaseName)); return(true); } else { return(false); } }
public override bool HandleDeleteCommand(Command cmd) { CheckDisposed(); ((LexReferenceMultiSlice)m_parentSlice).DeleteFromReference(GetObjectForMenusToOperateOn() as ILexReference); return true; // delete was done }
public override void HandleDeleteCommand(Command cmd) { CheckDisposed(); m_masterSlice.DeleteReference(GetObjectHvoForMenusToOperateOn()); }
/// <summary> /// decide whether to display this tree insert Menu Item /// </summary> /// <param name="commandObject"></param> /// <param name="display"></param> /// <returns></returns> public override bool OnDisplayDataTreeInsert(object commandObject, ref UIItemDisplayProperties display) { Slice slice = m_dataEntryForm.CurrentSlice; if (slice == null && m_dataEntryForm.Controls.Count > 0) { slice = m_dataEntryForm.FieldAt(0); } if (slice == null || (m_dataEntryForm.Mediator.PropertyTable.GetValue("ActiveClerk") as RecordClerk).ListSize == 0) { // don't display the datatree menu/toolbar items when we don't have a data tree slice. display.Visible = false; display.Enabled = false; return(true); } base.OnDisplayDataTreeInsert(commandObject, ref display); if (!(slice.Object is LexEntry) && !(slice.ContainingDataTree.Root is LexEntry)) { return(false); } FDO.Ling.LexEntry entry = slice.Object as LexEntry; if (entry == null) { entry = slice.ContainingDataTree.Root as LexEntry; } XCore.Command command = (XCore.Command)commandObject; if (command.Id.EndsWith("AffixProcess")) { bool enable = MoMorphType.IsAffixType(entry.MorphType); display.Enabled = enable; display.Visible = enable; return(true); } //if there aren't any alternate forms, go ahead and let the user choose either kind if (entry.AlternateFormsOS.Count == 0) { return(true); } if (command.Id.EndsWith("AffixAllomorph")) { if (!(entry.AlternateFormsOS.FirstItem is MoAffixAllomorph)) { display.Visible = false; } return(true); } if (command.Id.EndsWith("StemAllomorph")) { if (!(entry.AlternateFormsOS.FirstItem is MoStemAllomorph)) { display.Visible = false; } return(true); } return(true); //we handled this, no need to ask anyone else. }
private void AddCommandToConfigForList(ICmPossibilityList curList, XmlNode windowConfig) { // Create a new command node var cmdNode = CreateCustomCommandNode(curList); var cmdNodeImported = windowConfig.OwnerDocument.ImportNode(cmdNode, true); // Put the command node in the window configuration windowConfig.SelectSingleNode(GetCommandsXPath()).AppendChild(cmdNodeImported); // Add the command to the mediator var command = new Command(m_mediator, cmdNodeImported); Debug.Assert(m_mediator.CommandSet != null, "Empty mediator CommandSet. Should only occur in tests. Make sure it doesn't there either!"); m_mediator.CommandSet.Add(command.Id, command); }
/// <summary> /// Used to launch various import dialogs, but could do other things /// </summary> /// <param name="commandObject"></param> /// <returns></returns> public bool OnLaunchConnectedDialog(object commandObject) { CheckDisposed(); XCore.Command command = (XCore.Command)commandObject; System.Xml.XmlNode first = command.Parameters[0]; System.Xml.XmlNode classInfo = first.SelectSingleNode("dynamicloaderinfo"); Form formActive = ActiveForm; FwXWindow wndActive = formActive as FwXWindow; IFwExtension dlg = null; if (((classInfo as System.Xml.XmlElement)?.Attributes["class"]?.Value ?? "").Contains( "LinguaLinks")) { // Message is deliberately not localized. We expect this to affect maybe one person every couple of years based on recent // occurrences. Doubt it's worth translating. // The reason for the disabling is that model changes require significant changes to the Import code, // and we don't think it's worth the effort. What few LinguaLinks projects still require import can be handled // by installing a version 7 FieldWorks, importing, and then migrating. // (For example, the currently generated stage 5 XML assumes Senses still reference ReveralEntries, rather than the // current opposite link; and there were problems importing texts even in FLEx 8 (LT-2084)). MessageBox.Show( @"Fieldworks no longer supports import of LinguaLinks data. For any remaining projects that need this, our support staff can help convert your data. Please send a message to [email protected]", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); } try { try { dlg = (IFwExtension)DynamicLoader.CreateObject(classInfo); } catch (Exception error) { string message = XmlUtils.GetOptionalAttributeValue(classInfo, "notFoundMessage", null); // Make this localizable! if (message != null) { throw new ApplicationException(message, error); } } var oldWsUser = Cache.WritingSystemFactory.UserWs; dlg.Init(Cache, wndActive.Mediator, wndActive.PropTable); DialogResult dr = ((Form)dlg).ShowDialog(ActiveForm); if (dr == DialogResult.OK) { if (dlg is LexOptionsDlg) { LexOptionsDlg loDlg = dlg as LexOptionsDlg; if (oldWsUser != Cache.WritingSystemFactory.UserWs || loDlg.PluginsUpdated) { wndActive.SaveSettings(); MessageBoxUtils.Show(wndActive, LexTextStrings.LexTextApp_RestartToChangeUI_Content, LexTextStrings.LexTextApp_RestartToChangeUI_Title, MessageBoxButtons.OK); } } else if (dlg is LinguaLinksImportDlg || dlg is InterlinearImportDlg || dlg is LexImportWizard || dlg is NotebookImportWiz || dlg is LiftImportDlg) { // Make everything we've imported visible. wndActive.Mediator.SendMessage("MasterRefresh", wndActive); } } } finally { if (dlg != null && dlg is IDisposable) { (dlg as IDisposable).Dispose(); } } return(true); }
/// <summary> /// Using the current focus box content, approve it and apply it to all unanalyzed matching /// wordforms in the text. See LT-8833. /// </summary> /// <returns></returns> public void ApproveGuessOrChangesForWholeTextAndMoveNext(Command cmd) { // Go through the entire text looking for matching analyses that can be set to the new // value. if (SelectedOccurrence == null) return; var oldWf = SelectedOccurrence.Analysis.Wordform; var stText = SelectedOccurrence.Paragraph.Owner as IStText; if (stText == null || stText.ParagraphsOS.Count == 0) return; // paranoia, we should be in one of its paragraphs. // We don't need to discard existing guesses, even though we will modify Segment.Analyses, // since guesses for other wordforms will not be affected, and there will be no remaining // guesses for the word we're confirming everywhere. (This needs to be outside the block // for the UOW, since what we are suppressing happens at the completion of the UOW.) InterlinDoc.SuppressResettingGuesses( () => { // Needs to include GetRealAnalysis, since it might create a new one. UndoableUnitOfWorkHelper.Do(cmd.UndoText, cmd.RedoText, Cache.ActionHandlerAccessor, () => { IWfiAnalysis obsoleteAna; AnalysisTree newAnalysisTree = InterlinWordControl.GetRealAnalysis(true, out obsoleteAna); var wf = newAnalysisTree.Wordform; if (newAnalysisTree.Analysis == wf) { // nothing significant to confirm, so move on // (return means get out of this lambda expression, not out of the method). return; } SaveAnalysisForAnnotation(SelectedOccurrence, newAnalysisTree); // determine if we confirmed on a sentence initial wordform to its lowercased form bool fIsSentenceInitialCaseChange = oldWf != wf; if (wf != null) { ApplyAnalysisToInstancesOfWordform(newAnalysisTree.Analysis, oldWf, wf); } // don't try to clean up the old analysis until we've finished walking through // the text and applied all our changes, otherwise we could delete a wordform // that is referenced by dummy annotations in the text, and thus cause the display // to treat them like pronunciations, and just show an unanalyzable text (LT-9953) FinishSettingAnalysis(newAnalysisTree, InitialAnalysis); if (obsoleteAna != null) obsoleteAna.Delete(); }); }); // This should not make any data changes, since we're telling it not to save and anyway // we already saved the current annotation. And it can't correctly place the focus box // until the change we just did are completed and PropChanged sent. So keep this outside the UOW. OnNextBundle(cmd, false, false, false, true); }
internal virtual void HandleFwMenuSelection(object sender, EventArgs ea) { CheckDisposed(); if (m_fConstructingMenu) return; int iSel = m_clb.SelectedIndex; m_clb.HideForm(); FwMenuItem fmi = FindEnabledItem(iSel); if (fmi == null) return; var command = new XCore.Command(m_mediator, fmi.ConfigurationNode); m_mediator.SendMessage(fmi.Message, command); }
/// <summary> /// decide whether to display this tree insert Menu Item /// </summary> /// <param name="commandObject"></param> /// <param name="display"></param> /// <returns></returns> public override bool OnDisplayDataTreeInsert(object commandObject, ref UIItemDisplayProperties display) { Slice slice = m_dataEntryForm.CurrentSlice; if (slice == null && m_dataEntryForm.Slices.Count > 0) { slice = m_dataEntryForm.FieldAt(0); } if (slice == null || slice.IsDisposed || (m_dataEntryForm.Mediator.PropertyTable.GetValue("ActiveClerk") as RecordClerk).ListSize == 0) { // don't display the datatree menu/toolbar items when we don't have a data tree slice. // (If the slice is disposed, we're in a weird state, possibly trying to update the toolbar during OnIdle though we haven't // in fact finished reconstructing the tree. Leave things disabled, and hope they will get enabled // on the next call when things have stabilized.) display.Visible = false; display.Enabled = false; return(true); } base.OnDisplayDataTreeInsert(commandObject, ref display); if (!(slice.Object is ILexEntry) && !(slice.ContainingDataTree.Root is ILexEntry)) { return(false); } FDO.ILexEntry entry = slice.Object as ILexEntry; if (entry == null) { entry = slice.ContainingDataTree.Root as ILexEntry; } if (entry == null || !entry.IsValidObject) { // At one point this could happen during delete object. Not sure it will be possible when I // finish debugging that, but the defensive programming doesn't hurt. display.Enabled = false; display.Visible = false; return(true); } XCore.Command command = (XCore.Command)commandObject; if (command.Id.EndsWith("AffixProcess")) { var mmt = entry.PrimaryMorphType; bool enable = mmt != null && mmt.IsAffixType; display.Enabled = enable; display.Visible = enable; return(true); } //if there aren't any alternate forms, go ahead and let the user choose either kind if (entry.AlternateFormsOS.Count == 0) { return(true); } if (command.Id.EndsWith("AffixAllomorph")) { if (!(entry.AlternateFormsOS[0] is IMoAffixAllomorph)) { display.Visible = false; } return(true); } if (command.Id.EndsWith("StemAllomorph")) { if (!(entry.AlternateFormsOS[0] is IMoStemAllomorph)) { display.Visible = false; } return(true); } return(true); //we handled this, no need to ask anyone else. }
/// <summary> /// invoke the given XCore command. /// </summary> /// <param name="idCommand"></param> public void InvokeCommand(string idCommand) { XCore.Command cmd = m_mediator.CommandSet[idCommand] as XCore.Command; cmd.InvokeCommand(); this.ProcessPendingItems(); }
/// <summary> /// Used to launch various import dialogs, but could do other things /// </summary> /// <param name="commandObject"></param> /// <returns></returns> public bool OnLaunchConnectedDialog(object commandObject) { CheckDisposed(); XCore.Command command = (XCore.Command)commandObject; System.Xml.XmlNode first = command.Parameters[0]; System.Xml.XmlNode classInfo = first.SelectSingleNode("dynamicloaderinfo"); Form formActive = ActiveForm; FdoCache cache = GetActiveCache(formActive); if (cache != null) { FwXWindow wndActive = formActive as FwXWindow; SIL.FieldWorks.LexText.Controls.IFwExtension dlg = null; try { try { dlg = (SIL.FieldWorks.LexText.Controls.IFwExtension)Utils.DynamicLoader.CreateObject(classInfo); } catch (Exception error) { string message = XmlUtils.GetOptionalAttributeValue(classInfo, "notFoundMessage", null); // Make this localizable! if (message != null) { throw new ApplicationException(message, error); } } dlg.Init(cache, wndActive.Mediator); DialogResult dr = ((Form)dlg).ShowDialog(ActiveForm); if (dr == DialogResult.OK) { if (dlg is LexOptionsDlg) { LexOptionsDlg loDlg = dlg as LexOptionsDlg; string sWsUserOld = s_sWsUser; s_sWsUser = loDlg.NewUserWs; if ((sWsUserOld != s_sWsUser) || loDlg.PluginsUpdated) { // Make everything we've imported visible, // or make the plugin install/uninstall real. wndActive.Mediator.SendMessage("MasterRefresh", wndActive); } } else if (dlg is SIL.FieldWorks.IText.LinguaLinksImportDlg || dlg is SIL.FieldWorks.IText.InterlinearImportDlg || dlg is SIL.FieldWorks.LexText.Controls.LexImportWizard || dlg is SIL.FieldWorks.LexText.Controls.LiftImportDlg) { // Make everything we've imported visible. wndActive.Mediator.SendMessage("MasterRefresh", wndActive); } } } finally { if (dlg != null && dlg is IDisposable) { (dlg as IDisposable).Dispose(); } } } return(true); }