2020-09-12 20:43:41 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Itamar S. <itamar8910@gmail.com>
|
2022-02-15 13:28:01 -07:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-09-12 20:43:41 +03:00
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-09-12 20:43:41 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
#include <AK/DeprecatedString.h>
|
2020-09-12 20:43:41 +03:00
|
|
|
#include <AK/Vector.h>
|
|
|
|
#include <LibDiff/Hunks.h>
|
2021-05-03 20:31:58 +02:00
|
|
|
#include <LibGUI/AbstractScrollableWidget.h>
|
2020-09-12 20:43:41 +03:00
|
|
|
|
|
|
|
namespace HackStudio {
|
2021-05-03 20:31:58 +02:00
|
|
|
class DiffViewer final : public GUI::AbstractScrollableWidget {
|
2020-09-12 20:43:41 +03:00
|
|
|
C_OBJECT(DiffViewer)
|
|
|
|
public:
|
2022-02-15 13:28:01 -07:00
|
|
|
virtual ~DiffViewer() override = default;
|
2020-09-12 20:43:41 +03:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
void set_content(DeprecatedString const& original, DeprecatedString const& diff);
|
2020-09-12 20:43:41 +03:00
|
|
|
|
|
|
|
private:
|
2022-12-04 18:02:33 +00:00
|
|
|
DiffViewer(DeprecatedString const& original, DeprecatedString const& diff);
|
2020-09-12 20:43:41 +03:00
|
|
|
DiffViewer();
|
|
|
|
|
|
|
|
void setup_properties();
|
|
|
|
|
|
|
|
virtual void paint_event(GUI::PaintEvent&) override;
|
|
|
|
virtual void resize_event(GUI::ResizeEvent&) override;
|
|
|
|
|
|
|
|
void update_content_size();
|
|
|
|
|
|
|
|
enum class LinePosition {
|
|
|
|
Left,
|
|
|
|
Right,
|
|
|
|
Both,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class LineType {
|
|
|
|
Normal,
|
|
|
|
Diff,
|
|
|
|
Missing,
|
|
|
|
};
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
void draw_line(GUI::Painter&, DeprecatedString const& line, size_t y_offset, LinePosition, LineType);
|
2020-09-12 20:43:41 +03:00
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
static Vector<DeprecatedString> split_to_lines(DeprecatedString const& text);
|
2020-09-12 20:43:41 +03:00
|
|
|
|
|
|
|
static Gfx::Color red_background();
|
|
|
|
static Gfx::Color green_background();
|
|
|
|
static Gfx::Color gray_background();
|
|
|
|
|
|
|
|
size_t line_height() const;
|
|
|
|
|
|
|
|
Gfx::IntRect separator_rect() const;
|
|
|
|
|
2022-12-04 18:02:33 +00:00
|
|
|
Vector<DeprecatedString> m_original_lines;
|
2020-09-12 20:43:41 +03:00
|
|
|
Vector<Diff::Hunk> m_hunks;
|
|
|
|
};
|
|
|
|
}
|