Esempio n. 1
0
 public void PropChanged(int hvo, int tag, int ivMin, int cvIns, int cvDel)
 {
     if (Entry == null)                 // only do it once, or we get a stack overflow
     {
         NonUndoableUnitOfWorkHelper.DoSomehow(Parent.m_actionHandler, () => { Entry = Parent.MakeEntry("another entry"); });
     }
 }
Esempio n. 2
0
        private void ImportCustomFields(string liftPathname)
        {
            if (string.IsNullOrEmpty(liftPathname))
            {
                return;
            }
            NonUndoableUnitOfWorkHelper.DoSomehow(_cache.ActionHandlerAccessor, () =>
            {
                string sFilename;
                var fMigrationNeeded = Migrator.IsMigrationNeeded(liftPathname);
                if (fMigrationNeeded)
                {
                    var sOldVersion = Lift.Validation.Validator.GetLiftVersion(liftPathname);
                    sFilename       = Migrator.MigrateToLatestVersion(liftPathname);
                }
                else
                {
                    sFilename = liftPathname;
                }
                var flexImporter      = new FlexLiftMerger(_cache, FlexLiftMerger.MergeStyle.MsKeepOnlyNew, true);
                var parser            = new LiftParser <LiftObject, CmLiftEntry, CmLiftSense, CmLiftExample>(flexImporter);
                flexImporter.LiftFile = liftPathname;
                var liftRangesFile    = liftPathname + "-ranges";
                if (File.Exists(liftRangesFile))
                {
                    flexImporter.LoadLiftRanges(liftRangesFile);
                }

                parser.ReadLiftFile(sFilename);
            });
        }
        public void Process()
        {
            var cache = (FdoCache)Dialog.Mediator.PropertyTable.GetValue("cache");

            NonUndoableUnitOfWorkHelper.DoSomehow(cache.ActionHandlerAccessor, () =>
            {
                SortReversalSubEntriesInPlace(cache);
                MessageBox.Show(Dialog, LexEdStrings.SortReversalSubEntries_CompletedContent, LexEdStrings.SortReversalSubEntries_CompletedTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
            });
        }
Esempio n. 4
0
        /// <summary>
        /// If there are no pronunciation writing systems selected, make a default set, with IPA variants
        /// coming before EMC variants (if either of those exist).  If neither exists, the primary
        /// vernacular writing system is selected.
        /// </summary>
        private void InitializePronunciationWritingSystems()
        {
            if (m_currentPronunciationWritingSystems.Count > 0)
            {
                return;
            }

            NonUndoableUnitOfWorkHelper.DoSomehow(Cache.ActionHandlerAccessor,
                                                  () =>
            {
                var writingSystems = m_vernacularWritingSystems;
                var wsVern         = DefaultVernacularWritingSystem;
                var sVern          = wsVern.IcuLocale.ToLower();
                var idx            = sVern.IndexOf("_");
                sVern = idx > 0 ? sVern.Substring(0, idx + 1) : sVern + '_';
                // Add any relevant IPA writing systems: those that match the default vernacular at the start and end with _ipa
                foreach (var nws in writingSystems)
                {
                    var icuLocale = nws.IcuLocale.ToLower();
                    if (icuLocale.IndexOf(sVern) != 0)
                    {
                        continue;
                    }

                    idx = icuLocale.LastIndexOf("_ipa");
                    if (idx >= sVern.Length && idx == icuLocale.Length - 4)
                    {
                        m_currentPronunciationWritingSystems.Add(nws);
                    }
                }
                // Add any relevant EMC writing systems: match default vern at start and end with _emc.
                foreach (var nws in writingSystems)
                {
                    var icuLocale = nws.IcuLocale.ToLower();
                    if (icuLocale.IndexOf(sVern) != 0)
                    {
                        continue;
                    }

                    idx = icuLocale.LastIndexOf("_emc");
                    if (idx < sVern.Length || idx != icuLocale.Length - 4)
                    {
                        continue;
                    }

                    m_currentPronunciationWritingSystems.Add(nws);
                }
                // Add the primary vernacular writing system if nothing else fits.
                if (m_currentPronunciationWritingSystems.Count == 0)
                {
                    m_currentPronunciationWritingSystems.Add(wsVern);
                }
            });
        }
Esempio n. 5
0
        public void Process()
        {
            var cache = (FdoCache)Dialog.Mediator.PropertyTable.GetValue("cache");

            NonUndoableUnitOfWorkHelper.DoSomehow(cache.ActionHandlerAccessor, () =>
            {
                var fixedGuids = ReplacePOSGuidsWithGoldEticGuids(cache);
                var caption    = fixedGuids ? LexEdStrings.GoldEticGuidFixer_Guids_changed_Title : LexEdStrings.GoldEticGuidFixer_NoChangeTitle;
                var content    = fixedGuids ? LexEdStrings.GoldEticGuidFixer_GuidsChangedContent
                                                                                                 : LexEdStrings.GoldEticGuidFixer_NoChangeContent;
                MessageBox.Show(Dialog, content, caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
            });
        }
Esempio n. 6
0
        public static ICmPossibility AddPublicationType(string name, LcmCache cache)
        {
            Debug.Assert(cache.LangProject.LexDbOA.PublicationTypesOA != null);

            var item = cache.ServiceLocator.GetInstance <ICmPossibilityFactory>().Create();

            NonUndoableUnitOfWorkHelper.DoSomehow(cache.ActionHandlerAccessor, () =>
            {
                cache.LangProject.LexDbOA.PublicationTypesOA.PossibilitiesOS.Add(item);
                item.Name.set_String(cache.DefaultAnalWs, name);
            });
            return(item);
        }
Esempio n. 7
0
        public override void FixtureSetup()
        {
            base.FixtureSetup();
            FileUtils.Manager.SetFileAdapter(_mockFilesystem);

            FileUtils.EnsureDirectoryExists(_defaultConfigPath);
            NonUndoableUnitOfWorkHelper.DoSomehow(Cache.ActionHandlerAccessor, () =>
            {
                var styleFactory    = Cache.ServiceLocator.GetInstance <IStStyleFactory>();
                _characterTestStyle = styleFactory.Create(Cache.LangProject.StylesOC, "TestStyle", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, true, 2, false);
                _characterTestStyle.Usage.set_String(Cache.DefaultAnalWs, "Test Style");
                var propsBldr = TsStringUtils.MakePropsBldr();
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptForeColor, (int)FwTextPropVar.ktpvDefault,
                                           (int)ColorUtil.ConvertColorToBGR(Color.Red));
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptUnderline, (int)FwTextPropVar.ktpvDefault,
                                           (int)FwUnderlineType.kuntDouble);
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptUnderColor, (int)FwTextPropVar.ktpvDefault,
                                           (int)ColorUtil.ConvertColorToBGR(Color.Blue));
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptBold, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn);
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptItalic, (int)FwTextPropVar.ktpvEnum, (int)FwTextToggleVal.kttvForceOn);
                propsBldr.SetStrPropValue((int)FwTextPropType.ktptFontFamily, "times");
                _characterTestStyle.Rules = propsBldr.GetTextProps();
                _paraTestStyle            = styleFactory.Create(Cache.LangProject.StylesOC, "ParaTestStyle", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, false, 2, false);
                propsBldr.Clear();
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptBackColor, (int)FwTextPropVar.ktpvDefault,
                                           (int)ColorUtil.ConvertColorToBGR(Color.Lime));
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalCenter);
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptLineHeight, (int)FwTextPropVar.ktpvMilliPoint, -3000);
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptTrailingIndent, (int)FwTextPropVar.ktpvDefault, 4000);
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptFirstIndent, (int)FwTextPropVar.ktpvDefault, -5000);
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptLeadingIndent, (int)FwTextPropVar.ktpvDefault, 6000);
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptSpaceBefore, (int)FwTextPropVar.ktpvDefault, 7000);
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptSpaceAfter, (int)FwTextPropVar.ktpvDefault, 8000);
                _paraTestStyle.Rules = propsBldr.GetTextProps();
                _paraChildTestStyle  = styleFactory.Create(Cache.LangProject.StylesOC, "ParaChildTesttStyle",
                                                           ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, false, 3, false);
                propsBldr.Clear();
                propsBldr.SetIntPropValues((int)FwTextPropType.ktptAlign, (int)FwTextPropVar.ktpvEnum, (int)FwTextAlign.ktalJustify);
                _paraChildTestStyle.Rules     = propsBldr.GetTextProps();
                _paraChildTestStyle.BasedOnRA = _paraTestStyle;
                _bulletedTestStyle            = styleFactory.Create(Cache.LangProject.StylesOC, "Bulleted List", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, false, 2, false);
                _numberedTestStyle            = styleFactory.Create(Cache.LangProject.StylesOC, "Numbered List", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, false, 2, false);
                _homographTestStyle           = styleFactory.Create(Cache.LangProject.StylesOC, "Homograph-Number", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, true, 2, false);

                var characterStyleBasedOnSomething       = styleFactory.Create(Cache.LangProject.StylesOC, "CharacterStyleBasedOnSomething", ContextValues.InternalConfigureView, StructureValues.Body, FunctionValues.Line, true, 2, false);
                characterStyleBasedOnSomething.BasedOnRA = _characterTestStyle;
            });
        }
Esempio n. 8
0
        private void ParseUnparsedParagraphs()
        {
            ConcDecorator concDecorator = ConcDecorator;

            IStTxtPara[] needsParsing = concDecorator.InterestingTexts.SelectMany(txt => txt.ParagraphsOS).Cast <IStTxtPara>().Where(para => !para.ParseIsCurrent).ToArray();
            if (needsParsing.Length > 0)
            {
                NonUndoableUnitOfWorkHelper.DoSomehow(m_cache.ActionHandlerAccessor,
                                                      () =>
                {
                    foreach (IStTxtPara para in needsParsing)
                    {
                        ParagraphParser.ParseParagraph(para);
                    }
                });
            }
        }
Esempio n. 9
0
        private void ImportStyles(string importStylesLocation)
        {
            var stylesToRemove = _cache.LangProject.StylesOC.Where(style => !UnsupportedStyles.Contains(style.Name));

            // For LT-18267, record basedon and next properties of styles not
            // being exported, so they can be reconnected to the imported
            // styles of the same name.
            var preimportStyleLinks = _cache.LangProject.StylesOC.Where(style => UnsupportedStyles.Contains(style.Name)).ToDictionary(
                style => style.Name,
                style => new
            {
                BasedOn = style.BasedOnRA == null ? null : style.BasedOnRA.Name,
                Next    = style.NextRA == null ? null : style.NextRA.Name
            });

            NonUndoableUnitOfWorkHelper.DoSomehow(_cache.ActionHandlerAccessor, () =>
            {
                // Before importing styles, remove all the current styles, except
                // for styles that we don't support and so we don't expect will
                // be imported.
                foreach (var style in stylesToRemove)
                {
                    _cache.LangProject.StylesOC.Remove(style);
                }
            });
            // Be sure that the Remove action is committed and saved to disk before we re-import styles with the same guid.
            // If we don't then the changes won't be noticed as the Styles will be marked as transient and won't be saved.
            _cache.ActionHandlerAccessor.Commit();
            // Import styles
            NonUndoableUnitOfWorkHelper.DoSomehow(_cache.ActionHandlerAccessor, () =>
            {
                // ReSharper disable once UnusedVariable -- The FlexStylesXmlAccessor constructor does the work of importing.
                var stylesAccessor = new FlexStylesXmlAccessor(_cache.LangProject.LexDbOA, true, importStylesLocation);

                var postimportStylesToReconnect = _cache.LangProject.StylesOC.Where(style => UnsupportedStyles.Contains(style.Name));

                postimportStylesToReconnect.ForEach(postimportStyleToRewire =>
                {
                    var correspondingPreImportStyleInfo = preimportStyleLinks[postimportStyleToRewire.Name];

                    postimportStyleToRewire.BasedOnRA = _cache.LangProject.StylesOC.FirstOrDefault(style => style.Name == correspondingPreImportStyleInfo.BasedOn);

                    postimportStyleToRewire.NextRA = _cache.LangProject.StylesOC.FirstOrDefault(style => style.Name == correspondingPreImportStyleInfo.Next);
                });
            });
        }
Esempio n. 10
0
        /// <summary>
        /// Confirms there is at least one valid writing system in the list of pronunciation writing systems. Removes any writing systems
        /// in the list that aren't found in this project.
        /// </summary>
        /// <returns>True if one or more valid writing systems are found, otherwise false.</returns>
        private bool CheckValidPronunciationWritingSystem()
        {
            CoreWritingSystemDefinition ws = null;
            int currentIndex = 0;

            while (currentIndex < m_currentPronunciationWritingSystems.Count)
            {
                try
                {
                    ws = m_currentPronunciationWritingSystems[currentIndex];
                    currentIndex++;
                }
                catch (ArgumentException)
                {
                    // Remove the bad writing system from the list
                    NonUndoableUnitOfWorkHelper.DoSomehow(Cache.ActionHandlerAccessor, () =>
                                                          m_currentPronunciationWritingSystems.RemoveAt(currentIndex));
                }
            }
            return(m_currentPronunciationWritingSystems.Count > 0);
        }
        private void ImportStyles(string importStylesLocation)
        {
            NonUndoableUnitOfWorkHelper.DoSomehow(_cache.ActionHandlerAccessor, () =>
            {
                var stylesToRemove = _cache.LangProject.StylesOC.Where(style => !UnsupportedStyles.Contains(style.Name));

                // For LT-18267, record basedon and next properties of styles not
                // being exported, so they can be reconnected to the imported
                // styles of the same name.
                var preimportStyleLinks = _cache.LangProject.StylesOC.Where(style => UnsupportedStyles.Contains(style.Name)).ToDictionary(
                    style => style.Name,
                    style => new
                {
                    BasedOn = style.BasedOnRA == null ? null : style.BasedOnRA.Name,
                    Next    = style.NextRA == null ? null : style.NextRA.Name
                });

                // Before importing styles, remove all the current styles, except
                // for styles that we don't support and so we don't expect will
                // be imported.
                foreach (var style in stylesToRemove)
                {
                    _cache.LangProject.StylesOC.Remove(style);
                }

                // Import styles
                var stylesAccessor = new FlexStylesXmlAccessor(_cache.LangProject.LexDbOA, true, importStylesLocation);

                var postimportStylesToReconnect = _cache.LangProject.StylesOC.Where(style => UnsupportedStyles.Contains(style.Name));

                postimportStylesToReconnect.ForEach(postimportStyleToRewire =>
                {
                    var correspondingPreImportStyleInfo = preimportStyleLinks[postimportStyleToRewire.Name];

                    postimportStyleToRewire.BasedOnRA = _cache.LangProject.StylesOC.FirstOrDefault(style => style.Name == correspondingPreImportStyleInfo.BasedOn);

                    postimportStyleToRewire.NextRA = _cache.LangProject.StylesOC.FirstOrDefault(style => style.Name == correspondingPreImportStyleInfo.Next);
                });
            });
        }
