aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2002-11-19 04:57:35 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2002-11-19 04:57:35 +0800
commit0c8bfeb83dc68d13972f699b6eecf064d1f54fd1 (patch)
treed3952c8e1f3dca05069a6773827d917cd2ceb7f7
parent86946f8f29fe96644f836b4675ab6653d177ae99 (diff)
downloadgsoc2013-evolution-0c8bfeb83dc68d13972f699b6eecf064d1f54fd1.tar
gsoc2013-evolution-0c8bfeb83dc68d13972f699b6eecf064d1f54fd1.tar.gz
gsoc2013-evolution-0c8bfeb83dc68d13972f699b6eecf064d1f54fd1.tar.bz2
gsoc2013-evolution-0c8bfeb83dc68d13972f699b6eecf064d1f54fd1.tar.lz
gsoc2013-evolution-0c8bfeb83dc68d13972f699b6eecf064d1f54fd1.tar.xz
gsoc2013-evolution-0c8bfeb83dc68d13972f699b6eecf064d1f54fd1.tar.zst
gsoc2013-evolution-0c8bfeb83dc68d13972f699b6eecf064d1f54fd1.zip
Updated to use GtkTreeView.
2002-11-18 Jeffrey Stedfast <fejj@ximian.com> * rule-editor.c: Updated to use GtkTreeView. * vfolder-rule.c: Same. svn path=/trunk/; revision=18830
-rw-r--r--filter/ChangeLog6
-rw-r--r--filter/filter.glade8
-rw-r--r--filter/rule-editor.c120
-rw-r--r--filter/rule-editor.h4
-rw-r--r--filter/vfolder-rule.c83
5 files changed, 141 insertions, 80 deletions
diff --git a/filter/ChangeLog b/filter/ChangeLog
index 815481e7a7..cb0d1991e0 100644
--- a/filter/ChangeLog
+++ b/filter/ChangeLog
@@ -1,3 +1,9 @@
+2002-11-18 Jeffrey Stedfast <fejj@ximian.com>
+
+ * rule-editor.c: Updated to use GtkTreeView.
+
+ * vfolder-rule.c: Same.
+
2002-11-13 Not Zed <NotZed@Ximian.com>
* rule-context.c (load): Get the root node properly.
diff --git a/filter/filter.glade b/filter/filter.glade
index 079510db25..1c02f13dcc 100644
--- a/filter/filter.glade
+++ b/filter/filter.glade
@@ -330,9 +330,9 @@
<child>
<widget class="GtkTreeView" id="rule_list">
<property name="visible">True</property>
- <property name="headers_visible">True</property>
+ <property name="headers_visible">False</property>
<property name="rules_hint">False</property>
- <property name="reorderable">False</property>
+ <property name="reorderable">True</property>
<property name="enable_search">True</property>
</widget>
</child>
@@ -781,9 +781,9 @@
<child>
<widget class="GtkTreeView" id="rule_list">
<property name="visible">True</property>
- <property name="headers_visible">True</property>
+ <property name="headers_visible">False</property>
<property name="rules_hint">False</property>
- <property name="reorderable">False</property>
+ <property name="reorderable">True</property>
<property name="enable_search">True</property>
</widget>
</child>
diff --git a/filter/rule-editor.c b/filter/rule-editor.c
index b1f465eab3..60ffa7762d 100644
--- a/filter/rule-editor.c
+++ b/filter/rule-editor.c
@@ -224,8 +224,9 @@ editor_destroy (RuleEditor *re, GObject *deadbeef)
static void
add_editor_response (GtkWidget *dialog, int button, RuleEditor *re)
{
- GtkWidget *item;
- GList *l = NULL;
+ GtkTreeSelection *selection;
+ GtkTreePath *path;
+ GtkTreeIter iter;
if (button == GTK_RESPONSE_ACCEPT) {
if (!filter_rule_validate (re->edit)) {
@@ -246,15 +247,11 @@ add_editor_response (GtkWidget *dialog, int button, RuleEditor *re)
}
g_object_ref (re->edit);
- item = gtk_list_item_new_with_label (re->edit->name);
- g_object_set_data ((GObject *) item, "rule", re->edit);
- gtk_widget_show (item);
-
- l = g_list_append (l, GTK_LIST_ITEM (item));
-
- gtk_list_append_items (re->list, l);
- gtk_list_select_child (re->list, item);
+ gtk_list_store_append (re->model, &iter);
+ gtk_list_store_set (re->model, &iter, 0, re->edit->name, 1, re->edit, -1);
+ selection = gtk_tree_view_get_selection (re->list);
+ gtk_tree_selection_select_iter (selection, &iter);
re->current = re->edit;
rule_context_add_rule (re->context, re->current);
@@ -302,7 +299,8 @@ static void
edit_editor_response (GtkWidget *dialog, int button, RuleEditor *re)
{
FilterRule *rule;
- GtkWidget *item;
+ GtkTreePath *path;
+ GtkTreeIter iter;
int pos;
if (button == GTK_RESPONSE_ACCEPT) {
@@ -326,8 +324,12 @@ edit_editor_response (GtkWidget *dialog, int button, RuleEditor *re)
pos = rule_context_get_rank_rule (re->context, re->current, re->source);
if (pos != -1) {
- item = g_list_nth_data (GTK_LIST (re->list)->children, pos);
- gtk_label_set_text (GTK_LABEL (GTK_BIN (item)->child), re->edit->name);
+ path = gtk_tree_path_new ();
+ gtk_tree_path_append_index (path, pos);
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (re->model), &iter, path);
+ gtk_tree_path_free (path);
+
+ gtk_list_store_set (re->model, &iter, 0, re->edit->name, -1);
rule_editor_add_undo (re, RULE_EDITOR_LOG_EDIT, filter_rule_clone (re->current), pos, 0);
@@ -373,23 +375,23 @@ rule_edit (GtkWidget *widget, RuleEditor *re)
static void
rule_delete (GtkWidget *widget, RuleEditor *re)
{
- int pos;
- GList *l;
- GtkListItem *item;
+ GtkTreeSelection *selection;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ int pos, len;
d(printf ("delete rule\n"));
pos = rule_context_get_rank_rule (re->context, re->current, re->source);
if (pos != -1) {
- int len;
-
rule_context_remove_rule (re->context, re->current);
- item = g_list_nth_data (GTK_LIST (re->list)->children, pos);
- l = g_list_append (NULL, item);
- gtk_list_remove_items (re->list, l);
- g_list_free (l);
+ path = gtk_tree_path_new ();
+ gtk_tree_path_append_index (path, pos);
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (re->model), &iter, path);
+ gtk_list_store_remove (re->model, &iter);
+ gtk_tree_path_free (path);
- rule_editor_add_undo( re, RULE_EDITOR_LOG_REMOVE, re->current,
+ rule_editor_add_undo (re, RULE_EDITOR_LOG_REMOVE, re->current,
rule_context_get_rank_rule (re->context, re->current, re->current->source), 0);
#if 0
g_object_unref (re->current);
@@ -397,9 +399,16 @@ rule_delete (GtkWidget *widget, RuleEditor *re)
re->current = NULL;
/* now select the next rule */
- len = g_list_length (GTK_LIST (re->list)->children);
+ len = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (re->model), NULL);
pos = pos >= len ? len - 1 : pos;
- gtk_list_select_item (GTK_LIST (re->list), pos);
+
+ path = gtk_tree_path_new ();
+ gtk_tree_path_append_index (path, pos);
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (re->model), &iter, path);
+ gtk_tree_path_free (path);
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (re->list));
+ gtk_tree_selection_select_iter (selection, &iter);
}
rule_editor_set_sensitive (re);
@@ -408,8 +417,10 @@ rule_delete (GtkWidget *widget, RuleEditor *re)
static void
rule_move (RuleEditor *re, int from, int to)
{
- GList *l;
- GtkListItem *item;
+ GtkTreeSelection *selection;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+ FilterRule *rule;
g_object_ref (re->current);
rule_editor_add_undo (re, RULE_EDITOR_LOG_RANK, re->current,
@@ -418,11 +429,18 @@ rule_move (RuleEditor *re, int from, int to)
d(printf ("moving %d to %d\n", from, to));
rule_context_rank_rule (re->context, re->current, to);
- item = g_list_nth_data (re->list->children, from);
- l = g_list_append (NULL, item);
- gtk_list_remove_items_no_unref (re->list, l);
- gtk_list_insert_items (re->list, l, to);
- gtk_list_select_child (re->list, GTK_WIDGET (item));
+ path = gtk_tree_path_new ();
+ gtk_tree_path_append_index (path, from);
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (re->model), &iter, path);
+ gtk_tree_path_free (path);
+
+ gtk_tree_model_get (GTK_TREE_MODEL (re->model), &iter, 1, &rule, -1);
+ g_assert (rule != NULL);
+
+ gtk_list_store_remove (re->model, &iter);
+ gtk_list_store_insert (re->model, &iter, to);
+
+ gtk_list_store_set (re->model, &iter, 0, rule->name, 1, rule, -1);
rule_editor_set_sensitive (re);
}
@@ -484,9 +502,17 @@ set_sensitive (RuleEditor *re)
static void
-select_rule (GtkWidget *w, GtkWidget *child, RuleEditor *re)
+cursor_changed (GtkWidget *list, RuleEditor *re)
{
- re->current = g_object_get_data ((GObject *) child, "rule");
+ GtkTreeViewColumn *column;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+
+ gtk_tree_view_get_cursor (re->list, &path, &column);
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (re->model), &iter, path);
+ gtk_tree_path_free (path);
+
+ gtk_tree_model_get (GTK_TREE_MODEL (re->model), &iter, 1, &re->current, -1);
g_assert (re->current);
@@ -506,22 +532,16 @@ static void
set_source (RuleEditor *re, const char *source)
{
FilterRule *rule = NULL;
- GList *newitems = NULL;
+ GtkTreeIter iter;
- gtk_list_clear_items (GTK_LIST (re->list), 0, -1);
+ gtk_list_store_clear (re->model);
d(printf("Checking for rules that are of type %s\n", source?source:"<nil>"));
while ((rule = rule_context_next_rule (re->context, rule, source)) != NULL) {
- GtkWidget *item;
-
- d(printf(" hit %s(%s)\n", rule->name, source ? source : "<nil>"));
- item = gtk_list_item_new_with_label (rule->name);
- g_object_set_data ((GObject *) item, "rule", rule);
- gtk_widget_show (GTK_WIDGET (item));
- newitems = g_list_append (newitems, item);
+ gtk_list_store_append (re->model, &iter);
+ gtk_list_store_set (re->model, &iter, 0, rule->name, 1, rule, -1);
}
- gtk_list_append_items (re->list, newitems);
g_free (re->source);
re->source = g_strdup (source);
re->current = NULL;
@@ -619,6 +639,7 @@ editor_clicked (GtkWidget *dialog, int button, RuleEditor *re)
void
rule_editor_construct (RuleEditor *re, RuleContext *context, GladeXML *gui, const char *source)
{
+ GtkTreeSelection *selection;
GtkWidget *w;
int i;
@@ -635,9 +656,14 @@ rule_editor_construct (RuleEditor *re, RuleContext *context, GladeXML *gui, cons
g_signal_connect (w, "clicked", edit_buttons[i].func, re);
}
- re->list = (GtkList *) w = glade_xml_get_widget (gui, "rule_list");
- g_signal_connect (w, "select_child", GTK_SIGNAL_FUNC (select_rule), re);
- g_signal_connect (w, "button_press_event", GTK_SIGNAL_FUNC (double_click), re);
+ re->model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER);
+ re->list = (GtkTreeView *) glade_xml_get_widget (gui, "rule_list");
+ gtk_tree_view_set_model (re->list, (GtkTreeModel *) re->model);
+ selection = gtk_tree_view_get_selection (re->list);
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
+
+ g_signal_connect (re->list, "cursor-changed", GTK_SIGNAL_FUNC (cursor_changed), re);
+ g_signal_connect (re->list, "button_press_event", GTK_SIGNAL_FUNC (double_click), re);
g_signal_connect (re, "clicked", GTK_SIGNAL_FUNC (editor_clicked), re);
rule_editor_set_source (re, source);
diff --git a/filter/rule-editor.h b/filter/rule-editor.h
index a184b81c16..60185f965e 100644
--- a/filter/rule-editor.h
+++ b/filter/rule-editor.h
@@ -44,7 +44,9 @@ typedef struct _RuleEditorUndo RuleEditorUndo;
struct _RuleEditor {
GtkDialog parent_object;
- GtkList *list;
+ GtkListStore *model;
+ GtkTreeView *list;
+
RuleContext *context;
FilterRule *current;
FilterRule *edit; /* for editing/adding rules, so we only do 1 at a time */
diff --git a/filter/vfolder-rule.c b/filter/vfolder-rule.c
index ad31490188..923f24a55b 100644
--- a/filter/vfolder-rule.c
+++ b/filter/vfolder-rule.c
@@ -254,9 +254,9 @@ vfolder_eq (FilterRule *fr, FilterRule *cm)
static xmlNodePtr
xml_encode (FilterRule *fr)
{
+ VfolderRule *vr = (VfolderRule *) fr;
xmlNodePtr node, set, work;
GList *l;
- VfolderRule *vr = (VfolderRule *)fr;
node = FILTER_RULE_CLASS (parent_class)->xml_encode (fr);
g_assert(node != NULL);
@@ -342,7 +342,8 @@ struct _source_data {
RuleContext *rc;
VfolderRule *vr;
const char *current;
- GtkList *list;
+ GtkListStore *model;
+ GtkTreeView *list;
GtkButton *buttons[BUTTON_LAST];
};
@@ -365,9 +366,18 @@ set_sensitive (struct _source_data *data)
}
static void
-select_source (GtkWidget *widget, GtkWidget *child, struct _source_data *data)
+select_source (GtkWidget *list, struct _source_data *data)
{
- data->current = g_object_get_data ((GObject *) child, "source");
+ GtkTreeViewColumn *column;
+ GtkTreePath *path;
+ GtkTreeIter iter;
+
+ gtk_tree_view_get_cursor (data->list, &path, &column);
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (data->model), &iter, path);
+ gtk_tree_path_free (path);
+
+ gtk_tree_model_get (GTK_TREE_MODEL (data->model), &iter, 0, &data->current, -1);
+
set_sensitive (data);
}
@@ -384,7 +394,8 @@ source_add (GtkWidget *widget, struct _source_data *data)
{
static const char *allowed_types[] = { "mail/*", NULL };
GNOME_Evolution_Folder *folder;
- GtkListItem *item;
+ GtkTreeSelection *selection;
+ GtkTreeIter iter;
char *def, *uri;
GList *l;
@@ -408,13 +419,10 @@ source_add (GtkWidget *widget, struct _source_data *data)
uri = g_strdup (folder->physicalUri);
data->vr->sources = g_list_append (data->vr->sources, uri);
- l = NULL;
- item = (GtkListItem *)gtk_list_item_new_with_label (uri);
- g_object_set_data ((GObject *) item, "source", uri);
- gtk_widget_show ((GtkWidget *) item);
- l = g_list_append (NULL, item);
- gtk_list_append_items (data->list, l);
- gtk_list_select_child (data->list, (GtkWidget *) item);
+ gtk_list_store_append (data->model, &iter);
+ gtk_list_store_set (data->model, &iter, 0, uri, -1);
+ selection = gtk_tree_view_get_selection (data->list);
+ gtk_tree_selection_select_iter (selection, &iter);
data->current = uri;
}
@@ -425,24 +433,44 @@ source_add (GtkWidget *widget, struct _source_data *data)
static void
source_remove (GtkWidget *widget, struct _source_data *data)
{
+ GtkTreeSelection *selection;
const char *source;
+ GtkTreePath *path;
+ GtkTreeIter iter;
int index = 0;
GList *l;
- GtkListItem *item;
+ int len;
source = NULL;
while ((source = vfolder_rule_next_source (data->vr, source))) {
if (data->current == source) {
vfolder_rule_remove_source (data->vr, source);
- item = g_list_nth_data (data->list->children, index);
- l = g_list_append (NULL, item);
- gtk_list_remove_items (data->list, l);
- g_list_free (l);
+
+ path = gtk_tree_path_new ();
+ gtk_tree_path_append_index (path, index);
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (data->model), &iter, path);
+ gtk_list_store_remove (data->model, &iter);
+ gtk_tree_path_free (path);
+
data->current = NULL;
+
+ /* now select the next rule */
+ len = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (data->model), NULL);
+ index = index >= len ? len - 1 : index;
+
+ path = gtk_tree_path_new ();
+ gtk_tree_path_append_index (path, index);
+ gtk_tree_model_get_iter (GTK_TREE_MODEL (data->model), &iter, path);
+ gtk_tree_path_free (path);
+
+ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (data->list));
+ gtk_tree_selection_select_iter (selection, &iter);
+
break;
}
index++;
}
+
set_sensitive (data);
}
@@ -458,10 +486,12 @@ static GtkWidget *
get_widget (FilterRule *fr, RuleContext *rc)
{
VfolderRule *vr = (VfolderRule *) fr;
+ GtkTreeSelection *selection;
struct _source_data *data;
GtkWidget *widget, *frame;
GtkOptionMenu *omenu;
const char *source;
+ GtkTreeIter iter;
GladeXML *gui;
int i, row;
GList *l;
@@ -483,22 +513,19 @@ get_widget (FilterRule *fr, RuleContext *rc)
g_signal_connect (data->buttons[i], "clicked", edit_buttons[i].func, data);
}
- data->list = (GtkList *) glade_xml_get_widget (gui, "source_list");
+ data->model = gtk_list_store_new (1, G_TYPE_STRING);
+ data->list = (GtkTreeView *) glade_xml_get_widget (gui, "source_list");
+ gtk_tree_view_set_model (data->list, (GtkTreeModel *) data->model);
+ selection = gtk_tree_view_get_selection (data->list);
+ gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
- l = NULL;
source = NULL;
while ((source = vfolder_rule_next_source (vr, source))) {
- GtkListItem *item;
-
- item = (GtkListItem *) gtk_list_item_new_with_label (source);
- g_object_set_data ((GObject *) item, "source", (void *) source);
- gtk_widget_show (GTK_WIDGET (item));
- l = g_list_append (l, item);
+ gtk_list_store_append (data->model, &iter);
+ gtk_list_store_set (data->model, &iter, 0, source, -1);
}
- gtk_list_append_items (data->list, l);
-
- g_signal_connect (data->list, "select_child", GTK_SIGNAL_FUNC (select_source), data);
+ g_signal_connect (data->list, "cursor-changed", GTK_SIGNAL_FUNC (select_source), data);
omenu = (GtkOptionMenu *) glade_xml_get_widget (gui, "source_option");
l = GTK_MENU_SHELL (omenu->menu)->children;