Commit Graph

282 Commits

Author SHA1 Message Date
Andreas Kling
812ee330e6 GTreeView: Make it possible to multi-select with the Ctrl modifier 2019-11-11 22:20:02 +01:00
Andreas Kling
524da0ad01 LibGUI: Add "Vector<GWidget*> GWidget::child_widgets()"
This is quite inefficient since it constructs a new Vector each time.
2019-11-11 22:20:02 +01:00
Andreas Kling
3ef287eb9f GTreeView: Always repaint in response to did_update_model()
This could definitely be more efficient, but this is more correct than
doing nothing at all. :^)
2019-11-11 22:20:02 +01:00
Andreas Kling
dd2900eda0 Launcher: Remove the Launcher app, and all hacks in support of it
The Launcher's functionality has been replaced by the app shortcuts in
the system menu.

There were various window management hacks to ensure that the launcher
stayed below all other windows while also being movable, etc.
2019-11-11 13:13:08 +01:00
Andreas Kling
cab9933834 GToolBar: Make buttons exclusive if action belongs to exclusive group
This was probably what I had originally intended when I first wrote the
GActionGroup stuff, but it seems to have been forgotten.
2019-11-10 22:49:02 +01:00
Andreas Kling
3a01df9fb1 GWidget: Fix accidentally ignored set_relative_rect() with empty size
To protect the layout system from negative input values, we were using
an empty Rect() whenever an empty rect (width/height <= 0) was provided
to set_relative_rect().

This caused Terminal's scrollbar code to fail, since it relies on first
setting only the scrollbar width on startup, and then setting up the
proper geometry in response to the initial resize event.

Fixes #753.
2019-11-10 12:57:37 +01:00
Andreas Kling
ca538b6cee LibGUI: Add a simple GWidget class registry/factory
You can now register a GWidget subclass with REGISTER_GWIDGET(class)
and it will be available for factory construction through the new
GWidgetClassRegistration interface.

To obtain a GWidgetClassRegistration for a given class name, you call
GWidgetClassRegistration::find(class_name). You can also iterate over
all the registered classes using GWCR::for_each(callback).

This will be very useful for implementing a proper GUI designer, and
also in the future for things like script bindings.

NOTE: All of the registrations are done in GWidget.cpp at the moment
since I ran into trouble with the fricken linker pruning the global
constructors this mechanism relies on. :^)
2019-11-10 12:57:37 +01:00
Andreas Kling
29b2117564 LibGUI: Make GTreeView fire the on_selection hook
GTreeView was forgetting to call to base in did_update_selection().
This prevented GAbstractView from firing the on_selection hook and we
ended up with only the on_selection_change hook firing.
2019-11-09 11:57:08 +01:00
Andreas Kling
ce9b9c129d LibGUI: Include internal_data() in GModelIndex LogStream output 2019-11-09 11:56:28 +01:00
Rhin
503fe37eaa TextEditor: Enable/disable undo & redo buttons based on availability (#740) 2019-11-09 08:50:39 +01:00
Andreas Kling
e52fe07d2e GTableView: Paint with white background when model-less
This matches the behavior of GTreeView.
2019-11-09 00:41:00 +01:00
Andreas Kling
d22d9874f7 LibGUI: Allow overriding the button size when constructing GToolBar
This makes it easy to create a toolbar housing buttons of a size other
than 16x16.
2019-11-09 00:41:00 +01:00
Andreas Kling
0d2495e4e7 LibGUI: Allow construction of vertical GToolBars
There's currently a small paint glitch for vertical toolbars due to the
way StylePainter::paint_surface() draws a MidGray line at the bottom of
whatever a "surface" is supposed to be.
2019-11-09 00:41:00 +01:00
Andreas Kling
fa77a57257 GTextEditor: Allow moving the selected line(s) up/down in bulk
You can now press Ctrl+Shift+Up/Down in a GTextEditor and the currently
selected line(s) will all move together one step up/down.

If there is no selection, we move the line with the cursor on it. :^)
2019-11-08 20:14:42 +01:00
Andreas Kling
c16b1a515e GTextEditor: Add a way to flush any pending on_change notifications
Since on_change handlers can alter the text document we're working on,
we have to make sure they've been run before we try looking at spans.
This fixes some flakiness when a paint happened before HackStudio had
a chance to re-highlight some C++ while editing it.

