Esempio n. 1
0
        // Replace any updated writing systems in the attribute value.
        // Handles an input which may begin with $ws= and/or may have multiple WSs separated by comma.
        private bool FixWSAtttribute(XAttribute attr)
        {
            bool   changedFile = false;
            var    oldTag      = attr.Value;
            string prefix      = "";

            if (oldTag.StartsWith("$ws="))
            {
                prefix = "$ws=";
                oldTag = oldTag.Substring(prefix.Length);
            }
            string combinedTags = "";

            foreach (string input in oldTag.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                string convertedTag;
                string outputTag = input;
                if (WritingSystemServices.GetMagicWsIdFromName(oldTag) == 0 && TryGetNewTag(input, out convertedTag))
                {
                    changedFile = true;
                    outputTag   = convertedTag;
                }
                if (combinedTags != "")
                {
                    combinedTags += ",";
                }
                combinedTags += outputTag;
            }
            if (changedFile)
            {
                attr.Value = prefix + combinedTags;
            }
            return(changedFile);
        }
Esempio n. 2
0
        public InflectionFeatureEditor(XmlNode configurationNode)
            : this()
        {
            string displayWs = XmlUtils.GetOptionalAttributeValue(configurationNode, "displayWs", "best analorvern");

            m_displayWs = WritingSystemServices.GetMagicWsIdFromName(displayWs);
        }
Esempio n. 3
0
        public PhonologicalFeatureEditor(XmlNode configurationNode)
            : this()
        {
            string displayWs = XmlUtils.GetOptionalAttributeValue(configurationNode, "displayWs", "best analorvern");

            m_displayWs = WritingSystemServices.GetMagicWsIdFromName(displayWs);
            string layout = XmlUtils.GetAttributeValue(configurationNode, "layout");

            if (!String.IsNullOrEmpty(layout))
            {
                const string layoutName = "CustomMultiStringForFeatureDefn_";
                int          i          = layout.IndexOf(layoutName);
                if (i >= 0)
                {
                    m_featDefnAbbr = layout.Substring(i + layoutName.Length);
                }
            }
        }
Esempio n. 4
0
        private void ReplaceWSIdInValue(XElement elt, string pattern, ref bool changedFile)
        {
            XElement valueElt = elt.Element("value");

            if (valueElt == null)
            {
                return;
            }
            // Process matches in reverse order so length changes will not invalidate positions of earlier ones.
            var matches = new List <Match>();

            foreach (Match match in Regex.Matches(valueElt.Value, pattern))
            {
                matches.Insert(0, match);
            }
            foreach (Match match in matches)
            {
                Group  target    = match.Groups["target"];
                string oldTag    = target.Value;
                string prefixTag = "";
                if (oldTag.StartsWith("$ws="))
                {
                    prefixTag = "$ws=";
                    oldTag    = oldTag.Substring(prefixTag.Length);
                }
                string newTag;
                if (WritingSystemServices.GetMagicWsIdFromName(oldTag) == 0 && TryGetNewTag(oldTag, out newTag))
                {
                    newTag      = prefixTag + newTag;
                    changedFile = true;
                    string prefix = valueElt.Value.Substring(0, target.Index);
                    string suffix = valueElt.Value.Substring(target.Index + target.Length);
                    valueElt.Value = prefix + newTag + suffix;
                }
            }
        }
