Commits

mackx committed 7b6cd65

Allow negative filtering

Comments (0)

Files changed (1)

ctb/src/fileview.c

 static GtkWidget *g_widget_combo_logical_variables[FILE_FILTER_VARS];
 static GtkWidget *g_entry_filter;
 
+static GtkWidget *g_label_widget[FILE_FILTER_VARS];
+
 //============================================================================
 // Local Function Definitions
 //============================================================================
     // get variables
     for (i=0; i<FILE_FILTER_VARS; i++)
     {
-        variable = get_value_of_combo(GTK_COMBO_BOX(g_widget_combo_logical_variables[i]));
+        gchar *str;
+        variable = get_value_of_combo(GTK_COMBO_BOX(g_widget_combo_logical_variables[i])); // retured value needs to be g_freed
         if ((!variable) || (strlen(variable) <= 2)) break; // stop on first not selected variable
+        if (strstr(gtk_label_get_text(GTK_LABEL(g_label_widget[i])), "not") != NULL)
+        {
+            // contains a not
+            str = g_strdup_printf("!%s", variable);
+            ERRORPRINTF("Var:%s", str);
+        }
+        else
+        {
+            str = g_strdup_printf("%s", variable);
+        }
         // add to list
-        var_list = g_slist_append(var_list, variable);
+        var_list = g_slist_append(var_list, str);
+        g_free(variable); // need to free this
     }
     
     // Construct string
     g_widget_combo_logical_functions = widget;
 }
 
+static gboolean on_label_clicked (GtkWidget* button, GdkEventButton* event, gpointer data)
+{
+	int index = (int)data;
+    gchar name[5];
+    ERRORPRINTF("enter:%d", index);
+    
+    index--;
+    const gchar *p = gtk_label_get_text(GTK_LABEL(g_label_widget[index]));
+    if (strstr(p, "not") != NULL)
+    {
+        name[0] = 'A'+index; // get last char
+        name[1] = ':';
+        name[2] = '\0';
+    }
+    else
+    {
+        name[0] = 'n';
+        name[1] = 'o';
+        name[2] = 't';
+        name[3] = 'A'+index;
+        name[4] = '\0';
+    }
+    gtk_label_set_text(GTK_LABEL(g_label_widget[index]), name);
+    
+    // update the function
+    cb_changed(NULL, NULL);
+	
+	return FALSE;
+}
+
 // caller must make sure that the nr of entries in tag_list fits into the table
 static void create_logical_variable_widgets(GtkTable* table, GSList* var_list, GSList* var_value_list, gint table_width, gint table_height)
 {
     GtkListStore    *store;
     GtkTreeIter      iter;
     GtkCellRenderer *cell;
+    gchar name[10] = "A:";
 
     LOGPRINTF("enter");
 
     {
         LOGPRINTF("Adding %s", (char*)p->data);
         gtk_list_store_append( store, &iter );
-        gtk_list_store_set( store, &iter, 0, (char*)p->data, -1 );
+        gchar *p_tag = (gchar*)p->data;
+        if (p_tag[0] == '!') p_tag++;
+        gtk_list_store_set( store, &iter, 0, p_tag, -1 );
     }
 
     // Create the combo boxes
         for(y=0; y < table_height; y++)
         {
             int index = -1;
-            gchar name[3] = "A:";
             
             // hbox
             GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
+			// event box
+			GtkWidget *event_box = gtk_event_box_new ();
+            gtk_box_pack_start(GTK_BOX(hbox), event_box, FALSE, TRUE, 0);
+			gtk_widget_show (event_box);
+			
             name[0] = 'A'+n;
-            GtkWidget *label_widget = gtk_label_new(name);
-            gtk_box_pack_start(GTK_BOX(hbox), label_widget, FALSE, TRUE, 0);
-            gtk_widget_show(label_widget);
+            name[1] = '\0';
+            g_label_widget[n] = gtk_label_new(name);
+            gtk_container_add (GTK_CONTAINER (event_box), g_label_widget[n]);
+            gtk_widget_show(g_label_widget[n]);
             
-            /* Create combo box with store as data source. */
+			/* And bind an action to it */
+			gtk_widget_set_events (event_box, GDK_BUTTON_PRESS_MASK);
+			gtk_signal_connect (GTK_OBJECT(event_box), "button_press_event",
+								GTK_SIGNAL_FUNC (on_label_clicked), (gpointer)(n+1));
+			/* Create combo box with store as data source. */
             widget = gtk_combo_box_new_with_model( GTK_TREE_MODEL( store ) );
 
             /* Create cell renderer. */
             if (q)
             {
                 q = convert_system_tag_to_name(g_strdup(q)); // need to supply copy, since q is deleted when it matches a system-'filter'
-                LOGPRINTF("Looking for:[%d]%s", n, q);
+                ERRORPRINTF("Looking for:[%d]%s", n, q);
                 index = 0;
                 p = (GList *) var_list;
+                gchar *p_tag = q;
+                if (p_tag[0] == '!') p_tag++;
                 for (i = 0; i < n_tags; i++, p = p->next)
                 {
-                    if (strcmp((char*)p->data, q) == 0) break;
+                    if (strcmp((gchar*)p->data, p_tag) == 0) break;
+                }
+                {
+                    if (q[0] == '!')
+                    {
+                        name[0] = 'n';
+                        name[1] = 'o';
+                        name[2] = 't';
+                        name[3] = 'A'+n;
+                        name[4] = '\0';
+                        gtk_label_set_text(GTK_LABEL(g_label_widget[n]), name);
+                    }
                 }
                 if (i < n_tags) index = i+1;// first element is empty string, skip it
                 g_free(q);
             }
-            LOGPRINTF("Using:%d", index);
+            ERRORPRINTF("Using:%d", index);
             gtk_combo_box_set_active(GTK_COMBO_BOX(widget), index); 
             
             /* Connect signal to tour handler function */