Пример #1
0
        public static List <Tag> Extract(ExtractPolicy extractPolicy, IEnumerable <string> sources)
        {
            BinaryComponents.Utility.Collections.Set <string> tagsFound = new BinaryComponents.Utility.Collections.Set <string>();
            List <Tag> tags = new List <Tag>();

            foreach (string source in sources)
            {
                int start = 0;
                while (source != null)
                {
                    int found = source.IndexOf(PrefixParam, start);
                    if (found == -1)
                    {
                        break;                         // finished
                    }
                    else
                    {
                        Tag tag = new Tag();
                        tag.StartIndex = found;

                        start = found + 1;
                        if (source.Length > found + 2 && source[found + 1] == '{')
                        {
                            start++;                             // Jump over bracket.

                            //
                            //	Get Name
                            int separator = source.IndexOf('}', start);
                            if (separator != -1)
                            {
                                string name = source.Substring(start, separator - start).Trim();

                                if (name.Length > 0)
                                {
                                    tag.Name     = name;
                                    tag.EndIndex = separator + 1;
                                    bool alreadyFound = tagsFound.Contains(tag.Name);
                                    if (extractPolicy == ExtractPolicy.IncludeAllTags || !alreadyFound)
                                    {
                                        if (!alreadyFound)
                                        {
                                            tagsFound.Add(tag.Name);
                                        }
                                        tags.Add(tag);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(tags);
        }
Пример #2
0
        public void CopyToClipboard()
        {
            StringBuilder builder = new StringBuilder();

            //
            // Copy header information
            int count = 0;

            foreach (Column c in _listControl.Columns.VisibleItems)
            {
                if (count++ > 0)
                {
                    builder.Append("\t");
                }
                builder.Append(c.Name);
            }
            builder.Append(Environment.NewLine);

            List <object[]> selectedRows = new List <object[]>();

            //
            //	Get a list of rows that have been selected. If a group has
            //	been selected then all its rows get added if and only if none
            //	of its subitems have been selected otherwise the group is
            //	ignored in favour of the subitems.
            BinaryComponents.Utility.Collections.Set <object> rowsReadyToAdd = new BinaryComponents.Utility.Collections.Set <object>();
            int speculativeStartIndex = 0;

            foreach (RowIdentifier ri in _listControl.SelectedItems)
            {
                bool first = true;
                foreach (object[] row in ri.Items)
                {
                    if (first)
                    {
                        first = false;
                        if (rowsReadyToAdd.Contains(row))
                        {
                            if (speculativeStartIndex < selectedRows.Count)
                            {
                                selectedRows.RemoveRange(speculativeStartIndex, selectedRows.Count - speculativeStartIndex);
                            }
                        }
                        rowsReadyToAdd.Clear();
                        speculativeStartIndex = selectedRows.Count;
                    }
                    rowsReadyToAdd.Add(row);
                    selectedRows.Add(row);
                }
            }

            //
            //	Build the text we're going to use for the Clipboard
            foreach (object[] row in selectedRows)
            {
                bool first = true;
                foreach (Column column in _listControl.Columns.VisibleItems)
                {
                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        builder.Append("\t");
                    }
                    builder.Append(column.ColumnItemAccessor(row).ToString());
                }
                builder.Append(Environment.NewLine);
            }

            Clipboard.SetText(builder.ToString());
        }