microsoft / XmlNotepad

XML Notepad provides a simple intuitive User Interface for browsing and editing XML documents.
https://microsoft.github.io/XmlNotepad/
MIT License
980 stars 207 forks source link

(#60) add SchemaAwareText for TreeNode element labels #282

Closed WilczynskiT closed 1 year ago

WilczynskiT commented 1 year ago

Hello @lovettchris,

I did the #60 ;)

WilczynskiT commented 1 year ago

@microsoft-github-policy-service agree

WilczynskiT commented 1 year ago

The result:

Screenshot 2023-05-11 105726 lnk

lovettchris commented 1 year ago

Thanks for this, it surprisingly simple, and thought provoking. So there's some improvements I'd like to make:

  1. leaf nodes are redundant, this one shouldn't do it since the text is already on the right for this one. image

  2. first child is not always the right one, it needs to handle out of order children, some child is special, it contains a "name", "title" or "id" or "key", the way this child, perhaps better identified using xs:key/xs:keyref and DTD ID/IDREF. For example, in the basket.xml example it shows this, but clearly promoting a namespace attribute makes no sense here, it just happens to be the first child. image Similarly, in Hamlet the SPEECH elements are lucky they are promoting SPEAKER, only because it is the first child but what if it was the last child, it would then promote a LINE element which would be bad. So we need some smart selection of the right child to promote from some schema hints, and or some heuristics perhaps.

  3. There's a bug in the Hamlet example, is this a line wrapping problem? So promoted text will need to be trimmed or something: image

  4. for some types of XML like HTML this doesn't work at all, the promoted content is just not useful. image

  5. the text is the same color as the element which makes one think this text should be "findable" using CTRL+F, but it isn't. I agree it shouldn't be, but to help set this expectation we may need to lighten/darken it to "dim" the text to make it appear more like a hint and not an actual editable label. Speaking of editing there is in fact also some weird ghosting when you edit the label because the longer text label sits underneath the text box, so we should remove it in the editing case? image

WilczynskiT commented 1 year ago

Hello @lovettchris,

I added some changes. So:

  1. was fixed
  2. show SchemaAwareText only for labels: "name", "title", "id" and "key" (check "name", if not exist check "title" etc. | If none of them exist, then do not show SchemaAwareText)
  3. Now the bug not occurs (the name/title/id/key are shorter than whole descriptions/texts etc)
  4. The app checks the type of XML and does not show SchemaAwareText for HTML.
  5. SchemaAwareText uses light blue color now

Let me know what you think ;)

lovettchris commented 1 year ago

Thanks Tomasz, this is looking great. I'm going to do a bit more work on it after I merge this PR.

lovettchris commented 1 year ago

See my additions in https://github.com/microsoft/XmlNotepad/pull/288/