GNOME Bugzilla – Bug 5843
Support multiple chars for "%D " in title format.
Last modified: 2004-12-22 21:47:04 UTC
Package: gimp This isn't a bug _as such_ it's just that the way %Dx works in the title format function is v. annoying. Basically you can only _add_ one character at a time depending on if the gdisp is dirty, which really bugs me. The patch below solves this problem by allowing any of... %D{abcd}{xyz} %D(abcd)(xyz) %D[abcd][xyz] %D<abcd><xyz> ... where "abcd" will be show in the title when the gdisp is dirty and "xyz" will be shown when it is clean. I didn't do \\ parsing (but I will change it if you want), as I doubt people would want to use all the brackets (and it's much easier/simpler this way). Here is the patch (I used M-c c-set-style whitesmith -- which seemed pretty close but not perfect)... diff -ru gimp-1.1.15/app/gdisplay.c gimp-1.1.15-hacked/app/gdisplay.c --- gimp-1.1.15/app/gdisplay.c Wed Feb 2 12:21:32 2000 +++ gimp-1.1.15-hacked/app/gdisplay.c Wed Feb 2 16:58:20 2000 @@ -196,6 +196,57 @@ return printed; } +/* could use va_arg() and do indefinate ones, but we don't need it atm. */ +static size_t +gdisplay__format_title_params_2(char *format, + char **first_str, size_t *first_len, + char **second_str, size_t *second_len) +{ + char str_end = 0; + char *str = NULL; + char *dummy_str = NULL; + + if (format[0] == '{') + str_end = '}'; + else if (format[0] == '(') + str_end = ')'; + else if (format[0] == '[') + str_end = ']'; + else if (format[0] == '<') + str_end = '>'; + else /* could do ` and ' if we want, although that's less intuitive */ + return (0); + + + /* doesn't do any \\ escaping etc. ... but unless you want to use + * all of the above bracket types that's ok */ + + /* don't alter the args unless we are returning !0 */ + dummy_str = format + 1; + str = strchr (dummy_str, str_end); + if (!str) + return (0); + + *first_str = dummy_str; + *first_len = str - dummy_str; + ++str; + + if (*str == format[0]) + { + /* don't alter the args unless we are returning !0 */ + dummy_str = str + 1; + str = strchr(dummy_str, str_end); + if (str) + { + *second_str = dummy_str; + *second_len = str - dummy_str; + ++str; + } + } + + return (str - format); +} + static void gdisplay_format_title (GDisplay *gdisp, char *title, @@ -214,13 +265,13 @@ switch (gimage_base_type (gimage)) { case RGB: - image_type_str = (empty) ? _("RGB-empty") : _("RGB"); + image_type_str = _("RGB"); break; case GRAY: - image_type_str = (empty) ? _("grayscale-empty") : _("grayscale"); + image_type_str = _("grayscale"); break; case INDEXED: - image_type_str = (empty) ? _("indexed-empty") : _("indexed"); + image_type_str = _("indexed"); break; default: image_type_str = NULL; @@ -243,6 +294,61 @@ title[i++] = '%'; break; + case 'E': + { /* I'm not sure how a window can be empty ?? Need testing. */ + char *empty_str = NULL; + size_t empty_str_len = 0; + char *used_str = NULL; + size_t used_str_len = 0; + char empty_tmp = '*'; + char *str = NULL; + size_t len = 0; + + ++format; + + len = gdisplay__format_title_params_2(format, + &empty_str, &empty_str_len, + &used_str, &used_str_len); + + if (format[0] == 0) + { /* this is what the user wants */ + empty_str = &empty_tmp; + empty_str_len = 1; + /* _format_title_params_2 will fail */ + } + else if (!len) + { /* you can specify 1 char to display when the image is empty, + * compat with %D{}{} */ + empty_str = format; + empty_str_len = 1; + } + else + format += len; + + --format; /* as the for loop does one for us */ + + if (empty) + { + len = empty_str_len; + str = empty_str; + } + else + { + len = used_str_len; + str = used_str; + } + + if (!len) + break; + + if (len > (title_len - i)) + len = (title_len - i); + + memcpy(title + i, str, len); + i += len; + } + break; + case 'f': /* pruned filename */ i += print (title, title_len, i, "%s", g_basename (gimage_filename (gimage))); @@ -278,22 +384,67 @@ break; case 'D': /* dirty flag */ - if (format[1] == 0) - { - g_warning("image-title-format string ended within %%D-sequence"); - break; + { + char *dirty_str = NULL; + size_t dirty_str_len = 0; + char *clean_str = NULL; + size_t clean_str_len = 0; + char dirty_tmp = '*'; + char *str = NULL; + size_t len = 0; + + ++format; + + len = gdisplay__format_title_params_2(format, + &dirty_str, &dirty_str_len, + &clean_str, &clean_str_len); + + if (format[0] == 0) + { /* this is what the user wants */ + dirty_str = &dirty_tmp; + dirty_str_len = 1; + /* _format_title_params_2 will fail */ } - if (gimage->dirty) - title[i++] = format[1]; - format++; - break; + else if (!len) + { /* follow the original algo, where you can specify 1 char to + * display when the image is dirty */ + dirty_str = format; + dirty_str_len = 1; + ++format; + } + else + format += len; - /* Other cool things to be added: - * %m = memory used by picture - * some kind of resolution / image size thing - * people seem to want to know the active layer name - */ + --format; /* as the for loop does one for us */ + if (gimage->dirty) + { + len = dirty_str_len; + str = dirty_str; + } + else + { + len = clean_str_len; + str = clean_str; + } + + if (!len) + break; + + if (len > (title_len - i)) + len = (title_len - i); + + memcpy(title + i, str, len); + i += len; + } + break; + + /* Other cool things to be added: + * %m = memory used by picture + * some kind of resolution / image size thing + * people seem to want to know the active layer name + */ + default: g_warning ("image-title-format contains unknown format sequence '%%%c'", *format); break; @@ -1864,7 +2015,7 @@ } } -void + void gdisplays_resize_cursor_label (GimpImage *gimage) { GDisplay *gdisp; -- James Antill -- james@and.org I am always an optimist, but frankly there is no hope. -Hosni Mubarek ------- Bug moved to this database by debbugs-export@bugzilla.gnome.org 2001-01-28 10:48 ------- This bug was previously known as bug 5843 at http://bugs.gnome.org/ http://bugs.gnome.org/show_bug.cgi?id=5843 Originally filed under the gimp product and general component. The original reporter (james@and.org) of this bug does not have an account here. Reassigning to the exporter, debbugs-export@bugzilla.gnome.org. Reassigning to the default owner of the component, egger@suse.de.
Re-assigning all Gimp bugs to default component owner (Gimp bugs list)
This would be nice to have and easy to apply because the code has not changed significantly there. Assigned to current CVS because it's a wishlist item.
As I said on the mailing list when this was first suggested, I think this patch is overcomplex, and does not add any new functionality. You can get the same effect by using multiple %D* strings, eg: %Df%Do%Do puts "foo" in the title. The potential for string overruns in this kind of code is huge; the patch would need a thorough read-through to make sure it works correctly (and copes with format syntax errors correctly). Also, it uses too many brackets - what if we later want to use the syntax for something else? Austin
There is one thing that is possible with this patch but not possible to do by using multiple %D* strings: you can configure the title format to display "(clean)" or "(saved)" when the image has been saved to disk. The %D* string can only be used to display something when the image has been modified. By the way, even if this is not the appropriate place to mention it, I have another patch for the format string that is waiting to be applied since July 2000: ftp://ftp.gimp.org/pub/gimp/patches/gimp-quinet-000618-0.patch It allows the image title to display the width and height of the image in pixels or in real-world units. It also updates the gimprc and the manual page to document the changes. There is also a comment about some other things that would be nice to have: %m for the amount of memory used by the image, %l for the number of layers, %L for the name of the active layer.
2002-02-11 Michael Natterer <mitch@gimp.org> * app/gimprc.[ch] * app/config/gimpdisplayconfig.[ch] * app/gui/preferences-dialog.c: made the string which appears in the display's statusbar configurable separately from the title string. They still both have the same default value. * app/display/gimpdisplayshell.c: changed accordingly. Also added lots of new % expansions which implement all stuff mentioned in #5843. Didn't apply the original patch because it is overly complicated (the same can be acheived using %D and %C). Instead, applied a changed version of gimp-quinet-000618-0.patch. Added %Cx, which expands to 'x' if the image is clean. * docs/gimprc-1.3.5.in * etc/gimprc.in * etc/gimprc.win32: added documentation for the new stuff. Added the suggested stuff to current CVS. Closing this bug.