diff --git a/thunar/thunar-dialogs.c b/thunar/thunar-dialogs.c index 576252b..b7e4d6e 100644 --- a/thunar/thunar-dialogs.c +++ b/thunar/thunar-dialogs.c @@ -42,6 +42,39 @@ #include +gint calculate_rename_dialog_width(GtkWidget* dialog, const gchar* filename) { + /* This used to be the default dialog width. */ + gint min_dialog_width = 300; + + /* Set the maximum dialog width to be 32 pixels less than the screen + * width. The 32 has no special meaning, it just sounds good. + */ + GdkScreen* screen = gtk_window_get_screen ( GTK_WINDOW (dialog) ); + gint screen_width = gdk_screen_get_width(screen); + gint max_dialog_width = screen_width - 32; + + size_t filename_length = strnlen(filename, FILENAME_MAX); + + /* Set the dialog width to roughly ten pixels per character in the + * filename. Again, there's nothing special going on here. 10x just + * seems about right. + */ + gint dialog_width = 10 * (gint)filename_length; + + /* If that method results in a dialog that's too big or too small, + * resize it to be within the min/max that we calculated earlier. + */ + if (dialog_width < min_dialog_width) { + dialog_width = min_dialog_width; + } + + if (dialog_width > max_dialog_width) { + dialog_width = max_dialog_width; + } + + return dialog_width; +} + /** * thunar_dialogs_show_rename_file: @@ -96,7 +129,9 @@ thunar_dialogs_show_rename_file (gpointer parent, _("_Rename"), GTK_RESPONSE_OK, NULL); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); - gtk_window_set_default_size (GTK_WINDOW (dialog), 300, -1); + + gint dialog_width = calculate_rename_dialog_width(dialog, filename); + gtk_window_set_default_size (GTK_WINDOW (dialog), dialog_width, -1); g_free (title); /* move the dialog to the appropriate screen */