Пример #1
0
func fileSave(fts *models.FilesTreeStore) {
	log.Println("fileSave")
	obj := getCurrentTopObject(fts)
	filename := obj.Filename()
	if isGeneratedFilename(filename) {
		oldName := filename
		ok := true
		filename, ok = getFilenameToSave(fts)
		if !ok {
			return
		}
		dirMgr.SetCurrent(fileType(obj), tool.Dirname(filename))
		prefix, fname := dirMgr.FilenameToShow(filename)
		err := global.FileMgr(obj).Rename(oldName, fname)
		if err != nil {
			log.Printf("fileSave: %s\n", err)
			return
		}
		obj.SetPathPrefix(prefix)
	}
	dirMgr.SetCurrent(fileType(obj), tool.Dirname(filename))
	err := global.FileMgr(obj).Store(obj.Filename())
	if err != nil {
		log.Println(err)
	}
	return
}
Пример #2
0
func SeparatePathMode(m string) (path string, mode PositionMode) {
	path = tool.Dirname(m)
	mode = PositionMode(tool.Basename(m))
	return
	if !strings.Contains(m, "/") {
		mode = PositionMode(m)
		return
	}
	p := strings.Split(m, "/")
	if len(p) < 2 {
		mode = PositionMode(m)
		return
	}
	l := len(p) - 1
	for i, s := range p {
		switch {
		case i == 0:
			path = s
		case i < l:
			path = fmt.Sprintf("%s/%s", path, s)
		}
	}
	mode = PositionMode(p[l])
	return
}
Пример #3
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))
}
Пример #4
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
}
Пример #5
0
func fileSaveAs(fts *models.FilesTreeStore) {
	log.Println("fileSaveAs")
	filename, ok := getFilenameToSave(fts)
	if !ok {
		return
	}
	obj := getCurrentTopObject(fts)
	oldName := obj.Filename()
	prefix, fname := dirMgr.FilenameToShow(filename)
	err := global.FileMgr(obj).Rename(oldName, fname)
	if err != nil {
		log.Printf("fileSaveAs: %s\n", err)
		return
	}
	obj.SetPathPrefix(prefix)
	err = global.FileMgr(obj).Store(fname)
	if err != nil {
		log.Printf("fileSaveAs: %s\n", err)
		return
	}
	dirMgr.SetCurrent(fileType(obj), tool.Dirname(fname))
}