2014-02-17 01:54:58 -06:00
|
|
|
// +build !windows,!darwin,!plan9
|
|
|
|
|
|
|
|
// 7 february 2014
|
2014-03-12 20:55:45 -05:00
|
|
|
|
2014-02-19 10:41:10 -06:00
|
|
|
package ui
|
2014-02-17 01:54:58 -06:00
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// #cgo pkg-config: gtk+-3.0
|
2014-03-16 09:34:12 -05:00
|
|
|
// #include "gtk_unix.h"
|
2014-02-17 01:54:58 -06:00
|
|
|
// /* because cgo seems to choke on ... */
|
|
|
|
// /* TODO does NULL parent make the box application-global? docs are unclear */
|
2014-04-10 11:34:30 -05:00
|
|
|
// GtkWidget *gtkNewMsgBox(GtkMessageType type, GtkButtonsType buttons, char *title, char *text)
|
|
|
|
// {
|
|
|
|
// GtkWidget *k;
|
|
|
|
//
|
|
|
|
// k = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL, type, buttons, "%s", (gchar *) title);
|
|
|
|
// if (text != NULL)
|
|
|
|
// gtk_message_dialog_format_secondary_text((GtkMessageDialog *) k, "%s", (gchar *) text);
|
|
|
|
// return k;
|
|
|
|
// }
|
2014-02-17 01:54:58 -06:00
|
|
|
import "C"
|
|
|
|
|
2014-03-12 11:14:24 -05:00
|
|
|
func _msgBox(primarytext string, secondarytext string, msgtype C.GtkMessageType, buttons C.GtkButtonsType) (result C.gint) {
|
2014-02-17 01:54:58 -06:00
|
|
|
ret := make(chan C.gint)
|
|
|
|
defer close(ret)
|
|
|
|
uitask <- func() {
|
2014-03-12 11:14:24 -05:00
|
|
|
cprimarytext := C.CString(primarytext)
|
|
|
|
defer C.free(unsafe.Pointer(cprimarytext))
|
2014-04-10 11:34:30 -05:00
|
|
|
csecondarytext := (*C.char)(nil)
|
|
|
|
if secondarytext != "" {
|
|
|
|
csecondarytext = C.CString(secondarytext)
|
|
|
|
defer C.free(unsafe.Pointer(csecondarytext))
|
|
|
|
}
|
2014-03-12 11:14:24 -05:00
|
|
|
box := C.gtkNewMsgBox(msgtype, buttons, cprimarytext, csecondarytext)
|
2014-02-17 01:54:58 -06:00
|
|
|
response := C.gtk_dialog_run((*C.GtkDialog)(unsafe.Pointer(box)))
|
|
|
|
C.gtk_widget_destroy(box)
|
|
|
|
ret <- response
|
|
|
|
}
|
|
|
|
return <-ret
|
|
|
|
}
|
|
|
|
|
2014-03-12 11:14:24 -05:00
|
|
|
func msgBox(primarytext string, secondarytext string) {
|
2014-02-17 01:54:58 -06:00
|
|
|
// TODO add an icon?
|
2014-03-12 11:14:24 -05:00
|
|
|
_msgBox(primarytext, secondarytext, C.GtkMessageType(C.GTK_MESSAGE_OTHER), C.GtkButtonsType(C.GTK_BUTTONS_OK))
|
2014-02-17 01:54:58 -06:00
|
|
|
}
|
|
|
|
|
2014-03-12 11:14:24 -05:00
|
|
|
func msgBoxError(primarytext string, secondarytext string) {
|
|
|
|
_msgBox(primarytext, secondarytext, C.GtkMessageType(C.GTK_MESSAGE_ERROR), C.GtkButtonsType(C.GTK_BUTTONS_OK))
|
2014-02-17 01:54:58 -06:00
|
|
|
}
|