diff --git a/doc/rofi.1 b/doc/rofi.1 index dd8f9a0e..80c7974a 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -1185,6 +1185,8 @@ configuration { * \- "ctime" (change time) */ sorting\-method: "name"; + /** Group directories before files. */ + directories\-first: true; } } diff --git a/doc/rofi.1.markdown b/doc/rofi.1.markdown index 1ed5dbe1..00a39a19 100644 --- a/doc/rofi.1.markdown +++ b/doc/rofi.1.markdown @@ -713,6 +713,8 @@ configuration { * - "ctime" (change time) */ sorting-method: "name"; + /** Group directories before files. */ + directories-first: true; } } ``` diff --git a/source/dialogs/filebrowser.c b/source/dialogs/filebrowser.c index 750ea97b..f96ddb19 100644 --- a/source/dialogs/filebrowser.c +++ b/source/dialogs/filebrowser.c @@ -107,9 +107,11 @@ struct { enum FBSortingMethod sorting_method; enum FBSortingTime sorting_time; + gboolean directories_first; } file_browser_config = { - .sorting_method = FB_SORT_NAME, - .sorting_time = FB_MTIME, + .sorting_method = FB_SORT_NAME, + .sorting_time = FB_MTIME, + .directories_first = TRUE, }; static void free_list ( FileBrowserModePrivateData *pd ) @@ -131,7 +133,7 @@ static gint compare_name ( gconstpointer a, gconstpointer b, G_GNUC_UNUSED gpoin FBFile *fa = (FBFile *) a; FBFile *fb = (FBFile *) b; - if ( fa->type != fb->type ) { + if ( file_browser_config.directories_first && fa->type != fb->type ) { return fa->type - fb->type; } @@ -143,6 +145,10 @@ static gint compare_time ( gconstpointer a, gconstpointer b, G_GNUC_UNUSED gpoin FBFile *fa = (FBFile *) a; FBFile *fb = (FBFile *) b; + if ( file_browser_config.directories_first && fa->type != fb->type ) { + return fa->type - fb->type; + } + if ( fa->time < 0 ) { return -1; } @@ -333,6 +339,11 @@ static void file_browser_mode_init_config ( Mode *sw ) } } + p = rofi_theme_find_property ( wid, P_BOOLEAN, "directories-first", TRUE ); + if ( p != NULL && p->type == P_BOOLEAN ) { + file_browser_config.directories_first = p->value.b; + } + if ( found_error ) { rofi_view_error_dialog ( msg, FALSE );