Commit graph

55 commits

Author SHA1 Message Date
Joseph Bywater
15bc42479a LibGUI: Fix AbstractView selection after initial focusin event
After moving the cursor to the home position, clear the
selection.

Fixes #3925.
2020-11-06 00:33:47 +01:00
AnotherTest
6e9c6acc87 LibGUI: Implement shift-select
shift-selecting simply toggles all indices in the range between the
cursor and the index that is being 'selected'.
2020-11-03 16:47:56 +01:00
Joseph
9efcb5d290
LibGUI: Return early if drag_data_type is null (#3919)
If the user tries to drag an item with a null drag data type from an
AbstractView, return from the mouse event early.
2020-11-02 22:26:38 +01:00
Andreas Kling
a7f4f6afc3 LibGUI: Allow dragging a previously unselected item with a single click
Views would previously require that an item be selected before it could
be dragged. This patch makes us consider initiating a drag immediately
after the view has been selected, without requiring a mouseup event in
between.
2020-11-01 15:42:09 +01:00
Andreas Kling
844c5709ac LibGUI: Views should ignore double clicks that don't hit any index 2020-11-01 15:31:18 +01:00
Andreas Kling
e499b0f161 LibGUI: Invalidate view cursor on model update
This is sad (since it would be nice to preserve the cursor+selection)
but until we implement persistent model indexes, this at least prevents
us from keeping a stale cursor index.
2020-11-01 10:39:37 +01:00
Andreas Kling
aef56159a8 LibGUI: Add Widget focus policies
Every widget now has a GUI::FocusPolicy that determines how it can
receive focus:

- NoFocus: The widget is not focusable (default)
- TabFocus: The widget can be focused using the tab key.
- ClickFocus: The widget can be focused by clicking on it.
- StrongFocus: Both of the above.

For widgets that have a focus proxy, getting/setting the focus policy
will affect the proxy instead.
2020-10-30 17:03:28 +01:00
Andreas Kling
de3dc15a6e LibGUI: Default-initialize cursor when focusing an AbstractView
If an AbstractView receives focus without a valid cursor index, we now
ask it to move its cursor to the home position. This way, the user can
actually start moving the cursor after tabbing to a view.
2020-10-28 21:40:31 +01:00
Andreas Kling
1f789a07b1 LibGUI: Don't start AbstractView type-ahead search with tab key
This was preventing views from relinquishing focus via the keyboard.

Fixes #3862.
2020-10-28 21:26:27 +01:00
Andreas Kling
272af7685b LibGUI: Improve and simplify IconView item name wrapping
Move the wrapping logic to get_item_rects(). This makes mouse events
able to hit the wrapped labels, and various other little things stop
glitching out as well.

Also, instead of having a per-line width when wrapping icon names,
make the text rect wide enough to fit every line.
2020-10-27 16:10:30 +01:00
Andreas Kling
f6084d42d9 LibGUI: Call up to the correct base class in GUI::AbstractView 2020-10-26 21:01:45 +01:00
Tom
52a847a0eb LibGUI: Implement searching/jumping as you type in views
This allows the user to start typing and highlighting and jumping
to a match in ColumnsView, IconView, TableView and TreeView if
the model supports it.
2020-10-22 15:23:45 +02:00
Tom
307f0bc778 LibGUI: Fix scroll_into_view flipping between left/top and right/bottom
This fixes flipping between left/top and right/bottom when the rectangle
to make visible doesn't fit into the visible portion each time the
function is called.
2020-10-22 15:23:45 +02:00
Tom
a7533eb29c LibGUI: Clear selection if right-clicking item that isn't selected
If we're right-clicking on an item that isn't currently selected, clear
the selection first.

Fixes #3665
2020-10-06 15:04:23 +02:00
AnotherTest
e250591ff3 LibGUI: Do not clear the selection on right-click 2020-09-25 23:55:33 +02:00
Andreas Kling
d3adbed231 LibGUI: Move keyboard item activation up to AbstractView
All views want the same behavior, so move this to the base class. :^)
2020-09-24 21:35:47 +02:00
Andreas Kling
d8553a6406 LibGUI: Stop editing in views when the view is hidden
This fixes an issue in FileManager where an editor opened in the table
view mode would remain open after switching to the icon mode.
2020-09-24 21:14:14 +02:00
Andreas Kling
f52527ef9c LibGUI: Move editing key handling up to AbstractView
We want all views to respond to the editing key as long as the relevant
edit trigger is activated.
2020-09-24 11:42:11 +02:00
pkotzbach
8a21c528ad
LibGUI: Minor consistency cleanup in AbstractView::set_cursor() (#3478) 2020-09-14 20:55:07 +02:00
Andreas Kling
e860a9aa80 LibGUI: Unregister AbstractView from model on destruction
It was possible to leave stale view pointers in the model after a view
was destroyed while attached to a model.
2020-09-10 18:45:00 +02:00
Andreas Kling
27687b1c6e LibGUI: Handle cursor keydown events in AbstractView
Move the basic movement keys (up/down/left/right/home/end/pgup/pgdn)
up to AbstractView::keydown_event() and have it call the virtual
move_cursor() which is then implemented by subclasses.
2020-09-02 21:29:31 +02:00
Andreas Kling
4ba12e9c23 LibGUI: Simplify ListView hover highlighting
Instead of tracking the last valid hovered index, just hook the
mousemove event and make the cursor follow the hover when it changes.
2020-09-02 21:29:31 +02:00
Andreas Kling
daeb2bdc60 LibGUI: Don't return early from AbstractView::set_cursor()
Calling set_cursor() with the same cursor index is not necessarily
a no-op! For example, we may want to toggle the selection.
2020-09-01 16:33:31 +02:00
Andreas Kling
fed53e19c7 LibGUI: Make AbstractView::set_cursor() scrolling into view optional
Sometimes you just want to set the cursor programmatically without
scrolling the view to make the cursor visible.
2020-08-29 00:17:42 +02:00
Andreas Kling
734035857e LibGUI: Allow AbstractView::set_cursor(ModelIndex(), ...)
This should be a valid way to clear the cursor.
2020-08-29 00:16:58 +02:00
Andreas Kling
12dfeb9845 LibGUI: Allow rollback of model editing delegate input
In the StringModelEditingDelegate convenience class, we simply hook up
the escape key to editor rollback. This means you can cancel an ongoing
cell edit by pressing escape. :^)
2020-08-28 20:50:12 +02:00
Andreas Kling
f3e4b62be9 LibGUI: Add AbstractView "edit triggers" to improve editing control
This API allows the embedder of a view to decide which actions upon
the view will begin editing the current item.

