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*
Makefile
*~
CMakeFiles
CMakeCache.txt
cmake_install.cmake
stm32flash
*.cbp

31
main.c
View File

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

View File

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