Commit graph

1232 commits

Author SHA1 Message Date
Andreas Kling
6e0976d858 LibGUI: Make the GML parser a bit more fault-tolerant
It will now fail and whine in the debug log instead of asserting.
2020-12-20 14:30:40 +01:00
Andreas Kling
64ba41ea13 LibGUI: Make GUI::Label auto-sizing declarative
You can now set the "autosize" property on a GUI::Label and it will
automatically update its width preference to fit the text.
2020-12-20 12:36:32 +01:00
Andreas Kling
de08e7b8c9 LibGUI: Rename ProgressBar property caption => text and expose to GML 2020-12-20 12:29:40 +01:00
Andreas Kling
48b0f4844b LibGUI: Add a couple more Widget registrations
Make it possible to instantiate BreadcrumbBar, ProgressBar and TreeView
from GML. :^)
2020-12-20 12:15:49 +01:00
Andreas Kling
822dc56ef3 LibGUI: Introduce GML - a simple GUI Markup Language :^)
This patch replaces the UI-from-JSON mechanism with a more
human-friendly DSL.

The current implementation simply converts the GML into a JSON object
that can be consumed by GUI::Widget::load_from_json(). The parser is
not very helpful if you make a mistake.

The language offers a very simple way to instantiate any registered
Core::Object class by simply saying @ClassName

@GUI::Label {
    text: "Hello friends!"
    tooltip: ":^)"
}

Layouts are Core::Objects and can be assigned to the "layout" property:

@GUI::Widget {
    layout: @GUI::VerticalBoxLayout {
        spacing: 2
        margins: [8, 8, 8, 8]
    }
}

And finally, child objects are simply nested within their parent:

@GUI::Widget {
    layout: @GUI::HorizontalBoxLayout {
    }
    @GUI::Button {
        text: "OK"
    }
    @GUI::Button {
        text: "Cancel"
    }
}

This feels a *lot* more pleasant to write than the JSON we had. The fact
that no new code was being written with the JSON mechanism was pretty
telling, so let's approach this with developer convenience in mind. :^)
2020-12-20 11:59:40 +01:00
Linus Groh
fe88f46bc9 LibGUI: Don't assume main widget exists in Window::handle_resize_event()
Just like the other event handler functions, handle_resize_event()
shouldn't assume that the window has a main widget (which is being
resized in this case).

Fixes #4450.
2020-12-18 19:20:15 +01:00
Sahan Fernando
8dc0d9b7b7 LibGUI: Make autoformatting performed on InsertTextCommand visible to on_edit_action 2020-12-18 16:25:42 +01:00
Andreas Kling
598efa60a3 LibGUI: Table views with SelectRows should scroll entire rows into view 2020-12-17 00:54:58 +01:00
Andreas Kling
f0138fcb25 LibGUI: Move selection behavior from TableView up to AbstractView
Let's make SelectionBehavior a view concept where views can either
select individual items (row, index) or whole rows. Maybe some day
we'll do whole columns, but I don't think we need that now.
2020-12-17 00:54:58 +01:00
Andreas Kling
226ac8a47b LibGUI: Don't fill IconView item text background unless actually wanted
We were always filling the rect behind item texts, even when the widget
had fill_with_background_color() == false.
2020-12-16 19:39:26 +01:00
Andreas Kling
4236127fb9 LibGUI: Make the IconView cursor rect show up on the desktop
It was getting lost in some bogus coordinate conversion math while
trying to constrain unusually long item texts.
2020-12-16 19:39:26 +01:00
Andreas Kling
50aab509ce LibGUI: Add ScrollableWidget helpers for rect conversion
to_content_rect() and to_widget_rect() help you convert rects from one
coordinate space to the other.
2020-12-16 19:39:26 +01:00
Andreas Kling
2759d518b7 FileManager+LibGUI: Draw the item text for desktop icons with shadow
This makes it look nice regardless of wallpaper or background color.
2020-12-16 12:16:14 +01:00
Andreas Kling
0fef901513 LibGUI: Show app icons for executables with associated .af files
This is a rather ugly hack just to get app icons to show up in the
FileManager. It would be a lot nicer to embed icons in executables
instead but it's not obvious to me how to do that.
2020-12-16 12:08:55 +01:00
Andreas Kling
c44dbabda1 LibGUI: Generate nicer icons for symlinked files
Instead of symlinks showing up with the "filetype-symlink" icon, we now
generate a new icon by taking the target file's icon and slapping a
small arrow emblem on top of it.

