Implemented window closing action

This commit is contained in:
Mario Hüttel 2017-08-14 23:30:24 +02:00
parent a32a7e2377
commit be7879ed45
3 changed files with 30 additions and 13 deletions

5
.gitignore vendored
View File

@ -2,3 +2,8 @@
*.user* *.user*
Makefile Makefile
*~ *~
CMakeFiles
CMakeCache.txt
cmake_install.cmake
stm32flash
*.cbp

31
main.c
View File

@ -37,6 +37,14 @@ typedef struct _flasher {
GtkWidget **portEntry; GtkWidget **portEntry;
}flasher; }flasher;
static gboolean main_window_close(GtkWidget *widget, gpointer foo)
{
gtk_widget_destroy(widget);
gtk_main_quit();
return TRUE;
}
void parseParams(parameter *progParams, int argc, char **argv); void parseParams(parameter *progParams, int argc, char **argv);
void parseBuilder(GtkBuilder *builder, builderWidget *builderWidgets); void parseBuilder(GtkBuilder *builder, builderWidget *builderWidgets);
void startFlash(); void startFlash();
@ -48,6 +56,7 @@ int main(int argc, char *argv[]) {
static char fileName[MAXPARAMLENGTH] = {0}; static char fileName[MAXPARAMLENGTH] = {0};
static GtkWidget *startButton; static GtkWidget *startButton;
static GtkWidget *fileDialogButton; static GtkWidget *fileDialogButton;
static GtkWidget *main_window;
static GtkWidget *fileEntry; static GtkWidget *fileEntry;
static GtkWidget *portEntry; static GtkWidget *portEntry;
static GtkWidget *progressBar; static GtkWidget *progressBar;
@ -60,18 +69,7 @@ int main(int argc, char *argv[]) {
.hasValue = hasNoVal, .hasValue = hasNoVal,
.value = (void*)&gui .value = (void*)&gui
}, },
{ {.name = "--port",.hasValue = hasVal,.value = (void*)port},{.name = "--file",.hasValue = hasVal,.value = (void*)fileName},{.name = NULL}};
.name = "--port",
.hasValue = hasVal,
.value = (void*)port
},
{
.name = "--file",
.hasValue = hasVal,
.value = (void*)fileName
},
{.name = NULL}
};
static builderWidget builderWidgets[] = { static builderWidget builderWidgets[] = {
{ {
.widgetId = "startButton", .widgetId = "startButton",
@ -97,6 +95,10 @@ int main(int argc, char *argv[]) {
.widgetId = "Dialog", .widgetId = "Dialog",
.widget = &fileDialog .widget = &fileDialog
}, },
{
.widgetId = "mainWindow",
.widget = &main_window
},
{ {
.widgetId = NULL, .widgetId = NULL,
.widget = NULL .widget = NULL
@ -111,7 +113,7 @@ int main(int argc, char *argv[]) {
stmFlasher.fileEntry = &fileEntry; stmFlasher.fileEntry = &fileEntry;
stmFlasher.portEntry = &portEntry; stmFlasher.portEntry = &portEntry;
// TODO: above // TODO: above
gui = 1;
if (gui) { if (gui) {
gtk_init(&argc, &argv); gtk_init(&argc, &argv);
builder = gtk_builder_new(); builder = gtk_builder_new();
@ -120,6 +122,7 @@ int main(int argc, char *argv[]) {
//Get Widgets from Builder //Get Widgets from Builder
parseBuilder(builder, builderWidgets); parseBuilder(builder, builderWidgets);
g_signal_connect(startButton, "clicked", G_CALLBACK(startFlash), &stmFlasher); g_signal_connect(startButton, "clicked", G_CALLBACK(startFlash), &stmFlasher);
g_signal_connect(main_window, "delete-event", G_CALLBACK(main_window_close), NULL);
gtk_main(); gtk_main();
} else { } else {
startFlash(&stmFlasher); startFlash(&stmFlasher);
@ -130,7 +133,9 @@ int main(int argc, char *argv[]) {
} }
void startFlash(flasher *flashObj) { void startFlash(flasher *flashObj) {
printf("Flasher started\n");
return; return;
} }

View File

@ -32,8 +32,12 @@
</child> </child>
</object> </object>
</child> </child>
<child>
<placeholder/>
</child>
</object> </object>
<object class="GtkWindow" id="mainWindow"> <object class="GtkWindow" id="mainWindow">
<property name="visible">True</property>
<property name="can_focus">False</property> <property name="can_focus">False</property>
<child> <child>
<object class="GtkBox"> <object class="GtkBox">
@ -136,5 +140,8 @@
</child> </child>
</object> </object>
</child> </child>
<child type="titlebar">
<placeholder/>
</child>
</object> </object>
</interface> </interface>