Esempio n. 5
0
        /// <summary></summary>
        public static Slice Create(FdoCache cache, string editor, int flid, XmlNode node, ICmObject obj,
                                   StringTable stringTbl, IPersistenceProvider persistenceProvider, Mediator mediator, XmlNode caller, ObjSeqHashMap reuseMap)
        {
            Slice slice;

            switch (editor)
            {
            case "multistring":                     // first, these are the most common slices.
            {
                if (flid == 0)
                {
                    throw new ApplicationException("field attribute required for multistring " + node.OuterXml);
                }
                string wsSpec  = XmlUtils.GetOptionalAttributeValue(node, "ws");
                int    wsMagic = WritingSystemServices.GetMagicWsIdFromName(wsSpec);
                if (wsMagic == 0)
                {
                    throw new ApplicationException(
                              "ws must be 'all vernacular', 'all analysis', 'analysis vernacular', or 'vernacular analysis'"
                              + " it said '" + wsSpec + "'.");
                }


                bool forceIncludeEnglish = XmlUtils.GetOptionalBooleanAttributeValue(node, "forceIncludeEnglish", false);
                bool spellCheck          = XmlUtils.GetOptionalBooleanAttributeValue(node, "spell", true);
                // Either the part or the caller can specify that it isn't editable.
                // (The part may 'know' this, e.g. because it's a virtual attr not capable of editing;
                // more commonly the caller knows there isn't enough context for safe editing.
                bool editable = XmlUtils.GetOptionalBooleanAttributeValue(caller, "editable", true) &&
                                XmlUtils.GetOptionalBooleanAttributeValue(node, "editable", true);
                string           optionalWsSpec  = XmlUtils.GetOptionalAttributeValue(node, "optionalWs");
                int              wsMagicOptional = WritingSystemServices.GetMagicWsIdFromName(optionalWsSpec);
                MultiStringSlice msSlice         = reuseMap.GetSliceToReuse("MultiStringSlice") as MultiStringSlice;
                if (msSlice == null)
                {
                    slice = new MultiStringSlice(obj, flid, wsMagic, wsMagicOptional, forceIncludeEnglish, editable, spellCheck);
                }
                else
                {
                    slice = msSlice;
                    msSlice.Reuse(obj, flid, wsMagic, wsMagicOptional, forceIncludeEnglish, editable, spellCheck);
                }
                break;
            }

            case "defaultvectorreference":                     // second most common.
            {
                var rvSlice = reuseMap.GetSliceToReuse("ReferenceVectorSlice") as ReferenceVectorSlice;
                if (rvSlice == null)
                {
                    slice = new ReferenceVectorSlice(cache, obj, flid);
                }
                else
                {
                    slice = rvSlice;
                    rvSlice.Reuse(obj, flid);
                }
                break;
            }

            case "possvectorreference":
            {
                var prvSlice = reuseMap.GetSliceToReuse("PossibilityReferenceVectorSlice") as PossibilityReferenceVectorSlice;
                if (prvSlice == null)
                {
                    slice = new PossibilityReferenceVectorSlice(cache, obj, flid);
                }
                else
                {
                    slice = prvSlice;
                    prvSlice.Reuse(obj, flid);
                }
                break;
            }

            case "semdomvectorreference":
            {
                var prvSlice = reuseMap.GetSliceToReuse("SemanticDomainReferenceVectorSlice") as SemanticDomainReferenceVectorSlice;
                if (prvSlice == null)
                {
                    slice = new SemanticDomainReferenceVectorSlice(cache, obj, flid);
                }
                else
                {
                    slice = prvSlice;
                    prvSlice.Reuse(obj, flid);
                }
                break;
            }

            case "string":
            {
                if (flid == 0)
                {
                    throw new ApplicationException("field attribute required for basic properties " + node.OuterXml);
                }
                int ws = GetWs(mediator, cache, node);
                if (ws != 0)
                {
                    slice = new StringSlice(obj, flid, ws);
                }
                else
                {
                    slice = new StringSlice(obj, flid);
                }
                var fShowWsLabel = XmlUtils.GetOptionalBooleanAttributeValue(node, "labelws", false);
                if (fShowWsLabel)
                {
                    (slice as StringSlice).ShowWsLabel = true;
                }
                int wsEmpty = GetWs(mediator, cache, node, "wsempty");
                if (wsEmpty != 0)
                {
                    (slice as StringSlice).DefaultWs = wsEmpty;
                }
                break;
            }

            case "jtview":
            {
                string layout = XmlUtils.GetOptionalAttributeValue(caller, "param");
                if (layout == null)
                {
                    layout = XmlUtils.GetManditoryAttributeValue(node, "layout");
                }
                // Editable if BOTH the caller (part ref) AND the node itself (the slice) say so...or at least if neither says not.
                bool editable = XmlUtils.GetOptionalBooleanAttributeValue(caller, "editable", true) &&
                                XmlUtils.GetOptionalBooleanAttributeValue(node, "editable", true);
                slice = new ViewSlice(new XmlView(obj.Hvo, layout, stringTbl, editable));
                break;
            }

            case "summary":
            {
                slice = new SummarySlice();
                break;
            }

            case "enumcombobox":
            {
                slice = new EnumComboSlice(cache, obj, flid, stringTbl, node["deParams"]);
                break;
            }

            case "referencecombobox":
            {
                slice = new ReferenceComboBoxSlice(cache, obj, flid, persistenceProvider);
                break;
            }

            case "typeaheadrefatomic":
            {
                slice = new AtomicRefTypeAheadSlice(obj, flid);
                break;
            }

            case "msareferencecombobox":
            {
                slice = new MSAReferenceComboBoxSlice(cache, obj, flid, persistenceProvider);
                break;
            }

            case "lit":                     // was "message"
            {
                string message = XmlUtils.GetManditoryAttributeValue(node, "message");
                if (stringTbl != null)
                {
                    string sTranslate = XmlUtils.GetOptionalAttributeValue(node, "translate", "");
                    if (sTranslate.Trim().ToLower() != "do not translate")
                    {
                        message = stringTbl.LocalizeLiteralValue(message);
                    }
                }
                slice = new MessageSlice(message);
                break;
            }

            case "picture":
            {
                slice = new PictureSlice((ICmPicture)obj);
                break;
            }

            case "image":
            {
                try
                {
                    slice = new ImageSlice(DirectoryFinder.FWCodeDirectory, XmlUtils.GetManditoryAttributeValue(node, "param1"));
                }
                catch (Exception error)
                {
                    slice = new MessageSlice(String.Format(DetailControlsStrings.ksImageSliceFailed,
                                                           error.Message));
                }
                break;
            }

            case "checkbox":
            {
                slice = new CheckboxSlice(cache, obj, flid, node);
                break;
            }

            case "checkboxwithrefresh":
            {
                slice = new CheckboxRefreshSlice(cache, obj, flid, node);
                break;
            }

            case "time":
            {
                slice = new DateSlice(cache, obj, flid);
                break;
            }

            case "integer":                 // produced in the auto-generated parts from the conceptual model
            case "int":                     // was "integer"
            {
                slice = new IntegerSlice(cache, obj, flid);
                break;
            }

            case "gendate":
            {
                slice = new GenDateSlice(cache, obj, flid);
                break;
            }

            case "morphtypeatomicreference":
            {
                slice = new MorphTypeAtomicReferenceSlice(cache, obj, flid);
                break;
            }

            case "atomicreferencepos":
            {
                slice = new AtomicReferencePOSSlice(cache, obj, flid, persistenceProvider, mediator);
                break;
            }

            case "possatomicreference":
            {
                slice = new PossibilityAtomicReferenceSlice(cache, obj, flid);
                break;
            }

            case "atomicreferenceposdisabled":
            {
                slice = new AutomicReferencePOSDisabledSlice(cache, obj, flid, persistenceProvider, mediator);
                break;
            }

            case "defaultatomicreference":
            {
                slice = new AtomicReferenceSlice(cache, obj, flid);
                break;
            }

            case "defaultatomicreferencedisabled":
            {
                slice = new AtomicReferenceDisabledSlice(cache, obj, flid);
                break;
            }

            case "derivmsareference":
            {
                slice = new DerivMSAReferenceSlice(cache, obj, flid);
                break;
            }

            case "inflmsareference":
            {
                slice = new InflMSAReferenceSlice(cache, obj, flid);
                break;
            }

            case "phoneenvreference":
            {
                slice = new PhoneEnvReferenceSlice(cache, obj, flid);
                break;
            }

            case "sttext":
            {
                slice = new StTextSlice(obj, flid, GetWs(mediator, cache, node));
                break;
            }

            case "custom":
            {
                slice = (Slice)DynamicLoader.CreateObject(node);
                break;
            }

            case "customwithparams":
            {
                slice = (Slice)DynamicLoader.CreateObject(node,
                                                          new object[] { cache, editor, flid, node, obj, stringTbl,
                                                                         persistenceProvider, GetWs(mediator, cache, node) });
                break;
            }

            case "ghostvector":
            {
                slice = new GhostReferenceVectorSlice(cache, obj, node);
                break;
            }

            case "command":
            {
                slice = new CommandSlice(node["deParams"]);
                break;
            }

            case null:                          //grouping nodes do not necessarily have any editor
            {
                slice = new Slice();
                break;
            }

            case "message":
                // case "integer": // added back in to behave as "int" above
                throw new Exception("use of obsolete editor type (message->lit, integer->int)");

            case "autocustom":
                slice = MakeAutoCustomSlice(cache, obj, caller);
                if (slice == null)
                {
                    return(null);
                }
                break;

            case "defaultvectorreferencedisabled":                     // second most common.
            {
                ReferenceVectorDisabledSlice rvSlice = reuseMap.GetSliceToReuse("ReferenceVectorDisabledSlice") as ReferenceVectorDisabledSlice;
                if (rvSlice == null)
                {
                    slice = new ReferenceVectorDisabledSlice(cache, obj, flid);
                }
                else
                {
                    slice = rvSlice;
                    rvSlice.Reuse(obj, flid);
                }
                break;
            }

            default:
            {
                //Since the editor has not been implemented yet,
                //is there a bitmap file that we can show for this editor?
                //Such bitmaps belong in the distFiles xde directory
                string fwCodeDir = DirectoryFinder.FWCodeDirectory;
                string editorBitmapRelativePath = "xde/" + editor + ".bmp";
                if (File.Exists(Path.Combine(fwCodeDir, editorBitmapRelativePath)))
                {
                    slice = new ImageSlice(fwCodeDir, editorBitmapRelativePath);
                }
                else
                {
                    slice = new MessageSlice(String.Format(DetailControlsStrings.ksBadEditorType, editor));
                }
                break;
            }
            }
            slice.AccessibleName = editor;

            return(slice);
        }