Beispiel #1
0
func (f filenameFactory) HintFilename(filename string) (name string) {
	if tool.Suffix(filename) != f.suffix {
		log.Panicf("filenameFactory.HintFilename: invalid suffix\n")
		return
	}
	name = fmt.Sprintf("%s-%s.hints.xml", tool.Prefix(filename), f.suffix)
	return
}
Beispiel #2
0
func fileOpen(fts *models.FilesTreeStore, ftv *views.FilesTreeView) {
	log.Println("fileOpen")
	filename, ok := getFilenameToOpen()
	if !ok {
		return
	}
	prefix, fname := dirMgr.FilenameToShow(filename)
	var err error
	var obj tr.ToplevelTreeElementIf
	var fileMgr mod.FileManagerIf
	fileMgr, err = getFileMgr(FileType(tool.Suffix(fname)))
	obj, err = fileMgr.Access(fname)
	if err != nil {
		log.Printf("fileOpen error: %s\n", err)
		return
	}
	obj.SetPathPrefix(prefix)
	dirMgr.SetCurrent(fileType(obj), tool.Dirname(fname))
}
Beispiel #3
0
func getFilenameToSave(fts *models.FilesTreeStore) (filename string, ok bool) {
	obj := getCurrentTopObject(fts)
	filename, ok = runFileDialog([]FileType{fileType(obj)}, true, "Save file as")
	// force correct suffix:
	dirname := tool.Dirname(filename)
	basename := tool.Basename(filename)
	suffix := tool.Suffix(basename)
	if suffix == basename { // no suffix given
		filename = fmt.Sprintf("%s.%s", filename, string(fileType(obj)))
	} else if suffix != string(fileType(obj)) { // wrong suffix
		log.Printf("getFilenameToSave: wrong suffix %s, forcing correct %s\n", suffix, string(fileType(obj)))
		idx := strings.LastIndex(basename, ".")
		if idx < 0 { // should never happen
			filename = fmt.Sprintf("%s/%s.%s", dirname, basename, string(fileType(obj)))
		} else {
			filename = fmt.Sprintf("%s/%s.%s", dirname, basename[:idx], string(fileType(obj)))
		}
	}
	return
}