dialog.go
func CreateConfirmationDialog(title, question string, buttons []string, defaultButton int) *ConfirmationDialog {
	dlg := new(ConfirmationDialog)

	if len(buttons) == 0 {
		buttons = []string{"OK"}
	}

	cw, ch := term.Size()

	dlg.View = AddWindow(cw/2-12, ch/2-8, 30, 3, title)
	WindowManager().BeginUpdate()
	defer WindowManager().EndUpdate()
	dlg.View.SetConstraints(30, 3)
	dlg.View.SetModal(true)
	dlg.View.SetPack(Vertical)
	CreateFrame(dlg.View, 1, 1, BorderNone, Fixed)

	fbtn := CreateFrame(dlg.View, 1, 1, BorderNone, 1)
	CreateFrame(fbtn, 1, 1, BorderNone, Fixed)
	lb := CreateLabel(fbtn, 10, 3, question, 1)
	lb.SetMultiline(true)
	CreateFrame(fbtn, 1, 1, BorderNone, Fixed)

	CreateFrame(dlg.View, 1, 1, BorderNone, Fixed)
	frm1 := CreateFrame(dlg.View, 16, 4, BorderNone, Fixed)
	CreateFrame(frm1, 1, 1, BorderNone, 1)

	bText := buttons[0]
	btn1 := CreateButton(frm1, AutoSize, AutoSize, bText, Fixed)
	btn1.OnClick(func(ev Event) {
		dlg.result = DialogButton1

		WindowManager().DestroyWindow(dlg.View)
		WindowManager().BeginUpdate()
		closeFunc := dlg.onClose
		WindowManager().EndUpdate()
		if closeFunc != nil {
			closeFunc()
		}
	})
	var btn2, btn3 *Button

	if len(buttons) > 1 {
		CreateFrame(frm1, 1, 1, BorderNone, 1)
		btn2 = CreateButton(frm1, AutoSize, AutoSize, buttons[1], Fixed)
		btn2.OnClick(func(ev Event) {
			dlg.result = DialogButton2
			WindowManager().DestroyWindow(dlg.View)
			if dlg.onClose != nil {
				dlg.onClose()
			}
		})
	}
	if len(buttons) > 2 {
		CreateFrame(frm1, 1, 1, BorderNone, 1)
		btn3 = CreateButton(frm1, AutoSize, AutoSize, buttons[2], Fixed)
		btn3.OnClick(func(ev Event) {
			dlg.result = DialogButton3
			WindowManager().DestroyWindow(dlg.View)
			if dlg.onClose != nil {
				dlg.onClose()
			}
		})
	}

	CreateFrame(frm1, 1, 1, BorderNone, 1)

	if defaultButton == DialogButton2 && len(buttons) > 1 {
		ActivateControl(dlg.View, btn2)
	} else if defaultButton == DialogButton3 && len(buttons) > 2 {
		ActivateControl(dlg.View, btn3)
	} else {
		ActivateControl(dlg.View, btn1)
	}

	dlg.View.OnClose(func(ev Event) bool {
		if dlg.result == DialogAlive {
			dlg.result = DialogClosed
			if ev.X != 1 {
				WindowManager().DestroyWindow(dlg.View)
			}
			if dlg.onClose != nil {
				dlg.onClose()
			}
		}
		return true
	})

	return dlg
}
func CreateConfirmationDialog(title, question string, buttons []string, defaultButton int) *ConfirmationDialog {
	dlg := new(ConfirmationDialog)

	if len(buttons) == 0 {
		buttons = []string{"OK"}
	}

	cw, ch := term.Size()

	dlg.View = AddWindow(cw/2-12, ch/2-8, 30, 3, title)
	WindowManager().BeginUpdate()
	defer WindowManager().EndUpdate()
	dlg.View.SetConstraints(30, 3)
	dlg.View.SetModal(true)
	dlg.View.SetPack(Vertical)
	CreateFrame(dlg.View, 1, 1, BorderNone, Fixed)

	fbtn := CreateFrame(dlg.View, 1, 1, BorderNone, 1)
	CreateFrame(fbtn, 1, 1, BorderNone, Fixed)
	lb := CreateLabel(fbtn, 10, 3, question, 1)
	lb.SetMultiline(true)
	CreateFrame(fbtn, 1, 1, BorderNone, Fixed)

	CreateFrame(dlg.View, 1, 1, BorderNone, Fixed)
	frm1 := CreateFrame(dlg.View, 16, 4, BorderNone, Fixed)
	CreateFrame(frm1, 1, 1, BorderNone, 1)

	bText := buttons[0]
	btn1 := CreateButton(frm1, AutoSize, AutoSize, bText, Fixed)
	btn1.OnClick(func(ev Event) {
		dlg.result = DialogButton1

		WindowManager().DestroyWindow(dlg.View)
		WindowManager().BeginUpdate()
		closeFunc := dlg.onClose
		WindowManager().EndUpdate()
		if closeFunc != nil {
			closeFunc()
		}
	})
	var btn2, btn3 *Button

	if len(buttons) > 1 {
		CreateFrame(frm1, 1, 1, BorderNone, 1)
		btn2 = CreateButton(frm1, AutoSize, AutoSize, buttons[1], Fixed)
		btn2.OnClick(func(ev Event) {
			dlg.result = DialogButton2
			WindowManager().DestroyWindow(dlg.View)
			if dlg.onClose != nil {
				dlg.onClose()
			}
		})
	}
	if len(buttons) > 2 {
		CreateFrame(frm1, 1, 1, BorderNone, 1)
		btn3 = CreateButton(frm1, AutoSize, AutoSize, buttons[2], Fixed)
		btn3.OnClick(func(ev Event) {
			dlg.result = DialogButton3
			WindowManager().DestroyWindow(dlg.View)
			if dlg.onClose != nil {
				dlg.onClose()
			}
		})
	}

	CreateFrame(frm1, 1, 1, BorderNone, 1)

	if defaultButton == DialogButton2 && len(buttons) > 1 {
		ActivateControl(dlg.View, btn2)
	} else if defaultButton == DialogButton3 && len(buttons) > 2 {
		ActivateControl(dlg.View, btn3)
	} else {
		ActivateControl(dlg.View, btn1)
	}

	dlg.View.OnClose(func(ev Event) bool {
		if dlg.result == DialogAlive {
			dlg.result = DialogClosed
			if ev.X != 1 {
				WindowManager().DestroyWindow(dlg.View)
			}
			if dlg.onClose != nil {
				dlg.onClose()
			}
		}
		return true
	})

	return dlg
}
func CreateConfirmationDialog ( title , question string , buttons [ ] string , defaultButton int ) * ConfirmationDialog { dlg := new ( ConfirmationDialog ) if len ( buttons ) == 0 { buttons = [ ] string { " " } } cw , ch := term . Size ( ) dlg . View = AddWindow ( cw / 2 - 12 , ch / 2 - 8 , 30 , 3 , title ) WindowManager ( ) . BeginUpdate ( ) defer WindowManager ( ) . EndUpdate ( ) dlg . View . SetConstraints ( 30 , 3 ) dlg . View . SetModal ( true ) dlg . View . SetPack ( Vertical ) CreateFrame ( dlg . View , 1 , 1 , BorderNone , Fixed ) fbtn := CreateFrame ( dlg . View , 1 , 1 , BorderNone , 1 ) CreateFrame ( fbtn , 1 , 1 , BorderNone , Fixed ) lb := CreateLabel ( fbtn , 10 , 3 , question , 1 ) lb . SetMultiline ( true ) CreateFrame ( fbtn , 1 , 1 , BorderNone , Fixed ) CreateFrame ( dlg . View , 1 , 1 , BorderNone , Fixed ) frm1 := CreateFrame ( dlg . View , 16 , 4 , BorderNone , Fixed ) CreateFrame ( frm1 , 1 , 1 , BorderNone , 1 ) bText := buttons [ 0 ] btn1 := CreateButton ( frm1 , AutoSize , AutoSize , bText , Fixed ) btn1 . OnClick ( func ( ev Event ) { dlg . result = DialogButton1 WindowManager ( ) . DestroyWindow ( dlg . View ) WindowManager ( ) . BeginUpdate ( ) closeFunc := dlg . onClose WindowManager ( ) . EndUpdate ( ) if closeFunc != nil { closeFunc ( ) } } ) var btn2 , btn3 * Button if len ( buttons ) > 1 { CreateFrame ( frm1 , 1 , 1 , BorderNone , 1 ) btn2 = CreateButton ( frm1 , AutoSize , AutoSize , buttons [ 1 ] , Fixed ) btn2 . OnClick ( func ( ev Event ) { dlg . result = DialogButton2 WindowManager ( ) . DestroyWindow ( dlg . View ) if dlg . onClose != nil { dlg . onClose ( ) } } ) } if len ( buttons ) > 2 { CreateFrame ( frm1 , 1 , 1 , BorderNone , 1 ) btn3 = CreateButton ( frm1 , AutoSize , AutoSize , buttons [ 2 ] , Fixed ) btn3 . OnClick ( func ( ev Event ) { dlg . result = DialogButton3 WindowManager ( ) . DestroyWindow ( dlg . View ) if dlg . onClose != nil { dlg . onClose ( ) } } ) } CreateFrame ( frm1 , 1 , 1 , BorderNone , 1 ) if defaultButton == DialogButton2 && len ( buttons ) > 1 { ActivateControl ( dlg . View , btn2 ) } else if defaultButton == DialogButton3 && len ( buttons ) > 2 { ActivateControl ( dlg . View , btn3 ) } else { ActivateControl ( dlg . View , btn1 ) } dlg . View . OnClose ( func ( ev Event ) bool { if dlg . result == DialogAlive { dlg . result = DialogClosed if ev . X != 1 { WindowManager ( ) . DestroyWindow ( dlg . View ) } if dlg . onClose != nil { dlg . onClose ( ) } } return true } ) return dlg }
// CreateConfirmationDialog creates new confirmation dialog.
// c is a composer that manages the dialog
// title is a dialog title
// question is a text inside dialog for user to explain what happens
// buttons is a titles for button inside dialog. If the list is empty,
//  the dialog will have only one button 'OK'. If the list has more
//  than 3 button then only first three items will be used in the dialog
// defaultButton is the number of button that is active right after
//  dialog is created. If the number is greater than the number of
//  buttons, no button is active
CreateConfirmationDialog creates new confirmation dialog . c is a composer that manages the dialog title is a dialog title question is a text inside dialog for user to explain what happens buttons is a titles for button inside dialog . If the list is empty the dialog will have only one button OK . If the list has more than 3 button then only first three items will be used in the dialog defaultButton is the number of button that is active right after dialog is created . If the number is greater than the number of buttons no button is active