Commit graph

267 commits

Author SHA1 Message Date
Sam Atkins 926a275794 HexEditor: Move endianness selector to Value Inspector panel
It's clearer to have the choice here than hidden away in a menu. It also
means we don't need the column heading to say the endianness.
2024-05-07 16:33:59 -06:00
Sam Atkins 7d43685927 HexEditor: Add option to display offsets in decimal or hexadecimal 2024-04-09 09:24:23 +02:00
Sam Atkins f6a9ea7265 HexEditor: Add option for showing/hiding the offsets column 2024-04-09 09:24:23 +02:00
Sam Atkins 4640fc2c97 HexEditor: Move some calculations out of HexEditor.h header
These are gradually becoming more complicated, so they don't really make
sense in the header file any more.

No changes, just moving.
2024-04-09 09:24:23 +02:00
Shannon Booth e800605ad3 AK+LibURL: Move AK::URL into a new URL library
This URL library ends up being a relatively fundamental base library of
the system, as LibCore depends on LibURL.

This change has two main benefits:
 * Moving AK back more towards being an agnostic library that can
   be used between the kernel and userspace. URL has never really fit
   that description - and is not used in the kernel.
 * URL _should_ depend on LibUnicode, as it needs punnycode support.
   However, it's not really possible to do this inside of AK as it can't
   depend on any external library. This change brings us a little closer
   to being able to do that, but unfortunately we aren't there quite
   yet, as the code generators depend on LibCore.
2024-03-18 14:06:28 -04:00
Sam Atkins f00afa4a71 HexEditor: Avoid painting white rectangle on a white background
Most of the time, the background color for the hex and text areas will
be the widget's normal background color, so skip painting it in those
cases.
2024-03-15 08:37:21 +00:00
Sam Atkins d4c051ece2 HexEditor: Add gaps between byte groups 2024-03-15 08:37:21 +00:00
Sam Atkins 4a2a40a3c8 HexEditor: Break bytes-per-row into numbers of groups of bytes 2024-03-15 08:37:21 +00:00
Tim Ledbetter 3f6f3a90c1 HexEditor: Fix typo in parameter name 2024-02-21 23:32:15 +01:00
Tim Ledbetter f742334b93 HexEditor: Prefer enum class to enum for FindDialog::OptionId 2024-02-21 23:32:15 +01:00
Tim Ledbetter b330d83be4 HexEditor: Prefer ErrorOr to Result in FindDialog 2024-02-21 23:32:15 +01:00
Tim Ledbetter 2331d2bafa Userland: Propagate errors with TRY() where possible 2024-02-14 17:46:06 -05:00
Sam Atkins c6e5581682 HexEditor: Include annotation text in the "Delete annotation?" dialog
It's helpful to have some description of what you're deleting. :^)

40 characters is chosen completely arbitrarily, but seems reasonable.
2024-02-09 17:00:15 +00:00
Sam Atkins 56eb45ccbc HexEditor: Add toolbar and context menus to the Annotations panel
The Annotations panel is the most obvious place to perform actions
related to annotations, so let's make that possible. :^)

The toolbar gets open/save/save-as actions for annotations, and one for
adding an annotation. The table itself gets a context menu for editing
or deleting the selected annotation.
2024-02-09 17:00:15 +00:00
Sam Atkins a5d11c0a26 HexEditor: Convert panels to DynamicWidgetContainer
This lets the user swap them around and pop them out as separate windows
as desired. We do lose the ability to individually resize them though,
until DynamicWidgetContainer supports that.
2024-02-09 17:00:15 +00:00
Sam Atkins 6850ef9014 HexEditor: Respond to font changes 2024-02-09 16:59:02 +00:00
Sam Atkins 3318563ad9 HexEditor: Size the offset area based on the text width
This gets rid of the last use of the offset_margin_width() magic number.

