示例#1
0
        private static void DefineAnnotation(EditListDlg <SettingsListBase <AnnotationDef>, AnnotationDef> dialog,
                                             String name, AnnotationDef.AnnotationTargetSet targets, AnnotationDef.AnnotationType type, IList <string> items)
        {
            var defineAnnotationDlg = ShowDialog <DefineAnnotationDlg>(dialog.AddItem);

            RunUI(() =>
            {
                defineAnnotationDlg.AnnotationName    = name;
                defineAnnotationDlg.AnnotationType    = type;
                defineAnnotationDlg.AnnotationTargets = targets;
                defineAnnotationDlg.Items             = items ?? new string[0];
            });
            OkDialog(defineAnnotationDlg, defineAnnotationDlg.OkDialog);
        }
示例#2
0
        public static Annotations MergeAnnotations(SrmDocument document, IEnumerable <IdentityPath> selPaths,
                                                   out AnnotationDef.AnnotationTargetSet annotationTarget)
        {
            annotationTarget = AnnotationDef.AnnotationTargetSet.EMPTY;

            // If the nodes have matching text, colors, or annotations, then we should display these values
            // in the EditNodeDlg. Otherwise, we should not display any value for that variable.
            bool matchingText   = true;
            bool matchingColors = true;
            bool isFirstSelNode = true;
            bool allEmpty       = true;

            // These are the default values we want for the annotations, if the node(s) do not already have
            // annotations, or if the annotations do not match.
            string text       = null;
            int    colorIndex = -1;
            var    dictMatchingAnnotations = new Dictionary <string, string>();

            // Find what all nodes have in common as far as note, annotations, and color.
            foreach (IdentityPath selPath in selPaths)
            {
                if (Equals(selPath.Child, SequenceTree.NODE_INSERT_ID))
                {
                    continue;
                }

                var nodeDoc             = document.FindNode(selPath);
                var nodeAnnotations     = nodeDoc.Annotations;
                var dictNodeAnnotations = nodeAnnotations.ListAnnotations()
                                          .ToDictionary(nodeAnnotation => nodeAnnotation.Key,
                                                        nodeAnnotation => nodeAnnotation.Value);

                // If this is the first iteration, use the value for this node to start matching.
                if (isFirstSelNode)
                {
                    foreach (KeyValuePair <string, string> annotation in dictNodeAnnotations)
                    {
                        dictMatchingAnnotations.Add(annotation.Key, annotation.Value);
                    }
                    text           = nodeAnnotations.Note;
                    colorIndex     = nodeAnnotations.ColorIndex;
                    isFirstSelNode = false;
                }
                foreach (string key in dictMatchingAnnotations.Keys.ToArray())
                {
                    string value;
                    // If the list of annotations we are building for the dialog contains this key,
                    // check that the values are the same, otherwise the value for this annotation needs
                    // to be null for the dialog.
                    if (!dictNodeAnnotations.TryGetValue(key, out value) || !Equals(dictMatchingAnnotations[key], value))
                    {
                        dictMatchingAnnotations.Remove(key);
                    }
                }

                matchingText   = matchingText && nodeAnnotations.Note != null && Equals(text, nodeAnnotations.Note);
                matchingColors = matchingColors &&
                                 !nodeAnnotations.IsEmpty &&
                                 nodeAnnotations.ColorIndex != -1 &&
                                 Equals(colorIndex, nodeAnnotations.ColorIndex);

                allEmpty = allEmpty && nodeAnnotations.IsEmpty;

                // Update annotation target to include this type of node.
                annotationTarget = annotationTarget.Union(nodeDoc.AnnotationTarget);
            }
            if (!matchingText)
            {
                text = string.Empty;
            }
            if (allEmpty)
            {
                colorIndex = Settings.Default.AnnotationColor;
            }
            else if (!matchingColors)
            {
                colorIndex = -1;
            }
            return(new Annotations(text, dictMatchingAnnotations, colorIndex));
        }