Mercurial > geeqie
comparison src/pan-view.c @ 17:bd9ae48e4eb2
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
##### an offical release when making enhancements and translation updates. #####
Thu Mar 3 17:57:46 2005 John Ellis <johne@verizon.net>
* pan-view.c: Make subsequent searches for same string step through all
matches, also show match index and count in search result label.
author | gqview |
---|---|
date | Thu, 03 Mar 2005 23:03:06 +0000 |
parents | 3263965d5f9e |
children | bc5da5b63abd |
comparison
equal
deleted
inserted
replaced
16:651c8313449f | 17:bd9ae48e4eb2 |
---|---|
1173 | 1173 |
1174 return NULL; | 1174 return NULL; |
1175 } | 1175 } |
1176 | 1176 |
1177 /* when ignore_case and partial are TRUE, path should be converted to lower case */ | 1177 /* when ignore_case and partial are TRUE, path should be converted to lower case */ |
1178 static PanItem *pan_item_find_by_path(PanWindow *pw, ItemType type, const gchar *path, | 1178 static GList *pan_item_find_by_path(PanWindow *pw, ItemType type, const gchar *path, |
1179 gint ignore_case, gint partial) | 1179 gint ignore_case, gint partial) |
1180 { | 1180 { |
1181 GList *list = NULL; | |
1181 GList *work; | 1182 GList *work; |
1182 | 1183 |
1183 if (!path) return NULL; | 1184 if (!path) return NULL; |
1184 if (partial && path[0] == '/') return NULL; | 1185 if (partial && path[0] == '/') return NULL; |
1185 | 1186 |
1189 PanItem *pi; | 1190 PanItem *pi; |
1190 | 1191 |
1191 pi = work->data; | 1192 pi = work->data; |
1192 if ((pi->type == type || type == ITEM_NONE) && pi->fd) | 1193 if ((pi->type == type || type == ITEM_NONE) && pi->fd) |
1193 { | 1194 { |
1195 gint match = FALSE; | |
1196 | |
1194 if (path[0] == '/') | 1197 if (path[0] == '/') |
1195 { | 1198 { |
1196 if (pi->fd->path && strcmp(path, pi->fd->path) == 0) return pi; | 1199 if (pi->fd->path && strcmp(path, pi->fd->path) == 0) match = TRUE; |
1197 } | 1200 } |
1198 else if (pi->fd->name) | 1201 else if (pi->fd->name) |
1199 { | 1202 { |
1200 if (partial) | 1203 if (partial) |
1201 { | 1204 { |
1202 if (ignore_case) | 1205 if (ignore_case) |
1203 { | 1206 { |
1204 gchar *haystack; | 1207 gchar *haystack; |
1205 gint match; | |
1206 | 1208 |
1207 haystack = g_utf8_strdown(pi->fd->name, -1); | 1209 haystack = g_utf8_strdown(pi->fd->name, -1); |
1208 match = (strstr(haystack, path) != NULL); | 1210 match = (strstr(haystack, path) != NULL); |
1209 g_free(haystack); | 1211 g_free(haystack); |
1210 if (match) return pi; | |
1211 } | 1212 } |
1212 else | 1213 else |
1213 { | 1214 { |
1214 if (strstr(pi->fd->name, path)) return pi; | 1215 if (strstr(pi->fd->name, path)) match = TRUE; |
1215 } | 1216 } |
1216 } | 1217 } |
1217 else if (ignore_case) | 1218 else if (ignore_case) |
1218 { | 1219 { |
1219 if (strcasecmp(path, pi->fd->name) == 0) return pi; | 1220 if (strcasecmp(path, pi->fd->name) == 0) match = TRUE; |
1220 } | 1221 } |
1221 else | 1222 else |
1222 { | 1223 { |
1223 if (strcmp(path, pi->fd->name) == 0) return pi; | 1224 if (strcmp(path, pi->fd->name) == 0) match = TRUE; |
1224 } | 1225 } |
1225 } | 1226 } |
1227 | |
1228 if (match) list = g_list_prepend(list, pi); | |
1226 } | 1229 } |
1227 work = work->prev; | 1230 work = work->prev; |
1228 } | 1231 } |
1229 | 1232 |
1230 return NULL; | 1233 return g_list_reverse(list); |
1231 } | 1234 } |
1232 | 1235 |
1233 static PanItem *pan_item_find_by_coord(PanWindow *pw, ItemType type, gint x, gint y) | 1236 static PanItem *pan_item_find_by_coord(PanWindow *pw, ItemType type, gint x, gint y) |
1234 { | 1237 { |
1235 GList *work; | 1238 GList *work; |
1671 static void pan_window_layout_compute_folders_flower(PanWindow *pw, const gchar *path, | 1674 static void pan_window_layout_compute_folders_flower(PanWindow *pw, const gchar *path, |
1672 gint *width, gint *height, | 1675 gint *width, gint *height, |
1673 gint *scroll_x, gint *scroll_y) | 1676 gint *scroll_x, gint *scroll_y) |
1674 { | 1677 { |
1675 FlowerGroup *group; | 1678 FlowerGroup *group; |
1676 PanItem *pi; | 1679 GList *list; |
1677 | 1680 |
1678 group = pan_window_layout_compute_folders_flower_path(pw, path, 0, 0); | 1681 group = pan_window_layout_compute_folders_flower_path(pw, path, 0, 0); |
1679 pan_window_layout_compute_folder_flower_build(pw, group, NULL); | 1682 pan_window_layout_compute_folder_flower_build(pw, group, NULL); |
1680 | 1683 |
1681 pan_window_Layout_compute_folders_flower_size(pw, width, height); | 1684 pan_window_Layout_compute_folders_flower_size(pw, width, height); |
1682 | 1685 |
1683 pi = pan_item_find_by_path(pw, ITEM_BOX, path, FALSE, FALSE); | 1686 list = pan_item_find_by_path(pw, ITEM_BOX, path, FALSE, FALSE); |
1684 if (pi) | 1687 if (list) |
1685 { | 1688 { |
1689 PanItem *pi = list->data; | |
1686 *scroll_x = pi->x + pi->width / 2; | 1690 *scroll_x = pi->x + pi->width / 2; |
1687 *scroll_y = pi->y + pi->height / 2; | 1691 *scroll_y = pi->y + pi->height / 2; |
1688 } | 1692 } |
1693 g_list_free(list); | |
1689 } | 1694 } |
1690 | 1695 |
1691 static void pan_window_layout_compute_folders_linear_path(PanWindow *pw, const gchar *path, | 1696 static void pan_window_layout_compute_folders_linear_path(PanWindow *pw, const gchar *path, |
1692 gint *x, gint *y, gint *level, | 1697 gint *x, gint *y, gint *level, |
1693 PanItem *parent, | 1698 PanItem *parent, |
3148 } | 3153 } |
3149 | 3154 |
3150 static gint pan_search_by_path(PanWindow *pw, const gchar *path) | 3155 static gint pan_search_by_path(PanWindow *pw, const gchar *path) |
3151 { | 3156 { |
3152 PanItem *pi; | 3157 PanItem *pi; |
3158 GList *list; | |
3159 GList *found; | |
3153 ItemType type; | 3160 ItemType type; |
3161 gchar *buf; | |
3154 | 3162 |
3155 type = (pw->size > LAYOUT_SIZE_THUMB_LARGE) ? ITEM_IMAGE : ITEM_THUMB; | 3163 type = (pw->size > LAYOUT_SIZE_THUMB_LARGE) ? ITEM_IMAGE : ITEM_THUMB; |
3156 | 3164 |
3157 pi = pan_item_find_by_path(pw, type, path, FALSE, FALSE); | 3165 list = pan_item_find_by_path(pw, type, path, FALSE, FALSE); |
3158 if (!pi) return FALSE; | 3166 if (!list) return FALSE; |
3167 | |
3168 found = g_list_find(list, pw->click_pi); | |
3169 if (found && found->next) | |
3170 { | |
3171 found = found->next; | |
3172 pi = found->data; | |
3173 } | |
3174 else | |
3175 { | |
3176 pi = list->data; | |
3177 } | |
3159 | 3178 |
3160 pan_info_update(pw, pi); | 3179 pan_info_update(pw, pi); |
3161 image_scroll_to_point(pw->imd, pi->x + pi->width / 2, pi->y + pi->height / 2, 0.5, 0.5); | 3180 image_scroll_to_point(pw->imd, pi->x + pi->width / 2, pi->y + pi->height / 2, 0.5, 0.5); |
3162 | 3181 |
3163 pan_search_status(pw, (path[0] == '/') ? _("path found") : _("filename found")); | 3182 buf = g_strdup_printf("%s ( %d / %d )", |
3183 (path[0] == '/') ? _("path found") : _("filename found"), | |
3184 g_list_index(list, pi) + 1, | |
3185 g_list_length(list)); | |
3186 pan_search_status(pw, buf); | |
3187 g_free(buf); | |
3188 | |
3189 g_list_free(list); | |
3164 | 3190 |
3165 return TRUE; | 3191 return TRUE; |
3166 } | 3192 } |
3167 | 3193 |
3168 static gint pan_search_by_partial(PanWindow *pw, const gchar *text) | 3194 static gint pan_search_by_partial(PanWindow *pw, const gchar *text) |
3169 { | 3195 { |
3170 PanItem *pi; | 3196 PanItem *pi; |
3197 GList *list; | |
3198 GList *found; | |
3171 ItemType type; | 3199 ItemType type; |
3200 gchar *buf; | |
3172 | 3201 |
3173 type = (pw->size > LAYOUT_SIZE_THUMB_LARGE) ? ITEM_IMAGE : ITEM_THUMB; | 3202 type = (pw->size > LAYOUT_SIZE_THUMB_LARGE) ? ITEM_IMAGE : ITEM_THUMB; |
3174 | 3203 |
3175 pi = pan_item_find_by_path(pw, type, text, TRUE, FALSE); | 3204 list = pan_item_find_by_path(pw, type, text, TRUE, FALSE); |
3176 if (!pi) pi = pan_item_find_by_path(pw, type, text, FALSE, TRUE); | 3205 if (!list) list = pan_item_find_by_path(pw, type, text, FALSE, TRUE); |
3177 if (!pi) | 3206 if (!list) |
3178 { | 3207 { |
3179 gchar *needle; | 3208 gchar *needle; |
3180 | 3209 |
3181 needle = g_utf8_strdown(text, -1); | 3210 needle = g_utf8_strdown(text, -1); |
3182 pi = pan_item_find_by_path(pw, type, needle, TRUE, TRUE); | 3211 list = pan_item_find_by_path(pw, type, needle, TRUE, TRUE); |
3183 g_free(needle); | 3212 g_free(needle); |
3184 } | 3213 } |
3185 if (!pi) return FALSE; | 3214 if (!list) return FALSE; |
3215 | |
3216 found = g_list_find(list, pw->click_pi); | |
3217 if (found && found->next) | |
3218 { | |
3219 found = found->next; | |
3220 pi = found->data; | |
3221 } | |
3222 else | |
3223 { | |
3224 pi = list->data; | |
3225 } | |
3186 | 3226 |
3187 pan_info_update(pw, pi); | 3227 pan_info_update(pw, pi); |
3188 image_scroll_to_point(pw->imd, pi->x + pi->width / 2, pi->y + pi->height / 2, 0.5, 0.5); | 3228 image_scroll_to_point(pw->imd, pi->x + pi->width / 2, pi->y + pi->height / 2, 0.5, 0.5); |
3189 | 3229 |
3190 pan_search_status(pw, _("partial match")); | 3230 buf = g_strdup_printf("%s ( %d / %d )", |
3231 _("partial match"), | |
3232 g_list_index(list, pi) + 1, | |
3233 g_list_length(list)); | |
3234 pan_search_status(pw, buf); | |
3235 g_free(buf); | |
3236 | |
3237 g_list_free(list); | |
3191 | 3238 |
3192 return TRUE; | 3239 return TRUE; |
3193 } | 3240 } |
3194 | 3241 |
3195 static gint valid_date_separator(gchar c) | 3242 static gint valid_date_separator(gchar c) |
3196 { | 3243 { |
3197 return (c == '/' || c == '-' || c == ' ' || c == '.' || c == ','); | 3244 return (c == '/' || c == '-' || c == ' ' || c == '.' || c == ','); |
3198 } | 3245 } |
3199 | 3246 |
3200 static PanItem *pan_search_by_date_val(PanWindow *pw, ItemType type, gint year, gint month, gint day) | 3247 static GList *pan_search_by_date_val(PanWindow *pw, ItemType type, gint year, gint month, gint day) |
3201 { | 3248 { |
3249 GList *list = NULL; | |
3202 GList *work; | 3250 GList *work; |
3203 | 3251 |
3204 work = g_list_last(pw->list); | 3252 work = g_list_last(pw->list); |
3205 while (work) | 3253 while (work) |
3206 { | 3254 { |
3220 | 3268 |
3221 match = (tl->tm_year == year - 1900); | 3269 match = (tl->tm_year == year - 1900); |
3222 if (match && month >= 0) match = (tl->tm_mon == month - 1); | 3270 if (match && month >= 0) match = (tl->tm_mon == month - 1); |
3223 if (match && day > 0) match = (tl->tm_mday == day); | 3271 if (match && day > 0) match = (tl->tm_mday == day); |
3224 | 3272 |
3225 if (match) return pi; | 3273 if (match) list = g_list_prepend(list, pi); |
3226 } | 3274 } |
3227 } | 3275 } |
3228 } | 3276 } |
3229 | 3277 |
3230 return NULL; | 3278 return g_list_reverse(list); |
3231 } | 3279 } |
3232 | 3280 |
3233 static gint pan_search_by_date(PanWindow *pw, const gchar *text) | 3281 static gint pan_search_by_date(PanWindow *pw, const gchar *text) |
3234 { | 3282 { |
3235 PanItem *pi; | 3283 PanItem *pi = NULL; |
3284 GList *list; | |
3285 GList *found; | |
3236 gint year; | 3286 gint year; |
3237 gint month = -1; | 3287 gint month = -1; |
3238 gint day = -1; | 3288 gint day = -1; |
3239 gchar *ptr; | 3289 gchar *ptr; |
3240 gchar *mptr; | 3290 gchar *mptr; |
3241 struct tm *lt; | 3291 struct tm *lt; |
3242 time_t t; | 3292 time_t t; |
3243 gchar *message; | 3293 gchar *message; |
3244 gchar *buf; | 3294 gchar *buf; |
3295 gchar *buf_count; | |
3245 ItemType type; | 3296 ItemType type; |
3246 | 3297 |
3247 if (!text) return FALSE; | 3298 if (!text) return FALSE; |
3248 | 3299 |
3249 ptr = (gchar *)text; | 3300 ptr = (gchar *)text; |
3318 t = date_to_time(year, month, day); | 3369 t = date_to_time(year, month, day); |
3319 if (t < 0) return FALSE; | 3370 if (t < 0) return FALSE; |
3320 | 3371 |
3321 type = (pw->size > LAYOUT_SIZE_THUMB_LARGE) ? ITEM_IMAGE : ITEM_THUMB; | 3372 type = (pw->size > LAYOUT_SIZE_THUMB_LARGE) ? ITEM_IMAGE : ITEM_THUMB; |
3322 | 3373 |
3323 pi = pan_search_by_date_val(pw, type, year, month, day); | 3374 list = pan_search_by_date_val(pw, type, year, month, day); |
3375 if (list) | |
3376 { | |
3377 found = g_list_find(list, pw->click_pi); | |
3378 if (found && found->next) | |
3379 { | |
3380 found = found->next; | |
3381 pi = found->data; | |
3382 } | |
3383 else | |
3384 { | |
3385 pi = list->data; | |
3386 } | |
3387 } | |
3388 | |
3324 if (pi) | 3389 if (pi) |
3325 { | 3390 { |
3326 pan_info_update(pw, pi); | 3391 pan_info_update(pw, pi); |
3327 image_scroll_to_point(pw->imd, | 3392 image_scroll_to_point(pw->imd, |
3328 pi->x - PAN_FOLDER_BOX_BORDER * 5 / 2, | 3393 pi->x - PAN_FOLDER_BOX_BORDER * 5 / 2, |
3342 } | 3407 } |
3343 else | 3408 else |
3344 { | 3409 { |
3345 buf = date_value_string(t, DATE_LENGTH_YEAR); | 3410 buf = date_value_string(t, DATE_LENGTH_YEAR); |
3346 } | 3411 } |
3347 message = g_strdup_printf("%s%s%s%s %s", | 3412 |
3348 (pi) ? "" : "(", (pi) ? "" : _("no match"), (pi) ? "" : ") " , | 3413 if (pi) |
3349 _("Date:"), buf); | 3414 { |
3415 buf_count = g_strdup_printf("( %d / %d )", | |
3416 g_list_index(list, pi) + 1, | |
3417 g_list_length(list)); | |
3418 } | |
3419 else | |
3420 { | |
3421 buf_count = g_strdup_printf("(%s)", _("no match")); | |
3422 } | |
3423 | |
3424 message = g_strdup_printf("%s %s %s", _("Date:"), buf, buf_count); | |
3350 g_free(buf); | 3425 g_free(buf); |
3426 g_free(buf_count); | |
3351 pan_search_status(pw, message); | 3427 pan_search_status(pw, message); |
3352 g_free(message); | 3428 g_free(message); |
3429 | |
3430 g_list_free(list); | |
3353 | 3431 |
3354 return TRUE; | 3432 return TRUE; |
3355 } | 3433 } |
3356 | 3434 |
3357 static void pan_search_activate_cb(const gchar *text, gpointer data) | 3435 static void pan_search_activate_cb(const gchar *text, gpointer data) |