rofi-blocks icon indicating copy to clipboard operation
rofi-blocks copied to clipboard

Setting the selected line?

Open vredesbyyrd opened this issue 4 years ago • 6 comments

Hi,

Since rofi-blocks allows you to update list content on the fly, it could be great for making nested menus. One "issue" I have ran into is not being able to control what line is selected/active after selecting an entry.

Say you have a Main Menu with 5 items, each containing at least 1 submenu.

  1. Queue -> submenu
  2. Artists -> submenu
  3. Albums -> submenu
  4. Genres -> submenu
  5. Recent -> submenu

Menu option 5, Recent, contains 10 lines. When opening Recent line 5/10 is automatically the selected-row, where line 1 would be the expected behavior in this case.

In many uses cases rofi-blocks current behavior is an asset, this is just an example where its not.

You can currently mark a line as active or urgent, being able to do the same for -selected-row would be very nice to have.

{"text":"with object, you can use flags", "urgent":true},
{"text":"such as urgent and highlight", "highlight": true},
{"text":"The selected row",  "selected": true}

I have looked through rofi-blocks source to try and get an idea on whether or not it could be implemented, but I soon realized my c skills are just not up to the task :/

vredesbyyrd avatar Jan 16 '21 22:01 vredesbyyrd

Hi,

Thanks for trying at least :+1:

I think, and will assume, you mean highlight instead of active, but is a good name, if not better, that selected, since you have not selected the entry yet.

To be honest, I had this problem too, with the top_advanced.sh example. I am wondering what should happen when 2 or more lines are defined as active. As only one line should be active, I will have to choose the first or last., to simplify, I will choose the first one, and ignore the rest.

Edit: I do not see what should happen when I put active: false on an active line, should I set the first entry as active?

OmarCastro avatar Jan 17 '21 20:01 OmarCastro

I think, and will assume, you mean highlight instead of active, but is a good name, if not better, that selected, since you have not selected the entry yet.

Yup, typo on my part :/ I do agree that active is probably a more accurate description than selected in this regard, for reasons you described.

I am wondering what should happen when 2 or more lines are defined as active. As only one line should be active, I will have to choose the first or last., to simplify, I will choose the first one, and ignore the rest.

That sounds like correct behavior imo.

Edit: I do not see what should happen when I put active: false on an active line, should I set the first entry as active?

Hmmm, good question. Perhaps @fogine could offer some better input than me on this issue?

vredesbyyrd avatar Jan 17 '21 21:01 vredesbyyrd

I would design it in a similar manner to rofis selected-row option.. Only a single entry can be the active (selected) one at a time so it doesnt make sense to make the active option be nested as part of lines[].active. Instead it could be defined as top level option and take a number (index of a line) instead of boolean and if invalid index is defined, the first row/entry should be the active one

fogine avatar Jan 18 '21 14:01 fogine

I did play around with it, and decided to implement with @fogine input, it had less edge cases to worry than the active on the line. About the invalid index case, I let rofi handle it with rofi_view_set_selected_line, and it works as @fogine described.

The new property is active entry. Non-numeric values, negative and floating numbers are ignored

I also added a new example demonstrating it: focus_entry

OmarCastro avatar Jan 23 '21 00:01 OmarCastro

This works great :)

About the invalid index case, I let rofi handle it with rofi_view_set_selected_line

Nice.

After playing with it a bit and thinking about it more, having active entry set as a top-level entry does make more sense. Thanks for the input @fogine.

And much appreciate the quick implementation @OmarCastro!

vredesbyyrd avatar Jan 24 '21 02:01 vredesbyyrd

Hi, believe I ran into a bug.

Initial rofi view is a Main Menu with 5 items each contains at least 1 submenu.

  1. Queue -> submenu
  2. Artists -> submenu
  3. Albums -> submenu
  4. Genres -> submenu
  5. Recent -> submenu

User selects row 0, Queue. Queue contains 6 lines and user set {active entry: 5} (starting at 0), but on render of view line 0 displays as active entry.

Although line 0 displays as the active entry, using rofi's debugger output looks correct.


(process:8765): BlocksMode-DEBUG: 21:35:03.087: handling received line
(process:8765): BlocksMode-DEBUG: 21:35:03.087: entry_to_focus 5
(process:8765): BlocksMode-DEBUG: 21:35:03.087: reloading rofi view
(process:8765): BlocksMode-DEBUG: 21:35:03.099: calling on_render
(process:8765): BlocksMode-DEBUG: 21:35:03.099: on_render.selected line 5
(process:8765): BlocksMode-DEBUG: 21:35:03.099: on_render.next pos 1
(process:8765): BlocksMode-DEBUG: 21:35:03.099: on_render.active line 0
(process:8765): BlocksMode-DEBUG: 21:35:03.188: blocks_mode_get_num_entries
(process:8765): BlocksMode-DEBUG: 21:35:03.188: blocks_mode_get_message
(process:8765): BlocksMode-DEBUG: 21:35:03.203: calling on_render

it appears active linenum lines in initial view, in this case 5... hmmm.

Thanks for your time.

vredesbyyrd avatar Jan 25 '21 04:01 vredesbyyrd