Implement first draft of cell search
This commit is contained in:
parent
9f2544ee94
commit
8306c34292
@ -82,19 +82,48 @@
|
|||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkScrolledWindow">
|
<object class="GtkBox">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">False</property>
|
||||||
<property name="hscrollbar_policy">never</property>
|
<property name="orientation">vertical</property>
|
||||||
<property name="shadow_type">in</property>
|
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkTreeView" id="cell-tree">
|
<object class="GtkSearchEntry" id="cell-search">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<child internal-child="selection">
|
<property name="primary_icon_name">edit-find-symbolic</property>
|
||||||
<object class="GtkTreeSelection"/>
|
<property name="primary_icon_activatable">False</property>
|
||||||
|
<property name="primary_icon_sensitive">False</property>
|
||||||
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">False</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">0</property>
|
||||||
|
</packing>
|
||||||
|
</child>
|
||||||
|
<child>
|
||||||
|
<object class="GtkScrolledWindow">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="hscrollbar_policy">never</property>
|
||||||
|
<property name="shadow_type">in</property>
|
||||||
|
<child>
|
||||||
|
<object class="GtkTreeView" id="cell-tree">
|
||||||
|
<property name="visible">True</property>
|
||||||
|
<property name="can_focus">True</property>
|
||||||
|
<property name="headers_clickable">False</property>
|
||||||
|
<property name="enable_search">False</property>
|
||||||
|
<property name="enable_grid_lines">both</property>
|
||||||
|
<child internal-child="selection">
|
||||||
|
<object class="GtkTreeSelection"/>
|
||||||
|
</child>
|
||||||
|
</object>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
|
<packing>
|
||||||
|
<property name="expand">True</property>
|
||||||
|
<property name="fill">True</property>
|
||||||
|
<property name="position">1</property>
|
||||||
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
|
@ -45,6 +45,7 @@ struct open_button_data {
|
|||||||
GList **list_ptr;
|
GList **list_ptr;
|
||||||
GtkTreeStore *cell_store;
|
GtkTreeStore *cell_store;
|
||||||
GtkListBox *layer_box;
|
GtkListBox *layer_box;
|
||||||
|
GtkSearchEntry *search_entry;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -112,6 +113,7 @@ static void on_load_gds(gpointer button, gpointer user)
|
|||||||
char *filename;
|
char *filename;
|
||||||
GString *mod_date;
|
GString *mod_date;
|
||||||
GString *acc_date;
|
GString *acc_date;
|
||||||
|
GdkRGBA cell_text_color;
|
||||||
|
|
||||||
open_dialog = gtk_file_chooser_dialog_new("Open GDSII File", ptr->main_window, GTK_FILE_CHOOSER_ACTION_OPEN,
|
open_dialog = gtk_file_chooser_dialog_new("Open GDSII File", ptr->main_window, GTK_FILE_CHOOSER_ACTION_OPEN,
|
||||||
"Cancel", GTK_RESPONSE_CANCEL, "Open GDSII", GTK_RESPONSE_ACCEPT, NULL);
|
"Cancel", GTK_RESPONSE_CANCEL, "Open GDSII", GTK_RESPONSE_ACCEPT, NULL);
|
||||||
@ -172,10 +174,20 @@ static void on_load_gds(gpointer button, gpointer user)
|
|||||||
mod_date = generate_string_from_date(&gds_c->mod_time);
|
mod_date = generate_string_from_date(&gds_c->mod_time);
|
||||||
acc_date = generate_string_from_date(&gds_c->access_time);
|
acc_date = generate_string_from_date(&gds_c->access_time);
|
||||||
|
|
||||||
|
cell_text_color.alpha = 1;
|
||||||
|
cell_text_color.red = (double)61.0/(double)255.0;
|
||||||
|
cell_text_color.green = (double)152.0/(double)255.0;
|
||||||
|
cell_text_color.blue = 0.0;
|
||||||
|
|
||||||
|
/* Add cell to tree store model
|
||||||
|
* CELL_SEL_CELL_COLOR will always be green,
|
||||||
|
* because no cell cehcker is implemented, yet.
|
||||||
|
*/
|
||||||
gtk_tree_store_set (store, &celliter,
|
gtk_tree_store_set (store, &celliter,
|
||||||
CELL_SEL_CELL, gds_c,
|
CELL_SEL_CELL, gds_c,
|
||||||
CELL_SEL_MODDATE, mod_date->str,
|
CELL_SEL_MODDATE, mod_date->str,
|
||||||
CELL_SEL_ACCESSDATE, acc_date->str,
|
CELL_SEL_ACCESSDATE, acc_date->str,
|
||||||
|
CELL_SEL_CELL_COLOR, &cell_text_color, // TODO: implement cell checker
|
||||||
-1);
|
-1);
|
||||||
|
|
||||||
/* Delete GStrings including string data. */
|
/* Delete GStrings including string data. */
|
||||||
@ -328,6 +340,7 @@ GtkWindow *create_main_window()
|
|||||||
GtkTreeStore *cell_store;
|
GtkTreeStore *cell_store;
|
||||||
GtkWidget *listbox;
|
GtkWidget *listbox;
|
||||||
GtkWidget *conv_button;
|
GtkWidget *conv_button;
|
||||||
|
GtkWidget *search_entry;
|
||||||
static GList *gds_libs;
|
static GList *gds_libs;
|
||||||
static struct open_button_data open_data;
|
static struct open_button_data open_data;
|
||||||
static struct convert_button_data conv_data;
|
static struct convert_button_data conv_data;
|
||||||
@ -338,7 +351,9 @@ GtkWindow *create_main_window()
|
|||||||
|
|
||||||
|
|
||||||
cell_tree = GTK_TREE_VIEW(gtk_builder_get_object(main_builder, "cell-tree"));
|
cell_tree = GTK_TREE_VIEW(gtk_builder_get_object(main_builder, "cell-tree"));
|
||||||
cell_store = setup_cell_selector(cell_tree);
|
search_entry = GTK_WIDGET(gtk_builder_get_object(main_builder, "cell-search"));
|
||||||
|
open_data.search_entry = GTK_SEARCH_ENTRY(search_entry);
|
||||||
|
cell_store = setup_cell_selector(cell_tree, GTK_ENTRY(search_entry));
|
||||||
|
|
||||||
|
|
||||||
open_data.cell_store = cell_store;
|
open_data.cell_store = cell_store;
|
||||||
@ -371,6 +386,8 @@ GtkWindow *create_main_window()
|
|||||||
g_signal_connect(G_OBJECT(gtk_tree_view_get_selection(cell_tree)), "changed",
|
g_signal_connect(G_OBJECT(gtk_tree_view_get_selection(cell_tree)), "changed",
|
||||||
G_CALLBACK(cell_selection_changed), conv_button);
|
G_CALLBACK(cell_selection_changed), conv_button);
|
||||||
|
|
||||||
|
g_object_unref(main_builder);
|
||||||
|
|
||||||
return (conv_data.main_window);
|
return (conv_data.main_window);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,12 +60,79 @@ static gboolean tree_sel_func(GtkTreeSelection *selection,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief tree_sel_search_func
|
||||||
|
* @param model Tree model
|
||||||
|
* @param column Column id
|
||||||
|
* @param key Search key
|
||||||
|
* @param iter Iterator
|
||||||
|
* @param search_data User data. In this case always NULL
|
||||||
|
* @return returns false (!) if matches
|
||||||
|
*/
|
||||||
|
static gboolean tree_sel_search_func(GtkTreeModel *model, gint column, const gchar *key, GtkTreeIter *iter, gpointer *search_data)
|
||||||
|
{
|
||||||
|
(void)search_data;
|
||||||
|
(void)column;
|
||||||
|
struct gds_cell *cell;
|
||||||
|
struct gds_library *lib;
|
||||||
|
GtkTreePath *path;
|
||||||
|
GtkTreeIter lib_iter;
|
||||||
|
char *lib_str = NULL, *cell_str = NULL, *div_str = NULL, *key_copy;
|
||||||
|
gboolean result = TRUE;
|
||||||
|
|
||||||
|
gtk_tree_model_get(model, iter, CELL_SEL_CELL, &cell, -1);
|
||||||
|
path = gtk_tree_model_get_path(model, iter);
|
||||||
|
|
||||||
|
/* Libraries not selectable */
|
||||||
|
if (!cell)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
if (!gtk_tree_path_up(path)) {
|
||||||
|
gtk_tree_path_free(path);
|
||||||
|
printf("Cell without parent library found during search! Somethings really wrong!!!\n");
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Find name of parent library */
|
||||||
|
gtk_tree_model_get_iter(model, &lib_iter, path);
|
||||||
|
gtk_tree_model_get(model, &lib_iter, CELL_SEL_LIBRARY, &lib, -1);
|
||||||
|
gtk_tree_path_free(path);
|
||||||
|
|
||||||
|
if (!lib) {
|
||||||
|
printf("Parent library invalid!\n");
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Search for Library/Cell division operator */
|
||||||
|
key_copy = strdup(key);
|
||||||
|
if (!key_copy)
|
||||||
|
goto abort_search;
|
||||||
|
|
||||||
|
if ((div_str = strstr(key_copy, ":"))) {
|
||||||
|
lib_str = key_copy;
|
||||||
|
*div_str = 0x00;
|
||||||
|
cell_str = div_str + 1;
|
||||||
|
|
||||||
|
if (!strncmp(lib_str, lib->name, sizeof(lib->name))) {
|
||||||
|
if (!strncmp(cell_str, cell->name, sizeof(cell->name)))
|
||||||
|
result = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
result = (strncmp(key, cell->name, sizeof(cell->name)) ? TRUE : FALSE);
|
||||||
|
}
|
||||||
|
|
||||||
|
abort_search:
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Setup a GtkTreeView with the necessary columns
|
* @brief Setup a GtkTreeView with the necessary columns
|
||||||
* @param view Tree view to set up
|
* @param view Tree view to set up
|
||||||
|
* @param search_entry Entry field for search
|
||||||
* @return TreeStore for storing data inside the GtkTreeView
|
* @return TreeStore for storing data inside the GtkTreeView
|
||||||
*/
|
*/
|
||||||
GtkTreeStore *setup_cell_selector(GtkTreeView* view)
|
GtkTreeStore *setup_cell_selector(GtkTreeView* view, GtkEntry *search_entry)
|
||||||
{
|
{
|
||||||
GtkTreeStore *cell_store;
|
GtkTreeStore *cell_store;
|
||||||
|
|
||||||
@ -73,40 +140,19 @@ GtkTreeStore *setup_cell_selector(GtkTreeView* view)
|
|||||||
GtkCellRenderer *render_cell;
|
GtkCellRenderer *render_cell;
|
||||||
GtkCellRenderer *render_lib;
|
GtkCellRenderer *render_lib;
|
||||||
GtkTreeViewColumn *column;
|
GtkTreeViewColumn *column;
|
||||||
GdkRGBA cell_text_color;
|
|
||||||
GValue val = G_VALUE_INIT;
|
|
||||||
|
|
||||||
cell_store = gtk_tree_store_new(CELL_SEL_COLUMN_COUNT, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING);
|
cell_store = gtk_tree_store_new(CELL_SEL_COLUMN_COUNT, G_TYPE_POINTER, G_TYPE_POINTER, GDK_TYPE_RGBA, G_TYPE_STRING, G_TYPE_STRING);
|
||||||
gtk_tree_view_set_model(view, GTK_TREE_MODEL(cell_store));
|
gtk_tree_view_set_model(view, GTK_TREE_MODEL(cell_store));
|
||||||
|
|
||||||
render_dates = gtk_cell_renderer_text_new();
|
render_dates = gtk_cell_renderer_text_new();
|
||||||
render_cell = lib_cell_renderer_new();
|
render_cell = lib_cell_renderer_new();
|
||||||
render_lib = lib_cell_renderer_new();
|
render_lib = lib_cell_renderer_new();
|
||||||
|
|
||||||
/* Set foreground color for cell column */
|
|
||||||
cell_text_color.alpha = 1;
|
|
||||||
cell_text_color.red = (double)61.0/(double)255.0;
|
|
||||||
cell_text_color.green = (double)152.0/(double)255.0;
|
|
||||||
cell_text_color.blue = 0.0;
|
|
||||||
|
|
||||||
g_value_init(&val, G_TYPE_BOOLEAN);
|
|
||||||
g_value_set_boolean(&val, TRUE);
|
|
||||||
g_object_set_property(G_OBJECT(render_cell), "foreground-set", &val);
|
|
||||||
g_value_unset(&val);
|
|
||||||
|
|
||||||
g_value_init(&val, GDK_TYPE_RGBA);
|
|
||||||
g_value_set_boxed(&val, &cell_text_color);
|
|
||||||
g_object_set_property(G_OBJECT(render_cell), "foreground-rgba", &val);
|
|
||||||
g_value_unset(&val);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
column = gtk_tree_view_column_new_with_attributes("Library", render_lib, "gds-lib", CELL_SEL_LIBRARY, NULL);
|
column = gtk_tree_view_column_new_with_attributes("Library", render_lib, "gds-lib", CELL_SEL_LIBRARY, NULL);
|
||||||
gtk_tree_view_append_column(view, column);
|
gtk_tree_view_append_column(view, column);
|
||||||
|
|
||||||
/* Cell color: #3D9801 */
|
/* Cell color: #3D9801 */
|
||||||
column = gtk_tree_view_column_new_with_attributes("Cell", render_cell, "gds-cell", CELL_SEL_CELL, NULL);
|
column = gtk_tree_view_column_new_with_attributes("Cell", render_cell, "gds-cell", CELL_SEL_CELL, "foreground-rgba", CELL_SEL_CELL_COLOR, NULL);
|
||||||
gtk_tree_view_append_column(view, column);
|
gtk_tree_view_append_column(view, column);
|
||||||
|
|
||||||
column = gtk_tree_view_column_new_with_attributes("Mod. Date", render_dates, "text", CELL_SEL_MODDATE, NULL);
|
column = gtk_tree_view_column_new_with_attributes("Mod. Date", render_dates, "text", CELL_SEL_MODDATE, NULL);
|
||||||
@ -119,6 +165,14 @@ GtkTreeStore *setup_cell_selector(GtkTreeView* view)
|
|||||||
* This prevents selecting a library */
|
* This prevents selecting a library */
|
||||||
gtk_tree_selection_set_select_function(gtk_tree_view_get_selection(view), tree_sel_func, NULL, NULL);
|
gtk_tree_selection_set_select_function(gtk_tree_view_get_selection(view), tree_sel_func, NULL, NULL);
|
||||||
|
|
||||||
|
/* Searching */
|
||||||
|
if (search_entry) {
|
||||||
|
gtk_tree_view_set_enable_search(view, TRUE);
|
||||||
|
gtk_tree_view_set_search_column(view, CELL_SEL_CELL);
|
||||||
|
gtk_tree_view_set_search_equal_func(view, (GtkTreeViewSearchEqualFunc)tree_sel_search_func, NULL, NULL);
|
||||||
|
gtk_tree_view_set_search_entry(view, search_entry);
|
||||||
|
}
|
||||||
|
|
||||||
return cell_store;
|
return cell_store;
|
||||||
}
|
}
|
||||||
/** @} */
|
/** @} */
|
||||||
|
@ -37,12 +37,13 @@
|
|||||||
enum cell_store_columns {
|
enum cell_store_columns {
|
||||||
CELL_SEL_LIBRARY = 0,
|
CELL_SEL_LIBRARY = 0,
|
||||||
CELL_SEL_CELL,
|
CELL_SEL_CELL,
|
||||||
|
CELL_SEL_CELL_COLOR, /**< Cell column color */
|
||||||
CELL_SEL_MODDATE,
|
CELL_SEL_MODDATE,
|
||||||
CELL_SEL_ACCESSDATE,
|
CELL_SEL_ACCESSDATE,
|
||||||
CELL_SEL_COLUMN_COUNT /**< Not a column. Used to determine count of coumns **/
|
CELL_SEL_COLUMN_COUNT /**< Not a column. Used to determine count of coumns **/
|
||||||
};
|
};
|
||||||
|
|
||||||
GtkTreeStore *setup_cell_selector(GtkTreeView* view);
|
GtkTreeStore *setup_cell_selector(GtkTreeView* view, GtkEntry *search_entry);
|
||||||
|
|
||||||
#endif /* __TREE_STORE_H__ */
|
#endif /* __TREE_STORE_H__ */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user