The design where clients of GTextEditor perform syntax highlighting in
the "arbitrary code execution" on_change callback is not very good.
We should find a way to move highlighting closer to the editor.
2019-11-08 19:51:10 +01:00
Andreas Kling
8a024a3305 LibGUI: Rename GEventLoop.{cpp,h} => GWindowServerConnection
The GEventLoop class is long gone, and the only class in these files is
GWindowServerConnection, so let's update the file names. :^)
2019-11-08 11:40:25 +01:00
rhin123
96c1e36ed3 TextEditor: Added redo functionality & proper stack manipulation
Added redo functionality & added m_undo_stack_index that moves back &
forth on the stack depending on the undo's & redo's.
2019-11-07 22:29:59 +01:00
Andreas Kling
d3558b6137 LibCore+LibGUI: Allow inserting a CObject/GWidget before another
When adding a widget to a parent, you don't always want to append it to
the set of existing children, but instead insert it before one of them.

This patch makes that possible by adding CObject::insert_child_before()
which also produces a ChildAdded event with an additional before_child
pointer. This pointer is then used by GWidget to make sure that any
layout present maintains the correct order. (Without doing that, newly
added children would still be appended into the layout order, despite
having a different widget sibling order.)
2019-11-05 20:41:27 +01:00
Till Mayer
4c9fdad1bf LibGUI: Added getter for m_dragging 2019-11-04 20:55:46 +01:00
Andreas Kling
f5c2ae1192 GTextEditor: Move the cursor to column 0 after deleting a whole line 2019-11-04 12:36:10 +01:00
rhin123
9e608885d1 TextEditor: Added undo functionality
Created a stack where a vector of undo actions are stored.
2019-11-03 20:21:14 +01:00
Andreas Kling
1282b778e7 LibGUI: Move GTextPosition and GTextRange LogStream<< to their headers 2019-11-03 09:57:14 +01:00
George Pickering
704f48d7f3 POSIX compliance: (most) shell scripts converted to generic shell
Ports/.port_include.sh, Toolchain/BuildIt.sh, Toolchain/UseIt.sh
have been left largely untouched due to use of Bash-exclusive
functions and variables such as $BASH_SOURCE, pushd and popd.
2019-11-03 09:26:22 +01:00
Andreas Kling
b8bf998b61 LibGUI: Move text search functions from GTextEditor to GTextDocument
Also add a find_all() that retuns a Vector<GTextRange> and simply does
a find_next() loop, returning all the matching ranges.
2019-11-01 21:31:06 +01:00
Andreas Kling
a4709502d1 GTextEditor: Make text_position_at() protected 2019-10-30 20:28:44 +01:00
Andreas Kling
bddba567b3 LibGUI: Add GTextDocument::text_in_range(GTextRange)
This function returns a String containing the text in a given range.
GTextEditor::selected_text() is now just a wrapper around this.
2019-10-30 20:28:44 +01:00
Andreas Kling
014f8ca8c4 AK: Allow JsonValue to store 64-bit integers internally
Add dedicated internal types for Int64 and UnsignedInt64. This makes it
a bit more straightforward to work with 64-bit numbers (instead of just
implicitly storing them as doubles.)
2019-10-29 16:36:50 +01:00
Andreas Kling
f0da3ab9b2 LibGUI: Make GTextBox non-final
There's nothing wrong with subclassing GTextBox.
2019-10-28 19:08:48 +01:00
Andreas Kling
9b13a3905b LibGUI: Support multiple GTextEditors editing the same GTextDocument
With this patch, you can now assign the same GTextDocument to multiple
GTextEditor widgets via GTextEditor::set_document().

The editors have independent cursors and selection, but all changes
are shared, and immediately propagate to all editors.

This is very unoptimized and will do lots of unnecessary invalidation,
especially line re-wrapping and repainting over and over again.
2019-10-27 19:36:59 +01:00
Andreas Kling
f96c683543 LibGUI: Move visual line metadata from GTextDocument to GTextEditor
This patch decouples GTextDocument and GTextDocumentLine from the line
wrapping functionality of GTextEditor.

This should basically make it possible to have multiple GTextEditors
editing the same GTextDocument. Of course, that will require a bit more
work since there's no paint invalidation yet.
2019-10-27 18:00:07 +01:00
Andreas Kling
f1c6193d6d LibGUI: Move GTextDocument out of GTextEditor
The idea here is to decouple the document from the editor widget so you
could have multiple editors being views onto the same document.

