mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:47:34 +00:00
LibGUI: Add a ClipboardClient for GUI::Clipboard
Anyone who inherits from `GUI::Clipboard::ClipboardClient` will receive clipboard notifications via `clipboard_content_did_change()`. Update ClipboardHistoryModel, TextEditor and TerminalWidget to inherit from this class.
This commit is contained in:
parent
95f393ebcd
commit
0c53c2dfa2
8 changed files with 106 additions and 72 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2021, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -15,22 +16,17 @@
|
|||
|
||||
namespace GUI {
|
||||
|
||||
class ClipboardServerConnection;
|
||||
|
||||
class Clipboard {
|
||||
public:
|
||||
static Clipboard& the();
|
||||
class ClipboardClient {
|
||||
public:
|
||||
ClipboardClient();
|
||||
virtual ~ClipboardClient();
|
||||
|
||||
ByteBuffer data() const { return data_and_type().data; }
|
||||
String mime_type() const { return data_and_type().mime_type; }
|
||||
void set_data(ReadonlyBytes, const String& mime_type = "text/plain", const HashMap<String, String>& metadata = {});
|
||||
void clear();
|
||||
|
||||
void set_plain_text(const String& text)
|
||||
{
|
||||
set_data(text.bytes());
|
||||
}
|
||||
|
||||
void set_bitmap(const Gfx::Bitmap&);
|
||||
RefPtr<Gfx::Bitmap> bitmap() const;
|
||||
virtual void clipboard_content_did_change(String const& mime_type) = 0;
|
||||
};
|
||||
|
||||
struct DataAndType {
|
||||
ByteBuffer data;
|
||||
|
@ -38,14 +34,30 @@ public:
|
|||
HashMap<String, String> metadata;
|
||||
};
|
||||
|
||||
DataAndType data_and_type() const;
|
||||
|
||||
Function<void(const String& mime_type)> on_change;
|
||||
|
||||
static void initialize(Badge<Application>);
|
||||
static Clipboard& the();
|
||||
|
||||
DataAndType data_and_type() const;
|
||||
ByteBuffer data() const { return data_and_type().data; }
|
||||
String mime_type() const { return data_and_type().mime_type; }
|
||||
RefPtr<Gfx::Bitmap> bitmap() const;
|
||||
|
||||
void set_data(ReadonlyBytes const& data, String const& mime_type = "text/plain", HashMap<String, String> const& metadata = {});
|
||||
void set_plain_text(String const& text) { set_data(text.bytes()); }
|
||||
void set_bitmap(Gfx::Bitmap const&);
|
||||
void clear();
|
||||
|
||||
void clipboard_data_changed(Badge<ClipboardServerConnection>, String const& mime_type);
|
||||
|
||||
void register_client(Badge<ClipboardClient>, ClipboardClient& client) { m_clients.set(&client); }
|
||||
void unregister_client(Badge<ClipboardClient>, ClipboardClient& client) { m_clients.remove(&client); }
|
||||
|
||||
Function<void(String const& mime_type)> on_change;
|
||||
|
||||
private:
|
||||
Clipboard();
|
||||
Clipboard() = default;
|
||||
|
||||
HashTable<ClipboardClient*> m_clients;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue