Skip to content

Add option to allow expanders in empty folders #3593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions gresources/nemo-file-management-properties.glade
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,22 @@ along with . If not, see <http://www.gnu.org/licenses/>.
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="list_view_show_empty_expanders_checkbutton">
<property name="label" translatable="yes">Show expanders for empty folders</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">False</property>
<property name="use-underline">True</property>
<property name="xalign">0</property>
<property name="draw-indicator">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</object>
Expand Down
6 changes: 6 additions & 0 deletions libnemo-private/nemo-global-preferences.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ nemo_global_preferences_get_size_prefix_preference (void)
return 0;
}

gboolean
nemo_global_preferences_get_always_show_folder_expander (void)
{
return g_settings_get_boolean (nemo_list_view_preferences, NEMO_PREFERENCES_LIST_VIEW_ALWAYS_SHOW_EXPANDER);
}

char *
nemo_global_preferences_get_desktop_iid (void)
{
Expand Down
3 changes: 3 additions & 0 deletions libnemo-private/nemo-global-preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ enum
#define NEMO_PREFERENCES_LIST_VIEW_DEFAULT_VISIBLE_COLUMNS "default-visible-columns"
#define NEMO_PREFERENCES_LIST_VIEW_DEFAULT_COLUMN_ORDER "default-column-order"
#define NEMO_PREFERENCES_LIST_VIEW_ENABLE_EXPANSION "enable-folder-expansion"
#define NEMO_PREFERENCES_LIST_VIEW_ALWAYS_SHOW_EXPANDER "always-show-folder-expander"

#define NEMO_PREFERENCES_MAX_THUMBNAIL_THREADS "thumbnail-threads"

Expand Down Expand Up @@ -299,6 +300,8 @@ gint nemo_global_preferences_get_tooltip_flags (void);
gboolean nemo_global_preferences_should_load_plugin (const gchar *name, const gchar *key);
gchar **nemo_global_preferences_get_fileroller_mimetypes (void);

gboolean nemo_global_preferences_get_always_show_folder_expander (void);

gchar *nemo_global_preferences_get_mono_system_font (void);
gchar *nemo_global_preferences_get_mono_font_family_match (const gchar *in_family);

Expand Down
5 changes: 5 additions & 0 deletions libnemo-private/org.nemo.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,11 @@
<default>false</default>
<summary>If true, allow folders with content to be expanded in the current view.</summary>
</key>
<key name="always-show-folder-expander" type="b">
<default>false</default>
<summary>If true, also allow folders without content to be expanded.</summary>
<description>If true, show expander arrows for all folders, even empty ones. Note: reload once to see changes.</description>
</key>
</schema>

<schema id="org.nemo.sidebar-panels" path="/org/nemo/sidebar-panels/" gettext-domain="nemo">
Expand Down
5 changes: 5 additions & 0 deletions src/nemo-file-management-properties.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
#define NEMO_FILE_MANAGEMENT_PROPERTIES_OPEN_NEW_WINDOW_WIDGET "new_window_checkbutton"
#define NEMO_FILE_MANAGEMENT_PROPERTIES_TREE_VIEW_FOLDERS_WIDGET "treeview_folders_checkbutton"
#define NEMO_FILE_MANAGEMENT_PROPERTIES_SHOW_LIST_VIEW_EXPANDERS_WIDGET "list_view_show_expanders_checkbutton"
#define NEMO_FILE_MANAGEMENT_PROPERTIES_SHOW_EMPTY_FOLDER_EXPANDERS_WIDGET "list_view_show_empty_expanders_checkbutton"

#define NEMO_FILE_MANAGEMENT_PROPERTIES_SHOW_PREVIOUS_ICON_TOOLBAR_WIDGET "show_previous_icon_toolbar_togglebutton"
#define NEMO_FILE_MANAGEMENT_PROPERTIES_SHOW_NEXT_ICON_TOOLBAR_WIDGET "show_next_icon_toolbar_togglebutton"
Expand Down Expand Up @@ -1110,6 +1111,10 @@ nemo_file_management_properties_dialog_setup (GtkBuilder *builder,
NEMO_FILE_MANAGEMENT_PROPERTIES_SHOW_LIST_VIEW_EXPANDERS_WIDGET,
NEMO_PREFERENCES_LIST_VIEW_ENABLE_EXPANSION);

bind_builder_bool (builder, nemo_list_view_preferences,
NEMO_FILE_MANAGEMENT_PROPERTIES_SHOW_EMPTY_FOLDER_EXPANDERS_WIDGET,
NEMO_PREFERENCES_LIST_VIEW_ALWAYS_SHOW_EXPANDER);

setup_tooltip_items (builder);
connect_tooltip_items (builder);

Expand Down
20 changes: 17 additions & 3 deletions src/nemo-list-model.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <eel/eel-graphic-effects.h>
#include <libnemo-private/nemo-dnd.h>
#include <libnemo-private/nemo-file-utilities.h>
#include <libnemo-private/nemo-global-preferences.h>

enum {
SUBDIRECTORY_UNLOADED,
Expand Down Expand Up @@ -518,6 +519,13 @@ nemo_list_model_iter_has_child (GtkTreeModel *tree_model, GtkTreeIter *iter)

file_entry = g_sequence_get (iter->user_data);

/* If the file is a directory and always-show-expander is enabled, always return TRUE */
if (file_entry->file && nemo_file_is_directory (file_entry->file)) {
if (nemo_global_preferences_get_always_show_folder_expander()) {
return TRUE;
}
}

return (file_entry->files != NULL && g_sequence_get_length (file_entry->files) > 0);
}

Expand Down Expand Up @@ -1079,7 +1087,9 @@ nemo_list_model_add_file (NemoListModel *model, NemoFile *file,

got_count = nemo_file_get_directory_item_count (file, &count, &unreadable);

if ((!got_count && !unreadable) || count > 0) {
/* Always add dummy row if always-show-expander is enabled, or if directory has items */
if (nemo_global_preferences_get_always_show_folder_expander() ||
(!got_count && !unreadable) || count > 0) {
add_dummy_row (model, file_entry);
gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (model),
path, &iter);
Expand All @@ -1105,7 +1115,9 @@ update_dummy_row (NemoListModel *model,

got_count = nemo_file_get_directory_item_count (file, &count, &unreadable);

if ((got_count && count == 0) || (!got_count && unreadable)) {
/* Only remove dummy row if always-show-expander is disabled and directory is empty */
if (!nemo_global_preferences_get_always_show_folder_expander() &&
((got_count && count == 0) || (!got_count && unreadable))) {
files = file_entry->files;
if (g_sequence_get_length (files) == 1) {
GSequenceIter *dummy_ptr = g_sequence_get_iter_at_pos (files, 0);
Expand Down Expand Up @@ -1278,7 +1290,9 @@ nemo_list_model_remove (NemoListModel *model, GtkTreeIter *iter)

got_count = nemo_file_get_directory_item_count (parent_file_entry->file, &count, &unreadable);

if ((!got_count && !unreadable) || count > 0) {
/* Always add dummy row if always-show-expander is enabled, or if directory has items */
if (nemo_global_preferences_get_always_show_folder_expander() ||
(!got_count && !unreadable) || count > 0) {
add_dummy_row (model, parent_file_entry);
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/nemo-list-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,15 @@ expanders_enabled_changed_cb (NemoListView *view)
NEMO_PREFERENCES_LIST_VIEW_ENABLE_EXPANSION));
}

static void
always_show_expander_changed_cb (NemoListView *view)
{
g_return_if_fail (NEMO_IS_LIST_VIEW (view));
g_return_if_fail (GTK_IS_TREE_VIEW (view->details->tree_view) && view->details->tree_view != NULL);

/* Note: Changes require a manual refresh to take effect */
}

static void
list_selection_changed_callback (GtkTreeSelection *selection, gpointer user_data)
{
Expand Down Expand Up @@ -2537,6 +2546,11 @@ create_and_set_up_tree_view (NemoListView *view)
G_CALLBACK (expanders_enabled_changed_cb),
view);

g_signal_connect_swapped (nemo_list_view_preferences,
"changed::" NEMO_PREFERENCES_LIST_VIEW_ALWAYS_SHOW_EXPANDER,
G_CALLBACK (always_show_expander_changed_cb),
view);

view->details->columns = g_hash_table_new_full (g_str_hash,
g_str_equal,
(GDestroyNotify) g_free,
Expand Down