This looks rather nice. :^)
2020-12-16 12:08:48 +01:00
Andreas Kling
3d5e30a1e6 LibGUI: Add GUI::Icon::sizes()
This gives you a Vector<int> with all the sizes contained in the Icon.
2020-12-16 11:53:23 +01:00
Itamar
efe4da57df Loader: Stabilize loader & Use shared libraries everywhere :^)
The dynamic loader is now stable enough to be used everywhere in the
system - so this commit does just that.
No More .a Files, Long Live .so's!
2020-12-14 23:05:53 +01:00
Andreas Kling
396b09a1ec LibGUI: Don't focus BreadcrumbBar segments on click 2020-12-14 21:44:03 +01:00
Andreas Kling
818f7777c8 LibGUI: Add a basic BreadcrumbBar widget! :^)
This can be used to implement segmented path bars in FileManager and
wherever else wanted.
2020-12-14 20:43:42 +01:00
Andreas Kling
b00a347ac5 LibGUI: Protect GUI::Button across firing the on_click hook
If a hook triggers the deletion of the GUI::Button, we would be unable
to proceed in a well-defined manner here, so let's protect ourselves.

This probably needs to be done in a whole lot of places, since GUI
widgets are just ref-counted Core::Objects and running arbitrary code
can mean that they get deleted.
2020-12-14 20:43:42 +01:00
Andreas Kling
3ee5694e97 LibGUI: Simplify ComboBox/TextEditor relationship a bit
Instead of TextEditor knowing about the ComboBox button on the right
hand side, we now make ComboBox inherit from GUI::Frame, and make the
inner text editor widget frameless.

This allows us to place the button ourselves inside ComboBox without
any frame artifacts, and TextEditor no longer needs to keep track of
the geometry of that button.
2020-12-13 11:49:18 +01:00
Zac
dea399ff08 FileManager: focus_dependent_delete_action is correctly enabled/disabled
The focus_dependent_delete_action that sits in the file manager's
toolbar would always remain enabled, even if nothing was selected,
activating it if nothing was selected would then crash the application.

The action is now correctly enabled/disabled, but due to the way
selection works in TreeViews, something is always selected, what really
matters is if the TreeView has something selected, and it has focus.
As it currently stands, there is no way to know when the TreeView's
is_focused status changes. In order for this to work I added a callback
to the Widget class which fires when a widget receives or looses focus.
In that callback, the focus_dependent_delete_action's enabled value is
recalculated.
2020-12-11 09:36:44 +01:00
Sahan Fernando
8e1bda0e9d LibGUI: Show action shortcut in ToolBarButton tooltip 2020-12-09 15:00:34 +01:00
Ben Wiederhake
6c2ea4c4e9 Clipboard: Remove-unused bpp metadata
It's just more attack surface, and can be deduced from the format anyway.
2020-12-08 09:37:30 +01:00
Andreas Kling
ab289e183e LibGUI: Expose widget focus policy as a Core::Object property
This makes focus policies show up in the inspector which is helpful.
2020-12-07 19:46:34 +01:00
Linus Groh
886fe7e69f LibGUI: Allow GUI::Action to swallow key events when disabled
Sometimes an action should be disabled and the KeyEvent not posted to
the app's event loop nonetheless. In other words the action swallows the
KeyEvent without being activated.

Specific use-case: Terminal's Ctrl+Shift+{C,V}.
2020-12-07 15:55:12 +01:00
Sahan Fernando
4062add8ed LibGUI: Optimize GUI::Variant move constructor 2020-12-03 21:53:29 +01:00
Tom
f68115aba3 Taskbar: Wait on all waitable children in SIGCHLD handler
We need to call waitpid until no more waitable children are available.
This is necessary because SIGCHLD signals may coalesce into one when
multiple children terminate almost simultaneously.

Also, switch to EventLoop's asynchronous signal handling mechanism,
which allows more complex operations in the signal handler.
2020-12-02 12:57:25 +01:00
AnotherTest
169beff21e LibGUI: Add a ModelSelection::add_all(Vector) API
Using add() is very slow due to the change notifications.
2020-11-30 12:07:45 +01:00
AnotherTest
b66f3166cb LibGUI: Throw less view state away in model_did_update()
When `DontInvalidIndexes` is passed, be optimistic and keep the old
indices when the model validates them.
This is currently fine, as the group of models that use
DontInvalidateIndexes use it as "The old indices are still ok" (there's
a note about this in ProcessModel.cpp).
2020-11-30 12:07:45 +01:00
AnotherTest
c84756efa8 LibGUI: Don't start editing with (just) modifier keys when AnyKeyPressed
This fixes the control key starting an edit on (and inserting a nul
character into) a cell in Spreadsheet.
2020-11-30 12:07:45 +01:00
AnotherTest
71de8b7480 LibGUI: Remove `AbstractView::did_update_model()'
...and use `ModelClient::model_did_update()' instead.
This makes AbstractView a ModelClient (which it always was anyway).
2020-11-30 12:07:45 +01:00
Linus Groh
d66087ac2f LibGUI/FileIconProvider: Initialize s_filetype_image_icon
This was accidentally removed in 1c90321.
Fixes #4125.
2020-11-28 17:16:33 +01:00
Andreas Kling
1abda05d38 LibGUI: Make GUI::Dialogs non-minimizable by default 2020-11-28 10:26:05 +01:00
Andreas Kling
005afa4c6e LibGUI: Don't assert when right clicking on a vertical HeaderView
Just log a debug message instead. We still need to actually implement
vertical header context menus, but for now let's at least not crash.
2020-11-28 10:26:05 +01:00
Emanuel Sprung
3b7884ee8a TextEditor: Add button to match regular expression during search 2020-11-27 21:32:41 +01:00
Zac
018eff802b
LibGUI: Remove redundant set_title() call in FilePicker (#4153) 2020-11-24 18:41:44 +01:00
Jakub Berkop
c6bb3d452a
LibGUI: Widget::action_for_key_event() should fail for invalid shortcuts (#4137)
Previously GUI::Actions which were constructed without initializing
m_shortcut could be activated via an invalid GUI::Shortcut.

Steps to reproduce:
It was possible to enable TextEditor's markdown preview by pressing
Ctrl or Alt (Cmd/Ctrl) keys, which should not happen, as this Action
did not specify a shortcut.

This fix should apply to all other cases where actions where declared
without specifying a shortcut.
2020-11-23 18:41:15 +01:00
Zac
39bb346cef
LibGUI: Set FilePicker window icon based on mode (#4148) 2020-11-23 14:56:44 +01:00
BenJilks
7707ebcd63 LibGUI: Fix undo stack
This would undo all commands at once instead of one at a time.
2020-11-22 16:07:00 +01:00
Zac
6a569bbdd7 TextEditor: Change cursor behaviour when clicking empty space
When clicking empty space (beneath any used lines) in the TextEditor,
the cursor would jump to the start of the last line, rather than the
correct column, or the end of the line where appropriate. This was
because in the for_each_visual_line callback would return
IterationDecision::Continue if the clicked point wasn't in the line's
rect. Thus the callback would continue on each iteration and at the
end, would set the cursor to the default column of 0. To fix this I
added a bool to the callback's signature which tells the callback if
the for_each_visual_line method is on the last visual line. The
callback now does not return IterationDecision:Continue if
for_each_visual_line method is on the last line and the correct column
is then calculated with the line passed.
2020-11-19 21:59:13 +01:00
Andreas Kling
f72f4c5bca LibGUI: Remove AbstractTableView::doubleclick_event()
This work is already done (and more correctly) by the parent class
(AbstractView) if we just let it take care of the event instead.

Fixes the root cause of #4096.
2020-11-19 21:57:05 +01:00
Linus Groh
6b9ff8d6e2 LibGUI/FileIconProvider: Add config file and use patterns
This moves file extension to icon mappings from compile time macros to an
INI config file (/etc/FileIconProvider.ini), so file icons can easily be
customized and extended :^)

I also switched the format from a static file extension (".foo") to
glob-like patterns ("*.foo", using StringUtils::matches()), which allows
us to assign icons to specific exactly matching file names, like many
IDEs do - e.g. "CMakeLists.txt" or ".prettierrc".
2020-11-15 16:49:40 +01:00
Linus Groh
826096bac3 LibGUI: Make FileIconProvider aware of all supported image formats
By using Gfx::Bitmap::is_path_a_supported_image_format() we can
automatically provide the image icon for all supported image formats,
without keeping a second list of image file extensions.
2020-11-14 10:11:26 +01:00
Linus Groh
f0c2ee3c56 LibGUI: Add more extensions to FileIconProvider
This adds the following:

- cplusplus: .cxx, .cc, .c++
- header: .hpp, .hxx, .hh, .h++
- javascript: .mjs
2020-11-14 10:11:26 +01:00
Linus Groh
5b68ea8dde LibGfx: Make Bitmap path handling case insensitive
Bitmap::is_path_a_supported_image_format() and Bitmap::load_from_file()
now check the file extension with CaseSensitivity::CaseInsensitive.

This fixes a couple of inconsistencies, for example would
FileSystemModel::icon_for() recognize image files uppercase extensions
but couldn't create thumbnails for them (any attempt to create a bitmap
from such files would fail).
2020-11-14 10:11:26 +01:00
AmusedNetwork
de6483bcdb LibGUI: Set vertical distance between icons relative to scroll value
When calculating the vertical distance between icons, we should take
into account the value of the vertical scrollbar.

Fixes #4040
2020-11-11 15:14:09 +01:00
Andreas Kling
50aa726db7 LibGUI: Ignore application-global shortcuts in modal windows
This is making me question the usefulness of application-global
shortcuts, but for now let's just prevent them from triggering while
you're looking at a modal message box..
2020-11-10 19:41:03 +01:00
Tom
75f61fe3d9 AK: Make RefPtr, NonnullRefPtr, WeakPtr thread safe
This makes most operations thread safe, especially so that they
can safely be used in the Kernel. This includes obtaining a strong
reference from a weak reference, which now requires an explicit
call to WeakPtr::strong_ref(). Another major change is that
Weakable::make_weak_ref() may require the explicit target type.
Previously we used reinterpret_cast in WeakPtr, assuming that it
can be properly converted. But WeakPtr does not necessarily have
the knowledge to be able to do this. Instead, we now ask the class
itself to deliver a WeakPtr to the type that we want.

Also, WeakLink is no longer specific to a target type. The reason
for this is that we want to be able to safely convert e.g. WeakPtr<T>
to WeakPtr<U>, and before this we just reinterpret_cast the internal
WeakLink<T> to WeakLink<U>, which is a bold assumption that it would
actually produce the correct code. Instead, WeakLink now operates
on just a raw pointer and we only make those constructors/operators
available if we can verify that it can be safely cast.

In order to guarantee thread safety, we now use the least significant
bit in the pointer for locking purposes. This also means that only
properly aligned pointers can be used.
2020-11-10 19:11:52 +01:00
AmusedNetwork
eac0344ef0 LibGUI: Limit the height of item text in IconView
Set the max height of the text_rect to be the height difference
between two icons. Calculate the number of text lines that can be
displayed in this height, and display only that many.
2020-11-10 09:54:18 +01:00