Exemple #1
0
        /// <summary>
        /// Implement the "Move Down" command.
        /// </summary>
        public bool OnMoveItemDownInVector(object argument)
        {
            CheckDisposed();

            if (this.Object == null)
            {
                return(false);
            }
            IRnGenericRec rec = this.Object as IRnGenericRec;

            if (rec == null)
            {
                return(false);                          // shouldn't get here
            }
            IRnGenericRec recOwner = rec.Owner as IRnGenericRec;

            if (recOwner == null)
            {
                return(false);                          // shouldn't get here
            }
            int idxOrig = rec.OwnOrd;

            Debug.Assert(recOwner.SubRecordsOS[idxOrig] == rec);
            if (idxOrig == recOwner.SubRecordsOS.Count - 1)
            {
                return(false);                          // shouldn't get here.
            }
            UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(Resources.DetailControlsStrings.ksUndoMoveDown,
                                                            Resources.DetailControlsStrings.ksRedoMoveDown, Cache.ActionHandlerAccessor, () =>
            {
                // idxOrig + 2 looks strange, but it's the correct value to make this work.
                recOwner.SubRecordsOS.MoveTo(idxOrig, idxOrig, recOwner.SubRecordsOS, idxOrig + 2);
            });
            return(true);
        }
Exemple #2
0
        /// <summary>
        /// Have the utility do what it does.
        /// </summary>
        public void Process()
        {
            Debug.Assert(m_dlg != null);
            var cache                 = (FdoCache)m_dlg.Mediator.PropertyTable.GetValue("cache");
            var homographWsId         = cache.LanguageProject.HomographWs;
            var homographWs           = cache.ServiceLocator.WritingSystems.AllWritingSystems.Where(ws => ws.Id == homographWsId);
            var homographWsLabel      = homographWs.First().DisplayLabel;
            var defaultVernacularWs   = cache.LanguageProject.DefaultVernacularWritingSystem;
            var defaultVernacularWsId = defaultVernacularWs.Id;
            var changeWs              = false;

            if (homographWsId != defaultVernacularWsId)
            {
                var caution = string.Format(LexEdStrings.ksReassignHomographsCaution, homographWsLabel, defaultVernacularWs.DisplayLabel);
                if (MessageBox.Show(caution, LexEdStrings.ksReassignHomographs, MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    changeWs = true;
                }
            }
            if (changeWs)
            {
                UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(
                    LexEdStrings.ksUndoHomographWs, LexEdStrings.ksRedoHomographWs,
                    cache.ActionHandlerAccessor,
                    () =>
                {
                    cache.LanguageProject.HomographWs = defaultVernacularWsId;
                });
            }
            cache.LanguageProject.LexDbOA.ResetHomographNumbers(new ProgressBarWrapper(m_dlg.ProgressBar));
        }
Exemple #3
0
        protected override void HandleChooser()
        {
            const string displayWs = "best analysis";
            var          sense     = m_obj as ILexSense;

            if (sense == null)
            {
                Debug.Assert(sense != null, "This chooser can only be applied to senses");
                // ReSharper disable HeuristicUnreachableCode
                //reachable in release mode you usually intelligent program.
                return;
                // ReSharper restore HeuristicUnreachableCode
            }
            var linkCommandNode = m_configurationNode.SelectSingleNode("descendant::chooserLink");
            var chooser         = new SemanticDomainsChooser
            {
                Mediator = m_mediator, Cache = m_cache, DisplayWs = displayWs, Sense = sense,
                LinkNode = linkCommandNode, HelpTopicProvider = m_mediator.HelpTopicProvider
            };

            var labels = ObjectLabel.CreateObjectLabels(m_cache, m_obj.ReferenceTargetCandidates(m_flid),
                                                        m_displayNameProperty, displayWs);

            chooser.Initialize(labels, sense.SemanticDomainsRC);
            var result = chooser.ShowDialog();

            if (result == DialogResult.OK)
            {
                UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(Resources.DetailControlsStrings.ksUndoSet,
                                                                Resources.DetailControlsStrings.ksRedoSet,
                                                                m_cache.ActionHandlerAccessor,
                                                                () => sense.SemanticDomainsRC.Replace(sense.SemanticDomainsRC, chooser.SemanticDomains));
            }
        }
Exemple #4
0
        //methods

        public override ObjectLabel Execute()
        {
            // Make create lex entry dialog and invoke it.
            ObjectLabel result = null;

            using (InsertEntryDlg dlg = new InsertEntryDlg())
            {
                var morphType = GetMorphType();
                dlg.SetDlgInfo(m_cache, morphType, MsaType.kInfl, m_slot, m_mediator,
                               m_fPrefix ? InsertEntryDlg.MorphTypeFilterType.Prefix : InsertEntryDlg.MorphTypeFilterType.Suffix);
                dlg.DisableAffixTypeMainPosAndSlot();
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    bool      fCreated;
                    ILexEntry entry;
                    dlg.GetDialogInfo(out entry, out fCreated);
                    if (entry == null)
                    {
                        throw new ArgumentNullException("Expected entry cannot be null", "entry");
                    }
                    // TODO: what do to make sure it has an infl affix msa?
                    // this just assumes it will
                    bool fInflAffix = false;
                    foreach (var msa in entry.MorphoSyntaxAnalysesOC)
                    {
                        if (msa is IMoInflAffMsa)
                        {
                            fInflAffix = true;
                            break;
                        }
                    }
                    if (!fInflAffix)
                    {
                        UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(DetailControlsStrings.ksUndoCreatingInflectionalAffixCategoryItem,
                                                                        DetailControlsStrings.ksRedoCreatingInflectionalAffixCategoryItem,
                                                                        m_cache.ActionHandlerAccessor,
                                                                        () => {
                            var newby = m_cache.ServiceLocator.GetInstance <IMoInflAffMsaFactory>().Create();
                            entry.MorphoSyntaxAnalysesOC.Add(newby);
                        });
                    }
                    if (entry.MorphoSyntaxAnalysesOC.Count > 0)
                    {
                        result = ObjectLabel.CreateObjectLabel(m_cache, entry.MorphoSyntaxAnalysesOC.First(), "");
                    }
                }
            }
            return(result);
        }
Exemple #5
0
        /// <summary>
        /// Implement the "Promote" command.
        /// </summary>
        public bool OnPromoteSubitemInVector(object argument)
        {
            CheckDisposed();

            if (this.Object == null)
            {
                return(false);
            }
            IRnGenericRec rec = this.Object as IRnGenericRec;

            if (rec == null)
            {
                return(false);                          // shouldn't get here
            }
            IRnGenericRec recOwner = rec.Owner as IRnGenericRec;

            if (recOwner == null)
            {
                return(false);                          // shouldn't get here
            }
            // Grab the mediator now for later use, because this slice may get disposed before we
            // use it.
            Mediator mediator = m_mediator;

            UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(Resources.DetailControlsStrings.ksUndoPromote,
                                                            Resources.DetailControlsStrings.ksRedoPromote,
                                                            Cache.ActionHandlerAccessor, () =>
            {
                if (recOwner.Owner is IRnGenericRec)
                {
                    (recOwner.Owner as IRnGenericRec).SubRecordsOS.Insert(recOwner.OwnOrd + 1, rec);
                }
                else if (recOwner.Owner is IRnResearchNbk)
                {
                    (recOwner.Owner as IRnResearchNbk).RecordsOC.Add(rec);
                }
                else
                {
                    throw new Exception("RnGenericRec object not owned by either RnResearchNbk or RnGenericRec??");
                }
            });
            if (recOwner.Owner is IRnResearchNbk)
            {
                // If possible, jump to the newly promoted record.
                mediator.BroadcastMessageUntilHandled("JumpToRecord", rec.Hvo);
            }
            return(true);
        }
