aboutsummaryrefslogtreecommitdiff
path: root/window.go
diff options
context:
space:
mode:
authorPetter Rodhelind <petter.rodhelind@gmail.com>2018-02-25 10:46:59 +0100
committerPetter Rodhelind <petter.rodhelind@gmail.com>2018-02-25 10:46:59 +0100
commit0e86accb588445f09b07ec68e6cc62903f9ba7bd (patch)
tree4bd67a8acb1a41039fceaa126fb5180ffa6e6770 /window.go
parent1c1469d5522c7c7d7c03232d9c2711c5d96d3c18 (diff)
downloadpoe-0e86accb588445f09b07ec68e6cc62903f9ba7bd.tar.gz
poe-0e86accb588445f09b07ec68e6cc62903f9ba7bd.tar.bz2
poe-0e86accb588445f09b07ec68e6cc62903f9ba7bd.zip
Add alternative mouse clicks for one-btn-only laptops, fix scroll and add "save buffer with a new name".
Diffstat (limited to 'window.go')
-rw-r--r--window.go28
1 files changed, 21 insertions, 7 deletions
diff --git a/window.go b/window.go
index 9560ec6..763acc9 100644
--- a/window.go
+++ b/window.go
@@ -156,27 +156,40 @@ func (win *Window) LoadBuffer() bool {
win.file.mtime = info.ModTime()
win.file.read = true
- win.body.SetCursor(0, 0)
+ win.body.SetCursor(0, io.SeekStart)
return true
}
// SaveFile replaces disk file with buffer content. Returns error if no disk file is set.
func (win *Window) SaveFile() (int, error) {
- if win.file.name == FnEmptyWin {
+ if win.NameTag() == FnEmptyWin {
return 0, errors.New("no filename")
}
- if win.Name() == FnMessageWin {
+ if win.Name() == FnMessageWin { // can not save +poe window
return 0, nil
}
- if win.isdir {
+ // TODO: check this in real time in case of tag name change...
+ if win.isdir { // can not save a directory
return 0, nil
}
- f, err := os.OpenFile(win.NameAbs(), os.O_RDWR|os.O_CREATE, 0644)
+ // check for file existence if we recently changed the file name
+ openmasks := os.O_RDWR | os.O_CREATE
+ var namechange bool
+ if win.Name() != win.NameTag() { // user has changed name
+ openmasks |= os.O_EXCL // must not already exist
+ namechange = true // to skip sha256 checksum
+ }
+
+ f, err := os.OpenFile(win.NameTag(), openmasks, 0644)
if err != nil {
+ if os.IsExist(err) {
+ printMsg("%s already exists\n", win.NameTag())
+ return 0, nil
+ }
return 0, err
}
defer f.Close()
@@ -187,7 +200,8 @@ func (win *Window) SaveFile() (int, error) {
}
hhex := fmt.Sprintf("%x", h.Sum(nil))
- if hhex != win.file.sha256 {
+ // verify checksum if the file is not newly created via a namechange
+ if !namechange && hhex != win.file.sha256 {
return 0, errors.Errorf("file has been modified outside of poe")
}
@@ -232,7 +246,7 @@ func (win *Window) NameAbs() string {
return s
}
-func (win *Window) NameFromTag() string {
+func (win *Window) NameTag() string {
tstr := win.tagline.text.String()
if tstr == "" {
return ""