Added the new MsgBox() behavior to the GTK+ backend. It /almost/ works right; just needs some more changes...
This commit is contained in:
parent
641d11c6fe
commit
15afca6402
104
dialog_unix.go
104
dialog_unix.go
|
@ -22,59 +22,73 @@ import (
|
||||||
// }
|
// }
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
func _msgBox(parent *Window, primarytext string, secondarytext string, msgtype C.GtkMessageType, buttons C.GtkButtonsType) (result C.gint) {
|
func _msgBox(parent *Window, primarytext string, secondarytext string, msgtype C.GtkMessageType, buttons C.GtkButtonsType) (result chan int) {
|
||||||
ret := make(chan C.gint)
|
result = make(chan int)
|
||||||
defer close(ret)
|
go func() {
|
||||||
uitask <- func() {
|
ret := make(chan C.gint)
|
||||||
var pwin *C.GtkWindow = nil
|
defer close(ret)
|
||||||
|
uitask <- func() {
|
||||||
|
var pwin *C.GtkWindow = nil
|
||||||
|
|
||||||
// to implement parent, we need to put the GtkMessageDialog into a new window group along with parent
|
// to implement parent, we need to put the GtkMessageDialog into a new window group along with parent
|
||||||
// a GtkWindow can only be part of one group
|
// a GtkWindow can only be part of one group
|
||||||
// so we use this to save the parent window group (if there is one) and store the new window group
|
// so we use this to save the parent window group (if there is one) and store the new window group
|
||||||
// after showing the message box, we restore the previous window group, so future parent == nil can work properly
|
// after showing the message box, we restore the previous window group, so future parent == nil can work properly
|
||||||
// thanks to pbor and mclasen in irc.gimp.net/#gtk+
|
// thanks to pbor and mclasen in irc.gimp.net/#gtk+
|
||||||
var prevgroup *C.GtkWindowGroup = nil
|
var prevgroup *C.GtkWindowGroup = nil
|
||||||
var newgroup *C.GtkWindowGroup
|
var newgroup *C.GtkWindowGroup
|
||||||
|
|
||||||
if parent != nil {
|
if parent != nil {
|
||||||
pwin = togtkwindow(parent.sysData.widget)
|
pwin = togtkwindow(parent.sysData.widget)
|
||||||
// we can't remove a window from the "default window group"; otherwise this throws up Gtk-CRITICAL warnings
|
// we can't remove a window from the "default window group"; otherwise this throws up Gtk-CRITICAL warnings
|
||||||
if C.gtk_window_has_group(pwin) != C.FALSE {
|
if C.gtk_window_has_group(pwin) != C.FALSE {
|
||||||
prevgroup = C.gtk_window_get_group(pwin)
|
prevgroup = C.gtk_window_get_group(pwin)
|
||||||
C.gtk_window_group_remove_window(prevgroup, pwin)
|
C.gtk_window_group_remove_window(prevgroup, pwin)
|
||||||
|
}
|
||||||
|
newgroup = C.gtk_window_group_new()
|
||||||
|
C.gtk_window_group_add_window(newgroup, pwin)
|
||||||
}
|
}
|
||||||
newgroup = C.gtk_window_group_new()
|
|
||||||
C.gtk_window_group_add_window(newgroup, pwin)
|
|
||||||
}
|
|
||||||
|
|
||||||
cprimarytext := C.CString(primarytext)
|
cprimarytext := C.CString(primarytext)
|
||||||
defer C.free(unsafe.Pointer(cprimarytext))
|
defer C.free(unsafe.Pointer(cprimarytext))
|
||||||
csecondarytext := (*C.char)(nil)
|
csecondarytext := (*C.char)(nil)
|
||||||
if secondarytext != "" {
|
if secondarytext != "" {
|
||||||
csecondarytext = C.CString(secondarytext)
|
csecondarytext = C.CString(secondarytext)
|
||||||
defer C.free(unsafe.Pointer(csecondarytext))
|
defer C.free(unsafe.Pointer(csecondarytext))
|
||||||
}
|
}
|
||||||
box := C.gtkNewMsgBox(pwin, msgtype, buttons, cprimarytext, csecondarytext)
|
box := C.gtkNewMsgBox(pwin, msgtype, buttons, cprimarytext, csecondarytext)
|
||||||
response := C.gtk_dialog_run((*C.GtkDialog)(unsafe.Pointer(box)))
|
response := C.gtk_dialog_run((*C.GtkDialog)(unsafe.Pointer(box)))
|
||||||
C.gtk_widget_destroy(box)
|
C.gtk_widget_destroy(box)
|
||||||
|
|
||||||
if parent != nil {
|
if parent != nil {
|
||||||
C.gtk_window_group_remove_window(newgroup, pwin)
|
C.gtk_window_group_remove_window(newgroup, pwin)
|
||||||
C.g_object_unref(C.gpointer(unsafe.Pointer(newgroup))) // free the group
|
C.g_object_unref(C.gpointer(unsafe.Pointer(newgroup))) // free the group
|
||||||
if prevgroup != nil {
|
if prevgroup != nil {
|
||||||
C.gtk_window_group_add_window(prevgroup, pwin)
|
C.gtk_window_group_add_window(prevgroup, pwin)
|
||||||
} // otherwise it'll go back into the default group on its own
|
} // otherwise it'll go back into the default group on its own
|
||||||
}
|
}
|
||||||
|
|
||||||
ret <- response
|
ret <- response
|
||||||
}
|
}
|
||||||
return <-ret
|
result <- int(<-ret)
|
||||||
|
}()
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func msgBox(parent *Window, primarytext string, secondarytext string) {
|
func (w *Window) msgBox(primarytext string, secondarytext string) (done chan struct{}) {
|
||||||
_msgBox(parent, primarytext, secondarytext, C.GtkMessageType(C.GTK_MESSAGE_OTHER), C.GtkButtonsType(C.GTK_BUTTONS_OK))
|
done = make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
<-_msgBox(w, primarytext, secondarytext, C.GtkMessageType(C.GTK_MESSAGE_OTHER), C.GtkButtonsType(C.GTK_BUTTONS_OK))
|
||||||
|
done <- struct{}{}
|
||||||
|
}()
|
||||||
|
return done
|
||||||
}
|
}
|
||||||
|
|
||||||
func msgBoxError(parent *Window, primarytext string, secondarytext string) {
|
func (w *Window) msgBoxError(primarytext string, secondarytext string) (done chan struct{}) {
|
||||||
_msgBox(parent, primarytext, secondarytext, C.GtkMessageType(C.GTK_MESSAGE_ERROR), C.GtkButtonsType(C.GTK_BUTTONS_OK))
|
done = make(chan struct{})
|
||||||
|
go func() {
|
||||||
|
<-_msgBox(w, primarytext, secondarytext, C.GtkMessageType(C.GTK_MESSAGE_ERROR), C.GtkButtonsType(C.GTK_BUTTONS_OK))
|
||||||
|
done <- struct{}{}
|
||||||
|
}()
|
||||||
|
return done
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue