Add support for bits per row in config file
authorHugo Villeneuve <hugo@hugovil.com>
Tue, 22 Oct 2013 02:57:28 +0000 (22:57 -0400)
committerHugo Villeneuve <hugo@hugovil.com>
Wed, 6 Nov 2013 02:50:17 +0000 (21:50 -0500)
Also add support for viewing internal and external memory windows
in config file.

These 3 new variables are not yet connected (TODO).

src/app-config.c
src/app-config.h
src/viewmenu.c

index 58f76e5..ba9a18a 100644 (file)
@@ -51,12 +51,17 @@ app_config_init(void)
        cfg->clear_ram_on_file_load = false;
 
        /* UI settings */
-       cfg->layout = UI_LAYOUT1;
        cfg->win_width = 640;
        cfg->win_height = 480;
        cfg->hpane_pos = 100;
        cfg->vpane_pos = 200;
        cfg->main_pane_pos = 200;
+
+       /* View menu options */
+       cfg->layout = UI_LAYOUT1;
+       cfg->view_int_memory = 1;
+       cfg->view_ext_memory = 1;
+       cfg->bits_per_row = 16; /* 8 or 16 */
 }
 
 static int
@@ -83,19 +88,25 @@ app_config_load_from_key_file(GKeyFile *kf)
                                    &cfg->clear_ram_on_file_load);
 
        /* ui */
-       app_config_key_file_get_int(kf, "ui", "layout",  &cfg->layout);
-
-       if ((cfg->layout != UI_LAYOUT1) && (cfg->layout != UI_LAYOUT2)) {
-               log_fail_no_exit("Invalid layout, defaulting to layout 1");
-               cfg->layout = UI_LAYOUT1;
-       }
-
        app_config_key_file_get_int(kf, "ui", "win_width",  &cfg->win_width);
        app_config_key_file_get_int(kf, "ui", "win_height", &cfg->win_height);
        app_config_key_file_get_int(kf, "ui", "hpane_pos",  &cfg->hpane_pos);
        app_config_key_file_get_int(kf, "ui", "vpane_pos",  &cfg->vpane_pos);
        app_config_key_file_get_int(kf, "ui", "main_pane_pos",
                                    &cfg->main_pane_pos);
+
+       /* View */
+       app_config_key_file_get_int(kf, "view", "layout",  &cfg->layout);
+       if ((cfg->layout != UI_LAYOUT1) && (cfg->layout != UI_LAYOUT2)) {
+               log_fail_no_exit("Invalid layout, defaulting to layout 1");
+               cfg->layout = UI_LAYOUT1;
+       }
+       app_config_key_file_get_int(kf, "view", "int_memory",
+                                   &cfg->view_int_memory);
+       app_config_key_file_get_int(kf, "view", "ext_memory",
+                                   &cfg->view_ext_memory);
+       app_config_key_file_get_int(kf, "view", "bits_per_row",
+                                   &cfg->bits_per_row);
 }
 
 static char *
@@ -172,7 +183,6 @@ app_config_save(void)
 
                g_string_append(buf, "\n[ui]\n");
 
-               g_string_append_printf(buf, "layout=%d\n", cfg->layout);
                g_string_append_printf(buf, "win_width=%d\n", cfg->win_width);
                g_string_append_printf(buf, "win_height=%d\n", cfg->win_height);
                g_string_append_printf(buf, "hpane_pos=%d\n", cfg->hpane_pos);
@@ -180,6 +190,15 @@ app_config_save(void)
                g_string_append_printf(buf, "main_pane_pos=%d\n",
                                       cfg->main_pane_pos);
 
+               g_string_append(buf, "\n[view]\n");
+               g_string_append_printf(buf, "layout=%d\n", cfg->layout);
+               g_string_append_printf(buf, "int_memory=%d\n",
+                                      cfg->view_int_memory);
+               g_string_append_printf(buf, "ext_memory=%d\n",
+                                      cfg->view_ext_memory);
+               g_string_append_printf(buf, "bits_per_row=%d\n",
+                                      cfg->bits_per_row);
+
                file_path = app_config_get_file_path();
 
                g_file_set_contents(file_path, buf->str, buf->len, NULL);
index c655041..f153a9d 100644 (file)
@@ -41,12 +41,17 @@ struct app_config_t
        int clear_ram_on_file_load;
 
        /* UI settings */
-       int layout; /* UI Layout 1 or 2 */
        int win_width;
        int win_height;
        int hpane_pos;     /* For registers and program windows. */
        int vpane_pos; /* For internal and external memory windows. */
        int main_pane_pos; /* Between hpane and vpane. */
+
+       /* View menu options */
+       int layout; /* UI Layout 1 or 2 */
+       int view_int_memory;
+       int view_ext_memory;
+       int bits_per_row; /* 8 or 16 */
 };
 
 int
index 3024877..cf27685 100644 (file)
@@ -46,6 +46,26 @@ void toggle_layout(GtkWidget *widget, gpointer data)
        }
 }
 
+void toggle_int_memory(GtkWidget *widget, gpointer data)
+{
+       if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) {
+               log_info("  View internal memory (TODO)");
+               cfg->view_int_memory = 1;
+       } else {
+               cfg->view_int_memory = 0;
+       }
+}
+
+void toggle_ext_memory(GtkWidget *widget, gpointer data)
+{
+       if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget))) {
+               log_info("  View external memory (TODO)");
+               cfg->view_ext_memory = 1;
+       } else {
+               cfg->view_ext_memory = 0;
+       }
+}
+
 void
 view_add_layout_submenu(GtkWidget *parent)
 {
@@ -90,11 +110,17 @@ ViewAddMenu(GtkWidget *menu_bar)
 
        view = gtk_menu_item_new_with_label("View");
 
-       item = gtk_menu_item_new_with_label("Internal Memory");
+       item = gtk_check_menu_item_new_with_label("Internal Memory");
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
+       g_signal_connect(G_OBJECT(item), "activate",
+                        G_CALLBACK(toggle_int_memory), NULL);
 
-       item = gtk_menu_item_new_with_label("External Memory");
+       item = gtk_check_menu_item_new_with_label("External Memory");
        gtk_menu_shell_append(GTK_MENU_SHELL(menu), item);
+       gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
+       g_signal_connect(G_OBJECT(item), "activate",
+                        G_CALLBACK(toggle_ext_memory), NULL);
 
        AddMenuSeparator(menu);