mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:17:44 +00:00
ClipboardHistory: Listen for configuration changes
Resize the clipboard history size dynamically by listening for config changes. This is currently not ideal since we don't have the callbacks for `Config::Listener::config_i32_did_change`, so for now we are just taking the string and attempting to convert it to an int.
This commit is contained in:
parent
b1a3bb638b
commit
441e601689
3 changed files with 28 additions and 2 deletions
|
@ -6,9 +6,9 @@
|
|||
*/
|
||||
|
||||
#include "ClipboardHistoryModel.h"
|
||||
#include <LibConfig/Client.h>
|
||||
#include <AK/NumberFormat.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibConfig/Client.h>
|
||||
|
||||
NonnullRefPtr<ClipboardHistoryModel> ClipboardHistoryModel::create()
|
||||
{
|
||||
|
@ -121,3 +121,23 @@ void ClipboardHistoryModel::remove_item(int index)
|
|||
{
|
||||
m_history_items.remove(index);
|
||||
}
|
||||
|
||||
void ClipboardHistoryModel::config_string_did_change(String const& domain, String const& group, String const& key, String const& value_string)
|
||||
{
|
||||
if (domain != "ClipboardHistory" || group != "ClipboardHistory")
|
||||
return;
|
||||
|
||||
// FIXME: Once we can get notified for `i32` changes, we can use that instead of this hack.
|
||||
if (key == "NumHistoryItems") {
|
||||
auto value_or_error = value_string.to_int();
|
||||
if (!value_or_error.has_value())
|
||||
return;
|
||||
auto value = value_or_error.value();
|
||||
if (value < (int)m_history_items.size()) {
|
||||
m_history_items.remove(value, m_history_items.size() - value);
|
||||
invalidate();
|
||||
}
|
||||
m_history_limit = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue