Minor redesign to text events window

This makes it more consistent with the other settings windows

- Use editable cell for entry
- Use pane to resize both treeviews
- Make preview fixed size and on bottom
- Enable search for event name
This commit is contained in:
TingPing 2014-02-18 15:42:10 -05:00
parent dd128ce534
commit e6e5659b11
1 changed files with 153 additions and 97 deletions

View File

@ -43,14 +43,13 @@ extern char *pntevts_text[];
extern char *pntevts[]; extern char *pntevts[];
static GtkWidget *pevent_dialog = NULL, *pevent_dialog_twid, static GtkWidget *pevent_dialog = NULL, *pevent_dialog_twid,
*pevent_dialog_entry,
*pevent_dialog_list, *pevent_dialog_hlist; *pevent_dialog_list, *pevent_dialog_hlist;
enum enum
{ {
COL_EVENT_NAME, EVENT_COLUMN,
COL_EVENT_TEXT, TEXT_COLUMN,
COL_ROW, ROW_COLUMN,
N_COLUMNS N_COLUMNS
}; };
@ -149,21 +148,23 @@ pevent_dialog_close (GtkWidget *wid, gpointer arg)
} }
static void static void
pevent_dialog_update (GtkWidget * wid, GtkWidget * twid) pevent_edited (GtkCellRendererText *render, gchar *pathstr, gchar *new_text, gpointer data)
{ {
GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (pevent_dialog_list));
GtkTreePath *path;
GtkTreeIter iter;
GtkXText *xtext = GTK_XTEXT (pevent_dialog_twid);
int len, m; int len, m;
const char *text; const char *text;
char *out; char *out;
int sig; int sig;
GtkTreeIter iter;
GtkListStore *store;
if (!gtkutil_treeview_get_selected (GTK_TREE_VIEW (pevent_dialog_list), if (!gtkutil_treeview_get_selected (GTK_TREE_VIEW (pevent_dialog_list),
&iter, COL_ROW, &sig, -1)) &iter, ROW_COLUMN, &sig, -1))
return; return;
text = gtk_entry_get_text (GTK_ENTRY (wid)); text = new_text;
len = strlen (text); len = strlen (new_text);
if (pevt_build_string (text, &out, &m) != 0) if (pevt_build_string (text, &out, &m) != 0)
{ {
@ -182,8 +183,10 @@ pevent_dialog_update (GtkWidget * wid, GtkWidget * twid)
return; return;
} }
store = (GtkListStore *)gtk_tree_view_get_model (GTK_TREE_VIEW (pevent_dialog_list)); path = gtk_tree_path_new_from_string (pathstr);
gtk_list_store_set (store, &iter, COL_EVENT_TEXT, text, -1); gtk_tree_model_get_iter (model, &iter, path);
gtk_list_store_set (GTK_LIST_STORE (model), &iter, TEXT_COLUMN, new_text, -1);
gtk_tree_path_free (path);
if (pntevts_text[sig]) if (pntevts_text[sig])
free (pntevts_text[sig]); free (pntevts_text[sig]);
@ -200,9 +203,12 @@ pevent_dialog_update (GtkWidget * wid, GtkWidget * twid)
out[len + 1] = 0; out[len + 1] = 0;
check_special_chars (out, TRUE); check_special_chars (out, TRUE);
PrintTextRaw (GTK_XTEXT (twid)->buffer, out, 0, 0); PrintTextRaw (xtext->buffer, out, 0, 0);
free (out); free (out);
/* Scroll to bottom */
gtk_adjustment_set_value (xtext->adj, gtk_adjustment_get_upper (xtext->adj));
/* save this when we exit */ /* save this when we exit */
prefs.save_pevents = 1; prefs.save_pevents = 1;
} }
@ -215,8 +221,9 @@ pevent_dialog_hfill (GtkWidget * list, int e)
GtkTreeIter iter; GtkTreeIter iter;
GtkListStore *store; GtkListStore *store;
store = (GtkListStore *)gtk_tree_view_get_model (GTK_TREE_VIEW (pevent_dialog_hlist)); store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (list)));
gtk_list_store_clear (store); gtk_list_store_clear (store);
while (i < (te[e].num_args & 0x7f)) while (i < (te[e].num_args & 0x7f))
{ {
text = _(te[e].help[i]); text = _(te[e].help[i]);
@ -230,32 +237,20 @@ pevent_dialog_hfill (GtkWidget * list, int e)
} }
static void static void
pevent_dialog_unselect (void) pevent_selection_changed (GtkTreeSelection *sel, gpointer userdata)
{ {
gtk_entry_set_text (GTK_ENTRY (pevent_dialog_entry), "");
gtk_list_store_clear ((GtkListStore *)gtk_tree_view_get_model (GTK_TREE_VIEW (pevent_dialog_hlist)));
}
static void
pevent_dialog_select (GtkTreeSelection *sel, gpointer store)
{
char *text;
int sig;
GtkTreeIter iter; GtkTreeIter iter;
int sig;
if (!gtkutil_treeview_get_selected (GTK_TREE_VIEW (pevent_dialog_list), if (!gtkutil_treeview_get_selected (GTK_TREE_VIEW (pevent_dialog_list),
&iter, COL_ROW, &sig, -1)) &iter, ROW_COLUMN, &sig, -1))
{ {
pevent_dialog_unselect (); gtk_list_store_clear (GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (pevent_dialog_hlist))));
return;
} }
else
{
gtk_tree_model_get (store, &iter, COL_EVENT_TEXT, &text, -1);
gtk_entry_set_text (GTK_ENTRY (pevent_dialog_entry), text);
g_free (text);
pevent_dialog_hfill (pevent_dialog_hlist, sig); pevent_dialog_hfill (pevent_dialog_hlist, sig);
} }
}
static void static void
pevent_dialog_fill (GtkWidget *list) pevent_dialog_fill (GtkWidget *list)
@ -264,7 +259,7 @@ pevent_dialog_fill (GtkWidget * list)
GtkListStore *store; GtkListStore *store;
GtkTreeIter iter; GtkTreeIter iter;
store = (GtkListStore *)gtk_tree_view_get_model (GTK_TREE_VIEW (list)); store = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (list)));
gtk_list_store_clear (store); gtk_list_store_clear (store);
i = NUM_XP; i = NUM_XP;
@ -272,9 +267,9 @@ pevent_dialog_fill (GtkWidget * list)
{ {
i--; i--;
gtk_list_store_insert_with_values (store, &iter, 0, gtk_list_store_insert_with_values (store, &iter, 0,
COL_EVENT_NAME, te[i].name, EVENT_COLUMN, te[i].name,
COL_EVENT_TEXT, pntevts_text[i], TEXT_COLUMN, pntevts_text[i],
COL_ROW, i, -1); ROW_COLUMN, i, -1);
} }
while (i != 0); while (i != 0);
} }
@ -306,7 +301,6 @@ pevent_load_req_cb (void *arg1, char *file)
pevent_load (file); pevent_load (file);
pevent_make_pntevts (); pevent_make_pntevts ();
pevent_dialog_fill (pevent_dialog_list); pevent_dialog_fill (pevent_dialog_list);
pevent_dialog_unselect ();
prefs.save_pevents = 1; prefs.save_pevents = 1;
} }
} }
@ -345,12 +339,109 @@ pevent_test_cb (GtkWidget * wid, GtkWidget * twid)
} }
} }
static GtkWidget *
pevent_treeview_new (GtkWidget *box)
{
GtkWidget *scroll;
GtkListStore *store;
GtkTreeViewColumn *col;
GtkTreeSelection *sel;
GtkWidget *view;
GtkCellRenderer *render;
scroll = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN);
gtk_widget_set_size_request (GTK_WIDGET (scroll), -1, 250);
store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT);
g_return_val_if_fail (store != NULL, NULL);
view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
gtk_tree_view_set_fixed_height_mode (GTK_TREE_VIEW (view), TRUE);
gtk_tree_view_set_enable_search (GTK_TREE_VIEW (view), TRUE);
gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (view), TRUE);
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (view));
g_signal_connect (G_OBJECT (sel), "changed",
G_CALLBACK (pevent_selection_changed), NULL);
render = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (
GTK_TREE_VIEW (view), EVENT_COLUMN,
_("Event"), render,
"text", EVENT_COLUMN,
NULL);
render = gtk_cell_renderer_text_new ();
g_object_set (render, "editable", TRUE, NULL);
g_signal_connect (G_OBJECT (render), "edited",
G_CALLBACK (pevent_edited), NULL);
gtk_tree_view_insert_column_with_attributes (
GTK_TREE_VIEW (view), TEXT_COLUMN,
_("Text"), render,
"text", TEXT_COLUMN,
NULL);
col = gtk_tree_view_get_column (GTK_TREE_VIEW (view), EVENT_COLUMN);
gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_tree_view_column_set_resizable (col, TRUE);
gtk_tree_view_column_set_min_width (col, 100);
gtk_container_add (GTK_CONTAINER (scroll), view);
gtk_container_add (GTK_CONTAINER (box), scroll);
return view;
}
static GtkWidget *
pevent_hlist_treeview_new (GtkWidget *box)
{
GtkWidget *scroll;
GtkListStore *store;
GtkTreeViewColumn *col;
GtkWidget *view;
GtkCellRenderer *render;
scroll = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN);
store = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING);
g_return_val_if_fail (store != NULL, NULL);
view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
gtk_tree_view_set_fixed_height_mode (GTK_TREE_VIEW (view), TRUE);
gtk_tree_view_set_enable_search (GTK_TREE_VIEW (view), FALSE);
gtk_widget_set_can_focus (view, FALSE);
render = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (
GTK_TREE_VIEW (view), 0,
_("$ Number"), render,
"text", 0,
NULL);
render = gtk_cell_renderer_text_new ();
gtk_tree_view_insert_column_with_attributes (
GTK_TREE_VIEW (view), 1,
_("Description"), render,
"text", 1,
NULL);
col = gtk_tree_view_get_column (GTK_TREE_VIEW (view), 0);
gtk_tree_view_column_set_sizing (col, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
gtk_container_add (GTK_CONTAINER (scroll), view);
gtk_container_add (GTK_CONTAINER (box), scroll);
return view;
}
void void
pevent_dialog_show () pevent_dialog_show ()
{ {
GtkWidget *vbox, *hbox, *tbox, *wid, *bh, *th; GtkWidget *vbox, *hbox, *wid, *pane;
GtkListStore *store, *hstore;
GtkTreeSelection *sel;
if (pevent_dialog) if (pevent_dialog)
{ {
@ -363,70 +454,35 @@ pevent_dialog_show ()
TRUE, FALSE, pevent_dialog_close, NULL, TRUE, FALSE, pevent_dialog_close, NULL,
600, 455, &vbox, 0); 600, 455, &vbox, 0);
wid = gtk_vpaned_new (); pane = gtk_vpaned_new ();
th = gtk_vbox_new (0, 2); gtk_box_pack_start (GTK_BOX (vbox), pane, TRUE, TRUE, 0);
bh = gtk_vbox_new (0, 2);
gtk_widget_show (th);
gtk_widget_show (bh);
gtk_paned_pack1 (GTK_PANED (wid), th, 1, 1);
gtk_paned_pack2 (GTK_PANED (wid), bh, 0, 1);
gtk_box_pack_start (GTK_BOX (vbox), wid, 1, 1, 0);
store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, pevent_dialog_list = pevent_treeview_new (pane);
G_TYPE_STRING, G_TYPE_INT); pevent_dialog_fill (pevent_dialog_list);
pevent_dialog_list = gtkutil_treeview_new (th, GTK_TREE_MODEL (store), NULL,
COL_EVENT_NAME, _("Event"),
COL_EVENT_TEXT, _("Text"), -1);
sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (pevent_dialog_list));
g_signal_connect (G_OBJECT (sel), "changed",
G_CALLBACK (pevent_dialog_select), store);
pevent_dialog_twid = gtk_xtext_new (colors, 0); pevent_dialog_hlist = pevent_hlist_treeview_new (pane);
pevent_dialog_entry = gtk_entry_new ();
gtk_entry_set_max_length (GTK_ENTRY (pevent_dialog_entry), 255);
g_signal_connect (G_OBJECT (pevent_dialog_entry), "activate",
G_CALLBACK (pevent_dialog_update), pevent_dialog_twid);
gtk_box_pack_start (GTK_BOX (bh), pevent_dialog_entry, 0, 0, 0);
tbox = gtk_hbox_new (0, 0);
gtk_container_add (GTK_CONTAINER (bh), tbox);
wid = gtk_scrolled_window_new (NULL, NULL); wid = gtk_scrolled_window_new (NULL, NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (wid), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (wid), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
gtk_container_add (GTK_CONTAINER (tbox), wid); gtk_box_pack_start (GTK_BOX (vbox), wid, FALSE, TRUE, 0);
pevent_dialog_twid = gtk_xtext_new (colors, 0);
gtk_widget_set_sensitive (pevent_dialog_twid, FALSE);
gtk_widget_set_size_request (pevent_dialog_twid, -1, 75);
gtk_container_add (GTK_CONTAINER (wid), pevent_dialog_twid); gtk_container_add (GTK_CONTAINER (wid), pevent_dialog_twid);
gtk_xtext_set_font (GTK_XTEXT (pevent_dialog_twid), prefs.hex_text_font); gtk_xtext_set_font (GTK_XTEXT (pevent_dialog_twid), prefs.hex_text_font);
hstore = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING);
pevent_dialog_hlist = gtkutil_treeview_new (bh, GTK_TREE_MODEL (hstore),
NULL,
0, _("$ Number"),
1, _("Description"), -1);
pevent_dialog_fill (pevent_dialog_list);
hbox = gtk_hbutton_box_new (); hbox = gtk_hbutton_box_new ();
gtk_box_pack_end (GTK_BOX (vbox), hbox, 0, 0, 2); gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_SPREAD);
/*wid = gtk_button_new_with_label (_("Save")); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 4);
gtk_box_pack_end (GTK_BOX (hbox), wid, 0, 0, 0);
g_signal_connect (G_OBJECT (wid), "clicked",
G_CALLBACK (pevent_save_cb), NULL);
gtk_widget_show (wid);*/
gtkutil_button (hbox, GTK_STOCK_SAVE_AS, NULL, pevent_save_cb, gtkutil_button (hbox, GTK_STOCK_SAVE_AS, NULL, pevent_save_cb,
(void *) 1, _("Save As...")); (void *) 1, _("Save As..."));
gtkutil_button (hbox, GTK_STOCK_OPEN, NULL, pevent_load_cb, gtkutil_button (hbox, GTK_STOCK_OPEN, NULL, pevent_load_cb,
(void *) 0, _("Load From...")); NULL, _("Load From..."));
wid = gtk_button_new_with_label (_("Test All")); gtkutil_button (hbox, NULL, NULL, pevent_test_cb,
gtk_box_pack_end (GTK_BOX (hbox), wid, 0, 0, 0); pevent_dialog_twid, _("Test All"));
g_signal_connect (G_OBJECT (wid), "clicked", gtkutil_button (hbox, GTK_STOCK_OK, NULL, pevent_ok_cb,
G_CALLBACK (pevent_test_cb), pevent_dialog_twid); NULL, _("OK"));
wid = gtk_button_new_from_stock (GTK_STOCK_OK);
gtk_box_pack_start (GTK_BOX (hbox), wid, 0, 0, 0);
g_signal_connect (G_OBJECT (wid), "clicked",
G_CALLBACK (pevent_ok_cb), NULL);
gtk_widget_show_all (pevent_dialog); gtk_widget_show_all (pevent_dialog);
} }