2 #include "signals-editor.h"
4 gchar
* checkPinyin(gchar
*pinyin
) {
6 g_ascii_strdown(pinyin
, -1);
7 g_strcanon(pinyin
, "#012345abcdefghijklmnopqrstuvwxyz\n", '-');
8 result
= g_strsplit(pinyin
, "-", MAXTESTS
* 2);
10 pinyin
= g_strjoinv(NULL
, result
);
14 void on_buttonAddAdd_clicked (GtkWidget
*entry
, gpointer data
)
16 gchar
*processed
= checkPinyin(g_strdup(gtk_entry_get_text(GTK_ENTRY(entry
))));
20 void add_entry(gchar
*txt
) {
21 /* ignore if entry is empty */
26 gtk_list_store_append(GTK_LIST_STORE(liststore
), &newrow
);
28 gtk_list_store_set(GTK_LIST_STORE(liststore
), &newrow
, COL_TEXT
, txt
, -1);
31 if (treevalid
== FALSE
) {
32 treevalid
= gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore
), &mainIter
);
38 void remove_entry (GtkWidget
*treeview
, gpointer data
)
40 GtkTreeSelection
*sel
;
41 GtkTreeIter selected_row
;
43 sel
= gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview
));
45 if (gtk_tree_selection_get_selected(sel
, &liststore
, &selected_row
))
47 gtk_list_store_remove(GTK_LIST_STORE(liststore
), &selected_row
);
48 treevalid
= gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore
), &mainIter
);
53 void on_treeviewWords_cursor_changed(GtkTreeView
*treeview
, gpointer user_data
) {
54 GtkTreeSelection
*sel
;
55 sel
= gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview
));
57 if (gtk_tree_selection_get_selected(sel
, &liststore
, &mainIter
)) {
62 void on_treeview_edited (GtkCellRendererText
*celltext
,
63 const gchar
*string_path
, const gchar
*new_text
, gpointer data
) {
65 GtkTreeModel
*model
= GTK_TREE_MODEL(data
);
67 gtk_tree_model_get_iter_from_string(model
, &iter
, string_path
);
68 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
, COL_TEXT
, new_text
, -1);
69 treevalid
= gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore
), &mainIter
);
73 gboolean
on_treeother() {
74 treevalid
= gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore
), &mainIter
);
79 void on_buttonSave_clicked(GtkWidget
*filechooser
, gpointer data
) {
81 gchar
*filename
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(filechooser
));
88 void on_buttonOpen_clicked(GtkWidget
*filechooser
, gpointer data
) {
89 /* Eerst vragen oude op te slaan ? */
91 gchar
*filename
= gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(filechooser
));
93 if (g_str_has_suffix(filename
, ".sgc") || g_str_has_suffix(filename
, ".SGC")) {
94 if (openSGC(filename
)) {
95 gchar
*basename
= g_path_get_basename(filename
);
96 int end
= strlen(basename
)-3;
97 gchar
*basenamenoext
= g_malloc(end
* sizeof(gchar
));
98 gchar
*currentDir
= g_get_current_dir();
99 g_strlcpy(basenamenoext
, basename
, end
);
101 filename
= g_strjoin(NULL
, currentDir
, G_DIR_SEPARATOR_S
, WORDLISTS
, G_DIR_SEPARATOR_S
, basenamenoext
, G_DIR_SEPARATOR_S
, "wordlist.txt", NULL
);
104 g_free(basenamenoext
);
105 gtk_widget_unrealize(glade_xml_get_widget(xml
, "menuWordlists"));
112 void on_buttonSaveDistribution_clicked(GtkWidget
*entry
, gpointer data
) {
113 if (GTK_ENTRY(entry
)) {
114 saveSGC(gtk_entry_get_text(GTK_ENTRY(entry
)), base
);
117 void on_buttonSaveNew_clicked(GtkWidget
*entry
, gpointer data
) {
118 if (GTK_ENTRY(entry
)) {
119 gchar
*currentDir
= g_get_current_dir();
120 gchar
*filename
= g_strjoin(NULL
, currentDir
, G_DIR_SEPARATOR_S
, WORDLISTS
, G_DIR_SEPARATOR_S
, gtk_entry_get_text(GTK_ENTRY(entry
)), G_DIR_SEPARATOR_S
, "wordlist.txt", NULL
);
122 setBase(g_path_get_dirname(filename
));
124 if (g_access(base
, F_OK
) != 0) {
125 g_mkdir_with_parents(base
, 0755);
128 if (g_access(file
, F_OK
) == 0) {
131 gtk_window_set_title(GTK_WINDOW(glade_xml_get_widget(xml
, "windowWordlist")), file
);
132 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(glade_xml_get_widget(xml
, "filechooserdialogWordlist")), file
);
133 fclose(g_fopen(file
, "w"));
134 gtk_widget_unrealize(glade_xml_get_widget(xml
, "menuWordlists"));