Open NathanielACollier opened 6 years ago
It might be worth asking on StackOverflow using the avalonedit
tag to see how feasible this is.
Edit: https://stackoverflow.com/questions/47684332/turn-line-numbers-into-textboxes
One of the comments from the SO question was
You need to re-template a control which is responsible for line numbers. In normal mode it is to display a line number, and in focused/active/etc - your content. Keyword is ControlTemplate
I think I've made major progress on this, and I think that stack overflow guy is wrong about control templates. I think we need Adorners. What I've been able to do so far with rushing for time is make a button on every line number that shows the line number and is clickable. This is a huge step I think because I can associate a interactive control with a line number, and now it's just doing the work to get this done.
I can't promise anything time wise, but I think this is going to happen. Before I was very uncertain. Here is a picture of buttons over line numbers. I've not branched from ILEditor yet because I'm working on isolating exactly what is needed. I've branched my line number command piece here: https://github.com/NathanielACollier/AvalonEdit.Pieces.LineNumberMarginCommands/
@NathanielACollier Shall I leave it for you to implement the UI peace and maybe I could work on implementing the commands?
May I also note that I think if the user presses the left arrow key while in column 0 (the start of the line) it should perform a click on the margin button (you mentioned the line number would be clickable)
Thanks!
I'll work on the UI.
That arrow key is exactly what I was thinking. I was thinking that this morning. To start out my goal is those buttons to look right and show line number, then you click and it turns into a textbox (Maybe escape key or something turns it back into button, could also be dispatcher timer based, maybe both) and uses data context to keep up with which ones have commands in them. If your in column 0 on the line number and you left arrow then it goes to textbox (Makes button become textbox if needed) then if your in a textbox and you right arrow it goes to column 0 of the line.
I always associate too many concerns to things, but I do have the concern that this may not look that great...
To implement I'll be bringing over LineNumberMarginWithCommands, the Adorner class file, then call static install inside that Editor class like how FindReplace works. I like the idea of breaking up things that happen to AvalonEdit into classes with a static Install method.
The more time I spend thinking this through, the more I get inspired to actually do the work. :-)
I've changed the way it displays. It seems to me like the command should be next to the line number. Now it displays a textbox next to line number. I've typed the word "hat" next to line 1.
@NathanielACollier It is possible we could remove the grey outline around the textboxs? So it kind of looks like this? (IMO)
Maybe, I will look into that. Maybe that's the part that when you hover it's a textbox, and when you don't it's text. I know I could switch them, I'll see what that looks like.
I think if you mouse over line number, it will show textbox to side. If you enter a command and focus leaves the textbox it will turn into a label. I'm going to work on implementing this. Then I'll put screen shots in stages so the idea is better presented.
However if you hit enter in the textbox that become visible, then the command event would happen so that code is able to run based on command. Then textbox gets cleared and it's hidden. You'd only actually see commands next to line numbers as a label for the multiline commands.
I think this works pretty well. I'm calling the textbox visible as command entry mode, and the other case as just line number visible or an unexecuted command visible.
Normal line number display continues to look like this:
Then if you click line 3 it will focus the now displayed textbox and let you enter something:
If that textbox looses focus then it will go to like a command display mode:
Then if you click the line again you get command entry mode back:
Doing it this way avoids timers and code around mouse entering and leaving controls which I'd like to avoid. It seems like RDI SEU command entry is based on clicking.
I'm going to implement d and dd, and then post back here.
@NathanielACollier The progress is totally awesome. Can't wait to try it out!
The arrow key movement is now there. AvalonEdit line number on caret pos of start of line and left arrow key press will signal to turn on command mode and focus the command textbox for that line. If in command textbox you press right arrow at the end of the text then it will signal to AvalonEdit to put cursor on the line for which command is at. Then also in command textbox up and down arrow press now signal to next and previous commands to turn on. This is done with events being signaled from either the Adorner or the Line Number display calling functions on the line number model class.
I've got d command in there. I'll be working on dd. The manipulation of AvalonEdit line removal is a challenge... I may try to do i and i of n too since it deals with manipulating the line count.
I don't have much time to work on things, so I do apologize for the very long drawn out time this has taken.
@NathanielACollier Sorry for the late reply, but no problem. Take as much time as you need! 😄
While I've only briefly been exposed to the SEU line commands, I've seen alot of people at the company I work at use them. Being able to do both the single line commands, and block commands seems like it would be really useful. For a list of all the commands I found this: https://as400iseries.wordpress.com/2013/03/13/using-the-seu-editor/.
For implementing it would need to start with how to enter commands. It would need to be able to type text next to multiple line numbers. We'd need to be able to associate text fragments entered with the line number where it was entered.
AvalonEdit implements LineNumberMargin here: https://github.com/icsharpcode/AvalonEdit/blob/master/ICSharpCode.AvalonEdit/Editing/LineNumberMargin.cs. I made a repo and reduced the code needed to use the base LineNumberMargin but have some control over OnRendor here: https://github.com/NathanielACollier/AvalonEdit.Pieces.LineNumberMarginCommands/blob/master/AvalonEdit.Pieces/LineNumberMarginWithCommands.cs.
To me it would be better if there was some way to make your own line number margin that had interactive textboxes for each line number. I think the line number should not look like text boxes but turn into a blank textbox when you click one.