Esempio n. 12
0
 public ComplexConcParagraphData(SpanFactory <ShapeNode> spanFactory, FeatureSystem featSys, IStTxtPara para)
 {
     m_para  = para;
     m_shape = new Shape(spanFactory, begin => new ShapeNode(spanFactory, FeatureStruct.New(featSys).Symbol("bdry").Symbol("paraBdry").Value));
     if (!GenerateShape(spanFactory, featSys))
     {
         // if there are any analyses that are out-of-sync with the baseline, we force a parse
         // and try again, somehow this can happen even though we have already parsed all
         // paragraphs that is out-of-date
         NonUndoableUnitOfWorkHelper.DoSomehow(m_para.Cache.ActionHandlerAccessor, () =>
         {
             using (var pp = new ParagraphParser(m_para.Cache))
             {
                 pp.ForceParse(m_para);
             }
         });
         m_shape.Clear();
         if (!GenerateShape(spanFactory, featSys))
         {
             throw new InvalidOperationException("A paragraph cannot be parsed properly.");
         }
     }
 }
Esempio n. 13
0
 public void DoSomehow_WorksWhenNoUowIsActive()
 {
     m_actionHandler.EndUndoTask();
     NonUndoableUnitOfWorkHelper.DoSomehow(m_actionHandler, () => MakeEntry("an entry"));
 }
Esempio n. 14
0
 public void DoSomehow_WorksDuringOtherUow()
 {
     // Baseclass arranges that a UOW is active at the start of all test methods.
     NonUndoableUnitOfWorkHelper.DoSomehow(m_actionHandler, () => MakeEntry("an entry"));
 }