File: mkdir.tcl

package info (click to toggle)
tkworld 1.4.0-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 952 kB
  • ctags: 336
  • sloc: tcl: 10,189; makefile: 36
file content (318 lines) | stat: -rw-r--r-- 6,931 bytes parent folder | download | duplicates (2)
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
namespace eval mkdir {
    variable mkdir

    # Define the mkdir array structure so that all variables are
    # defined for the callbacks in the radiobuttons and checkbuttons.
    array set mkdir {
	list.reset ""
	list.clear ""
	entry.dir ""
	entry.regexp ""
	dialog ""
	dir ""
	make_parent ""
    }
}

# mkdir::create --
#
#   Method to create the dialog box for the mkdir command.
#
# Note
#
#   This dialog will not grab focus so the user can keep it open
#   and run other tkWorld dialogs.  Imagine how tedious it would be
#   if you had to close the dialog to run your command, then reopen
#   it to modify it.  By not making this a modal dialog, we do not
#   have to implement any last command saving characteristics since
#   the user can just leave the dialog open.
#
# Args
#
#   None.
#
# Returns
#
#   None.

proc mkdir::create { } {
    global tkWorld
    variable mkdir

    # Put the focus on the mkdir dialog if it is already open.
    if [winfo exists $mkdir(dialog)] {
	switch -- [wm state $mkdir(dialog)] {
	    normal {
		raise $mkdir(dialog)
	    }
	    withdrawn -
	    iconic {
		wm deiconify $mkdir(dialog)
	    }
	}
	focus $mkdir(dialog)
	return
    } else {
	set mkdir(dialog) [dialog::create .mkdir Mkdir]
    }

    # The first tab has the dir information, along with the make
    # parent command line option.
    set tab1 [tabnotebook::page [dialog::interior \
	    $mkdir(dialog)] "Options"]

    # Use a frame to encapsulate the dir options so that
    # the frame can be centered accross the grid columns.
    set f1 [frame $tab1.f1 \
	    -class TabnotebookFrame]
    label $f1.dir_label \
	    -text "Directory" \
	    -width 10
    set mkdir(entry.dir) [entry $f1.entry_dir \
	    -width 35 \
	    -textvariable mkdir::mkdir(dir)]
    grid $f1.dir_label $f1.entry_dir \
	    -sticky w \
	    -padx 2 \
	    -pady 2

    # Build the make parent option frame
    set f2 [frame $tab1.f2 \
	    -class TabnotebookFrame]
    checkbutton $f2.make_parent \
	    -text "Make Parent" \
	    -variable mkdir::mkdir(make_parent) \
	    -onvalue "p" \
	    -offvalue ""
    grid $f2.make_parent \
	    -padx 2 \
	    -pady 2 \
	    -sticky w

    # Build the first tab.
    pack $f1 $f2 \
	    -side top \
	    -fill x \
	    -padx 5 \
	    -pady 5 \
	    -ipadx 5 \
	    -ipady 5

    # The 2nd tab has directory permission information.
    set tab2 [tabnotebook::page [dialog::interior \
	    $mkdir(dialog)] "Permissions"]
    set f3 [frame $tab2.f3 \
	    -class TabnotebookFrame]

    set col 0
    foreach t "All User Group Other" {
	set x [string tolower $t]
	set cb($x) [checkbox::create $f3.$x "$t"]
	grid $f3.$x \
		-row 0 \
		-column $col \
		-sticky w \
		-padx 5 \
		-pady 0
	incr col
    }
    foreach {a b} {Read 4 Write 2 Execute 1} {
	set t [string tolower $a]
	checkbox::add $cb(all) $a $b "0" mkdir::mkdir(all_perm_$t)
	checkbox::add $cb(user) $a $b "0" mkdir::mkdir(user_perm_$t)
	checkbox::add $cb(group) $a $b "0" mkdir::mkdir(group_perm_$t)
	checkbox::add $cb(other) $a $b "0" mkdir::mkdir(other_perm_$t)
    }
    unset a b col cb x t

    # Build the second tab.
    pack $f3 \
	    -side top \
	    -fill x \
	    -padx 5 \
	    -pady 5 \
	    -ipadx 5 \
	    -ipady 5

    # Duhhhhhh......
    focus $mkdir(entry.dir)

    # Define the lists for the reset and clear methods
    set mkdir(list.reset) "make_parent all_perm_read all_perm_write \
	    all_perm_execute user_perm_read user_perm_write \
	    user_perm_execute group_perm_read group_perm_write \
	    group_perm_execute other_perm_read other_perm_write \
	    other_perm_execute"
    set mkdir(list.clear) "dir"
}

# mkdir::ok --
#
#   Method to insert the command the user has created into the CC.
#
# Args
#
#   None.
#
# Returns
#
#   None.

proc mkdir::ok { } {
    global tkWorld
    variable mkdir

    # Build the directory list with the working directory in
    # it so it works.
    set dlist ""
    foreach d $mkdir(dir) {
	if [regexp $tkWorld(working_dir) $d] {
	    append dlist "$d "
	} else {
	    append dlist "$tkWorld(working_dir)/$d "
	}
    }

    # Build the first argument if we should build the
    # parent directory.
    set cmd_arg ""
    if [string length $mkdir(make_parent)] {
	set cmd_arg "-$mkdir(make_parent) "
    }

    # Now define the permission stuff if they are turned on.
    foreach x "all user group other" {
	set total($x) [expr $mkdir($x\_perm_read) + \
		$mkdir($x\_perm_write) + \
		$mkdir($x\_perm_execute)]
    }
    if {$total(all) > 0} {
	append cmd_arg "-m \"$total(all)$total(all)$total(all)\" "
    } elseif {$total(user) > 0 || $total(group) > 0 || $total(other) > 0} {
	append cmd_arg "-m \"$total(user)$total(group)$total(other)\" "
    } else {
	append cmd_arg {"000"}
    }
    unset total

    # Insert the Tcl command list in the Command Center with the
    # proper formatting of a space between each argument on the
    # command line.  If there are no options given by the user,
    # then don't display it in the CC.

    if [string length $cmd_arg] {
	set cmd_arg [string trimright $cmd_arg " "]
	$tkWorld(cmd_center) insert insert \
		"mkdir $cmd_arg $dlist"
    } else {
	$tkWorld(cmd_center) insert insert \
		"mkdir $dlist"
    }

    # Activate the buttons in the toolbar for the command center.
    toolbar::group_state cmd_center active
    toolbar::button_state $toolbar::toolbar(stop) disabled

    # Change to the default background/foreground of the
    # directory entry.
    $mkdir(entry.dir) configure -bg white -fg black

    # Give a warning if no directory name is supplied.
    if ![string length $mkdir(dir)] {
	$mkdir(entry.dir) configure -bg yellow
	stderr::log 3001
    }
}

# mkdir::reset --
#
#   Method to reset the radio and checkbuttons in the dialog.
#
# Args
#
#   None.
#
# Returns
#
#   None.

proc mkdir::reset { } {
    variable mkdir

    # Allow for the permission elements to maintain an integer value.
    foreach x $mkdir(list.reset) {
	switch -glob $x {
	    all_perm* -
	    user_perm* -
	    group_perm* -
	    other_perm* {
		set mkdir($x) 0
	    }
	    default {
		set mkdir($x) ""
	    }
	}
    }
}

# mkdir::clear --
#
#   Method to clear entry items of their text and reset the
#   background and foreground properties.
#
# Args
#
#   None.
#
# Returns
#
#   None.

proc mkdir::clear { } {
    variable mkdir

    # Reset the data structure elements and bg/fg.
    foreach x $mkdir(list.clear) {
	set mkdir($x) ""
	$mkdir(entry.$x) configure -bg #ffffff -fg #000000
    }

    focus $mkdir(entry.dir)
}

# mkdir::help --
#
#   Method to invoke the Mkdir Command Help.
#
# Args
#
#   None.
#
# Returns
#
#   None.

proc mkdir::help { } {
    global tkWorld

    help::create "help/mkdir.html" "Mkdir Command Help"
}

# mkdir::close --
#
#   Close the dialog up.
#
# Args
#
#   None.
#
# Returns
#
#   None.

proc mkdir::close { } {
    variable mkdir
    
    balloonhelp::cancel
    destroy $mkdir(dialog)
}