fix list.selected behavior

master
itwrx 1 year ago
parent 372a2076f4
commit 1dd810c6b3
  1. 30
      views/routine_list.nim

@ -4,7 +4,7 @@ EZ-Bkup is released under the General Public License 3.0.
See COPYING or <https://www.gnu.org/licenses/> for details.]#
import owlkettle
import std/osproc, std/os, std/logging
import osproc, os, logging, sequtils
import edit_routine_dialog
import "../models/routine", "../shared"
@ -13,14 +13,9 @@ viewable RoutineList:
runStatus: string
selected: seq[RoutineId]
# hey, hook.
hooks:
# yes, you, the build hook.
build:
# i love you. :)
state.selected = selectedPreload()
proc changed(state: bool)
state.selected = selectedPreload()
var thread: Thread[RoutineListState]
@ -50,15 +45,15 @@ proc rsyncThread(list: RoutineListState) {.thread.} =
routineRuncount += 1
for source in routine.sources:
for destination in routine.destinations:
#try without requiring superuser privs by default.
#rsyncRunCmd = "rsync -aq " & source & " " & destination
#try without requiring superuser privs by default.
#rsyncRunCmd = "rsync -aq " & source & " " & destination
#quote sources and destinations to handle possible spaces.
rsyncRunCmd = "rsync -aq " & "'" & source & "'" & " " & "'" & destination & "'"
rsyncRun = execCmdEx(rsyncRunCmd)
if rsyncRun.exitCode != 0:
#handle permission denied error.
if rsyncRun.exitCode == 23:
rsyncRun.exitCode = 0
rsyncRun.exitCode = 0
#rsyncRunCmd = "pkexec rsync -aq " & source & " " & destination
#quote sources and destinations to handle possible spaces.
rsyncRunCmd = "pkexec rsync -aq " & "'" & source & "'" & " " & "'" & destination & "'"
@ -115,19 +110,16 @@ method view(list: RoutineListState): Widget =
orient = OrientX
margin = 6
spacing = 6
Switch {.expand: false, vAlign: AlignCenter.}:
state = routine.selByDef
Switch {.expand: false, vAlign: AlignCenter.}:
state = sequtils.any(list.selected, proc (id: RoutineId): bool = id == routine.id)
tooltip = "Enable/Disable this Routine for the current Bkup run."
proc changed(state: bool) =
if state == true:
list.selected.add(routine.id)
list.selected.add(routine.id)
else:
let index = list.selected.find(routine.id)
if index != -1:
list.selected.delete(index)
if not list.changed.isNil:
list.changed.callback(true)
list.selected.delete(index)
Label:
text = "<span size=\"large\">" & routine.name & "</span>"
xAlign = 0
@ -145,13 +137,15 @@ method view(list: RoutineListState): Widget =
mode = EditRoutineUpdate
if res.kind == DialogAccept:
# The "Update" button was clicked
list.routineModel.update(EditRoutineDialogState(state).routine)
list.routineModel.update(EditRoutineDialogState(state).routine)
list.selected = selectedPreload()
# Delete Button
Button {.expand: false.}:
icon = "user-trash-symbolic"
tooltip = "Delete this Routine. Warning: will not ask you to confirm."
proc clicked() =
list.routineModel.delete(routine.id)
list.selected = selectedPreload()
if routine.id in list.selected:
Box:
orient = OrientY

Loading…
Cancel
Save