Exemple #1
0
// empty fTypes means all types enabled
func runFileDialog(fTypes []FileType, toSave bool, announce string) (filename string, ok bool) {
	var action gtk.FileChooserAction
	var buttonText string
	if toSave {
		action = gtk.FILE_CHOOSER_ACTION_SAVE
		buttonText = "Save"
	} else {
		action = gtk.FILE_CHOOSER_ACTION_OPEN
		buttonText = "Open"
	}
	dialog, err := gtk.FileChooserDialogNewWith2Buttons(
		announce,
		nil,
		action,
		"Cancel",
		gtk.RESPONSE_CANCEL,
		buttonText,
		gtk.RESPONSE_OK)
	if err != nil {
		log.Printf("runFileDialog error: %s\n", err)
		return
	}
	if len(fTypes) == 0 {
		for _, t := range allFileTypes {
			fTypes = append(fTypes, t)
		}
	}
	if len(fTypes) == 1 {
		log.Printf("runFileDialog: set current to %s.\n", dirMgr.Current(fTypes[0]))
		dialog.SetCurrentFolder(dirMgr.Current(fTypes[0]))
	} else {
		log.Printf("runFileDialog: set current to %s.\n", backend.XmlRoot())
		dialog.SetCurrentFolder(backend.XmlRoot())
	}
	for _, ft := range fTypes {
		ff, _ := gtk.FileFilterNew()
		ff.SetName(descriptionFileTypes[ft])
		ff.AddPattern(fmt.Sprintf("*.%s", string(ft)))
		dialog.AddFilter(ff)
	}
	response := dialog.Run()
	ok = (gtk.ResponseType(response) == gtk.RESPONSE_OK)
	filename = dialog.GetFilename()
	dialog.Destroy()
	return
}
Exemple #2
0
// FileFilter creates a *gtk.FileFilter.
func FileFilter() *gtk.FileFilter {
	w, _ := gtk.FileFilterNew()
	return w
}