Exemple #1
0
        public static void DumpNotesTree(INotesElement tree, int indent)
        {
            if (object.ReferenceEquals(tree, null))
            {
                throw new ArgumentNullException("tree");
            }

            if (indent < 0)
            {
                throw new ArgumentOutOfRangeException("indent", indent, "Indent has to be non-negative");
            }

            string indentStr = String.Empty;

            for (int i = 0; i < indent; i++)
            {
                indentStr += "  ";
            }

            Console.WriteLine("{0}{1}", indentStr, tree.PassiveSummary);

            IList <INotesElement> childs = tree.Children;

            if (childs != null)
            {
                foreach (INotesElement child in childs)
                {
                    DumpNotesTree(child, indent + 1);
                }
            }
        }
Exemple #2
0
		public NotesElementTreeNode(INotesElement notesElement)
		{
			if (object.ReferenceEquals(notesElement, null))
				throw new ArgumentNullException("notesElement");

			this.NodeType = NotesElementTreeNodeType.NotesElement;
			this.NotesElement = notesElement;
			this.ParseIssue = null;
		}
Exemple #3
0
		/// <summary>
		/// Add a <see cref="Notes"/> tree recursively to the GUI.
		/// This builds up the NodeView NodeStore,
		/// adds formatting to the TextView and
		/// possibly does other things, too.
		/// </summary>
		/// <param name="tree">The current element of the Notes tree.</param>
		/// <param name="parentNode">Optionally, a NodeView parent node
		/// to which to attach a to-be-created node, or <c>null</c>.</param>
		protected void AddNotesTree(INotesElement tree, NotesElementTreeNode parentNode)
		{
			if (object.ReferenceEquals(tree, null))
				throw new ArgumentNullException("tree");

			IList<ISemanticLocatable> syntaxElements = tree.SyntaxElements;
			if (syntaxElements != null) {
				foreach (ISemanticLocatable elem in syntaxElements) {
					ColorizeSyntaxElement(elem);
				}
			}

			var node = new NotesElementTreeNode(tree);

			// Add node as child of the given parent, or as root note if none given.
			if (object.ReferenceEquals(parentNode, null))
				this.nodeviewNotes.NodeStore.AddNode(node);
			else
				parentNode.AddChild(node);

			// Add potential parsing issues as children to the node.
			IList<ParseIssue> issues = tree.ParseIssues;
			if (issues != null) {
				foreach (ParseIssue issue in issues) {
					// Flat (no sub-issues), we can do this without recursion.
					node.AddChild(new NotesElementTreeNode(issue));
					ColorizeParseIssue(issue);
				}
			}

			// Add notes element children as children to the node.
			IList<INotesElement> childs = tree.Children;
			if (childs != null) {
				foreach (INotesElement child in childs) {
					// Do this recursively, as the notes element child
					// can contain further childs as well.
					AddNotesTree(child, node);
				}
			}
		}
Exemple #4
0
        public void INotesElementTest()
        {
            var notes1 = new Notes(new StringReader(
                                       "2016-09-15\nsw software1\n\tblubber\nsw software2\nsw software3\n"));

            INotesElement elem0 = notes1;

            Assert.IsNotNull(elem0,
                             "Notes parse as INotesElement");
            Assert.AreEqual("Notes with 1 days", elem0.PassiveSummary,
                            "Notes parse passive summary");

            IList <INotesElement> elem0Children = elem0.Children;

            Assert.AreEqual(1, elem0Children.Count,
                            "Notes parse children");
            INotesElement elem1 = elem0Children[0];

            Assert.IsNotNull(elem1,
                             "Day 0 as INotesElement");
            Assert.AreEqual("2016-09-15: 3 entries", elem1.PassiveSummary,
                            "Day 0 passive summary");

            IList <INotesElement> elem1Children = elem1.Children;

            Assert.AreEqual(4, elem1Children.Count,
                            "Day 0 children");
            Assert.AreEqual("Date 15 September 2016, chapter 1, comment: (none)", elem1Children[0].PassiveSummary,
                            "Day 0 child 0 (Notes.Day.Intro)");
            Assert.AreEqual("Category sw / \"software1\"; body lines count 1", elem1Children[1].PassiveSummary,
                            "Day 0 child 1 (Notes.Day.Entry, software1)");
            Assert.AreEqual("Category sw / \"software2\"; body lines count 0", elem1Children[2].PassiveSummary,
                            "Day 0 child 2 (Notes.Day.Entry, software2)");
            Assert.AreEqual("Category sw / \"software3\"; body lines count 0", elem1Children[3].PassiveSummary,
                            "Day 0 child 3 (Notes.Day.Entry, software3)");
        }
Exemple #5
0
 public static void DumpNotesTree(INotesElement tree)
 {
     DumpNotesTree(tree, 0);
 }
Exemple #6
0
		void NodeviewNotes_NodeSelection_Changed(object sender, EventArgs e)
		{
			// Clear state message at the point of a new user interaction.
			// (If node got *de*-selected, rather have a blank status bar
			// than still the information we would have jumped to line <n>.)
			this.statusbar1.Pop(_SbCtxState);

			// Clean up previous "current" colorization. (But keep all other tags.)
			TextBuffer buf = this.textviewText.Buffer;
			buf.RemoveTag(_TagCurrentNotesElement, buf.StartIter, buf.EndIter);
			buf.RemoveTag(_TagCurrentNotesElementLinewise, buf.StartIter, buf.EndIter);

			// Try to retrieve the currently selected node.
			var node = this.nodeviewNotes.NodeSelection.SelectedNode as NotesElementTreeNode;
			if (object.ReferenceEquals(node, null))
				// Keep state.
				return;

			// Scroll TextView to associated position in the text,
			// and tag possibly interesting ranges.
			TextIter start, end;
			switch (node.NodeType) {
			case NotesElementTreeNodeType.NotesElement:
				INotesElement elem = node.NotesElement;
				start = buf.GetIterAtLineOffset(elem.StartLineNumber - 1, 0);
				end = buf.GetIterAtLineOffset(elem.StartLineNumber - 1 + elem.TotalLineCount, 0);

				// Tag entire selected notes element's lines range as current.
				buf.ApplyTag(_TagCurrentNotesElementLinewise, start, end);

				// Remove selection, set cursor to start of element, scroll window to there.
				buf.SelectRange(start, start);
				this.textviewText.ScrollToIter(start, 0, true, 0, 0.5);

				// Inform the user about what has been done.
				this.statusbar1.Push(_SbCtxState,
					string.Format("Jumped to plaintext line {0}.", elem.StartLineNumber));

				break;
			case NotesElementTreeNodeType.ParseIssue:
				if (node.ParseIssue.Location.StartLine < 1) {
					this.statusbar1.Push(_SbCtxState, "Can't jump to parse issue location as none is known.");
					break;
				}

				string locStr;
				if (node.ParseIssue.Location.StartCharacter > 0 &&
				    node.ParseIssue.Location.EndCharacter > 0) {
					start = buf.GetIterAtLineOffset(
						node.ParseIssue.Location.StartLine - 1,
						node.ParseIssue.Location.StartCharacter - 1);
					end = buf.GetIterAtLineOffset(
						node.ParseIssue.Location.EndLine - 1,
						node.ParseIssue.Location.EndCharacter - 1);
					locStr = string.Format("({0},{1})-({2},{3})",
						node.ParseIssue.Location.StartLine,
						node.ParseIssue.Location.StartCharacter,
						node.ParseIssue.Location.EndLine,
						node.ParseIssue.Location.EndCharacter);
				}
				else {
					start = buf.GetIterAtLine(node.ParseIssue.Location.StartLine - 1);
					end = buf.GetIterAtLine(node.ParseIssue.Location.EndLine - 1);
					locStr = string.Format("line {0} to {1} (exclusive)",
						node.ParseIssue.Location.StartLine,
						node.ParseIssue.Location.EndLine);
				}
				buf.SelectRange(start, end);
				this.textviewText.ScrollToIter(start, 0, true, 0, 0.5);

				// Inform the user about what has been done.
				// TODO: More detail? Would need preparing in the previous code part.
				this.statusbar1.Push(_SbCtxState,
					string.Format("Marked parse issue location at {0}.", locStr));

				break;
			default:
				this.statusbar1.Push(_SbCtxState,
					string.Format("Selected node with unknown node type {0}.", node.NodeType));
				break;
			}
		}
Exemple #7
0
		/// <summary>
		/// Add a <see cref="Notes"/> tree recursively to the GUI.
		/// See the other overload for details.
		/// </summary>
		/// <param name="tree">The root of the Notes tree.</param>
		protected void AddNotesTree(INotesElement tree)
		{
			AddNotesTree(tree, null);
		}