check if the directory is empty before nav operations

Mentioned in #23.
This commit is contained in:
Gokcehan 2016-10-05 18:26:55 +03:00
parent 1f129476a8
commit 1683cdfd47

12
nav.go
View File

@ -344,6 +344,10 @@ func (nav *Nav) cd(wd string) error {
}
func (nav *Nav) toggle() {
if nav.currEmpty() {
return
}
path := nav.currPath()
if nav.marks[path] {
@ -357,6 +361,10 @@ func (nav *Nav) toggle() {
func (nav *Nav) save(keep bool) error {
if len(nav.marks) == 0 {
if nav.currEmpty() {
return errors.New("no file selected")
}
path := nav.currPath()
if err := saveFiles([]string{path}, keep); err != nil {
@ -413,6 +421,10 @@ func (nav *Nav) paste() error {
return nil
}
func (nav *Nav) currEmpty() bool {
return len(nav.dirs[len(nav.dirs)-1].fi) == 0
}
func (nav *Nav) currDir() *Dir {
return nav.dirs[len(nav.dirs)-1]
}