summaryrefslogtreecommitdiff
path: root/linux/toolbar.cpp
diff options
context:
space:
mode:
authorleo2006-03-24 06:05:29 +0000
committerleo2006-03-24 06:05:29 +0000
commitad91d3a5d89bf04a53d8a0467ea9fb927f8f11c2 (patch)
tree8c6bb40e2f5a7ac1fbb092f3ac1f4e3569dd9d39 /linux/toolbar.cpp
parent55f093aa82a6bc6f43c04bb74e4d39ad969ec064 (diff)
Added search box.
git-svn-id: http://svn.leocad.org/trunk@526 c7d43263-9d01-0410-8a33-9dba5d9f93d6
Diffstat (limited to 'linux/toolbar.cpp')
-rw-r--r--linux/toolbar.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/linux/toolbar.cpp b/linux/toolbar.cpp
index 84348be..431fffb 100644
--- a/linux/toolbar.cpp
+++ b/linux/toolbar.cpp
@@ -332,6 +332,14 @@ void fill_piecetree()
}
}
}
+
+ GtkTreeIter iter;
+ gtk_tree_store_append(model, &iter, NULL);
+ gtk_tree_store_set(model, &iter, 0, "Search Results", 1, NULL, -1);
+
+ GtkTreeIter entry;
+ gtk_tree_store_append(GTK_TREE_STORE(model), &entry, &iter);
+ gtk_tree_store_set(GTK_TREE_STORE(model), &entry, 0, "No pieces found", 1, NULL, -1);
}
// Callback for the pieces list.
@@ -420,6 +428,82 @@ void piececombo_add (const char* str)
}
}
+static gint piececombo_key(GtkWidget* widget, GdkEventKey* event)
+{
+ if (event->keyval == GDK_Return)
+ {
+ const gchar* str = gtk_entry_get_text(GTK_ENTRY(pieceentry));
+ PiecesLibrary* Lib = lcGetPiecesLibrary();
+
+ // Save search.
+ int Index = Lib->FindCategoryIndex("Search Results");
+
+ if (Index == -1)
+ {
+ Lib->AddCategory("Search Results", (const char*)str);
+ Index = Lib->GetNumCategories() - 1;
+ }
+ else
+ Lib->SetCategory(Index, "Search Results", (const char*)str);
+
+ // Find search category row.
+ GtkTreeModel* model = gtk_tree_view_get_model(GTK_TREE_VIEW(piecetree));
+ GtkTreeIter iter;
+
+ if (!gtk_tree_model_get_iter_first(model, &iter))
+ return FALSE;
+
+ do
+ {
+ gchar* name;
+ gtk_tree_model_get(model, &iter, 0, &name, -1);
+
+ if (strcmp(name, "Search Results"))
+ continue;
+
+ GtkTreeIter child;
+
+ // Remove all children.
+ while (gtk_tree_model_iter_children(model, &child, &iter))
+ gtk_tree_store_remove(GTK_TREE_STORE(model), &child);
+
+ // Perform search.
+ PtrArray<PieceInfo> SinglePieces, GroupedPieces;
+ Lib->GetCategoryEntries(Index, true, SinglePieces, GroupedPieces);
+
+ // Merge and sort the arrays.
+ SinglePieces += GroupedPieces;
+ SinglePieces.Sort(PiecesSortFunc, NULL);
+
+ // Add results.
+ for (int i = 0; i < SinglePieces.GetSize(); i++)
+ {
+ PieceInfo* Info = SinglePieces[i];
+
+ GtkTreeIter entry;
+ gtk_tree_store_append(GTK_TREE_STORE(model), &entry, &iter);
+ gtk_tree_store_set(GTK_TREE_STORE(model), &entry, 0, Info->m_strDescription, 1, Info, -1);
+ }
+
+ if (SinglePieces.GetSize() == 0)
+ {
+ GtkTreeIter entry;
+ gtk_tree_store_append(GTK_TREE_STORE(model), &entry, &iter);
+ gtk_tree_store_set(GTK_TREE_STORE(model), &entry, 0, "No pieces found", 1, NULL, -1);
+ }
+
+ // Expand results.
+ GtkTreePath* path = gtk_tree_model_get_path(model, &iter);
+ gtk_tree_view_expand_row(GTK_TREE_VIEW(piecetree), path, FALSE);
+ gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(piecetree), path, NULL, TRUE, 0.5f, 0.0f);
+ gtk_tree_path_free(path);
+
+ } while (gtk_tree_model_iter_next(model, &iter));
+ }
+
+ return FALSE;
+}
+
static void piececombo_changed (GtkWidget *widget, gpointer data)
{
PiecesLibrary *pLib = lcGetPiecesLibrary();
@@ -673,6 +757,7 @@ GtkWidget* create_piecebar (GtkWidget *window, GLWindow *share)
gtk_widget_show (pieceentry);
gtk_box_pack_start(GTK_BOX(hbox), pieceentry, TRUE, TRUE, 0);
gtk_signal_connect(GTK_OBJECT(pieceentry), "changed", GTK_SIGNAL_FUNC(piececombo_changed), NULL);
+ gtk_signal_connect(GTK_OBJECT(pieceentry), "key_press_event", GTK_SIGNAL_FUNC(piececombo_key), NULL);
button = gtk_button_new();
gtk_widget_show (button);