I initially tried using `character_width() * 10` and found it was not
accurate enough with between-character spacing, so instead this measures
a specific string. All offset strings should be the same width in a
fixed-width font.
2024-02-09 16:59:02 +00:00
Sam Atkins 0fdbdc5084 HexEditor: Use glyph_fixed_width() for character width 2024-02-09 16:59:02 +00:00
Sam Atkins d3012f2df1 HexEditor: Share the code for updating the content size
And make setting the bytes_per_row a no-op if it's the same value.
2024-02-09 16:59:02 +00:00
Sam Atkins db23d0f464 HexEditor: Save and reuse horizontal positions when painting 2024-02-09 16:59:02 +00:00
Sam Atkins 60f52aa0ef HexEditor: Save and reuse vertical positions when painting rows
Rather than repeatedly calculating the same y offset over and over,
calculate it once per row, and re-use that result.
2024-02-09 16:59:02 +00:00
Sam Atkins 4af565362c HexEditor: Remove redundant checks in offset_at()
Neither of these is possible based on the if statement above them.
2024-02-09 16:59:02 +00:00
Sam Atkins ca3f21f273 HexEditor: Account for padding in offset_at()
Compare the x position with the start of the hex characters, which is
m_padding pixels to the right of hex_start_x. (And the same for the
text characters.) If the position is within the padding area, clamp it
so it's on the nearest character.

This was previously covered-up somewhat by using the buggy
m_address_bar_width value to calculate the start and end x positions of
these areas. Fixing that in the previous commit made this more obvious.
2024-02-09 16:59:02 +00:00
Sam Atkins c4dc150ed7 HexEditor: Extract some content-width calculations
We repeat the same calculations a lot, and it's easy to make mistakes.

m_address_bar_width and offset_margin_width() have basically the same
purpose, but both are a little wrong. This removes the former, but
we'll get to the latter soon.
2024-02-09 16:59:02 +00:00
Sam Atkins 4dc3816853 HexEditor: Combine row-iteration loops 2024-02-09 16:59:02 +00:00
Sam Atkins 8b5d2c710b HexEditor: Make border of offset area straight down
Subtracting 1 from both axes causes a kink in the line, because the
start point isn't also translated. The clip rect prevents us from
painting too far down, so we can just remove the translated() call.
2024-02-09 16:59:02 +00:00
Sam Atkins f57d9789f8 HexEditor: Paint byte characters with correct width 2024-02-09 16:59:02 +00:00
Sam Atkins e2f927a7a7 HexEditor: Give i and j variables clearer names 2024-02-09 16:59:02 +00:00
Sam Atkins d930ea1242 HexEditor: Add an option to load an annotations file on startup 2024-01-31 17:38:56 +00:00
Sam Atkins 4cef57a021 HexEditor: Parse arguments using ArgsParser 2024-01-31 17:38:56 +00:00
Sam Atkins 56caee44e3 HexEditor: Save and load annotations to/from JSON files
This is a fairly simple JSON format: A single array, containing objects,
with the Annotation fields as key:value pairs.

When reading a file, we let invalid or missing keys fall back to the
default values. This is mostly intended to set a pattern so that if we
add new fields in the future, we won't fail to load old annotations
files. If loading the file fails though, we keep the previously loaded
set of annotations.
2024-01-31 17:38:56 +00:00
Sam Atkins aa07c232f1 HexEditor: Optionally display annotations in the side panel 2024-01-30 23:34:49 +00:00
Sam Atkins 8cac2e89a9 HexEditor: Store annotations in a Model
A model is necessary for displaying a list of them in the UI. We might
as well make that their home.
2024-01-30 23:34:49 +00:00
Sam Atkins a54952795a HexEditor: Add comments to annotations
The comment appears as a tooltip when hovering over the annotation.

