-
Notifications
You must be signed in to change notification settings - Fork 1
/
xpostul8.tcl
executable file
·1807 lines (1460 loc) · 51.4 KB
/
xpostul8.tcl
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
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/env wish8.5
##############################################
# Xpostulate - crossposting blog client and social network dashboard
# (c) tony baldwin / [email protected] / http://tonybaldwin.me
# released according to the terms of the Gnu Public License, v. 3 or later
# further licensing details at the end of the code.
package require http
package require base64
uplevel #0 [list source ~/.xpost/xpost.conf]
image create photo xptiny -format GIF -file ~/.xpost/xpost-tiny.gif
#############################
# I've been told that there are better ways to get stuff done
# than using tonso global variables.
# nonetheless, I'm about to name a whole herd of global variables:
global tagsc
global tube
global tbname
global tbpswd
global wpname
global wppswd
global ljname
global ljpswd
global djpwsd
global djname
global ijname
global ijpswd
global dwname
global dwpswd
global wpname
global wppswd
global blgrname
global blgpswd
global filename
global brow
global wbg
global wtx
global post
global plength
global login
global lurl
global subject
global mood
global tunes
global tags
global year
global mon
global day
global hour
global min
global mood
global tunes
global tags
global ptext
global lprops
global usej
global usepic
global sname
global spswd
global udate
global loc
global priv
global cats
global cwpurl
global cwpname
global cwppass
global furl
global fname
global fpwrd
set allvars [list furl fname fpwrd surl spswd txfg txbg brow wbg wtx cwpurl cwpname cwppass wpname wppswd ljname djname djpswd ljpswd ijname ijpswd dwname dwpswd sname udate loc priv tube tbname tbpswd novar]
set tagsc "0"
set subject "subject"
set mood "mood"
set tags "enter, tags, here"
set tunes "music"
set usepic " "
set usej "which journal?"
set lurl " "
set udate "status.net update"
set loc "127.0.0.1"
set cats "unfiled"
set year [clock format [clock second] -format %Y]
set mon [clock format [clock seconds] -format %m]
set day [clock format [clock seconds] -format %d]
set hour [clock format [clock seconds] -format %H]
set min [clock format [clock seconds] -format %M]
set filename " "
set currentfile " "
set wrap word
font create font -family fixed
set novar "cows"
set file_types {
{"All Files" * }
{"Xposts" {.post}}
{"html, xml" {.html .HTML .xml .XML}}
{"Text Files" { .txt .TXT}}
}
############33
# keybindings
bind . <Escape> leave
bind . <Control-z> {catch {.txt.txt edit undo}}
bind . <Control-r> {catch {.txt.txt edit redo}}
bind . <Control-a> {.txt.txt tag add sel 1.0 end}
bind . <F4> specialbox
bind . <F3> {FindPopup}
bind . <Control-s> {file_save}
bind . <Control-b> {file_saveas}
bind . <Control-o> {OpenFile}
bind . <Control-q> {clear}
bind . <F8> {prefs}
bind . <F7> {browz}
bind . <F5> {wordcount}
tk_setPalette background $::wbg foreground $::wtx
wm title . "Xpostulate - x-posting blog client"
######3
# Menus
#################################
# menu bar buttons
frame .fluff -bd 1 -relief raised
tk::label .fluff.xpb -image xptiny
tk::menubutton .fluff.mb -text File -menu .fluff.mb.f
tk::menubutton .fluff.ed -text Edit -menu .fluff.ed.t
tk::menubutton .fluff.ins -text HTML -menu .fluff.ins.t
tk::menubutton .fluff.bb -text BBcode -menu .fluff.bb.t
tk::menubutton .fluff.view -text View -menu .fluff.view.t
tk::label .fluff.font1 -text "Font size:"
ttk::combobox .fluff.size -width 4 -value [list 8 10 12 14 16 18 20 22] -state readonly
bind .fluff.size <<ComboboxSelected>> [list sizeFont .txt.txt .fluff.size]
# file menu
#############################
menu .fluff.mb.f -tearoff 1
.fluff.mb.f add command -label "Open" -command {OpenFile} -accelerator Ctrl+o
.fluff.mb.f add command -label "Save" -command {file_save} -accelerator Ctrl+s
.fluff.mb.f add command -label "SaveAs" -command {file_saveas} -accelerator Ctrl-b
.fluff.mb.f add command -label "Clear" -command {clear} -accelerator Ctrl+q
.fluff.mb.f add separator
.fluff.mb.f add command -label "Quit" -command {leave} -accelerator Escape
# edit menu
######################################3
menu .fluff.ed.t -tearoff 1
.fluff.ed.t add command -label "Cut" -command cut_text -accelerator Ctrl+x
.fluff.ed.t add command -label "Copy" -command copy_text -accelerator Ctrl+c
.fluff.ed.t add command -label "Paste" -command paste_text -accelerator Ctrl+v
.fluff.ed.t add command -label "Select all" -command ".txt.txt tag add sel 1.0 end" -accelerator Ctrl+a
.fluff.ed.t add command -label "Undo" -command {catch {.txt.txt edit undo}} -accelerator Ctrl+z
.fluff.ed.t add command -label "Redo" -command {catch {.txt.txt edit redo}} -accelerator Ctrl+r
.fluff.ed.t add separator
.fluff.ed.t add command -label "Search/Replace" -command {FindPopup} -accelerator F3
.fluff.ed.t add command -label "convert <tags>" -command {fixtags}
.fluff.ed.t add separator
.fluff.ed.t add command -label "Word Count" -command {wordcount} -accelerator F5
.fluff.ed.t add separator
.fluff.ed.t add command -label "Preferences" -command {prefs} -accelerator F8
tk::button .fluff.help -text "Help" -command {help}
tk::button .fluff.abt -text "About" -command {about}
# inserts menu
###########################3
menu .fluff.ins.t -tearoff 1
.fluff.ins.t add command -label "LJ Cut" -command {cutin}
.fluff.ins.t add command -label "LJ User" -command {userin}
.fluff.ins.t add command -label "Community" -command {commin}
.fluff.ins.t add command -label "Hyperlink" -command {linkin}
.fluff.ins.t add command -label "DW User" -command {userdw}
.fluff.ins.t add command -label "DW Cut" -command {cutdw}
.fluff.ins.t add separator
.fluff.ins.t add command -label "Ruler" -command {hrin}
.fluff.ins.t add command -label "BlockQuote" -command {bquote}
.fluff.ins.t add command -label "LineBreak" -command {bne}
.fluff.ins.t add separator
.fluff.ins.t add command -label "Time Stamp" -command {indate}
.fluff.ins.t add command -label "Special Characters" -underline 0 -command specialbox -accelerator F4
# bbcode menu
##################
menu .fluff.bb.t -tearoff 1
.fluff.bb.t add command -label "Link" -command {bblink}
.fluff.bb.t add command -label "Image" -command {bimg}
.fluff.bb.t add command -label "E-mail" -command {bmail}
.fluff.bb.t add command -label "Friendica" -command {bfren}
.fluff.bb.t add command -label "Xpostulate" -command {xpostin}
.fluff.bb.t add command -label "Youtube" -command {ytube}
.fluff.bb.t add command -label "BlockQuote" -command {bbquote}
.fluff.bb.t add command -label "CodeBlock" -command {bcode}
.fluff.bb.t add command -label "Time Stamp" -command {indate}
# view menu
####################################
menu .fluff.view.t -tearoff 1
.fluff.view.t add command -label "My WordPress" -command {
exec $::brow http://$::wpname.wordpress.com &
}
.fluff.view.t add command -label "My InsaneJournal" -command {
exec $::brow "http://$::ijname.insanejournal.com" &
}
.fluff.view.t add command -label "My LiveJournal" -command {
exec $::brow "http://$::ljname.livejournal.com" &
}
.fluff.view.t add command -label "My DreamWidth" -command {
exec $::brow "http://$::dwname.livejournal.com" &
}
.fluff.view.t add command -label "My Deadjournal" -command {
exec $::brow "http://$::djname.deadjournal.com" &
}
.fluff.view.t add command -label "My Tumblr.com" -command {
exec $::brow http://$::tbname.tumblr.com &
}
.fluff.view.t add command -label "Custom WP" -command {
exec $::brow $::cwpurl &
}
.fluff.view.t add command -label "Friendica" -command {
exec $::brow $::furl &
}
.fluff.view.t add command -label "StatusNet" -command {
exec $::brow "$::surl" &
}
# pack em in...
############################
pack .fluff.xpb -in .fluff -side left
pack .fluff.mb -in .fluff -side left
pack .fluff.ed -in .fluff -side left
pack .fluff.ins -in .fluff -side left
pack .fluff.bb -in .fluff -side left
pack .fluff.view -in .fluff -side left
pack .fluff.font1 -in .fluff -side left
pack .fluff.size -in .fluff -side left
pack .fluff.help -in .fluff -side right
pack .fluff.abt -in .fluff -side right
pack .fluff -in . -fill x
# a few post parameters
###########################################
frame .ljo
grid [tk::label .ljo.sujet -text "Subject:"]\
[tk::entry .ljo.assunto -textvariable subject]\
[tk::label .ljo.tagz -text "Tags:"]\
[tk::entry .ljo.tagit -textvariable tags]\
[tk::label .ljo.ct -text "Category:"]\
[tk::entry .ljo.cats -textvariable cats]
grid [tk::label .ljo.md -text "Mood:"]\
[tk::entry .ljo.mude -textvariable mood]\
[tk::label .ljo.tunages -text "Music:"]\
[tk::entry .ljo.tunez -textvariable tunes]\
[tk::label .ljo.l0c -text "Location:"]\
[tk::entry .ljo.lcn -textvariable loc]
frame .sec
grid [tk::label .sec.pr -text "Privacy:"]\
[tk::radiobutton .sec.pub -value "default" -text "public" -variable priv]\
[tk::radiobutton .sec.fri -value "usemask" -text "friends" -variable priv]\
[tk::radiobutton .sec.pri -value "private" -text "private" -variable priv]
pack .ljo -in . -fill x
pack .sec -in . -fill x
frame .lj1
# post buttons
###################
tk::label .lj1.lbl1 -text "Post to:"
tk::entry .lj1.uj -textvariable usej
tk::menubutton .lj1.post -text "on this site:" -menu .lj1.post.t
# xml post menu
##############################
menu .lj1.post.t -tearoff 1
.lj1.post.t add command -label LiveJournal -command ljpost
.lj1.post.t add command -label InsaneJournal -command ijpost
.lj1.post.t add command -label DreamWidth -command dwpost
.lj1.post.t add command -label DeadJournal -command djpost
.lj1.post.t add command -label WordPress -command wppost
.lj1.post.t add command -label CustomWP -command cwpost
.lj1.post.t add command -label Tumblr -command tbpost
.lj1.post.t add command -label Friendica -command fpost
pack .lj1 -in . -fill x
pack .lj1.lbl1 -in .lj1 -side left
pack .lj1.uj -in .lj1 -side left
# pack .lj1.oj -in .lj1 -side left
pack .lj1.post -in .lj1 -side left
# Here is the text widget
########################################TEXT WIDGET
# amazingly simple, this part, considering the great power in this little widget...
# of course, that's because someone a lot smarter than me built the widget already.
# that sure was nice of them...
frame .txt -bd 2 -relief sunken
text .txt.txt -yscrollcommand ".txt.ys set" -xscrollcommand ".txt.xs set" -maxundo 0 -undo true -wrap word -bg $::txbg -fg $::txfg
scrollbar .txt.ys -command ".txt.txt yview"
scrollbar .txt.xs -command ".txt.txt xview" -orient horizontal
pack .txt.xs -in .txt -side bottom -fill x
pack .txt.txt -in .txt -side left -fill both -expand true
pack .txt.ys -in .txt -side left -fill y
pack .txt -in . -fill both -expand true
focus .txt.txt
set foco .txt.txt
bind .txt.txt <FocusIn> {set foco .txt.txt}
# status net
###########################################
frame .dt
grid [tk::label .dt.ol -text "StatusNet:"]\
[tk::entry .dt.ent -width 70 -textvariable udate]\
[tk::button .dt.tw -text "Post" -command "snet"]\
[tk::button .dt.tc -text "Clear" -command "sud"]\
[tk::button .dt.qt -text "Quit" -command {exit}]
pack .dt -in . -fill x
proc sud {} {
set ::udate " "
}
###
# font size, affects size of font in editor, not in post
# to affect font in post, you have to use html tags...sorry
# I should built that in.
########################################################
proc sizeFont {txt combo} {
set font [$txt cget -font]
font configure $font -size [list [$combo get]]
}
###
# open
############################
proc OpenFile {} {
if {$::filename != " "} {
eval exec tcltext &
} else {
global filename
set filename [tk_getOpenFile -filetypes $::file_types]
wm title . "Now Tickling: $::filename"
set data [open $::filename RDWR]
.txt.txt delete 1.0 end
while {![eof $data]} {
.txt.txt insert end [read $data 1000]
}
close $data
.txt.txt mark set insert 1.0
}
}
##
# save & save-as
###########################
proc file_save {} {
if {$::filename != " "} {
set data [.txt.txt get 1.0 {end -1c}]
set fileid [open $::filename w]
puts -nonewline $fileid $data
close $fileid
} else {file_saveas}
}
proc file_saveas {} {
global filename
set filename [tk_getSaveFile -filetypes $::file_types]
set data [.txt.txt get 1.0 {end -1c}]
wm title . "Now Tickling: $::filename"
set fileid [open $::filename w]
puts -nonewline $fileid $data
close $fileid
}
# about message box
####################################ABOUT
proc about {} {
toplevel .about
wm title .about "About Xpostulate"
# tk_setPalette background $::wbg
tk::message .about.t -text "Xpostulate\n by Tony Baldwin\n http://tonybaldwin.me\n A x-posting blogging client written in tcl/tk\n Released under the GPL\n For more info see README, or\n http://tonyb.us/xpost\n" -width 280
tk::button .about.o -text "Okay" -command {destroy .about}
pack .about.t -in .about -side top
pack .about.o -in .about -side top
}
# find/replace/go to line
############################################FIND REPLACE DIALOG
proc FindPopup {} {
global seltxt repltxt
toplevel .fpop
# -width 12c -height 4c
wm title .fpop "Find Stuff... (but not your socks)"
frame .fpop.l1 -bd 2 -relief raised
tk::label .fpop.l1.fidis -text "FIND :"
tk::entry .fpop.l1.en1 -width 20 -textvariable seltxt
tk::button .fpop.l1.finfo -text "Forward" -command {FindWord -forwards $seltxt}
tk::button .fpop.l1.finbk -text "Backward" -command {FindWord -backwards $seltxt}
tk::button .fpop.l1.tagall -text "Highlight All" -command {TagAll}
pack .fpop.l1.fidis -in .fpop.l1 -side left
pack .fpop.l1.en1 -in .fpop.l1 -side left
pack .fpop.l1.finfo -in .fpop.l1 -side left
pack .fpop.l1.finbk -in .fpop.l1 -side left
pack .fpop.l1.tagall -in .fpop.l1 -side left
pack .fpop.l1 -in .fpop -fill x
frame .fpop.l2 -bd 2 -relief raised
tk::label .fpop.l2.redis -text "REPLACE:"
tk::entry .fpop.l2.en2 -width 20 -textvariable repltxt
tk::button .fpop.l2.refo -text "Forward" -command {ReplaceSelection -forwards}
tk::button .fpop.l2.reback -text "Backward" -command {ReplaceSelection -backwards}
tk::button .fpop.l2.repall -text "Replace All" -command {ReplaceAll}
pack .fpop.l2.redis -in .fpop.l2 -side left
pack .fpop.l2.en2 -in .fpop.l2 -side left
pack .fpop.l2.refo -in .fpop.l2 -side left
pack .fpop.l2.reback -in .fpop.l2 -side left
pack .fpop.l2.repall -in .fpop.l2 -side left
pack .fpop.l2 -in .fpop -fill x
frame .fpop.l3 -bd 2 -relief raised
tk::label .fpop.l3.goto -text "Line No. :"
tk::entry .fpop.l3.line -textvariable lino
tk::button .fpop.l3.now -text "Go" -command {gotoline}
tk::button .fpop.l3.dismis -text Done -command {destroy .fpop}
pack .fpop.l3.goto -in .fpop.l3 -side left
pack .fpop.l3.line -in .fpop.l3 -side left
pack .fpop.l3.now -in .fpop.l3 -side left
pack .fpop.l3.dismis -in .fpop.l3 -side right
pack .fpop.l3 -in .fpop -fill x
# focus .fpop.en1
}
########################FIND/REPLACE#########
## all this find-replace stuff needs work...
#############################################
proc FindWord {swit seltxt} {
global found
set l1 [string length $seltxt]
scan [.txt.txt index end] %d nl
scan [.txt.txt index insert] %d cl
if {[string compare $swit "-forwards"] == 0 } {
set curpos [.txt.txt index "insert + $l1 chars"]
for {set i $cl} {$i < $nl} {incr i} {
#.txt.txt mark set first $i.0
.txt.txt mark set last $i.end ;#another way "first lineend"
set lpos [.txt.txt index last]
set curpos [.txt.txt search $swit -exact $seltxt $curpos]
if {$curpos != ""} {
selection clear .txt.txt
.txt.txt mark set insert "$curpos + $l1 chars "
.txt.txt see $curpos
set found 1
break
} else {
set curpos $lpos
set found 0
}
}
} else {
set curpos [.txt.txt index insert]
set i $cl
.txt.txt mark set first $i.0
while {$i >= 1} {
set fpos [.txt.txt index first]
set i [expr $i-1]
set curpos [.txt.txt search $swit -exact $seltxt $curpos $fpos]
if {$curpos != ""} {
selection clear .txt.txt
.txt.txt mark set insert $curpos
.txt.txt see $curpos
set found 1
break
} else {
.txt.txt mark set first $i.0
.txt.txt mark set last "first lineend"
set curpos [.txt.txt index last]
set found 0
}
}
}
}
proc FindSelection {swit} {
global seltxt GotSelection
if {$GotSelection == 0} {
set seltxt [selection get STRING]
set GotSelection 1
}
FindWord $swit $seltxt
}
proc FindValue {} {
FindPopup
}
proc TagSelection {} {
global seltxt GotSelection
if {$GotSelection == 0} {
set seltxt [selection get STRING]
set GotSelection 1
}
TagAll
}
proc ReplaceSelection {swit} {
global repltxt seltxt found
set l1 [string length $seltxt]
FindWord $swit $seltxt
if {$found == 1} {
.txt.txt delete insert "insert + $l1 chars"
.txt.txt insert insert $repltxt
}
}
proc ReplaceAll {} {
global seltxt repltxt
set l1 [string length $seltxt]
set l2 [string length $repltxt]
scan [.txt.txt index end] %d nl
set curpos [.txt.txt index 1.0]
for {set i 1} {$i < $nl} {incr i} {
.txt.txt mark set last $i.end
set lpos [.txt.txt index last]
set curpos [.txt.txt search -forwards -exact $seltxt $curpos $lpos]
if {$curpos != ""} {
.txt.txt mark set insert $curpos
.txt.txt delete insert "insert + $l1 chars"
.txt.txt insert insert $repltxt
.txt.txt mark set insert "insert + $l2 chars"
set curpos [.txt.txt index insert]
} else {
set curpos $lpos
}
}
}
proc TagAll {} {
global seltxt
set l1 [string length $seltxt]
scan [.txt.txt index end] %d nl
set curpos [.txt.txt index insert]
for {set i 1} {$i < $nl} {incr i} {
.txt.txt mark set last $i.end
set lpos [.txt.txt index last]
set curpos [.txt.txt search -forwards -exact $seltxt $curpos $lpos]
if {$curpos != ""} {
.txt.txt mark set insert $curpos
scan [.txt.txt index "insert + $l1 chars"] %f pos
.txt.txt tag add $seltxt $curpos $pos
.txt.txt tag configure $seltxt -background yellow -foreground purple
.txt.txt mark set insert "insert + $l1 chars"
set curpos $pos
} else {
set curpos $lpos
}
}
}
###THEMES
######COLORPROCS
##############################################
# set text widget colors
#######################
proc tback {} {
global i
set color [tk_chooseColor -initialcolor [.txt.txt cget -bg]]
if {$color != ""} {.txt.txt configure -bg $color}
set ::txbg $color
}
proc tfore {} {
global i
set color [tk_chooseColor -initialcolor [.txt.txt cget -fg]]
if {$color != ""} {.txt.txt configure -fg $color}
set ::txfg $color
}
# set window color
################################
proc winback {} {
global wbg
set wbg [tk_chooseColor -initialcolor $::wbg]
if {$wbg != ""} {tk_setPalette background $wbg}
set $::wbg $wbg
}
#set window font color
###################################
proc wintex {} {
global wtx
set wtx [tk_chooseColor -initialcolor $::wtx]
if {$wtx != ""} {tk_setPalette background $::wbg foreground $wtx}
set $::wtx $wtx
}
# special character box
# largely borrowed from David "Pa" McClamrock's SuperNotepad
################################################################
global charlist
set charlist [list \
"¡" "¢" "£" "¤" "¥" \
"¦" "§" "¨" "©" "ª" \
"«" "¬" "" "®" "¯" \
"°" "±" "²" "³" "´" \
"µ" "¶" "·" "¸" "¹" \
"º" "»" "¼" "½" "¾" \
"¿" "À" "Á" "Â" "Ã" \
"Ä" "Å" "Æ" "Ç" "È" \
"É" "Ê" "Ë" "Ì" "Í" \
"Î" "Ï" "Ð" "Ñ" "Ò" \
"Ó" "Ô" "Õ" "Ö" "×" \
"Ø" "Ù" "Ú" "Û" "Ü" \
"Ý" "Þ" "ß" "à" "á" \
"â" "ã" "ä" "å" "æ" \
"ç" "è" "é" "ê" "ë" \
"ì" "í" "î" "ï" "ñ" \
"ò" "ó" "ô" "õ" "ö" \
"÷" "ø" "ù" "ú" "û" \
"ü" "ý" "þ" "ÿ"]
# Procedure for finding correct text or entry widget
# and inserting special (or non-special) characters:
########################################################33
proc findwin {char} {
global foco
set winclass [winfo class $foco]
$foco insert insert $char
if {$winclass == "Text"} {
$foco edit separator
}
after 10 {focus $foco}
}
###########################################################################################
# Procedure for setting up special-character selection box (borrowed from supernotepad by David "Pa" McClamrock)
proc range {start cutoff finish {step 1}} {
# "Step" has to be an integer, and
# no infinite loops that go nowhere are allowed:
if {$step == 0 || [string is integer -strict $step] == 0} {
error "range: Step must be an integer other than zero"
}
# Does the range include the last number?
switch $cutoff {
"to" {set inclu 1}
"no" {set inclu 0}
default {
error "range: Use \"to\" for an inclusive range,\
or \"no\" for a noninclusive range"
}
}
# Is the range ascending or descending (or neither)?
set ascendo [expr $finish - $start]
if {$ascendo > -1} {
set up 1
} else {
set up 0
}
# If range is descending and step is positive but doesn't have a "+" sign,
# change step to negative:
if {$up == 0 && $step > 0 && [string first "+" $start] != 0} {
set step [expr $step * -1]
}
set ranger [list] ; # Initialize list variable for generated range
switch "$up $inclu" {
"1 1" {set op "<=" ; # Ascending, inclusive range}
"1 0" {set op "<" ; # Ascending, noninclusive range}
"0 1" {set op ">=" ; # Descending, inclusive range}
"0 0" {set op ">" ; # Descending, noninclusive range}
}
# Generate a list containing the specified range of integers:
for {set i $start} "\$i $op $finish" {incr i $step} {
lappend ranger $i
}
return $ranger
}
set specialbutts [list]
# This special box was borrowed from Pa McClamrock's Supernotepad.
proc specialbox {} {
global charlist foco buttlist
toplevel .spec
wm title .spec "Special"
set bigfons -adobe-helvetica-bold-r-normal--14-*-*-*-*-*-*
set row 0
set col 0
foreach c [range 0 no [llength $charlist]] {
set chartext [lindex $charlist $c]
grid [button .spec.but($c) -text $chartext -font $bigfons \
-pady 1 -padx 2 -borderwidth 1] \
-row $row -column $col -sticky news
bind .spec.but($c) <Button-1> {
set butt %W
set charx [$butt cget -text]
findwin $charx
}
incr col
if {$col > 4} {
set col 0
incr row
}
}
grid [button .spec.amp -text "&"] -row $row -column 4 -sticky news
bind .spec.amp <Button-1> {findwin "&"}
set bigoe_data "
#define bigoe_width 17
#define bigoe_height 13
static unsigned char bigoe_bits[] = {
0xf8, 0xfe, 0x01, 0xfe, 0xff, 0x01, 0xcf, 0x07, \
0x00, 0x87, 0x07, 0x00, 0x07, 0x07, 0x00, 0x07, \
0x3f, 0x00, 0x07, 0x3f, 0x00, 0x07, 0x07, 0x00, \
0x07, 0x07, 0x00, 0x07, 0x07, 0x00, 0x8e, 0x07, \
0x00, 0xfc, 0xff, 0x01, 0xf8, 0xfe, 0x01 };"
image create bitmap bigoe -data $bigoe_data
grid [button .spec.oebig -image bigoe \
-pady 1 -padx 2 -borderwidth 1] \
-row [expr $row+1] -column 0 -sticky news
bind .spec.oebig <Button-1> {findwin "Œ"}
set liloe_data "
#define liloe_width 13
#define liloe_height 9
static unsigned char liloe_bits[] = {
0xbc, 0x07, 0xfe, 0x0f, 0xc3, 0x18, 0xc3, 0x18, \
0xc3, 0x1f, 0xc3, 0x00, 0xe7, 0x18, 0xfe, 0x0f, \
0x3c, 0x07 };"
image create bitmap liloe -data $liloe_data
grid [button .spec.oelil -image liloe -pady 1 \
-pady 1 -padx 2 -borderwidth 1] \
-row [expr $row+1] -column 1 -sticky news
bind .spec.oelil <Button-1> {findwin "œ"}
grid [button .spec.lt -text "<"] \
-row [expr $row+1] -column 2 -sticky news
bind .spec.lt <Button-1> {findwin "<"}
grid [button .spec.gt -text ">"] \
-row [expr $row+1] -column 3 -sticky news
bind .spec.gt <Button-1> {findwin ">"}
grid [button .spec.quot -text "\""] \
-row [expr $row+1] -column 4 -sticky news
bind .spec.quot <Button-1> {findwin """}
grid [button .spec.nbsp -text " "] \
-row [expr $row+2] -column 0 -columnspan 2 -sticky news
bind .spec.nbsp <Button-1> {findwin " "}
grid [button .spec.close -text "Close" \
-command {destroy .spec}] -row [expr $row+2] \
-column 2 -columnspan 3 -sticky news
foreach butt [list .spec.oebig .spec.oelil .spec.nbsp .spec.amp \
.spec.lt .spec.gt .spec.quot .spec.close] {
$butt configure -pady 1 -padx 2 -borderwidth 1
}
}
## go to line number
proc gotoline {} {
set newlineno [.fpop.l3.line get]
.txt.txt mark set insert $newlineno.0
.txt.txt see insert
focus .txt.txt
set foco .txt.txt
}
## show word count
proc wordcount {} {
set wordsnow [.txt.txt get 1.0 {end -1c}]
set wordlist [split $wordsnow]
set countnow 0
foreach item $wordlist {
if {$item ne ""} {
incr countnow
}
}
toplevel .count
wm title .count "Word Count"
tk::label .count.word -text "Current count:"
tk::label .count.show -text "$countnow words"
tk::button .count.ok -text "Okay" -command {destroy .count}
pack .count.word -in .count -side top
pack .count.show -in .count -side top
pack .count.ok -in .count -side top
}
#############################################
# insertions menu commands
## insert time stamp
proc indate {} {
if {![info exists date]} {set date " "}
set date [clock format [clock seconds] -format "%R %p %D"]
.txt.txt insert insert $date
}
proc userin {} {
.txt.txt insert insert "<lj user=\"put name here\"> "
}
proc commin {} {
.txt.txt insert insert "<lj comm=\"put name here\"> "
}
proc cutin {} {
.txt.txt insert insert "<lj-cut text=\"put text here\"> "
}
# note distinct dreamwidth cut and user
proc userdw {} {
.txt.txt insert insert "<user name=\"put name here\"> "
}
proc cutdw {} {
.txt.txt insert insert "<cut text=\"put text here\"> "
}
# bbcode tags
# to be inserted in the post.
###################################
proc bblink {} {
toplevel .link
wm title .link "Insert Hyperlink"
frame .link.s
grid [tk::label .link.s.l1 -text "URL:"]\
[tk::entry .link.s.e1 -width 40 -textvariable inurl]
grid [tk::label .link.s.l2 -text "Link text:"]\
[tk::entry .link.s.e2 -width 40 -textvariable ltxt]
pack .link.s -in .link -side left
frame .link.btns
grid [tk::button .link.btns.in -text "Insert link" -command {.txt.txt insert insert "\[url=$inurl\]$ltxt\[/url\]"}]\
[tk::button .link.btns.out -text "Done" -command {destroy .link}]
pack .link.btns -in .link -side left
}
proc bcode {} {
.txt.txt insert insert "\[code\]INSERT CODE TEXT HERE\[/code\]"
}
proc xpostin {} {
.txt.txt insert insert "Xpostul8"
}
proc ytube {} {
.txt.txt insert insert "\[youtube\]INSERT VIDEO URL HERE\[/youtube\]"
}
proc bbquote {} {
.txt.txt insert insert "\[quote\]INSERT QUOTED TEXT HERE\[/quote\]"
}
proc bimg {} {
toplevel .link
wm title .link "Insert Image"
frame .link.s
grid [tk::label .link.s.l1 -text "IMG URL:"]\
[tk::entry .link.s.e1 -width 40 -textvariable imurl]
pack .link.s -in .link -side left
frame .link.btns
grid [tk::button .link.btns.in -text "Insert link" -command {.txt.txt insert insert "\[img\]$imurl\[/img\]"}]\
[tk::button .link.btns.out -text "Done" -command {destroy .link}]
pack .link.btns -in .link -side left
}
proc bmail {} {
toplevel .link
wm title .link "Insert E-mail"
frame .link.s
grid [tk::label .link.s.l1 -text "E-mail address:"]\
[tk::entry .link.s.e1 -width 40 -textvariable eml]
pack .link.s -in .link -side left
frame .link.btns
grid [tk::button .link.btns.in -text "Insert link" -command {.txt.txt insert insert "\[mail\]$eml\[/mail\]"}]\
[tk::button .link.btns.out -text "Done" -command {destroy .link}]
pack .link.btns -in .link -side left
}
proc bfren {} {
.txt.txt insert insert "~friendika"
}
# some html tags