Esempio n. 1
0
File: newgtk.go Progetto: sqp/godock
// FileChooserDialogWith2Buttons creates a *gtk.FileChooserDialog.
func FileChooserDialogWith2Buttons(title string, parent *gtk.Window, action gtk.FileChooserAction,
	firstText string, firstID gtk.ResponseType,
	secondText string, secondID gtk.ResponseType) *gtk.FileChooserDialog {

	w, _ := gtk.FileChooserDialogNewWith2Buttons(title, parent, action, firstText, firstID, secondText, secondID)
	return w
}
Esempio n. 2
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
}
Esempio n. 3
0
func (u *gtkUI) importFingerprintsForDialog(account *config.Account, w *gtk.Dialog) {
	dialog, _ := gtk.FileChooserDialogNewWith2Buttons(
		i18n.Local("Import fingerprints"),
		&w.Window,
		gtk.FILE_CHOOSER_ACTION_OPEN,
		i18n.Local("_Cancel"),
		gtk.RESPONSE_CANCEL,
		i18n.Local("_Import"),
		gtk.RESPONSE_OK,
	)

	if gtk.ResponseType(dialog.Run()) == gtk.RESPONSE_OK {
		num, ok := u.importFingerprintsFor(account, dialog.GetFilename())
		if ok {
			u.notify(i18n.Local("Fingerprints imported"), fmt.Sprintf(i18n.Local("%d fingerprint(s) were imported correctly."), num))
		} else {
			u.notify(i18n.Local("Failure importing fingerprints"), fmt.Sprintf(i18n.Local("Couldn't import any fingerprints from %s."), dialog.GetFilename()))
		}
	}
	dialog.Destroy()
}
Esempio n. 4
0
func (u *gtkUI) exportFingerprintsForDialog(account *config.Account, w *gtk.Dialog) {
	dialog, _ := gtk.FileChooserDialogNewWith2Buttons(
		i18n.Local("Export fingerprints"),
		&w.Window,
		gtk.FILE_CHOOSER_ACTION_SAVE,
		i18n.Local("_Cancel"),
		gtk.RESPONSE_CANCEL,
		i18n.Local("_Export"),
		gtk.RESPONSE_OK,
	)

	dialog.SetCurrentName("otr.fingerprints")

	if gtk.ResponseType(dialog.Run()) == gtk.RESPONSE_OK {
		ok := u.exportFingerprintsFor(account, dialog.GetFilename())
		if ok {
			u.notify(i18n.Local("Fingerprints exported"), i18n.Local("Fingerprints were exported correctly."))
		} else {
			u.notify(i18n.Local("Failure exporting fingerprints"), fmt.Sprintf(i18n.Local("Couldn't export fingerprints to %s."), dialog.GetFilename()))
		}
	}
	dialog.Destroy()
}
Esempio n. 5
0
func (*RealGtk) FileChooserDialogNewWith2Buttons(title string, parent gtki.Window, action gtki.FileChooserAction, first_button_text string, first_button_id gtki.ResponseType, second_button_text string, second_button_id gtki.ResponseType) (gtki.FileChooserDialog, error) {
	return wrapFileChooserDialog(gtk.FileChooserDialogNewWith2Buttons(title, unwrapWindow(parent), gtk.FileChooserAction(action), first_button_text, gtk.ResponseType(first_button_id), second_button_text, gtk.ResponseType(second_button_id)))
}
Esempio n. 6
0
File: others.go Progetto: sqp/godock
func onFileChooserOpen(obj *gtk.Button, data fileChooserData) {
	var parent *gtk.Window

	var title string
	var action gtk.FileChooserAction

	switch data.key.Type {
	case cftype.KeyFolderSelector:
		title = tran.Slate("Pick up a directory")
		action = gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER

	case cftype.KeyImageSelector:
		title = tran.Slate("Pick up an image")
		action = gtk.FILE_CHOOSER_ACTION_OPEN

	default:
		title = tran.Slate("Pick up a file")
		action = gtk.FILE_CHOOSER_ACTION_OPEN
	}

	dialog, _ := gtk.FileChooserDialogNewWith2Buttons(title, parent, action,
		"_OK", gtk.RESPONSE_OK, "_Cancel", gtk.RESPONSE_CANCEL)

	// Set the current folder to the current value in conf.
	value, _ := data.entry.GetText()
	if value == "" || value[0] != '/' {
		if data.key.IsType(cftype.KeyImageSelector) {
			println("need dir pictures")
			// dialog.SetCurrentFolder(filepath.Dir(value)) // g_get_user_special_dir (G_USER_DIRECTORY_PICTURES) :
		} else {
			println(os.Getenv("HOME"))
			dialog.SetCurrentFolder(os.Getenv("HOME"))
		}
	} else {
		dialog.SetCurrentFolder(filepath.Dir(value))
	}

	if data.key.IsType(cftype.KeyImageSelector) { // Add shortcuts to icons of the system.
		dialog.AddShortcutFolder("/usr/share/icons")
		dialog.AddShortcutFolder("/usr/share/pixmaps")
	}

	if data.key.IsType(cftype.KeyFileSelector, cftype.KeySoundSelector) { // Add shortcuts to system icons directories.
		filter := newgtk.FileFilter()
		filter.SetName(tran.Slate("All"))
		filter.AddPattern("*")
		dialog.AddFilter(filter)
	}

	if data.key.IsType(cftype.KeyFileSelector, cftype.KeyImageSelector) { // Preview and images filter.
		filter := newgtk.FileFilter()
		filter.SetName(tran.Slate("Image"))
		filter.AddPixbufFormats()
		dialog.AddFilter(filter)

		img := newgtk.Image()
		dialog.SetPreviewWidget(img)
		dialog.Connect("update-preview", onFileChooserUpdatePreview, img)
	}

	dialog.Show()
	answer := dialog.Run()
	if gtk.ResponseType(answer) == gtk.RESPONSE_OK {
		data.entry.SetText(dialog.GetFilename())
	}
	dialog.Destroy()
}