summaryrefslogtreecommitdiffstats
path: root/ds9/library/medit.tcl
blob: 65d71e8833b399fc3ed1f1048b574982910e9519 (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
#  Copyright (C) 1999-2018
#  Smithsonian Astrophysical Observatory, Cambridge, MA, USA
#  For conditions of distribution and use, see copyright notice in "copyright"

package provide DS9 1.0

# Menus

proc EditMainMenu {} {
    global ds9
    global current

    menu $ds9(mb).edit
    $ds9(mb).edit add command -label [msgcat::mc {Undo}] -command UndoFrame \
	-accelerator "${ds9(ctrl)}Z"
    $ds9(mb).edit add separator
    $ds9(mb).edit add command -label [msgcat::mc {Cut}] -command CutFrame \
	-accelerator "${ds9(ctrl)}X"
    $ds9(mb).edit add command -label [msgcat::mc {Copy}] -command CopyFrame \
	-accelerator "${ds9(ctrl)}C"
    $ds9(mb).edit add command -label [msgcat::mc {Paste}] -command PasteFrame \
	-accelerator "${ds9(ctrl)}V"
    $ds9(mb).edit add separator
    $ds9(mb).edit add radiobutton -label [msgcat::mc {None}] \
	-variable current(mode) -value none -command ChangeMode
    $ds9(mb).edit add radiobutton -label [msgcat::mc {Region}] \
	-variable current(mode) -value region -command ChangeMode
    $ds9(mb).edit add radiobutton -label [msgcat::mc {Crosshair}] \
	-variable current(mode) -value crosshair -command ChangeMode
    $ds9(mb).edit add radiobutton -label [msgcat::mc {Colorbar}] \
	-variable current(mode) -value colorbar -command ChangeMode
    $ds9(mb).edit add radiobutton -label [msgcat::mc {Pan}] \
	-variable current(mode) -value pan -command ChangeMode
    $ds9(mb).edit add radiobutton -label [msgcat::mc {Zoom}] \
	-variable current(mode) -value zoom -command ChangeMode
    $ds9(mb).edit add radiobutton -label [msgcat::mc {Rotate}] \
	-variable current(mode) -value rotate -command ChangeMode
    $ds9(mb).edit add radiobutton -label [msgcat::mc {Crop}] \
	-variable current(mode) -value crop -command ChangeMode
    $ds9(mb).edit add radiobutton -label [msgcat::mc {Catalog}] \
	-variable current(mode) -value catalog -command ChangeMode
    $ds9(mb).edit add radiobutton -label [msgcat::mc {Examine}] \
	-variable current(mode) -value examine -command ChangeMode
    $ds9(mb).edit add radiobutton -label [msgcat::mc {3D}] \
	-variable current(mode) -value 3d -command ChangeMode

    switch $ds9(wm) {
	x11 -
	win32 {
	    $ds9(mb).edit add separator
	    $ds9(mb).edit add command -label "[msgcat::mc {Preferences}]..." \
		-command PrefsDialog
	}
	aqua {}
    }

    # Bindings
    bind $ds9(top) <<Undo>> UndoFrame
    bind $ds9(top) <<Cut>> CutFrame
    bind $ds9(top) <<Copy>> CopyFrame
    bind $ds9(top) <<Paste>> PasteFrame
}

proc PrefsDialogEditMenu {w} {
    global ds9

    set f [ttk::labelframe $w.medit -text [msgcat::mc {Edit}]]

    ttk::menubutton $f.menu -text [msgcat::mc {Menu}] -menu $f.menu.menu
    PrefsDialogButtonbarEdit $f.buttonbar

    grid $f.menu $f.buttonbar -padx 2 -pady 2

    set m $f.menu.menu
    menu $m
    $m add radiobutton -label [msgcat::mc {None}] \
	-variable pcurrent(mode) -value none
    $m add radiobutton -label [msgcat::mc {Region}] \
	-variable pcurrent(mode) -value region
    $m add radiobutton -label [msgcat::mc {Crosshair}] \
	-variable pcurrent(mode) -value crosshair
    $m add radiobutton -label [msgcat::mc {Colorbar}] \
	-variable pcurrent(mode) -value colorbar
    $m add radiobutton -label [msgcat::mc {Pan}] \
	-variable pcurrent(mode) -value pan
    $m add radiobutton -label [msgcat::mc {Zoom}] \
	-variable pcurrent(mode) -value zoom
    $m add radiobutton -label [msgcat::mc {Rotate}] \
	-variable pcurrent(mode) -value rotate
    $m add radiobutton -label [msgcat::mc {Crop}] \
	-variable pcurrent(mode) -value crop
    $m add radiobutton -label [msgcat::mc {Catalog}] \
	-variable pcurrent(mode) -value catalog
    $m add radiobutton -label [msgcat::mc {Examine}] \
	-variable pcurrent(mode) -value examine
    $m add radiobutton -label [msgcat::mc {3D}] \
	-variable pcurrent(mode) -value 3d

    pack $f -side top -fill both -expand true
}

# Buttons

proc ButtonsEditDef {} {
    global pbuttons

    array set pbuttons {
	edit,undo 0 
	edit,cut 0
	edit,copy 0
	edit,paste 0
	edit,none 1
	edit,region 1
	edit,crosshair 1
	edit,colorbar 1
	edit,pan 1
	edit,zoom 1
	edit,rotate 1
	edit,crop 1
	edit,catalog 1
	edit,examine 1
	edit,3d 1
	edit,prefs 0
    }
}

proc CreateButtonsEdit {} {
    global buttons
    global ds9
    global current

    ttk::frame $ds9(buttons).edit

    ButtonButton $ds9(buttons).edit.undo \
	[string tolower [msgcat::mc {Undo}]] UndoFrame
    ButtonButton $ds9(buttons).edit.cut \
	[string tolower [msgcat::mc {Cut}]] CutFrame
    ButtonButton $ds9(buttons).edit.copy \
	[string tolower [msgcat::mc {Copy}]] CopyFrame
    ButtonButton $ds9(buttons).edit.paste \
	[string tolower [msgcat::mc {Paste}]] PasteFrame

    RadioButton $ds9(buttons).edit.none \
	[string tolower [msgcat::mc {None}]] \
	current(mode) none ChangeMode
    RadioButton $ds9(buttons).edit.region \
	[string tolower [msgcat::mc {Region}]] \
	current(mode) region ChangeMode
    RadioButton $ds9(buttons).edit.crosshair \
	[string tolower [msgcat::mc {Cross}]] \
	current(mode) crosshair ChangeMode
    RadioButton $ds9(buttons).edit.colorbar \
	[string tolower [msgcat::mc {Colorbar}]] \
	current(mode) colorbar ChangeMode
    RadioButton $ds9(buttons).edit.pan \
	[string tolower [msgcat::mc {Pan}]] \
	current(mode) pan ChangeMode
    RadioButton $ds9(buttons).edit.zoom \
	[string tolower [msgcat::mc {Zoom}]] \
	current(mode) zoom ChangeMode
    RadioButton $ds9(buttons).edit.rotate \
	[string tolower [msgcat::mc {Rotate}]] \
	current(mode) rotate ChangeMode
    RadioButton $ds9(buttons).edit.crop \
	[string tolower [msgcat::mc {Crop}]] \
	current(mode) crop ChangeMode
    RadioButton $ds9(buttons).edit.catalog \
	[string tolower [msgcat::mc {Cat}]] \
	current(mode) catalog ChangeMode
    RadioButton $ds9(buttons).edit.examine \
	[string tolower [msgcat::mc {Exam}]] \
	current(mode) examine ChangeMode
    RadioButton $ds9(buttons).edit.3d \
	[string tolower [msgcat::mc {3D}]] \
	current(mode) 3d ChangeMode

    ButtonButton $ds9(buttons).edit.prefs \
	[string tolower [msgcat::mc {Preferences}]] PrefsDialog

    set buttons(edit) "
        $ds9(buttons).edit.undo pbuttons(edit,undo)
        $ds9(buttons).edit.cut pbuttons(edit,cut)
        $ds9(buttons).edit.copy pbuttons(edit,copy)
        $ds9(buttons).edit.paste pbuttons(edit,paste)
        $ds9(buttons).edit.none pbuttons(edit,none)
        $ds9(buttons).edit.region pbuttons(edit,region)
        $ds9(buttons).edit.crosshair pbuttons(edit,crosshair)
        $ds9(buttons).edit.colorbar pbuttons(edit,colorbar)
        $ds9(buttons).edit.pan pbuttons(edit,pan)
        $ds9(buttons).edit.zoom pbuttons(edit,zoom)
        $ds9(buttons).edit.rotate pbuttons(edit,rotate)
        $ds9(buttons).edit.crop pbuttons(edit,crop)
        $ds9(buttons).edit.catalog pbuttons(edit,catalog)
        $ds9(buttons).edit.examine pbuttons(edit,examine)
        $ds9(buttons).edit.3d pbuttons(edit,3d)
        $ds9(buttons).edit.prefs pbuttons(edit,prefs)
    "
}

proc PrefsDialogButtonbarEdit {f} {
    global ds9
    global buttons
    global pbuttons

    ttk::menubutton $f -text [msgcat::mc {Buttonbar}] -menu $f.menu
    
    set m $f.menu
    menu $m
    $m add checkbutton -label [msgcat::mc {Undo}] \
	-variable pbuttons(edit,undo) -command {UpdateButtons buttons(edit)}
    $m add separator
    $m add checkbutton -label [msgcat::mc {Cut}] \
	-variable pbuttons(edit,cut) -command {UpdateButtons buttons(edit)}
    $m add checkbutton -label [msgcat::mc {Copy}] \
	-variable pbuttons(edit,copy) -command {UpdateButtons buttons(edit)}
    $m add checkbutton -label [msgcat::mc {Paste}] \
	-variable pbuttons(edit,paste) -command {UpdateButtons buttons(edit)}
    $m add separator
    $m add checkbutton -label [msgcat::mc {None}] \
	-variable pbuttons(edit,none) -command {UpdateButtons buttons(edit)}
    $m add checkbutton -label [msgcat::mc {Region}] \
	-variable pbuttons(edit,region) -command {UpdateButtons buttons(edit)}
    $m add checkbutton -label [msgcat::mc {Crosshair}] \
	-variable pbuttons(edit,crosshair) -command {UpdateButtons buttons(edit)}
    $m add checkbutton -label [msgcat::mc {Colorbar}] \
	-variable pbuttons(edit,colorbar) -command {UpdateButtons buttons(edit)}
    $m add checkbutton -label [msgcat::mc {Pan}] \
	-variable pbuttons(edit,pan) -command {UpdateButtons buttons(edit)}
    $m add checkbutton -label [msgcat::mc {Zoom}] \
	-variable pbuttons(edit,zoom) -command {UpdateButtons buttons(edit)}
    $m add checkbutton -label [msgcat::mc {Rotate}] \
	-variable pbuttons(edit,rotate) -command {UpdateButtons buttons(edit)}
    $m add checkbutton -label [msgcat::mc {Crop}] \
	-variable pbuttons(edit,crop) -command {UpdateButtons buttons(edit)}
    $m add checkbutton -label [msgcat::mc {Catalog}] \
	-variable pbuttons(edit,catalog) -command {UpdateButtons buttons(edit)}
    $m add checkbutton -label [msgcat::mc {Examine}] \
	-variable pbuttons(edit,examine) -command {UpdateButtons buttons(edit)}
    $m add checkbutton -label [msgcat::mc {3D}] \
	-variable pbuttons(edit,3d) -command {UpdateButtons buttons(3d)}
    $m add separator
    $m add checkbutton -label [msgcat::mc {Preferences}] \
	-variable pbuttons(edit,prefs) -command {UpdateButtons buttons(edit)}
}

# Support

proc UpdateEditMenu {} {
    global ds9
    global current
    global marker

    global debug
    if {$debug(tcl,update)} {
	puts stderr "UpdateEditMenu"
    }

    switch -- $current(mode) {
	pointer -
	region {
	    if {$current(frame) != {}} {
		set l [$current(frame) has marker undo]
		if {$l != {}} {
		    $ds9(mb).edit entryconfig [msgcat::mc {Undo}] \
			-state normal
		} else {
		    $ds9(mb).edit entryconfig [msgcat::mc {Undo}] \
			-state disabled
		}

		if {[$current(frame) has marker select]} {
		    $ds9(mb).edit entryconfig [msgcat::mc {Cut}] \
			-state normal
		    $ds9(mb).edit entryconfig [msgcat::mc {Copy}] \
			-state normal
		} else {
		    $ds9(mb).edit entryconfig [msgcat::mc {Cut}] \
			-state disabled
		    $ds9(mb).edit entryconfig [msgcat::mc {Copy}] \
			-state disabled
		}

		if {$marker(copy) != {} } {
		    if {[$marker(copy) has marker paste]} {
			$ds9(mb).edit entryconfig [msgcat::mc {Paste}] \
			    -state normal
		    } else {
			$ds9(mb).edit entryconfig [msgcat::mc {Paste}] \
			    -state disabled
		    }
		} else {
		    $ds9(mb).edit entryconfig [msgcat::mc {Paste}] \
			-state disabled
		}
	    } else {
		$ds9(mb).edit entryconfig [msgcat::mc {Undo}] -state disabled
		$ds9(mb).edit entryconfig [msgcat::mc {Cut}] -state disabled
		$ds9(mb).edit entryconfig [msgcat::mc {Copy}] -state disabled
		$ds9(mb).edit entryconfig [msgcat::mc {Paste}] -state disabled
	    }
	}
	none -
	crosshair -
	colorbar -
	pan -
	zoom -
	rotate -
	crop -
	catalog -
	examine -
	iexam -
	3d {$ds9(mb).edit entryconfig [msgcat::mc {Undo}] -state disabled}
    }
}