1
0
mirror of https://github.com/raphnet/gc_n64_usb-v3 synced 2024-12-21 14:58:51 -05:00

Mempak open

This commit is contained in:
Raphael Assenat 2015-10-26 08:31:40 -04:00
parent dd2ec8f71e
commit ba93485172
3 changed files with 62 additions and 7 deletions

View File

@ -87,6 +87,17 @@ Author: Raphaël Assénat
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
</object>
<object class="GtkFileFilter" id="n64_mempak_filter">
<patterns>
<pattern>*.mpk</pattern>
<pattern>*.n64</pattern>
</patterns>
</object>
<object class="GtkFileFilter" id="n64_note_filter">
<patterns>
<pattern>*.note</pattern>
</patterns>
</object>
<object class="GtkListStore" id="n64_notes">
<columns>
<!-- column-name Note -->

View File

@ -8,6 +8,8 @@
#define GET_ELEMENT(TYPE, ELEMENT) (TYPE *)gtk_builder_get_object(app->builder, #ELEMENT)
#define GET_UI_ELEMENT(TYPE, ELEMENT) TYPE *ELEMENT = GET_ELEMENT(TYPE, ELEMENT)
void errorPopop(struct application *app, const char *message);
struct application {
GtkBuilder *builder;
GtkWindow *mainwindow;

View File

@ -19,9 +19,11 @@ struct mpkedit_data *mpkedit_new(struct application *app)
return NULL;
}
// mpke->mpk = mempak_new();
mpke->mpk = mempak_loadFromFile("/home/raph/0Dream/programming/multiuse_pcbX/gc_n64_usb-v3/tmp/perfect_dark_b.N64");
mpke->mpk = mempak_new();
if (!mpke->mpk) {
free(mpke);
return NULL;
}
return mpke;
}
@ -33,6 +35,16 @@ void mpkedit_free(struct mpkedit_data *mpke)
}
}
void mpke_replaceMpk(struct application *app, mempak_structure_t *mpk)
{
if (app->mpke->mpk) {
mempak_free(app->mpke->mpk);
}
app->mpke->mpk = mpk;
mpke_syncModel(app);
}
void mpke_syncModel(struct application *app)
{
GET_UI_ELEMENT(GtkListStore, n64_notes);
@ -78,14 +90,44 @@ G_MODULE_EXPORT void mpke_new(GtkWidget *win, gpointer data)
{
struct application *app = data;
mempak_free(app->mpke->mpk);
app->mpke->mpk = mempak_new();
mpke_syncModel(app);
mpke_replaceMpk(app, mempak_new());
}
G_MODULE_EXPORT void mpke_open(GtkWidget *win, gpointer data)
{
struct application *app = data;
GtkWidget *dialog;
GET_UI_ELEMENT(GtkWindow, n64_mempak_window_editor);
GET_UI_ELEMENT(GtkFileFilter, n64_mempak_filter);
GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
int res;
dialog = gtk_file_chooser_dialog_new("Load N64 mempak image",
n64_mempak_window_editor,
action,
"_Cancel",
GTK_RESPONSE_CANCEL,
"_Open",
GTK_RESPONSE_ACCEPT,
NULL);
gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), n64_mempak_filter);
res = gtk_dialog_run (GTK_DIALOG(dialog));
if (res == GTK_RESPONSE_ACCEPT) {
char *filename;
GtkFileChooser *chooser = GTK_FILE_CHOOSER(dialog);
mempak_structure_t *mpk;
filename = gtk_file_chooser_get_filename(chooser);
mpk = mempak_loadFromFile(filename);
if (mpk) {
mpke_replaceMpk(app, mpk);
} else {
errorPopop(app, "Failed to load mempak");
}
}
gtk_widget_destroy(dialog);
}
G_MODULE_EXPORT void mpke_saveas(GtkWidget *win, gpointer data)