Finally fix all the race conditions.

This commit is contained in:
Dianne Skoll
2025-10-23 22:00:06 -04:00
parent 65add3d32e
commit a1488d93ad

View File

@@ -1753,8 +1753,9 @@ proc complete_through_today { w } {
proc CreateModifyDialog {w day firstDay args} { proc CreateModifyDialog {w day firstDay args} {
bind $w <Destroy> { bind $w <Destroy> {
global EditingReminder global EditingReminder ModifyDialogResult
set EditingReminder 0 set EditingReminder 0
set ModifyDialogResult -2
} }
# Set up: Year, Month, Day, WeekdayName # Set up: Year, Month, Day, WeekdayName
@@ -2248,14 +2249,16 @@ proc ModifyDayHelper {d firstDay} {
toggle_complete_through .mod toggle_complete_through .mod
bind .mod <ButtonPress-1> [list raise .mod] bind .mod <ButtonPress-1> [list raise .mod]
while {1} { while {1} {
grab .mod catch {
raise .mod grab .mod
focus .mod.entry raise .mod
focus .mod.entry
}
set ModifyDialogResult -1 set ModifyDialogResult -1
tkwait variable ModifyDialogResult tkwait variable ModifyDialogResult
if {$ModifyDialogResult == 1} { if {$ModifyDialogResult == 1 || $ModifyDialogResult == -2 || ![winfo exists .mod]} {
catch {focus $oldFocus} catch {focus $oldFocus}
destroy .mod catch { destroy .mod }
return 0 return 0
} }
set problem [catch {set rem [CreateReminder .mod]} err] set problem [catch {set rem [CreateReminder .mod]} err]
@@ -2265,9 +2268,10 @@ proc ModifyDayHelper {d firstDay} {
} else { } else {
if {$ModifyDialogResult == 3} { if {$ModifyDialogResult == 3} {
set rem [EditReminder $rem Cancel "Add reminder"] set rem [EditReminder $rem Cancel "Add reminder"]
if {$ModifyDialogResult == 1} { if {$ModifyDialogResult == 1 || $ModifyDialogResult == -2} {
continue continue
} }
set ModifyDialogResult 2
} }
set opts [RemindDialogToOptions .mod] set opts [RemindDialogToOptions .mod]
catch {focus $oldFocus} catch {focus $oldFocus}
@@ -2634,6 +2638,10 @@ proc EditReminder {rem args} {
text .edit.t -width 80 -height 5 -relief sunken text .edit.t -width 80 -height 5 -relief sunken
.edit.t insert end $rem .edit.t insert end $rem
frame .edit.f frame .edit.f
bind .edit <Destroy> {
global ModifyDialogResult
set ModifyDialogResult -2
}
set n 0 set n 0
foreach but $args { foreach but $args {
incr n incr n
@@ -2651,8 +2659,15 @@ proc EditReminder {rem args} {
grab .edit grab .edit
tkwait variable ModifyDialogResult tkwait variable ModifyDialogResult
catch {focus $oldFocus} catch {focus $oldFocus}
if {$ModifyDialogResult == -2 || ![winfo exists .edit]} {
catch {destroy .edit}
return ""
}
set rem [.edit.t get 1.0 end] set rem [.edit.t get 1.0 end]
catch {destroy .edit} catch {
bind .edit <Destroy> ""
destroy .edit
}
return $rem return $rem
} }
@@ -3944,14 +3959,16 @@ proc EditTaggedReminderHelper { w } {
set oldFocus [focus] set oldFocus [focus]
bind .mod <ButtonPress-1> [list raise .mod] bind .mod <ButtonPress-1> [list raise .mod]
while {1} { while {1} {
raise .mod catch {
grab .mod grab .mod
focus .mod.entry raise .mod
focus .mod.entry
}
set ModifyDialogResult -1 set ModifyDialogResult -1
tkwait variable ModifyDialogResult tkwait variable ModifyDialogResult
if {$ModifyDialogResult == 1} { if {$ModifyDialogResult == 1 || $ModifyDialogResult == -2 || ![winfo exists .mod]} {
catch {focus $oldFocus} catch {focus $oldFocus}
destroy .mod catch { destroy .mod }
return 0 return 0
} }
set problem [catch {set rem [CreateReminder .mod]} err] set problem [catch {set rem [CreateReminder .mod]} err]
@@ -3961,13 +3978,13 @@ proc EditTaggedReminderHelper { w } {
} }
if {$ModifyDialogResult == 4} { if {$ModifyDialogResult == 4} {
set rem [EditReminder $rem "Cancel" "Replace reminder"] set rem [EditReminder $rem "Cancel" "Replace reminder"]
if {$ModifyDialogResult == 1} { if {$ModifyDialogResult == 1 || $ModifyDialogResult == -2} {
continue continue
} }
set ModifyDialogResult 2
} }
set opts [RemindDialogToOptions .mod] set opts [RemindDialogToOptions .mod]
catch {focus $oldFocus} catch {focus $oldFocus}
destroy .mod
set problem [catch { set problem [catch {
if {$ModifyDialogResult == 2} { if {$ModifyDialogResult == 2} {
ReplaceTaggedReminder $tag $rem $opts ReplaceTaggedReminder $tag $rem $opts
@@ -3975,6 +3992,7 @@ proc EditTaggedReminderHelper { w } {
DeleteTaggedReminder $tag DeleteTaggedReminder $tag
} }
} err] } err]
catch { destroy .mod }
if {$problem} { if {$problem} {
show_error $err show_error $err
return 1 return 1