mirror of
https://salsa.debian.org/dskoll/remind.git
synced 2026-04-16 06:18:47 +02:00
-- Beginning of infrastructure for editing reminders from TkRemind.
This commit is contained in:
252
scripts/tkremind
252
scripts/tkremind
@@ -11,7 +11,7 @@
|
||||
#
|
||||
#--------------------------------------------------------------
|
||||
|
||||
# $Id: tkremind,v 1.8 1998-03-04 18:13:13 dfs Exp $
|
||||
# $Id: tkremind,v 1.9 1998-03-13 02:52:20 dfs Exp $
|
||||
|
||||
# the next line restarts using wish \
|
||||
exec wish "$0" "$@"
|
||||
@@ -75,6 +75,9 @@ set PrintSize letter
|
||||
set PrintOrient landscape
|
||||
set PrintFill 1
|
||||
|
||||
# Highest tag seen so far. Array of tags is stored in ReminderTags()
|
||||
set HighestTagSoFar 0
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# Initialize -- initialize things
|
||||
#---------------------------------------------------------------------------
|
||||
@@ -218,6 +221,9 @@ proc CreateCalWindow { firstDay mondayFirst daysInMonth month year dayNames } {
|
||||
while { $row <= $numRows } {
|
||||
button .h.col$col.num$row -text "" -justify center -command "" -state disabled -relief flat
|
||||
text .h.col$col.t$row -width 12 -height 1 -wrap word -relief sunken -state disabled
|
||||
.h.col$col.t$row tag bind TAGGED <Enter> "TaggedEnter .h.col$col.t$row"
|
||||
.h.col$col.t$row tag bind TAGGED <Leave> "TaggedLeave .h.col$col.t$row"
|
||||
.h.col$col.t$row tag bind TAGGED <ButtonPress-1> "EditTaggedReminder .h.col$col.t$row"
|
||||
pack .h.col$col.num$row -side top -fill x -expand 0
|
||||
pack .h.col$col.t$row -side top -fill both -expand 1
|
||||
incr row
|
||||
@@ -288,7 +294,7 @@ proc FillCalWindow {} {
|
||||
gets $file line
|
||||
CreateCalWindow $firstWkday $mondayFirst $daysInMonth $monthName $year $DayNames
|
||||
while { [gets $file line] >= 0 } {
|
||||
if { [regexp {^([0-9][0-9][0-9][0-9])/([0-9][0-9])/([0-9][0-9]) +([^ ]+) +[^ ]+ +[^ ]+ +[^ ]+(.*)} $line all year month day type stuff] == 0 } {
|
||||
if { [regexp {^([0-9][0-9][0-9][0-9])/([0-9][0-9])/([0-9][0-9]) +([^ ]+) +([^ ]+) +[^ ]+ +[^ ]+(.*)} $line all year month day type tag stuff] == 0 } {
|
||||
continue
|
||||
}
|
||||
if { $type != "*"} {
|
||||
@@ -302,7 +308,11 @@ proc FillCalWindow {} {
|
||||
if { [string length [string trim [.h.col$c.t$r get 1.0]]] != 0} {
|
||||
.h.col$c.t$r insert end " .....\n"
|
||||
}
|
||||
.h.col$c.t$r insert end [string trim $stuff]
|
||||
if {[regexp {TKTAG([0-9])+} $tag all tagno]} {
|
||||
.h.col$c.t$r insert end [string trim $stuff] "TAGGED TKTAG$tagno"
|
||||
} else {
|
||||
.h.col$c.t$r insert end [string trim $stuff]
|
||||
}
|
||||
.h.col$c.t$r insert end "\n"
|
||||
.h.col$c.t$r configure -state disabled
|
||||
|
||||
@@ -755,6 +765,71 @@ proc CreateModifyDialog {w day firstDay} {
|
||||
CenterWindow $w
|
||||
}
|
||||
|
||||
#***********************************************************************
|
||||
# %PROCEDURE: RemindDialogToOptions
|
||||
# %ARGUMENTS:
|
||||
# w -- dialog window
|
||||
# %RETURNS:
|
||||
# A list of flag/value pairs representing the current state of
|
||||
# the "create reminder" dialog.
|
||||
#***********************************************************************
|
||||
proc RemindDialogToOptions { w } {
|
||||
global OptionType SkipType repbut expbut advbut advcount
|
||||
global timebut timeadvbut timerepbut
|
||||
global dSaturday dSunday dMonday dTuesday dWednesday dThursday dFriday
|
||||
set ans {}
|
||||
lappend ans "-global-OptionType" $OptionType
|
||||
lappend ans "-global-SkipType" $SkipType
|
||||
foreach win [winfo children $w] {
|
||||
set winstem [winfo name $win]
|
||||
switch -exact -- [winfo class $win] {
|
||||
"Menubutton" {
|
||||
lappend ans "-text-$winstem" [$win cget -text]
|
||||
}
|
||||
"Checkbutton" {
|
||||
lappend ans "-global-$winstem" [eval set $winstem]
|
||||
}
|
||||
"Entry" {
|
||||
lappend ans "-entry-$winstem" [$win get]
|
||||
}
|
||||
}
|
||||
}
|
||||
return $ans
|
||||
}
|
||||
|
||||
#***********************************************************************
|
||||
# %PROCEDURE: OptionsToRemindDialog
|
||||
# %ARGUMENTS:
|
||||
# w -- Remind dialog window
|
||||
# opts -- option list set by RemindDialogToOptions
|
||||
# %RETURNS:
|
||||
# Nothing
|
||||
# %DESCRIPTION:
|
||||
# Sets parameters in the dialog box according to saved options.
|
||||
#***********************************************************************
|
||||
proc OptionsToRemindDialog { w opts } {
|
||||
global OptionType SkipType repbut expbut advbut advcount
|
||||
global timebut timeadvbut timerepbut
|
||||
global dSaturday dSunday dMonday dTuesday dWednesday dThursday dFriday
|
||||
foreach {flag value} $opts {
|
||||
switch -glob -- $flag {
|
||||
"-text-*" {
|
||||
set win [string range $flag 6 end]
|
||||
$w.$win configure -text $value
|
||||
}
|
||||
"-global-*" {
|
||||
set win [string range $flag 8 end]
|
||||
set $win $value
|
||||
}
|
||||
"-entry-*" {
|
||||
set win [string range $flag 7 end]
|
||||
$w.$win delete 0 end
|
||||
$w.$win insert end $value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#---------------------------------------------------------------------------
|
||||
# CreateMonthMenu -- create a menu with all the months of the year
|
||||
# Arguments:
|
||||
@@ -836,8 +911,7 @@ proc CreateYearMenu {w {every 1}} {
|
||||
# firstDay -- first weekday in month (0-6)
|
||||
#---------------------------------------------------------------------------
|
||||
proc ModifyDay {d firstDay} {
|
||||
global ModifyDialogResult AppendFile
|
||||
|
||||
global ModifyDialogResult AppendFile HighestTagSoFar ReminderTags
|
||||
catch {destroy .mod}
|
||||
toplevel .mod
|
||||
CreateModifyDialog .mod $d $firstDay
|
||||
@@ -865,13 +939,21 @@ proc ModifyDay {d firstDay} {
|
||||
continue
|
||||
}
|
||||
}
|
||||
set opts [RemindDialogToOptions .mod]
|
||||
catch {focus $oldFocus}
|
||||
destroy .mod
|
||||
Status "Writing reminder..."
|
||||
set f [open $AppendFile a]
|
||||
puts $f "# Next reminder was created with TkRemind"
|
||||
puts $f $err
|
||||
puts $f ""
|
||||
incr HighestTagSoFar
|
||||
set ReminderTags($HighestTagSoFar) 1
|
||||
puts $f "# TKTAG$HighestTagSoFar Next reminder was created with TkRemind. DO NOT EDIT"
|
||||
puts $f "# $opts"
|
||||
if {[string range $err 0 3] == "REM "} {
|
||||
puts $f "REM TAG TKTAG$HighestTagSoFar [string range $err 4 end]"
|
||||
} else {
|
||||
puts $f $err
|
||||
}
|
||||
puts $f "# TKEND"
|
||||
close $f
|
||||
FillCalWindow
|
||||
RestartBackgroundRemindDaemon
|
||||
@@ -1460,12 +1542,12 @@ proc DaemonReadable { file } {
|
||||
catch { close $file }
|
||||
return
|
||||
}
|
||||
switch -glob $line {
|
||||
switch -glob -- $line {
|
||||
"NOTE reminder*" {
|
||||
scan $line "NOTE reminder %s %s" time now
|
||||
IssueBackgroundReminder $file $time $now
|
||||
}
|
||||
"NOTE newdate"{
|
||||
"NOTE newdate" {
|
||||
Initialize
|
||||
FillCalWindow
|
||||
}
|
||||
@@ -1535,8 +1617,12 @@ proc IssueBackgroundReminder { file time now } {
|
||||
}
|
||||
|
||||
proc main {} {
|
||||
global AppendFile HighestTagSoFar
|
||||
wm withdraw .
|
||||
puts "\nTkRemind Copyright (c) 1996-1998 by David F. Skoll\n"
|
||||
puts "Scanning for tags..."
|
||||
ScanForTags $AppendFile
|
||||
puts "Highest tag: $HighestTagSoFar"
|
||||
puts "Initializing..."
|
||||
Initialize
|
||||
puts "Creating calendar window..."
|
||||
@@ -1553,5 +1639,151 @@ proc main {} {
|
||||
StartBackgroundRemindDaemon
|
||||
}
|
||||
|
||||
#***********************************************************************
|
||||
# %PROCEDURE: ScanForTags
|
||||
# %ARGUMENTS:
|
||||
# fname -- name of file to scan
|
||||
# %RETURNS:
|
||||
# Nothing
|
||||
# %DESCRIPTION:
|
||||
# Scans the file for all tags of the form "TKTAGnnnn" and builds
|
||||
# the tag array. Also adjusts HighestTagSoFar
|
||||
#***********************************************************************
|
||||
proc ScanForTags { fname } {
|
||||
global HighestTagSoFar ReminderTags
|
||||
if {[catch { set f [open $fname "r"]}]} {
|
||||
return
|
||||
}
|
||||
while {[gets $f line] >= 0} {
|
||||
switch -regexp -- $line {
|
||||
{^# TKTAG[0-9]+} {
|
||||
regexp {^# TKTAG([0-9]+)} $line dummy tagno
|
||||
if {$tagno > $HighestTagSoFar} {
|
||||
set HighestTagSoFar $tagno
|
||||
}
|
||||
set ReminderTags($tagno) 1
|
||||
}
|
||||
}
|
||||
}
|
||||
close $f
|
||||
}
|
||||
|
||||
#***********************************************************************
|
||||
# %PROCEDURE: ReadTaggedOptions
|
||||
# %ARGUMENTS:
|
||||
# tag -- tag to match
|
||||
# %RETURNS:
|
||||
# A list of options for the dialog box for the tagged reminder
|
||||
# %DESCRIPTION:
|
||||
# Scans the file for specified tag and returns the "options" list for the
|
||||
# reminder.
|
||||
#***********************************************************************
|
||||
proc ReadTaggedOptions { tag } {
|
||||
global AppendFile
|
||||
if {[catch { set f [open $AppendFile "r"]}]} {
|
||||
return ""
|
||||
}
|
||||
while {[gets $f line] >= 0} {
|
||||
if {[string match "# $tag *" $line]} {
|
||||
gets $f line
|
||||
close $f
|
||||
return [string range $line 2 end]
|
||||
}
|
||||
}
|
||||
close $f
|
||||
return ""
|
||||
}
|
||||
|
||||
#***********************************************************************
|
||||
# %PROCEDURE: GetCurrentReminder
|
||||
# %ARGUMENTS:
|
||||
# w -- text window
|
||||
# %RETURNS:
|
||||
# The tag (TKTAGnnnn) for current editable reminder, or "" if no
|
||||
# current editable reminder.
|
||||
#***********************************************************************
|
||||
proc GetCurrentReminder { w } {
|
||||
set tags [$w tag names current]
|
||||
set index [lsearch -glob $tags "TKTAG*"]
|
||||
if {$index < 0} {
|
||||
return ""
|
||||
}
|
||||
set tag [lindex $tags $index]
|
||||
return $tag
|
||||
}
|
||||
|
||||
#***********************************************************************
|
||||
# %PROCEDURE: TaggedEnter
|
||||
# %ARGUMENTS:
|
||||
# w -- text window
|
||||
# %RETURNS:
|
||||
# Nothing
|
||||
# %DESCRIPTION:
|
||||
# Highlights an "editable" reminder as mouse moves into it
|
||||
#***********************************************************************
|
||||
proc TaggedEnter { w } {
|
||||
set tag [GetCurrentReminder $w]
|
||||
if {$tag != ""} {
|
||||
$w tag configure $tag -foreground #FF0000
|
||||
}
|
||||
}
|
||||
#***********************************************************************
|
||||
# %PROCEDURE: TaggedLeave
|
||||
# %ARGUMENTS:
|
||||
# w -- text window
|
||||
# %RETURNS:
|
||||
# Nothing
|
||||
# %DESCRIPTION:
|
||||
# Removes highlight from an "editable" reminder as mouse leaves it
|
||||
#***********************************************************************
|
||||
proc TaggedLeave { w } {
|
||||
set tag [GetCurrentReminder $w]
|
||||
if {$tag != ""} {
|
||||
$w tag configure $tag -foreground #000000
|
||||
}
|
||||
}
|
||||
|
||||
#***********************************************************************
|
||||
# %PROCEDURE: EditTaggedReminder
|
||||
# %ARGUMENTS:
|
||||
# w -- text window
|
||||
# %RETURNS:
|
||||
# Nothing
|
||||
# %DESCRIPTION:
|
||||
# Opens a dialog box to edit the current editable reminder
|
||||
#***********************************************************************
|
||||
proc EditTaggedReminder { w } {
|
||||
set tag [GetCurrentReminder $w]
|
||||
if {$tag == ""} {
|
||||
return
|
||||
}
|
||||
|
||||
# Read in options
|
||||
set opts [ReadTaggedOptions $tag]
|
||||
if {$opts == ""} {
|
||||
return
|
||||
}
|
||||
|
||||
toplevel .mod
|
||||
CreateModifyDialog .mod 1 0
|
||||
wm title .mod "Edit Reminder..."
|
||||
wm iconname .mod "Edit Reminder"
|
||||
OptionsToRemindDialog .mod $opts
|
||||
|
||||
tkwait visibility .mod
|
||||
set oldFocus [focus]
|
||||
while {1} {
|
||||
grab .mod
|
||||
focus .mod.entry
|
||||
set ModifyDialogResult -1
|
||||
tkwait variable ModifyDialogResult
|
||||
catch {focus $oldFocus}
|
||||
destroy .mod
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
main
|
||||
|
||||
# For debugging only...
|
||||
# fileevent stdin readable "DaemonReadable stdin"
|
||||
|
||||
Reference in New Issue
Block a user