diff --git a/ez_bkup.nim b/ez_bkup.nim index e718d89..8b21496 100644 --- a/ez_bkup.nim +++ b/ez_bkup.nim @@ -8,7 +8,7 @@ import "models/routine", "shared" import views/[edit_routine_dialog, routine_list, app_menu_button] const APP_NAME = "EZ-Bkup" -let databasePath = appPath & "/ez-bkup.sqlite" +#let databasePath = appPath & "/ez-bkup.sqlite" viewable App: ## The main application @@ -43,7 +43,8 @@ method view(app: AppState): Widget {.locks: "unknown".} = # Button to create a new routine Button: style = [ButtonSuggested] - text = "+ Routine" + text = "+ Routine" + tooltip = "Create a new Bkup Routine" proc clicked() = ## Opens the EditRoutineDialog for creating a new routine let (res, state) = app.open: gui: diff --git a/models/routine.nim b/models/routine.nim index 737d9e3..1e63ec1 100644 --- a/models/routine.nim +++ b/models/routine.nim @@ -184,4 +184,13 @@ proc clear*(model: RoutineModel) = model.db.exec("DELETE FROM Routine") # Update RoutineModel.routines - model.routines.clear() \ No newline at end of file + model.routines.clear() + +#preload the selected seq with routines that have selByDef == true. +proc selectedPreload*(): seq[RoutineId] = + var selected: seq[RoutineId] + let model = newRoutineModel(databasePath) + for routine in model.routineSeq(): + if routine.selByDef == true: + selected.add(routine.id) + return selected \ No newline at end of file diff --git a/shared.nim b/shared.nim index e218131..a93dd55 100644 --- a/shared.nim +++ b/shared.nim @@ -4,19 +4,10 @@ EZ-Bkup is released under the General Public License 3.0. See COPYING or for details.]# import logging, times, os, distros -#import "models/routine" - -#store the RoutineIds of ea. Routine selected for the current Bkup run. -#[type SelectedRoutine* = object - id*: RoutineId - name*: string - sources*: seq[string] - destinations*: seq[string] - -type CurrentRun* = object - status*: string]# +import "models/routine" let appPath* = getHomeDir() & ".ez-bkup" +let databasePath* = appPath & "/ez-bkup.sqlite" if not dirExists(appPath): createDir(appPath) diff --git a/views/routine_editor.nim b/views/routine_editor.nim index 1980f7f..a15271f 100644 --- a/views/routine_editor.nim +++ b/views/routine_editor.nim @@ -41,11 +41,8 @@ method view(editor: RoutineEditorState): Widget {.locks: "unknown".} = orient = OrientX spacing = 6 Label {.expand: false.}: - #later, this may be "selected by default?", instead. - #"selected" checkboxes wiould be added to the list view. - #to allow the user to select which routines are used for a given run. - text = "Enabled?" - tooltip = "Should this Routine be enabled for inclusion in the Bkup run?" + text = "Enabled by default?" + tooltip = "Should this Routine be enabled for inclusion in any Bkup run by default?" xAlign = 0 useMarkup = true Switch {.expand: false.}: diff --git a/views/routine_list.nim b/views/routine_list.nim index 46ac5f5..d56bfa1 100644 --- a/views/routine_list.nim +++ b/views/routine_list.nim @@ -11,6 +11,14 @@ import "../models/routine", "../shared" viewable RoutineList: routineModel: RoutineModel runStatus: string + selected: seq[RoutineId] + + # hey, hook. + hooks: + # yes, you, the build hook. + build: + # i love you. :) + state.selected = selectedPreload() proc changed(state: bool) @@ -33,8 +41,7 @@ proc rsyncThread(list: RoutineListState) {.thread.} = var routineRunCount: int routineRunCount = 0 for routine in list.routineModel.routineSeq(): - #using this as "selected" for now. - if routine.selByDef == true: + if routine.id in list.selected: #skip routines that don't have at least one source and one destination. if routine.sources.len != 0 and routine.destinations.len != 0: list.runStatus = "Horses, please to be holding..." @@ -77,7 +84,7 @@ method view(list: RoutineListState): Widget {.locks: "unknown".} = orient = OrientY if list.routineModel.routineSeq().len() > 0: ListBox: - for it, routine in list.routineModel.routineSeq(): + for it, routine in list.routineModel.routineSeq(): Box: orient = OrientY margin = 6 @@ -85,7 +92,20 @@ method view(list: RoutineListState): Widget {.locks: "unknown".} = Box: orient = OrientX margin = 6 - spacing = 6 + spacing = 6 + Switch {.expand: false, vAlign: AlignCenter.}: + state = routine.selByDef + tooltip = "Enable/Disable this Routine for the current Bkup run." + proc changed(state: bool) = + if state == true: + 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) Label: text = "" & routine.name & "" xAlign = 0 @@ -110,7 +130,7 @@ method view(list: RoutineListState): Widget {.locks: "unknown".} = tooltip = "Delete this Routine. Warning: will not ask you to confirm." proc clicked() = list.routineModel.delete(routine.id) - if routine.selByDef: + if routine.id in list.selected: Box: orient = OrientY margin = 6 @@ -192,7 +212,6 @@ method view(list: RoutineListState): Widget {.locks: "unknown".} = xAlign = 0 useMarkup = true proc clicked() = - #list.runStatus = "Running Bkup..." createThread(thread, rsyncThread, list) else: Box {.expand: false.}: