mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 21:38:11 +00:00
LibGUI: Remove confusing GModelNotification concept
This was a bad idea and it didn't stick. Instead we should just use the simple "on_foo" hook functions like we do for everything else. :^)
This commit is contained in:
parent
4f3234148a
commit
f7dce05c82
6 changed files with 8 additions and 51 deletions
|
@ -58,17 +58,15 @@ DirectoryView::DirectoryView(GWidget* parent)
|
||||||
|
|
||||||
m_item_view->set_model_column(GDirectoryModel::Column::Name);
|
m_item_view->set_model_column(GDirectoryModel::Column::Name);
|
||||||
|
|
||||||
m_item_view->on_model_notification = [this](const GModelNotification& notification) {
|
m_table_view->model()->on_model_update = [this](auto&) {
|
||||||
if (notification.type() == GModelNotification::Type::ModelUpdated) {
|
set_status_message(String::format("%d item%s (%u byte%s)",
|
||||||
set_status_message(String::format("%d item%s (%u byte%s)",
|
model().row_count(),
|
||||||
model().row_count(),
|
model().row_count() != 1 ? "s" : "",
|
||||||
model().row_count() != 1 ? "s" : "",
|
model().bytes_in_files(),
|
||||||
model().bytes_in_files(),
|
model().bytes_in_files() != 1 ? "s" : ""));
|
||||||
model().bytes_in_files() != 1 ? "s" : ""));
|
|
||||||
|
|
||||||
if (on_path_change)
|
if (on_path_change)
|
||||||
on_path_change(model().path());
|
on_path_change(model().path());
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
m_model->on_thumbnail_progress = [this](int done, int total) {
|
m_model->on_thumbnail_progress = [this](int done, int total) {
|
||||||
|
|
|
@ -26,14 +26,6 @@ void ProcessTableView::refresh()
|
||||||
model()->update();
|
model()->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProcessTableView::model_notification(const GModelNotification& notification)
|
|
||||||
{
|
|
||||||
if (notification.type() == GModelNotification::ModelUpdated) {
|
|
||||||
// Do something?
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pid_t ProcessTableView::selected_pid() const
|
pid_t ProcessTableView::selected_pid() const
|
||||||
{
|
{
|
||||||
if (!model()->selected_index().is_valid())
|
if (!model()->selected_index().is_valid())
|
||||||
|
|
|
@ -17,7 +17,4 @@ public:
|
||||||
void refresh();
|
void refresh();
|
||||||
|
|
||||||
Function<void(pid_t)> on_process_selected;
|
Function<void(pid_t)> on_process_selected;
|
||||||
|
|
||||||
private:
|
|
||||||
virtual void model_notification(const GModelNotification&) override;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,17 +28,10 @@ void GAbstractView::set_model(RefPtr<GModel>&& model)
|
||||||
did_update_model();
|
did_update_model();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GAbstractView::model_notification(const GModelNotification& notification)
|
|
||||||
{
|
|
||||||
if (on_model_notification)
|
|
||||||
on_model_notification(notification);
|
|
||||||
}
|
|
||||||
|
|
||||||
void GAbstractView::did_update_model()
|
void GAbstractView::did_update_model()
|
||||||
{
|
{
|
||||||
if (!model() || model()->selected_index() != m_edit_index)
|
if (!model() || model()->selected_index() != m_edit_index)
|
||||||
stop_editing();
|
stop_editing();
|
||||||
model_notification(GModelNotification(GModelNotification::ModelUpdated));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GAbstractView::did_update_selection()
|
void GAbstractView::did_update_selection()
|
||||||
|
|
|
@ -34,12 +34,10 @@ public:
|
||||||
Function<void(const GModelIndex&)> on_activation;
|
Function<void(const GModelIndex&)> on_activation;
|
||||||
Function<void(const GModelIndex&)> on_selection;
|
Function<void(const GModelIndex&)> on_selection;
|
||||||
Function<void(const GModelIndex&, const GContextMenuEvent&)> on_context_menu_request;
|
Function<void(const GModelIndex&, const GContextMenuEvent&)> on_context_menu_request;
|
||||||
Function<void(const GModelNotification&)> on_model_notification;
|
|
||||||
|
|
||||||
Function<OwnPtr<GModelEditingDelegate>(const GModelIndex&)> aid_create_editing_delegate;
|
Function<OwnPtr<GModelEditingDelegate>(const GModelIndex&)> aid_create_editing_delegate;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void model_notification(const GModelNotification&);
|
|
||||||
virtual void did_scroll() override;
|
virtual void did_scroll() override;
|
||||||
void activate(const GModelIndex&);
|
void activate(const GModelIndex&);
|
||||||
void update_edit_widget_position();
|
void update_edit_widget_position();
|
||||||
|
|
|
@ -18,27 +18,6 @@ enum class GSortOrder {
|
||||||
Descending
|
Descending
|
||||||
};
|
};
|
||||||
|
|
||||||
class GModelNotification {
|
|
||||||
public:
|
|
||||||
enum Type {
|
|
||||||
Invalid = 0,
|
|
||||||
ModelUpdated,
|
|
||||||
};
|
|
||||||
|
|
||||||
explicit GModelNotification(Type type, const GModelIndex& index = GModelIndex())
|
|
||||||
: m_type(type)
|
|
||||||
, m_index(index)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Type type() const { return m_type; }
|
|
||||||
GModelIndex index() const { return m_index; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
Type m_type { Invalid };
|
|
||||||
GModelIndex m_index;
|
|
||||||
};
|
|
||||||
|
|
||||||
class GModel : public RefCounted<GModel> {
|
class GModel : public RefCounted<GModel> {
|
||||||
public:
|
public:
|
||||||
struct ColumnMetadata {
|
struct ColumnMetadata {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue