summaryrefslogtreecommitdiff
path: root/support/dinbrief-gui/dinbrief.vfs/menu.tcl
blob: 7b375af26f48108b07fdcb55765b8f39c045e93a (plain)
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
if {[winfo exists .menu]} {
    destroy .menu
}

# set currentFile ""

namespace eval global {
    array set value {
	file ""
	justOpened no
	fontSize 9
	verticalAddressAlign \\centeraddress
	addressRules \\windowrules
	backAddressRules \\backaddressrule
	paperFoldMarks \\windowtics
	pdflatex pdflatex
	pdfViewer xpdf
	smartQuotes C
	list-O-matic deep
	numberAlign right
	... \\ldots
	windowGeometry 550x550+20+20
	language ngerman
	refLineOverFold 1
	addressPos \\addressstd
	1000.dezimal, {. ,}
	lastSearchString ""
    }
    variable defaultDir\
	[file dirname [file dirname [file normalize [info script]]]]
    after idle [list cd $defaultDir]
    variable valueFile [file join $defaultDir global.vars]
    set value(defaultFile) [file join $defaultDir default.dinbrief]
    if {[file exists $valueFile]} {
	array set value [cat $valueFile]
    }
    wm geometry . $value(windowGeometry)
    option add *Entry.font		"Helvetica $value(fontSize)"
    option add *Label.font		"Helvetica $value(fontSize)"
    option add *Button.font		"Helvetica $value(fontSize)"
    option add *Menubutton.font		"Helvetica $value(fontSize)"
    option add *Checkbutton.font	"Helvetica $value(fontSize)"
    option add *Labelframe.font		"Helvetica $value(fontSize)"
    option add *Text.font		"Helvetica $value(fontSize)" 
}



proc global::globalSetting {args} {
    variable value
    if {[llength $args] > 1} {
	array set value $args
    } elseif {[llength $args] == 0} {
	array get value
    } else {
	set value([lindex $args 0])
    }
}

proc global::storeGlobalSettings {} {
    variable value
    variable valueFile
    globalSetting windowGeometry [wm geometry .]
    saveString [array get value] $valueFile
}

namespace eval global {
    namespace export *
}

namespace import -force global::*

after idle {::Richtext::setQuotes [globalSetting smartQuotes]}

wm protocol . WM_DELETE_WINDOW {
    .menu.file invoke Ende
}

[menu .menu] add cascade\
    -label Datei\
    -menu [menu .menu.file -tearoff 0]

.menu.file add command\
    -label Neu\
    -command [lambda {} {
	. configure -cursor watch
	update
	set defaultFile [globalSetting defaultFile]
	set failure 0
	if {[file exists $defaultFile]} {
	    if {[catch {
		putContents [cat $defaultFile]
	    } err]} {
		set failure 1
	    }
	} else {
	    set failure 1
	}
	if {$failure} {
	    foreach entry [winfo children .] {
		switch [winfo class $entry] {
		    Entry {
			$entry delete 0 end
		    }
		    Text - Richtext - Scrolledtext - Scrolledrichtext {
			$entry delete 1.0 end
		    }
		}
	    }
	}
	wm title . "DIN-Brief"
	globalSetting file ""
	. configure -cursor ""
    }]

.menu.file add command\
    -label {Öffnen ...}\
    -command [lambda {} {
	set f [tk_getOpenFile -filetypes {
	    {{DIN-Brief} {.dinbrief .DIN-Brief}}
	    {{Alle} *}
	}]
	if {$f ne ""} {
	    loadContents $f
	    # globalSetting file [file normalize $f]
	    globalSetting file [relPathFromTo [pwd] $f]
	    wm title . "DIN-Brief: [file rootname [file tail $f]]"
	    globalSetting justOpened yes
	} else {
	    globalSetting justOpened no
	}
	after idle [list initTabTags .maintext]
    }]

.menu.file add command\
    -label {Erneut öffnen}\
    -command [lambda {} {
	set currentFile [globalSetting file]
	if {$currentFile eq ""} {
	    .menu.file invoke Neu
	} else {
	    loadContents $currentFile
	    wm title . "DIN-Brief: [file rootname [file tail $currentFile]]"
	    after idle [list initTabTags .maintext]
	}
    }]

after idle [list .menu.file invoke {Erneut öffnen}]

.menu.file add command\
    -label {Öffnen als Vorlage ...}\
    -command [lambda {} {
	.menu.file invoke {Öffnen ...}
	if {[globalSetting justOpened]} {
	    globalSetting file ""
	    wm title . Din-Brief
	}
    }]

.menu.file add separator

.menu.file add command\
    -label Speichern\
    -command [lambda {} {
	. configure -cursor watch
	update
 	set currentFile [globalSetting file]
 	if {$currentFile ne ""} {
 	    saveContents $currentFile
 	    wm title . "DIN-Brief: [file rootname [file tail $currentFile]]"
 	} else {
 	    .menu.file invoke {Speichern als ...}
 	}
	. configure -cursor ""
    }]

.menu.file add command\
    -label {Speichern als ...}\
    -command [lambda {} {
	. configure -cursor watch
	update
 	set f [tk_getSaveFile\
		   -defaultextension .dinbrief\
		   -filetypes {
		       {{DIN-Brief}
			   {.dinbrief .DIN-Brief}}
		       {{Alle}
			   *}
		   }]
 	if {$f ne ""} {
 	    saveContents $f
 	    globalSetting file [file normalize $f]
 	    wm title . "DIN-Brief: [file rootname [file tail $f]]"
 	}
	. configure -cursor ""
    }]

.menu.file add command\
    -label {Speichern als Default-Brief}\
    -command [lambda {} {
	. configure -cursor watch
	update
	set defaultFile [globalSetting defaultFile]
	saveContents $defaultFile
	globalSetting file ""
	wm title . DIN-Brief
	. configure -cursor ""
    }]

.menu.file add separator

.menu.file add command\
    -label {Export nach LaTeX}\
    -command [lambda {} {
	. configure -cursor watch
	update
	set currentFile [globalSetting file]
	if {$currentFile eq ""} {
	    set f default
	} else {
	    set workingDir [file dirname $currentFile]
	    set workingFile [string map {" " _} [file tail $currentFile]]
	    set f [file join $workingDir [file rootname $workingFile]]
	}
	saveString [formular2tex] $f.tex
	. configure -cursor ""
    }]

.menu.file add command\
    -label {Export nach PDF}\
    -command [lambda {} {
	set currentFile [globalSetting file]
	.menu.file invoke {Export nach LaTeX}
	if {$currentFile eq ""} {
	    set rootname default
	} else {
# 	    set workingDir [file dirname $currentFile]
# 	    set workingFile [string map {" " _} [file tail $currentFile]]
# 	    set rootname\
# 		[file join $workingDir [file rootname $workingFile]]
	    set rootname [string map {" " _} [file rootname $currentFile]]
	}
	if {![file executable [globalSetting pdflatex]]} {
	    .menu.external invoke {Pfad von pdflatex}
	} else {
	    globalSetting justOpened yes
	}
	if {[globalSetting justOpened]} {
	    set cmd [list\
			 exec [globalSetting pdflatex]\
			 --interaction nonstopmode\
			 $rootname.tex]
	    if {[catch $cmd err]} {
		puts $err
		echo But don't worry,\
		    possibly just changed language,\
		    just another try ...
		eval $cmd
	    }
	}
    }]

.menu.file add separator

.menu.file add command\
    -label Ende\
    -command {
	if {[globalSetting file] ne ""} {
	    .menu.file invoke Speichern
	}
	storeGlobalSettings
	exit
    }

.menu add cascade\
    -label Bearbeiten\
    -menu [menu .menu.edit -tearoff no]

.menu.edit add command\
    -label Ausschneiden\
    -command {
	event generate [focus] <<Cut>>
	event generate [focus] <<Change>>
    }\
    -accelerator Ctrl-x

.menu.edit add command\
    -label Kopieren\
    -command {
	event generate [focus] <<Copy>>
    }\
    -accelerator Ctrl-c

.menu.edit add command\
    -label Einfügen\
    -command {
	event generate [focus] <<Paste>>
	event generate [focus] <<Change>>
    }\
    -accelerator Ctrl-v

.menu.edit add separator

.menu.edit add command\
    -label "Datum ([clock format [clock seconds] -format {%d.%m.%y}])"\
    -command [lambda {} {
	set window [focus]
	switch [winfo class $window] {
	    Text - Richtext - Scrolledtext - Scrolledrichtext {
		foreach {to from} [lreverse [$window tag ranges sel]] {
		    $window delete $from $to
		}
		$window insert insert\
		    [clock format [clock seconds] -format {%d.%m.%y}]
	    }
	    Entry {
		catch {
		    $window delete sel.first sel.last
		}
		$window insert insert\
		    [clock format [clock seconds] -format {%d.%m.%y}]
	    }
	}
    }]