To maintain the old behavior, we will begin editing when an item is
either double-clicked, or when the "edit key" (return) is pressed.
2020-08-28 20:40:12 +02:00
Andreas Kling
9947262eaa LibGUI: Ctrl+clicking on an AbstractView should move cursor
Don't just toggle the selection of the index, also move the cursor to
where the user is clicking.
2020-08-27 18:41:54 +02:00
Andreas Kling
9cf37901cd LibGUI: Add a cursor to AbstractView, separate from the selection
Views now have a cursor index (retrievable via cursor_index()) which
is separate from the selection.

Until now, we've been using the first entry in the selection as
"the cursor", which gets messy whenever you want to select more than
one index in the model.

When setting the cursor, the selection is implicitly updated as well
to maintain the old behavior (for the most part.)

Going forward, this will make it much easier to implement things like
shift-select (extend selection from cursor) and such. :^)
2020-08-27 18:36:31 +02:00
Andreas Kling
f86c074be8 LibGUI: Pressing Return in an editable TableView should begin editing
This matches what happens when you double-click on a cell.
2020-08-24 21:20:54 +02:00
Andreas Kling
0f0b37d137 LibGUI: Return focus to view when stopping editing
If the editing widget (as provided by the editing delegate) was focused
when editing stops, have the view take back focus.
2020-08-24 21:10:00 +02:00
Andreas Kling
032f567422 LibGUI: Always update() after changing AbstractView sort column/order
Otherwise we may end up with a stale appearance until something else
causes it to repaint.
2020-08-24 21:06:42 +02:00
Andreas Kling
9102b624ac LibGUI+DevTools+Applications: Use ModelIndex::data() in many places
This way you don't have to keep track of which model it came from.
2020-08-16 16:44:09 +02:00
Andreas Kling
a1e381a0f8 LibGUI: Move GUI::Model::Role to GUI::ModelRole
This is preparation for using ModelRole in the ModelIndex API.
2020-08-16 16:44:09 +02:00
Andreas Kling
e1ed71ef9e LibGUI: Make model sorting imperative and move order to AbstractView
Instead of SortingProxyModel having a column+order, we move that state
to AbstractView. When you click on a column header, the view tells the
model to resort the relevant column with the new order.

This is implemented in SortingProxyModel by simply walking all the
reified source/proxy mappings and resorting their row indexes.
2020-08-16 16:44:09 +02:00
thankyouverycool
6a78db07f1 LibGUI: Add hover highlighting and keyboard controls to ComboBox
Adds a new highlighting effect to the actively selected row in
ComboBox ListView. ComboBoxEditor can now be controlled with
page up, page down, and the up and down arrow keys. ESC and loss
of focus now cause comboboxes to close. Now activates on mouseup
as well as return.
2020-07-15 13:19:44 +02:00
Tom
d4c6ae8263 LibGUI: Add ability to disable multiselect for views 2020-07-13 19:49:34 +02:00
Tom
f266f0e880 LibGUI: Improve IconView performance with large selections
This implements the following optimizations:

* Rather than clearing a HashTable of selected items and re-populating
  it every time the selection rectangle changes, determine the delta
  by only examining the items that might be in the area where the
  selection may have changed compared to the previous area. Then
  only add/remove selection items as needed.

* When painting, only query and paint the items actually visible.
  Also, keep a local cache of item information such as calculated
  rectangles and selection state, so it doesn't have to be calculated
  over and over again.
2020-07-13 19:49:34 +02:00
Andreas Kling
d851863704 Userspace: Remove a bunch of unnecessary Kernel/API/KeyCode.h includes 2020-07-04 17:25:31 +02:00
Andreas Kling
11c4a28660 Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
Andreas Kling
04187576ff LibGUI: Models should always specify font via Model::Role::Font
This gets rid of one field in ColumnData. The goal is to get rid of all
fields and lose ColumnData entirely.
2020-05-21 19:55:44 +02:00
angel
e0a16f8752 FileManager+LibGUI: Allow drop on entire DirectoryView
Previously, drag and drop would only work when dragging between node
items on a DirectoryView. This commit makes it possible to drag files to
the empty area of the DirectoryView and copy files more easily between
windows.
2020-04-20 12:15:26 +02:00
Andreas Kling
57464be8f1 LibGUI: Scroll AbstractView to top on model change 2020-04-14 19:12:10 +02:00
Andreas Kling
5390d53a80 LibGUI: Remove debug spam in AbstractView::did_update_model() 2020-04-12 14:20:04 +02:00
Andreas Kling
8e4751a963 LibGUI: Add a way for models to update without invalidating indexes
This is really just a workaround to keep SystemMonitor's process table
working right wrt selection retention during resorts (while also doing
full index invalidation on things like ProfileViewer inversion.)

It's starting to feel like the model abstraction is not super great
and we'll need a better approach if we want to actually build some more
dynamic functionality into our views.
2020-04-12 12:03:33 +02:00
Andreas Kling
a06548eaf7 LibGUI: Keep still-valid indexes in selection after a model update
This is a stop-gap patch solution for the annoying problem of models
being bad at updating. At least the process table will retain your
selection in SystemMonitor now.
2020-04-09 09:53:28 +02:00
Andreas Kling
031d242e0e LibGUI: Clear any hovered index when the cursor leaves an AbstractView 2020-04-03 21:14:34 +02:00
Sergey Bugaev
7bd077a3ae LibGUI: Fix index invalidation
When the model gets updated, we have to let go of the old indexes,
because they're invalid from that moment on.

Fixes https://github.com/SerenityOS/serenity/issues/1541
2020-03-30 23:05:14 +02:00
Andreas Kling
b4fde72013 LibGUI: Brighten icons when hovering items in item views
View classes now track their hovered item and paint them in a slightly
brighter shade to liven up the user interface. :^)
2020-03-30 19:57:44 +02:00
DAlperin
8e1645423f
LibGUI: Make descendants of AbstractView define their own select_all() (#1201)
AbstractView does not know which column it's displaying which makes it
impossible to implement the select_all functionality up there. Now
descendants override the pure virtual select_all method and implement
it themselves.
2020-02-25 16:03:15 +01:00