A couple of properties of the TextEditor would ideally be set in GML,
but either don't have a setter exposed, or the GML compiler doesn't
recognise the enum. I'll fix those up after the current big GML
compiler PR gets merged.
2024-01-30 23:34:49 +00:00
Sam Atkins 44ca55aaf8 LibFileSystemAccessClient+Userland: Return file paths as ByteStrings
Where it was straightforward to do so, I've updated the users to also
use ByteStrings for their file paths, but most of them have a temporary
String::from_byte_string() call instead.
2024-01-29 23:14:39 +00:00
Sam Atkins 9657f4cabb LibGUI+Userland: Take ByteString in set_most_recently_open_file() 2024-01-24 11:07:03 +00:00
Hugh Davenport 13c66ebf12 DevTools: Add fullscreen option
All except SQLStudio, as that causes a crash
2024-01-14 15:18:43 -07:00
Sam Atkins cbd28c9110 HexEditor: Add annotations system
Allow the user to highlight sections of the edited document, giving them
arbitrary background colors. These annotations can be created from a
selection, or by manually specifying the start and end offsets.
Annotations can be edited or deleted by right-clicking them.

Any color can be used for the background. Dark colors automatically make
the text white for easier readability. When creating a new annotation,
we use whatever color the user last picked as this is slightly more
likely to be the one they want.

Icons contributed by Cubic Love.

Co-authored-by: Cubic Love <7754483+cubiclove@users.noreply.github.com>
2024-01-14 13:45:02 +00:00
Sam Atkins 1168e46c1d HexEditor: Extract pixel-position-to-byte-offset code 2024-01-14 13:45:02 +00:00
Sam Atkins 84dd0ce1ae HexEditor: Wrap selection and behavior in a struct 2024-01-14 13:45:02 +00:00
Sam Atkins fb6a9dd2f5 HexEditor: Clarify code for selecting byte colors
Instead of assigning, then sometimes reassigning these colors, set them
once. This makes it easier to see how we prioritize the different
factors that affect the styling.

`highlight_flag` is now `selected` since it represents if the byte is
within the current selection.
2024-01-06 16:08:49 +00:00
Sam Atkins 8ae4464fa5 HexEditor: Propagate HexDocumentFile creation errors in save_as() 2024-01-06 16:08:49 +00:00
Sam Atkins 034ec62cee HexEditor: Get document cells once per paint, not twice
HexDocument::get() involves a hash lookup, so let's store the returned
Cell instead of calling it twice for its two fields.
2024-01-06 16:08:49 +00:00
Sam Atkins da52c5e82a HexEditor: Make edited bytes bold
This will help them still stand out once we introduce annotations, which
also modify the colors.
2024-01-06 16:08:49 +00:00
Sam Atkins 27adbd1792 HexEditor: Stop allocating a String for every character printed
When we have a single char, we can directly construct a StringView for
it instead, which doesn't require a String allocation.
2024-01-06 16:08:49 +00:00
tetektoza 2751f32a18 HexEditor: Move drawing cursor under a lambda and reuse it
This is a cleanup patch dones for paint event for HexEditor, moving
repeated chunks of code under a common lambda.
2023-12-27 09:22:09 +01:00
tetektoza 017dea2993 HexEditor: Don't initialize background/text colors twice
This is a cleanup patch, moves a chunk of repeated code to one place
instead of assigning variables with the same values twice in two
different places of code.
2023-12-27 09:22:09 +01:00
tetektoza bd1d384cf6 HexEditor: Remove moving cursor outside bounds if selecting with mouse
Currently if users select last bytes in HexEditor with mouse in either
Hex or Text mode, they will be able to move cursor on the byte outside
bounds. If then they try to write something in either of those modes,
app will crash.

This patch moves the recently added "replace" cursor to always be on the
last byte of the selection instead of being on the byte after the last
selected byte.
2023-12-27 09:22:09 +01:00
tetektoza c4c9971ed0 HexEditor: Change cursor type from caret to black box
This patch changes cursor type from caret to black box for both Hex and
Text modes, because right now the way how blinking caret looks like is
more closer to "insert" mode in similar editors, whereas the real
behavior of this cursor is more of a "replace" mode seen in similar
editors like GHex.
2023-12-27 09:22:09 +01:00
tetektoza 1ea675a9ec HexEditor: Remove blinking of the cursor 2023-12-27 09:22:09 +01:00