Beispiel #1
0
 public void Unbalanced()
 {
     List<int> l1 = new List<int> {1, 60, 76}, l2 = new List<int> {3, 19, 22, 51, 56, 66, 67, 90};
       var cpls = new Coupler().Couple(l1, l2).ToList();
       Assert.AreEqual(2, cpls.Count);
       Assert.AreEqual(1, cpls[0].Begin);
       Assert.AreEqual(66, cpls[1].End);
 }
Beispiel #2
0
        private void FormClosed(MainWindow form)
        {
            if (!form.Result) { return; }

              var positions = form.Positions.OrderBy(p => p.Index).ToList();
              Document doc = Globals.ThisAddIn.Application.ActiveDocument;

              try
              {
            doc.Application.UndoRecord.StartCustomRecord("Fixing citations");
            Range litRange = doc.Application.Selection.Range;
            var lits = form.Positions.OrderBy(p => p.NewIndexValue).ToList();
            litRange.Text = lits.Select(p => p.Ref).Aggregate((s1, s2) => string.Format("{0}\r{1}", s1, s2));
            var template = doc.Application.ListGalleries[WdListGalleryType.wdNumberGallery].ListTemplates[1];
            template.ListLevels[1].StartAt = lits[0].NewIndexValue;
            litRange.ListFormat.ApplyListTemplate(template);

            var lb = Counter.SymbolIndices(doc.Range(), "[");
            var rb = Counter.SymbolIndices(doc.Range(), "]");
            var ranges = new Coupler().Couple(lb, rb).ToList();

            var places = ranges
              .Select(r => Tuple.Create(r, doc.Range(r.Begin + 1, r.End)))
              .Select(t => new CitationPlace(t.Item1, t.Item2.Text))
              .OrderByDescending(p => p.Loc.Begin).ToList();

            foreach (var p in places)
            {
              var range = doc.Range(p.Loc.Begin + 1, p.Loc.End);
              range.Text = p.Format(i => positions[i].NewIndexValue);
            }
              }
              finally
              {
            doc.Application.UndoRecord.EndCustomRecord();
              }
        }
Beispiel #3
0
 public void SimpleCoupling()
 {
     List<int> l1 = new List<int> {1, 5, 7}, l2 = new List<int> {3, 6, 9};
       var cpls = new Coupler().Couple(l1, l2).ToList();
       Assert.AreEqual(3, cpls.Count);
 }