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 }
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 }