comparison src/bar_sort.c @ 1320:055ed09d5a03

improved bar_sort configuration
author nadvornik
date Tue, 24 Feb 2009 22:21:28 +0000
parents 55ea4962887a
children 3bc4967aaa57
comparison
equal deleted inserted replaced
1319:358685fb9dc9 1320:055ed09d5a03
24 #include "editors.h" 24 #include "editors.h"
25 #include "ui_bookmark.h" 25 #include "ui_bookmark.h"
26 #include "ui_fileops.h" 26 #include "ui_fileops.h"
27 #include "ui_menu.h" 27 #include "ui_menu.h"
28 #include "ui_misc.h" 28 #include "ui_misc.h"
29 #include "rcfile.h"
29 30
30 31
31 /* 32 /*
32 *------------------------------------------------------------------- 33 *-------------------------------------------------------------------
33 * sort bar 34 * sort bar
169 } 170 }
170 else 171 else
171 { 172 {
172 bar_sort_mode_sync(sd, BAR_SORT_MODE_COLLECTION); 173 bar_sort_mode_sync(sd, BAR_SORT_MODE_COLLECTION);
173 } 174 }
174 options->layout.panels.sort.mode_state = sd->mode;
175 } 175 }
176 176
177 /* this takes control of src_list */ 177 /* this takes control of src_list */
178 static void bar_sort_undo_set(SortData *sd, GList *src_list, FileData *src, const gchar *dest) 178 static void bar_sort_undo_set(SortData *sd, GList *src_list, FileData *src, const gchar *dest)
179 { 179 {
349 } 349 }
350 } 350 }
351 351
352 static void bar_sort_set_action(SortData *sd, SortActionType action, const gchar *filter_key) 352 static void bar_sort_set_action(SortData *sd, SortActionType action, const gchar *filter_key)
353 { 353 {
354 options->layout.panels.sort.action_state = sd->action = action; 354 sd->action = action;
355 if (action == BAR_SORT_FILTER) 355 if (action == BAR_SORT_FILTER)
356 { 356 {
357 if (!filter_key) filter_key = ""; 357 if (!filter_key) filter_key = "";
358 sd->filter_key = filter_key; 358 sd->filter_key = filter_key;
359 g_free(options->layout.panels.sort.action_filter);
360 options->layout.panels.sort.action_filter = g_strdup(filter_key);
361 } 359 }
362 else 360 else
363 { 361 {
364 sd->filter_key = NULL; 362 sd->filter_key = NULL;
365 g_free(options->layout.panels.sort.action_filter);
366 options->layout.panels.sort.action_filter = g_strdup("");
367 } 363 }
368 } 364 }
369 365
370 static void bar_sort_set_copy_cb(GtkWidget *button, gpointer data) 366 static void bar_sort_set_copy_cb(GtkWidget *button, gpointer data)
371 { 367 {
391 bar_sort_set_action(sd, BAR_SORT_FILTER, key); 387 bar_sort_set_action(sd, BAR_SORT_FILTER, key);
392 } 388 }
393 389
394 static void bar_sort_set_selection(SortData *sd, SortSelectionType selection) 390 static void bar_sort_set_selection(SortData *sd, SortSelectionType selection)
395 { 391 {
396 options->layout.panels.sort.selection_state = sd->selection = selection; 392 sd->selection = selection;
397 } 393 }
398 394
399 static void bar_sort_set_selection_image_cb(GtkWidget *button, gpointer data) 395 static void bar_sort_set_selection_image_cb(GtkWidget *button, gpointer data)
400 { 396 {
401 SortData *sd = data; 397 SortData *sd = data;
553 g_free(sd->undo_src); 549 g_free(sd->undo_src);
554 g_free(sd->undo_dest); 550 g_free(sd->undo_dest);
555 g_free(sd); 551 g_free(sd);
556 } 552 }
557 553
558 GtkWidget *bar_sort_new(LayoutWindow *lw) 554 static GtkWidget *bar_sort_new(LayoutWindow *lw, SortActionType action, SortModeType mode, SortSelectionType selection, const gchar *filter_key)
559 { 555 {
560 SortData *sd; 556 SortData *sd;
561 GtkWidget *buttongrp; 557 GtkWidget *buttongrp;
562 GtkWidget *label; 558 GtkWidget *label;
563 GtkWidget *tbar; 559 GtkWidget *tbar;
564 GtkWidget *combo; 560 GtkWidget *combo;
565 SortModeType mode;
566 GList *editors_list, *work; 561 GList *editors_list, *work;
567 gboolean have_filter; 562 gboolean have_filter;
568 563
569 if (!lw) return NULL; 564 if (!lw) return NULL;
570 565
571 sd = g_new0(SortData, 1); 566 sd = g_new0(SortData, 1);
572 567
573 sd->lw = lw; 568 sd->lw = lw;
574 569
575 mode = CLAMP(options->layout.panels.sort.mode_state, 0, BAR_SORT_MODE_COUNT - 1); 570 sd->action = action;
576 sd->action = CLAMP(options->layout.panels.sort.action_state, 0, BAR_SORT_ACTION_COUNT - 1);
577 571
578 if (sd->action == BAR_SORT_FILTER && 572 if (sd->action == BAR_SORT_FILTER && (!filter_key || !filter_key[0]))
579 (!options->layout.panels.sort.action_filter || !options->layout.panels.sort.action_filter[0])) 573 {
580 sd->action = BAR_SORT_COPY; 574 sd->action = BAR_SORT_COPY;
575 }
581 576
582 sd->selection = CLAMP(options->layout.panels.sort.selection_state, 0, BAR_SORT_SELECTION_COUNT - 1); 577 sd->selection = selection;
583 sd->undo_src = NULL; 578 sd->undo_src = NULL;
584 sd->undo_dest = NULL; 579 sd->undo_dest = NULL;
585 580
586 sd->vbox = gtk_vbox_new(FALSE, PREF_PAD_GAP); 581 sd->vbox = gtk_vbox_new(FALSE, PREF_PAD_GAP);
587 g_object_set_data(G_OBJECT(sd->vbox), "bar_sort_data", sd); 582 g_object_set_data(G_OBJECT(sd->vbox), "bar_sort_data", sd);
623 work = work->next; 618 work = work->next;
624 gboolean select = FALSE; 619 gboolean select = FALSE;
625 620
626 if (!editor_is_filter(editor->key)) continue; 621 if (!editor_is_filter(editor->key)) continue;
627 622
628 if (sd->action == BAR_SORT_FILTER && strcmp(editor->key, options->layout.panels.sort.action_filter) == 0) 623 if (sd->action == BAR_SORT_FILTER && strcmp(editor->key, filter_key) == 0)
629 { 624 {
630 bar_sort_set_action(sd, sd->action, editor->key); 625 bar_sort_set_action(sd, sd->action, editor->key);
631 select = TRUE; 626 select = TRUE;
632 have_filter = TRUE; 627 have_filter = TRUE;
633 } 628 }
669 bar_sort_mode_sync(sd, mode); 664 bar_sort_mode_sync(sd, mode);
670 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), sd->mode); 665 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), sd->mode);
671 666
672 return sd->vbox; 667 return sd->vbox;
673 } 668 }
669
670 GtkWidget *bar_sort_new_from_config(LayoutWindow *lw, const gchar **attribute_names, const gchar **attribute_values)
671 {
672 GtkWidget *bar;
673
674 gboolean enabled = TRUE;
675 gint action = 0;
676 gint mode = 0;
677 gint selection = 0;
678 gchar *filter_key = NULL;
679
680 while (attribute_names && *attribute_names)
681 {
682 const gchar *option = *attribute_names++;
683 const gchar *value = *attribute_values++;
684
685 if (READ_BOOL_FULL("enabled", enabled)) continue;
686 if (READ_INT_CLAMP_FULL("action", action, 0, BAR_SORT_ACTION_COUNT - 1)) continue;
687 if (READ_INT_CLAMP_FULL("mode", mode, 0, BAR_SORT_MODE_COUNT - 1)) continue;
688 if (READ_INT_CLAMP_FULL("selection", selection, 0, BAR_SORT_SELECTION_COUNT - 1)) continue;
689 if (READ_CHAR_FULL("filter_key", filter_key)) continue;
690
691 DEBUG_1("unknown attribute %s = %s", option, value);
692 }
693 bar = bar_sort_new(lw, action, mode, selection, filter_key);
694
695 g_free(filter_key);
696 if (enabled) gtk_widget_show(bar);
697 return bar;
698 }
699
700 GtkWidget *bar_sort_new_default(LayoutWindow *lw)
701 {
702 return bar_sort_new_from_config(lw, NULL, NULL);
703 }
704
705 void bar_sort_write_config(GtkWidget *bar, GString *outstr, gint indent)
706 {
707 SortData *sd;
708
709 if (!bar) return;
710 sd = g_object_get_data(G_OBJECT(bar), "bar_sort_data");
711 if (!sd) return;
712
713 WRITE_STRING("<bar_sort\n");
714 indent++;
715 write_bool_option(outstr, indent, "enabled", GTK_WIDGET_VISIBLE(bar));
716 WRITE_INT(*sd, mode);
717 WRITE_INT(*sd, action);
718 WRITE_INT(*sd, selection);
719 WRITE_CHAR(*sd, filter_key);
720 indent--;
721 WRITE_STRING("/>\n");
722 }
723
724
674 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ 725 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */