limetext/lime — pull request #401 by snowiow (2014-09-22 13:45:49+00:00)
Title: close_all_views command + bugfix

The CloseAll method in window.go acted strange. So ive added the following prints:

```go
func (w *Window) CloseAllViews() {
for _, v := range w.views {
fmt.Println("new iteration")
for i, _ := range w.views {
fmt.Println(w.views[i].Id())
}
fmt.Printf("to be removed %d\n", v.Id())
v.Close()
}
}
```
```go
func (w *Window) remove(v *View) {
w.lock.Lock()
defer w.lock.Unlock()
for i, vv := range w.views {
if v == vv {
fmt.Printf("v: %d vv: %d\n", v.Id(), vv.Id())
end := len(w.views) - 1
if i != end {
copy(w.views[i:], w.views[i+1:])
}
w.views = w.views[:end]
return
}
}
log4go.Error("Wanted to remove view %+v, but it doesn't appear to be a child of this window", v)
}
```

The output was the following:
```
new iteration
324
326
328
to be removed 324
v: 324 vv: 324
new iteration
326
328
to be removed 328
v: 328 vv: 328
new iteration
326
to be removed 328
```
It seems, that the current implementation struggles, when deleting during the iteration. I don't know whats the best alternative, but I tried this approach, which is working:

```go
func (w *Window) CloseAllViews() {
for len(w.views) > 0 {
w.views[0].Close()
}
}
```

If anybody has a better alternative, please let me know. :)