Copy manuals adapted
[sgc.git] / signals-editor.c
blobe68a64233720d1aa152a6a8d6d0678ae6adcd5f4
1 #include "sgc.h"
2 #include "signals-editor.h"
4 gchar * checkPinyin(gchar *pinyin) {
5 gchar **result;
6 g_ascii_strdown(pinyin, -1);
7 g_strcanon(pinyin, "#012345abcdefghijklmnopqrstuvwxyz\n", '-');
8 result = g_strsplit(pinyin, "-", MAXTESTS * 2);
9 g_free(pinyin);
10 pinyin = g_strjoinv(NULL, result);
11 return pinyin;
14 void on_buttonAddAdd_clicked (GtkWidget *entry, gpointer data)
16 gchar *processed = checkPinyin(g_strdup(gtk_entry_get_text(GTK_ENTRY(entry))));
17 add_entry(processed);
20 void add_entry(gchar *txt) {
21 /* ignore if entry is empty */
22 if (txt && *txt)
24 GtkTreeIter newrow;
26 gtk_list_store_append(GTK_LIST_STORE(liststore), &newrow);
28 gtk_list_store_set(GTK_LIST_STORE(liststore), &newrow, COL_TEXT, txt, -1);
29 // g_free(txt);
31 if (treevalid == FALSE) {
32 treevalid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore), &mainIter);
34 updateWidgets();
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);
49 updateWidgets();
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)) {
58 updateWidgets();
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);
66 GtkTreeIter iter;
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);
70 updateWidgets();
73 gboolean on_treeother() {
74 treevalid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore), &mainIter);
75 updateWidgets();
76 return false;
79 void on_buttonSave_clicked(GtkWidget *filechooser, gpointer data) {
80 gchar *basenamenoext;
81 gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(filechooser));
82 fileSave(filename);
83 fileOpen(filename);
84 g_free(filename);
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);
100 g_free(filename);
101 filename = g_strjoin(NULL, currentDir, G_DIR_SEPARATOR_S, WORDLISTS, G_DIR_SEPARATOR_S, basenamenoext, G_DIR_SEPARATOR_S, "wordlist.txt", NULL);
102 g_free(currentDir);
103 g_free(basename);
104 g_free(basenamenoext);
105 gtk_widget_unrealize(glade_xml_get_widget(xml, "menuWordlists"));
108 fileOpen(filename);
109 g_free(filename);
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);
121 clear(NULL);
122 setBase(g_path_get_dirname(filename));
123 setFile(filename);
124 if (g_access(base, F_OK) != 0) {
125 g_mkdir_with_parents(base, 0755);
128 if (g_access(file, F_OK) == 0) {
129 fileOpen(file);
130 } else {
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"));