This doesn't work yet, since the document and editor are coupled in
various ways still (including a per-line back-pointer to the editor.)
2019-10-27 16:44:16 +01:00
Andreas Kling
de2b25e2c1 LibGUI: Move GTextRange and GTextPosition to their own header files 2019-10-27 11:23:53 +01:00
Andreas Kling
db5178fb8f GTextEditor: Double-clicking on a span should select the span
This makes double-clicking on a C++ token in HackStudio select the
whole token, which is pretty nice. It's not perfect in all cases,
but a lot nicer than just expanding until we hit whitespace. :^)
2019-10-27 11:18:19 +01:00
Andreas Kling
8fa466e496 GTextEditor: Backspace over soft tabs
This makes the backspace erase backwards until the next soft tab stop.
We currently always use 4 as the soft tab width, but I suppose we could
make it configurable at some point. :^)
2019-10-27 10:42:48 +01:00
Andreas Kling
4089690cf1 GFilePicker: Allow overriding the window title for get_open_filepath() 2019-10-26 21:42:34 +02:00
Andreas Kling
b513a787fb GTextEditor: set_text() should clear any existing spans 2019-10-26 20:21:12 +02:00
Andreas Kling
bc2026d26d LibGUI: Make GTextEditor::Span have a range instead of two positions
A GTextRange is really just two GTextPositions (start and end) anyway.
This way we can say nice things like "if (range.contains(position))"
2019-10-26 15:33:19 +02:00
Andreas Kling
4fa8acf6ea GTextEditor: The Home key should jump to the first non-space character
Press Home twice to get to column 0. This feels way more natural.
2019-10-26 14:02:39 +02:00
Andreas Kling
532001f4c1 GTextEditor: Arrow keys should only modify selection when Shift is held 2019-10-26 14:01:53 +02:00
Andreas Kling
98a6149b4f LibGUI: Make GWindow drive relayout and do it recursively
Instead of only doing a relayout in the widget you're invalidating,
we now do a recursive top-down relayout so everything gets updated.

This fixes invalid results after updating a preferred size in some
situations with nested layouts.
2019-10-26 12:28:54 +02:00
Andreas Kling
59107a7cfe GTextEditor: Allow setting a custom font for each span 2019-10-26 00:13:07 +02:00
Andreas Kling
0d53d74d5f GTextEditor: Add a "span" mechanism for having custom-style text ranges
It's now possible to give GTextEditor a vector of Span objects.
Spans currently tell the editor which color to use for each character
in the span. This can be used to implement syntax highlighting :^)
2019-10-25 21:07:02 +02:00
Brandon Scott
51e655f903 LibGUI: Added window creation callback to GApplication/GWindow
Added a window creation callback to GApplication that gets called
by GWindow which will reset any pending exit request in the
CEventLoop.

This is to prevent a bug which prevents your application from
starting up if you had a message box or other dialog before
showing your main application form. The bug was triggered by
there being no more visible windows which was triggering a
premature quit().
2019-10-25 15:29:19 +02:00
Brandon Scott
a1c89c2734 LibGUI: Add very limited multi-label support to GStatusBar
Created a constructor argument and getter/setter methods to allow
you to have a multi-label status bar.
2019-10-24 09:57:27 +02:00
Andreas Kling
41289e652f GWidget: On second thought, don't assert on negative sizes in rects
Just neutralize incoming negative-size rects in set_relative_rect().
2019-10-23 20:50:01 +02:00
Andreas Kling
b916e34fed LibGUI: GTabWidget should not set children to have negative size
This could happen if a child was added to a GTabWidget before the
GTabWidget had its first layout.

Also add an assertion to catch this in GWidget::set_relative_rect()
since it was not immediately obvious what was happening.
2019-10-23 19:51:09 +02:00
Andreas Kling
31b5047894 LibGUI: Allow override the font on a per-index basis in GListView
This should be ported to all of the GAbstractView subclasses.
2019-10-22 21:38:04 +02:00
Andreas Kling
b89f64cb55 LibGUI: Make it possible to wrap a Font in a GVariant 2019-10-22 21:37:11 +02:00
Andreas Kling
0a0dfeee8b LibGUI: Make GTextEditor::set_cursor() public
Also clamp the cursor value to the possible range instead of asserting
when trying to set a cursor past the end of the document.
2019-10-21 19:01:27 +02:00
Brandon Scott
efc2fc6888 LibGUI: Fix GMenu submenu shortcut bug.
I was encountering an entire system crash when the window server
attempted to do something with the shortcut text on a submenu. This
bug only seemed to appear when I had a lone submenu inside of a menu.
2019-10-13 08:45:49 +02:00