File: details.tcl

package info (click to toggle)
dotfile 2.2-1
  • links: PTS
  • area: main
  • in suites: hamm, slink
  • size: 4,596 kB
  • ctags: 456
  • sloc: tcl: 11,732; sh: 965; makefile: 304; csh: 13; ansic: 7
file content (219 lines) | stat: -rw-r--r-- 8,576 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
######################################################################
### This function creates the deailts window, where the
### user can select which pages he want's to load
###
### The details page works on the following variables.
### __textChildren: an associativ array, which maps from the index of
###                 the element to the indexes of all it's children
### __textParent:   an associativ array, which maps from the index of
###                 the element, to the index of it's parent
### __textFunction: an associativ array, which maps from the index of
###                 the element, to the name of the function, which have
###                 created the page.
### __loadFile:     an associativ array, which have the element indexes as
###                 keys, and as values, information about whether the page
###                 shall be loaded.
### __overWrite:    an associativ array from index to information wether
###                 the page shall overwrite or append.
######################################################################
proc createDetails {merge loadFile} {
  global __textLine __loadFile __overWrite __textFunction
  set w [toplevel .details]
  grabSet .details
  wm resizable $w 0 0

  label $w.label -text "Merge Overwrite[space 20]Menu Pages"
  pack $w.label -anchor w
  ### packing the menu page information
  pack [frame $w.frame] -fill both -expand 1
  set frame $w.frame
  text $frame.text -yscrollcommand "$frame.scroll set" -cursor left_ptr \
       -font [$w.label cget -font]
  $frame.text tag configure line -wrap none
  scrollbar $frame.scroll -command "$frame.text yview"
  pack $frame.text  -side left -fill both -expand 1
  pack $frame.scroll -side left -fill y -expand 0

  ### inserting the menus
  set __textLine -1
  insertMenus $frame.text 0 "" -1 $merge
  bindtags $frame.text None

  ### inserting the "load setup"
  set i [$frame.text index insert]
  $frame.text insert insert "_______________________________________________________________________________________________________________________________________________________________\n"
  $frame.text tag add line $i insert

  checkbutton $frame.text.loadSetup -variable __loadSetup \
      -text "Load Setup"
  $frame.text window create end -window $frame.text.loadSetup
  if {!$loadFile} {
    $frame.text.loadSetup configure -state disabled
  }
  
  ### packing the help text
  label $w.help -wraplength 500 -justify left -text "\nHere you should select which pages you which to load. You select a page by pressing the left mouse button on the name of the page. If you which to load a whole menu structore press the left mouse button on the top of the menu structore.\n\nIn the left colum, you may select how you which the pages to be loaded. You can either select \"Overwrite\" in which case the page will overwrite any existing page, or you may select \"Merge\", in which case ExtEntries will be merged together.\nPlease note that you can not merge save files."
  pack $w.help -fill x -expand 1
  ### packing the OK button
  button $w.ok -text CLOSE -command {destroy .details}
  button $w.helppage -text Help -command "help`gotoTag load_detail"
  pack $w.ok $w.helppage -side right

  ### taking the grab
  grabSet $w
  tkwait window $w
  set merge {}
  set overwrite {}
  foreach elm [array names __loadFile] {
    if {$__loadFile($elm) && [info exists __textFunction($elm)]} {
      if {$__overWrite($elm)} {
        lappend overwrite $__textFunction($elm)
      } else {
        lappend merge  $__textFunction($elm)
      }
    }
  }
  return [list $overwrite $merge]
}