.menu.edit add command\
    -label Seitenwechsel\
    -command {tk::TextInsert [focus] \n\u000c\n}\
    -accelerator Ctrl-l

.menu.edit add separator

.menu.edit add command\
    -label Suche\
    -command {
	focus .maintext.text
	after idle {
	    toggleSearchMode .maintext
	}
    }\
    -accelerator F3

.menu.edit add command\
    -label Rückgängig\
    -command {
	event generate [focus] <<Undo>>
    }\
    -accelerator Ctrl-z

.menu.edit add command\
    -label Wiederholen\
    -command {
	event generate [focus] <<Redo>>
    }\
    -accelerator Ctrl-y

proc switchMenuEdit {state args} {
    foreach i $args {
	.menu.edit entryconfigure $i -state $state
    }
}

bind Entry <FocusIn> {
    switchMenuEdit normal 0 1 2 4 5 7 8 9
    switchMenuEdit disabled 5 7 8 9
}

bind Richtext <FocusIn> {
    switchMenuEdit normal 0 1 2 4 5 7 8 9
    switchMenuEdit disabled 5 7
}

bind Richtext <Button-3> {
    focus %W
    tk_popup .menu.edit %X %Y
}

menu .menu.editEntry -tearoff 0

[lambda {menu1 menu2 args} {
    foreach i $args {
	$menu2 add command\
	    -label [$menu1 entrycget $i -label]\
	    -command [$menu1 entrycget $i -command]
    }
}] .menu.edit .menu.editEntry 0 1 2 4

bind Entry <Button-3> {
    focus %W
    tk_popup .menu.editEntry %X %Y
}

.menu add cascade\
    -label Ansicht\
    -menu [menu .menu.view -tearoff no]

.menu.view add cascade\
    -label Schriftgröße\
    -menu [menu .menu.view.fontsize]

foreach i {9 10 11 12 13 14 15} {
    .menu.view.fontsize add radiobutton\
	-label $i\
	-variable ::global::value(fontSize)\
	-command [list setFontSize $i]
}

.menu.view add separator

.menu.view add command\
    -label Vorschau\
    -command [lambda {} {
	set currentFile [globalSetting file]
	.menu.file invoke {Export nach PDF}
	if {[globalSetting justOpened]} {
	    if {$currentFile eq ""} {
		set rootname default
	    } else {
# 		set dirname [file dirname $currentFile]
# 		set tailname [string map {" " _} [file tail $currentFile]]
# 		set rootname [file rootname $dirname/$tailname]
		set rootname [string map {" " _} [file rootname $currentFile]]
	    }
	    if {![file executable [globalSetting pdfViewer]]} {
		.menu.external invoke {PDF-Betrachter}
	    }
	    if {[globalSetting justOpened]} {
		exec [globalSetting pdfViewer] $rootname.pdf
	    }
	}
    }]

.menu add cascade -label Einstellungen -menu [menu .menu.settings]

.menu.settings add checkbutton\
    -label {Typografischer Gedankenstrich}\
    -variable ::Richtext::typoDashRequired\

.menu.settings add cascade\
    -label {Anführungszeichen}\
    -menu [menu .menu.settings.smartquotes]

.menu.settings.smartquotes add radiobutton\
    -label Schreibmaschine\
    -command [list ::Richtext::setQuotes C]\
    -variable ::global::value(smartQuotes)\
    -value C

.menu.settings.smartquotes add radiobutton\
    -label Deutsch\
    -command [list ::Richtext::setQuotes de]\
    -variable ::global::value(smartQuotes)\
    -value de

.menu.settings.smartquotes add radiobutton\
    -label Englisch\
    -command [list ::Richtext::setQuotes en]\
    -variable ::global::value(smartQuotes)\
    -value en

.menu.settings.smartquotes add radiobutton\
    -label Französisch\
    -command [list ::Richtext::setQuotes fr]\
    -variable ::global::value(smartQuotes)\
    -value fr

.menu.settings.smartquotes add radiobutton\
    -label Schweiz\
    -command [list ::Richtext::setQuotes ch]\
    -variable ::global::value(smartQuotes)\
    -value ch

.menu.settings add cascade\
    -label {Typografische Zeichenersetzung}\
    -menu [menu .menu.settings.typographicalChars -tearoff 0]

.menu.settings.typographicalChars add checkbutton\
    -label {Punkte (...)}\
    -variable ::global::value(...)\
    -onvalue \\ldots\
    -offvalue ...

.menu.settings add separator

.menu.settings add checkbutton\
    -label {Absenderzeile mit Unterstrich}\
    -variable ::global::value(backAddressRules)\
    -onvalue \\backaddressrule\
    -offvalue \\nobackaddressrule

.menu.settings add checkbutton\
    -label {Adressfeld mit Strichen umrandet}\
    -variable ::global::value(addressRules)\
    -onvalue \\windowrules\
    -offvalue \\nowindowrules

.menu.settings add checkbutton\
    -label {Adressfeld vertikal zentriert}\
    -variable ::global::value(verticalAddressAlign)\
    -onvalue \\centeraddress\
    -offvalue \\normaladdress

.menu.settings add checkbutton\
    -label {Nutztext verlängert}\
    -variable ::global::value(addressPos)\
    -onvalue \\addresshigh\
    -offvalue \\addressstd

.menu.settings add checkbutton\
    -label {Falzmarkierungen}\
    -variable ::global::value(paperFoldMarks)\
    -onvalue \\windowtics\
    -offvalue \\nowindowtics

.menu.settings add checkbutton\
    -label {Bezugszeile immer über dem Falz}\
    -variable ::global::value(refLineOverFold)

.menu.settings add separator

.menu.settings add checkbutton\
    -label {Zahlenspalten rechts- bzw. kommabündig}\
    -variable ::global::value(numberAlign)\
    -onvalue right\
    -offvalue left

.menu.settings add checkbutton\
    -label {Deutsches Dezimalkomma}\
    -variable ::global::value(1000.dezimal,)\
    -onvalue {. ,}\
    -offvalue {, .}

.menu.settings add separator

.menu.settings add cascade\
    -label Listenformat\
    -menu [menu .menu.settings.listOmatic -tearoff 0]

.menu.settings.listOmatic add radiobutton\
    -label Aus\
    -variable ::global::value(list-O-matic)\
    -value none

.menu.settings.listOmatic add radiobutton\
    -label Einfach\
    -variable ::global::value(list-O-matic)\
    -value flat

.menu.settings.listOmatic add radiobutton\
    -label Verschachtelt\
    -variable ::global::value(list-O-matic)\
    -value deep

.menu.settings add cascade\
    -label {Silbentrennung Sprache}\
    -menu [menu .menu.settings.lang -tearoff 0]

[lambda {list} {
    foreach {lang label} $list {
	.menu.settings.lang add radiobutton\
	    -label $label\
	    -value $lang\
	    -variable ::global::value(language)
    }
}] {
    ngerman Deutsch
    UKenglish {Englisch (Vereinigtes Königreich)}
    USenglish {Englisch (Vereinigte Staaten)}
    francais Französisch
    italian Italienisch
    spanish Spanisch
    portuges Portugiesisch
    swedish Schwedisch
    polish Polnisch
    esperanto Esperanto
    german {Deutsch (Alte Rechtschreibung)}
}

.menu.settings add command\
    -label {Silbentrennung Ausnahmen ...}\
    -command editHyphenations

.menu add cascade\
    -label {Externe Hilfsprogramme}\
    -menu [menu .menu.external]

.menu.external add command\
    -label {Pfad von pdflatex}\
    -command [lambda {} {
	globalSetting pdflatex\
	    [tk_getOpenFile -title "Genauer Pfad für PDFlatex"]
	if {[file executable [globalSetting pdflatex]]} {
	    globalSetting justOpened yes
	} else {
	    globalSetting justOpened no
	}
    }]

.menu.external add command\
    -label {PDF-Betrachter}\
    -command [lambda {} {
	globalSetting pdfViewer\
	    [tk_getOpenFile -title {PDF-Betrachter auswählen}]
	if {[file executable [globalSetting pdfViewer]]} {
	    globalSetting justOpened yes
	} else {
	    globalSetting justOpened no
	}
    }]

.menu add cascade -label ? -menu [menu .menu.help -tearoff 0]

.menu.help add command\
    -label "Über dinbrief"\
    -command {
	tk_dialog .info Info\
	    "dinbrief V.1.0\n(c) 2005 Wolf-Dieter Busch"\
	    info 0 Ok
    }

. configure -menu .menu