Skip to content

Commit

Permalink
implement a function/callback to refresh the community presets list
Browse files Browse the repository at this point in the history
  • Loading branch information
Digitalone1 committed Mar 29, 2024
1 parent 015d606 commit 142cd65
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
12 changes: 12 additions & 0 deletions data/ui/presets_menu.ui
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,18 @@
</child>
</object>
</child>

<child>
<object class="GtkButton" id="refresh_community_list">
<property name="valign">start</property>
<property name="halign">center</property>
<property name="label" translatable="yes">Refresh</property>
<property name="tooltip-text" translatable="yes">Refresh to show new installed community presets</property>
<style>
<class name="suggested-action" />
</style>
</object>
</child>
</object>
</property>
</object>
Expand Down
22 changes: 19 additions & 3 deletions src/presets_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ struct _PresetsMenu {

GtkStringFilter* filter_string_community;

GtkButton* refresh_community_list;

GSettings* settings;

Data* data;
Expand Down Expand Up @@ -254,13 +256,26 @@ void setup_community_presets_listview(PresetsMenu* self,
}),
self);

auto refresh_community_listview = +[](GtkButton* button, PresetsMenu* self) {
// Empty the list, if it's populated.
if (const auto n_items = g_list_model_get_n_items(G_LIST_MODEL(self->presets_list_community)); n_items != 0U) {
gtk_string_list_splice(self->presets_list_community, 0U, n_items, nullptr);
}

// Fill the empty list
for (const auto& path : self->data->application->presets_manager->get_all_community_presets_paths(preset_type)) {
gtk_string_list_append(self->presets_list_community, path.c_str());
}
};

g_signal_connect(self->refresh_community_list, "clicked", G_CALLBACK(refresh_community_listview), self);

gtk_list_view_set_factory(listview_community, factory);

g_object_unref(factory);

for (const auto& path : self->data->application->presets_manager->get_all_community_presets_paths(preset_type)) {
gtk_string_list_append(presets_list_community, path.c_str());
}
// Initialize the list
refresh_community_listview(self->refresh_community_list, self);
}

template <PresetType preset_type>
Expand Down Expand Up @@ -659,6 +674,7 @@ void presets_menu_class_init(PresetsMenuClass* klass) {
gtk_widget_class_bind_template_child(widget_class, PresetsMenu, filter_string_community);
gtk_widget_class_bind_template_child(widget_class, PresetsMenu, new_preset_name);
gtk_widget_class_bind_template_child(widget_class, PresetsMenu, last_used_name);
gtk_widget_class_bind_template_child(widget_class, PresetsMenu, refresh_community_list);

gtk_widget_class_bind_template_callback(widget_class, create_preset);
gtk_widget_class_bind_template_callback(widget_class, import_preset_from_disk);
Expand Down

0 comments on commit 142cd65

Please sign in to comment.