######################################################################
### This function insert the element 'top' and all it's children
######################################################################
proc insertMenus {w level  top parent merge} {
  global __subPath __menu2funk __textLine __loadFile __textChildren __textParent
  global __textFunction __overWrite

  ### calculate the name of the menu
  set menuPath [split $top "/"]
  set name [lindex $menuPath  end]
  if {$name == ""} {
    set name ALL
  }

  ### set the parrent
  incr __textLine
  set __textParent($__textLine) $parent
  set self $__textLine

  ### create the radio buttons
  if {![info exists __overWrite($__textLine)]} {
    set __overWrite($__textLine) 1
  } 
  radiobutton $w.merge_$__textLine -variable __overWrite($__textLine) -value 0\
      -command "radioSelect $__textLine 0 setFromCursor"
  radiobutton $w.overwrite_$__textLine -variable __overWrite($__textLine) \
      -value 1 -command "radioSelect $__textLine 1 setFromCursor"
  $w window create end -window $w.merge_$__textLine
  $w insert insert "  "
  $w window create end -window $w.overwrite_$__textLine
  if {!$merge} {
    set __overWrite($__textLine) 1
    foreach elm "$w.merge_$__textLine $w.overwrite_$__textLine" {
      bind $elm <1> {
        tk_dialog .error "Option disabled" "This option is disabled, either because you've just opened the Dot.Gen., and by that reason there is nothing to merge with, or because you've chosen a save file. Save files can not be merged, you have to export the selected file, and import it as a export file." info 0 OK
      }
      $elm configure -state disabled
    }
  }
  
  ### insert the name into the text widget, and set the tag
  $w insert end [space $level]
  set index [$w index insert]
  $w insert end "$name"
  $w tag add tag$__textLine $index insert
  $w insert end \n
  $w tag bind tag$__textLine <1> "tagSelect $w $__textLine setFromCursor"
  if {![info exists __loadFile($__textLine)]} {
    set __loadFile($__textLine) 1
  }
  if {$__loadFile($__textLine) == 1} {
    $w tag configure tag$__textLine -background [$w cget -fg] \
        -foreground [$w cget -bg]
  } elseif {$__loadFile($__textLine) == -1} {
    $w tag configure tag$__textLine -background grey
  }

  ### insert all it's children
  set __textChildren($self) {}
  if {[info exists __subPath($top/)]} {
    ### The element is a menu
    foreach page $__subPath($top/) {
      set child [insertMenus $w [expr $level +4] $top/$page $self $merge]
      lappend __textChildren($self) $child
    }
    if {$level == 4} {
      set i [$w index insert]
      $w insert insert "_______________________________________________________________________________________________________________________________________________________________"
      $w tag add line $i insert
      $w insert insert \n\n
    }
  } else {
    set __textFunction($self) $__menu2funk($top)
  }
  return $self
}

######################################################################
### This function is called, when the mouse is pressed over an element
### It then calls recursive, to (un)set all the children of the element
### and to grey out all the parrents of the element.
######################################################################
proc tagSelect {w self type {value 0}} {
  global __loadFile __textChildren __textParent
  set fg [$w cget -fg]
  set bg [$w cget -bg]

  if {$type == "setFromCursor"} {
    set __loadFile($self) [expr ($__loadFile($self)+1)%2]
  } elseif {$type == "setFromParent"} {
    set __loadFile($self) $value
  } 

  ### set the color of the foreground and background
  if {$type == "setFromChild"} {
    set fg [$w cget -fg]
    set bg grey
    set __loadFile($self) -1
  } else {
    if {$__loadFile($self)} {
      set fg [$w cget -bg]
      set bg [$w cget -fg]
    } else {
      set fg [$w cget -fg]
      set bg [$w cget -bg]
    }
  }
  $w tag configure tag$self -foreground  $fg -background $bg

  ### call recursive
  if {$type != "setFromChild"} {
    foreach child $__textChildren($self) {
      tagSelect $w $child "setFromParent" $__loadFile($self)
    }
  }
  if {$type != "setFromParent"} {
    if {$__textParent($self) != -1} {
      tagSelect $w $__textParent($self) "setFromChild"
    }
  }
}

######################################################################
### This function is called when a radio element is selected.
### It then calls recursive to set all the children, and to
### unset all the parrent.
######################################################################
proc radioSelect {self value type} {
  global __overWrite __textChildren __textParent

  set __overWrite($self) $value

  if {$type != "setFromParent" && $__textParent($self) != -1} {
    radioSelect $__textParent($self) "" setFromChild
  }
  if {$type != "setFromChild"} {
    foreach child $__textChildren($self) {
      radioSelect $child $value setFromParent
    }
  }
}