Exemple #6
0
        public override ObjectLabel Execute()
        {
            ObjectLabel result = null;

            if (m_lexEntryRef != null)
            {
                using (LinkEntryOrSenseDlg dlg = new LinkEntryOrSenseDlg())
                {
                    ILexEntry le = null;
                    // assume the owner is the entry (e.g. owner of LexEntryRef)
                    le = m_lexEntryRef.OwnerOfClass <ILexEntry>();
                    dlg.SetDlgInfo(m_cache, m_mediator, m_propertyTable, le);
                    dlg.SetHelpTopic("khtpChooseLexicalEntryOrSense");
                    if (dlg.ShowDialog(m_parentWindow) == DialogResult.OK)
                    {
                        ICmObject obj = dlg.SelectedObject;
                        if (obj != null)
                        {
                            if (!m_lexEntryRef.PrimaryLexemesRS.Contains(obj))
                            {
                                try
                                {
                                    UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(
                                        LexEdStrings.ksUndoCreatingEntry,
                                        LexEdStrings.ksRedoCreatingEntry,
                                        Cache.ActionHandlerAccessor,
                                        () =>
                                    {
                                        if (!m_lexEntryRef.ComponentLexemesRS.Contains(obj))
                                        {
                                            m_lexEntryRef.ComponentLexemesRS.Add(obj);
                                        }
                                        m_lexEntryRef.PrimaryLexemesRS.Add(obj);
                                    });
                                }
                                catch (ArgumentException)
                                {
                                    MessageBoxes.ReportLexEntryCircularReference(m_lexEntryRef.Owner, obj, true);
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handle the OK button click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// ------------------------------------------------------------------------------------
        private void m_btnOK_Click(object sender, EventArgs e)
        {
            using (new WaitCursor(this))
            {
                string undo, redo;
                TeResourceHelper.MakeUndoRedoLabels("kstidUndoRedoScriptureProperties",
                                                    out undo, out redo);

                UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(undo, redo,
                                                                m_cache.ServiceLocator.GetInstance <IActionHandler>(), () =>
                {
                    ProcessScriptNumberSettings();
                    ProcessRefFormattingSettings();
                    ProcessVersificationSettings();
                    ProcessFootnoteSettings();
                });
            }
        }
Exemple #8
0
        /// <summary>
        /// If OK, then make FS have the selected feature value(s).
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PhonologicalFeatureChooserDlg_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (DialogResult == DialogResult.OK)
            {
                using (new WaitCursor(this))
                {
                    UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(MEStrings.ksUndoSelectionOfPhonologicalFeatures,
                                                                    MEStrings.ksRedoSelectionOfPhonologicalFeatures, m_cache.ActionHandlerAccessor, () =>
                    {
                        if (m_fs == null)
                        {
                            // Didn't have one to begin with. See whether we want to create one.
                            if (m_hvoOwner != 0 && CheckFeatureStructure())
                            {
                                // The last argument is meaningless since we expect this property to be owning
                                // or collection.
                                var hvoFs = m_cache.DomainDataByFlid.MakeNewObject(FsFeatStrucTags.kClassId, m_hvoOwner, m_owningFlid, -2);
                                m_fs      = m_cache.ServiceLocator.GetInstance <IFsFeatStrucRepository>().GetObject(hvoFs);
                            }
                        }

                        if (m_fs != null)
                        {
                            // clean out any extant features in the feature structure
                            m_fs.FeatureSpecsOC.Clear();
                            UpdateFeatureStructure();
                        }
                    });
                }
            }

            if (m_mediator != null)
            {
                m_mediator.PropertyTable.SetProperty("phonFeatListDlgLocation", Location);
                m_mediator.PropertyTable.SetProperty("phonFeatListDlgSize", Size);
            }
        }
Exemple #9
0
            int MakeRealObject(ITsString tssTyped)
            {
                // Figure whether owning atomic or owning collection or owning sequence. Throw if none.
                // Unless we're making an unowned IText for a Notebook Record.
                ISilDataAccess     sdaReal    = m_fdoCache.DomainDataByFlid;
                IFwMetaDataCache   mdc        = sdaReal.MetaDataCache;
                CellarPropertyType typeOwning =
                    (CellarPropertyType)(mdc.GetFieldType(m_flidEmptyProp) & (int)CellarPropertyTypeFilter.VirtualMask);
                // Make a new object of the specified class in the specified property.
                int ord = 0;

                switch (typeOwning)
                {
                default:
                    if (m_flidEmptyProp != RnGenericRecTags.kflidText)
                    {
                        throw new Exception("ghost string property must be owning object property");
                    }
                    break;

                case CellarPropertyType.OwningAtomic:
                    ord = -2;
                    break;

                case CellarPropertyType.OwningCollection:
                    ord = -1;
                    break;

                case CellarPropertyType.OwningSequence:
                    // ord = 0 set above (inserting the first and only object at position 0).
                    break;
                }
                string sClassRaw    = mdc.GetClassName(m_clidDst);
                string sClass       = m_mediator.StringTbl.GetString(sClassRaw, "ClassNames");
                string sUndo        = String.Format(DetailControlsStrings.ksUndoCreate0, sClass);
                string sRedo        = String.Format(DetailControlsStrings.ksRedoCreate0, sClass);
                int    hvoNewObj    = 0;
                int    hvoStringObj = 0;

                UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(sUndo, sRedo, m_fdoCache.ServiceLocator.GetInstance <IActionHandler>(), () =>
                {
                    // Special case: if we just created a Text in RnGenericRecord, and we want to show the contents
                    // of an StTxtPara, make the intermediate objects
                    if (m_flidEmptyProp == RnGenericRecTags.kflidText)
                    {
                        var servLoc     = Cache.ServiceLocator;
                        var text        = servLoc.GetInstance <ITextFactory>().Create();
                        var stText      = servLoc.GetInstance <IStTextFactory>().Create();
                        text.ContentsOA = stText;
                        var para        = servLoc.GetInstance <IStTxtParaFactory>().Create();
                        stText.ParagraphsOS.Add(para);
                        hvoNewObj    = text.Hvo;
                        hvoStringObj = para.Hvo;
                        // Set the RnGenericRec's Text property to reference the new text
                        sdaReal.SetObjProp(m_hvoObj, m_flidEmptyProp, hvoNewObj);
                    }
                    else
                    {
                        hvoNewObj = hvoStringObj = sdaReal.MakeNewObject(m_clidDst, m_hvoObj, m_flidEmptyProp, ord);
                    }

                    // Set its property m_flidStringProp to tssTyped. If it is multilingual, choose based on ghostWs.
                    var typeString = (CellarPropertyType)(mdc.GetFieldType(m_flidStringProp) &
                                                          (int)CellarPropertyTypeFilter.VirtualMask);
                    switch (typeString)
                    {
                    default:
                        throw new Exception("ghost property must store strings!");

                    case CellarPropertyType.MultiString:
                    case CellarPropertyType.MultiUnicode:
                        sdaReal.SetMultiStringAlt(hvoStringObj, m_flidStringProp, m_wsToCreate, tssTyped);
                        break;

                    case CellarPropertyType.String:
                        sdaReal.SetString(hvoStringObj, m_flidStringProp, tssTyped);
                        break;
                    }

                    string ghostInitMethod = XmlUtils.GetOptionalAttributeValue(m_nodeObjProp, "ghostInitMethod");
                    if (ghostInitMethod != null)
                    {
                        var obj      = m_fdoCache.ServiceLocator.GetInstance <ICmObjectRepository>().GetObject(hvoNewObj);
                        Type objType = obj.GetType();
                        System.Reflection.MethodInfo mi = objType.GetMethod(ghostInitMethod);
                        mi.Invoke(obj, null);
                    }
                });
                return(hvoNewObj);
            }
Exemple #10
0
        /// <summary>
        /// Implement the "Demote..." command.
        /// </summary>
        public bool OnDemoteSubitemInVector(object argument)
        {
            CheckDisposed();

            if (this.Object == null)
            {
                return(false);
            }
            IRnGenericRec rec = this.Object as IRnGenericRec;

            if (rec == null)
            {
                return(false);                          // shouldn't get here
            }
            IRnGenericRec newOwner = null;

            if (Object.Owner is IRnGenericRec)
            {
                IRnGenericRec recOwner = Object.Owner as IRnGenericRec;
                if (recOwner.SubRecordsOS.Count == 2)
                {
                    if (Object.OwnOrd == 0)
                    {
                        newOwner = recOwner.SubRecordsOS[1];
                    }
                    else
                    {
                        newOwner = recOwner.SubRecordsOS[0];
                    }
                }
                else
                {
                    List <IRnGenericRec> owners = new List <IRnGenericRec>();
                    foreach (var recT in recOwner.SubRecordsOS)
                    {
                        if (recT != rec)
                        {
                            owners.Add(recT);
                        }
                    }
                    newOwner = ContainingDataTree.ChooseNewOwner(owners.ToArray(),
                                                                 Resources.DetailControlsStrings.ksChooseOwnerOfDemotedSubrecord);
                }
            }
            else
            {
                return(false);
            }
            if (newOwner == null)
            {
                return(true);
            }
            if (newOwner == rec)
            {
                throw new Exception("RnGenericRec cannot own itself!");
            }

            UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(Resources.DetailControlsStrings.ksUndoDemote,
                                                            Resources.DetailControlsStrings.ksRedoDemote, Cache.ActionHandlerAccessor, () =>
            {
                newOwner.SubRecordsOS.Insert(0, rec);
            });
            return(true);
        }
Exemple #11
0
        /// <summary>
        /// Create configuration file for analysis writing systems in Reversal Index
        /// </summary>
        /// <param name="wsMgr">IWritingSystemManager</param>
        /// <param name="cache">The FDO cache</param>
        /// <param name="defaultConfigDir">Default Configuration directory</param>
        /// <param name="projectsDir">Projects directory</param>
        /// <param name="originalProjectName">Project Name</param>
        public static void CreateOrRemoveReversalIndexConfigurationFiles(WritingSystemManager wsMgr, LcmCache cache, string defaultConfigDir,
                                                                         string projectsDir, string originalProjectName)
        {
            var defaultWsFilePath = Path.Combine(defaultConfigDir, RevIndexDir,
                                                 AllIndexesFileName + ConfigFileExtension);
            var newWsFilePath = Path.Combine(projectsDir, originalProjectName, ConfigDir,
                                             RevIndexDir);
            var analysisWsArray = cache.LangProject.AnalysisWss.Trim().Replace("  ", " ").Split(' ');

            if (Directory.Exists(newWsFilePath))
            {
                //Delete old Configuration Files for WS's that are no longer part of this project
                var files = Directory.GetFiles(newWsFilePath, "*" + ConfigFileExtension, SearchOption.AllDirectories);
                foreach (var file in files)
                {
                    XAttribute wsAtt;
                    GetWsAttributeFromFile(file, out wsAtt);
                    if (wsAtt != null && !string.IsNullOrEmpty(wsAtt.Value) && !analysisWsArray.Contains(wsAtt.Value))
                    {
                        File.Delete(file);
                    }
                }
            }
            else
            {
                // Ensure the directory exists
                Directory.CreateDirectory(newWsFilePath);
            }
            //Create new Configuration File
            foreach (var curWs in analysisWsArray)
            {
                if (curWs.ToLower().Contains("audio"))
                {
                    continue;
                }

                var curWsLabel            = wsMgr.Get(curWs).DisplayLabel;
                var newWsCompleteFilePath = Path.Combine(newWsFilePath, curWs + ConfigFileExtension);
                if (File.Exists(newWsCompleteFilePath))
                {
                    XAttribute wsAtt;
                    var        configDoc = GetWsAttributeFromFile(newWsCompleteFilePath, out wsAtt);
                    if (wsAtt == null)
                    {
                        // How did we get here??? Only AllReversalIndexes should have no WS! Best I can figure, this is a pre-wsAtt config
                        var config = configDoc.Element(DictConfigElement);
                        if (config == null || !config.HasAttributes)
                        {
                            File.Delete(newWsCompleteFilePath);                             // the file is corrupt; delete it and start over
                        }
                        else
                        {
                            config.SetAttributeValue(WsAttribute, curWs);
                            configDoc.Save(newWsCompleteFilePath);
                            continue;
                        }
                    }
                    else if (wsAtt.Value != curWs)
                    {
                        // REVIEW (Hasso) 2016.09: what to do? Rename the conflicting file, or re-WS the config? Can't ask, b/c FDO has no UI
                        // If the user has duplicated some other Reversal Index Config and given it this name, it is possible they were trying
                        // to configure the RI for this WS. Update the Config to point to this WS
                        wsAtt.Value = curWs;
                        configDoc.Save(newWsCompleteFilePath);
                        continue;
                    }
                    else
                    {
                        continue;                         // the file was already in the correct state; nothing to do
                    }
                }

                File.Copy(defaultWsFilePath, newWsCompleteFilePath, false);
                File.SetAttributes(newWsCompleteFilePath, FileAttributes.Normal);
                var xmldoc     = XDocument.Load(newWsCompleteFilePath);
                var xAttribute = xmldoc.XPathSelectElement(DictConfigElement).Attribute("name");
                xAttribute.Value = curWsLabel;
                xAttribute       = xmldoc.XPathSelectElement(DictConfigElement).Attribute(WsAttribute);
                xAttribute.Value = curWs;
                xmldoc.Save(newWsCompleteFilePath);

                var wsObj = wsMgr.Get(curWs);
                if (wsObj != null && wsObj.DisplayLabel.ToLower().IndexOf("audio", StringComparison.Ordinal) == -1)
                {
                    UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW("Undo Adding reversal Guid", "Redo Adding reversal Guid",
                                                                    cache.ActionHandlerAccessor,
                                                                    () => GetOrCreateWsGuid(wsObj, cache));
                }
            }
        }