File: UserActions.tcl

package info (click to toggle)
coccinella 0.96.20-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 13,184 kB
  • sloc: tcl: 124,744; xml: 206; makefile: 66; sh: 62
file content (184 lines) | stat: -rw-r--r-- 4,762 bytes parent folder | download | duplicates (4)
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
#  UserActions.tcl ---
#  
#      This file is part of The Coccinella application. It implements typical
#      user actions, such as callbacks from buttons and menus.
#      
#  Copyright (c) 2000-2005  Mats Bengtsson
#  
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#   
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#   
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#  
# $Id: UserActions.tcl,v 1.52 2008-05-09 07:30:49 matben Exp $

package provide UserActions 1.0

namespace eval ::UserActions:: {
    
}
    
# UserActions::DoPrintCanvas --
#
#       Platform independent printing of canvas.

proc ::UserActions::DoPrintCanvas {wcan} {
    global  this prefs wDlgs
        
    set w [winfo toplevel $wcan]
    
    switch -- $this(platform) {
	macosx {
	    ::Mac::Printer::Print $w
	}
	windows {
	    if {!$this(package,printer)} {
		::UI::MessageBox -icon error -title [mc "Error"] \
		  -message [mc "Cannot find necessary Tcl extension."]
	    } else {
		::Windows::Printer::Print $wcan
	    }
	}
	unix {
	    ::Dialogs::UnixPrintPS $wDlgs(print) $wcan
	}
    }
}

# UserActions::DoPrintText --
#
#

proc ::UserActions::DoPrintText {wtext args} {
    global  this prefs wDlgs
        
    if {[winfo class $wtext] ne "Text"} {
	error "::UserActions::DoPrintText: $wtext not a text widget!"
    }
    switch -- $this(platform) {
	macosx {
	    ::Mac::MacCarbonPrint::PrintText $wtext
	}
	windows {
	    if {!$this(package,printer)} {
		::UI::MessageBox -icon error -title [mc "Error"] \
		  -message [mc "Cannot find necessary Tcl extension."]
	    } else {
		::Windows::Printer::DoPrintText $wtext
	    }
	}
	unix {
	    ::Dialogs::UnixPrintPS $wDlgs(print) $wtext
	}
    }
}

proc ::UserActions::PageSetup {w} {
    global  this prefs wDlgs
    
    switch -- $this(platform) {
	macosx {
	    ::Mac::MacCarbonPrint::PageSetup $w
	}
	windows {
	    if {!$this(package,printer)} {
		::UI::MessageBox -icon error -title [mc "Error"] \
		  -message [mc "Cannot find necessary Tcl extension."]
	    } else {
		::Windows::Printer::PageSetup
	    }
	}
	unix {
	    ::PSPageSetup::PSPageSetup .page
	}
    }
}

# UserActions::DoConnect --
#
#       Protocol independent open connection to server.

proc ::UserActions::DoConnect { } {
    ::Login::Dlg
}

# @@@ Much of this should be put in a kind of application destructor.
#     Maybe as: bind <Destroy> . Destructor

# UserActions::DoQuit ---
#
#       Is called just before quitting to be able to save various
#       preferences etc.
#       
# Arguments:
#       args        ?-warning boolean?
#       
# Results:
#       0 if not quited, else exitted

proc ::UserActions::DoQuit {args} {
    global  prefs this
    
    array set argsArr {
	-warning      0
    }
    array set argsArr $args
    if {$argsArr(-warning)} {
	set ans [::UI::MessageBox -title [mc "Quit"] -type yesno -icon warning \
	  -default yes -message [mc "Do you actually want to quit?"]]
	if {$ans eq "no"} {
	    return 0
	}
    }
    
    # Run all quit hooks. 
    # Give components a chance to act before session ends.
    ::hooks::run preQuitAppHook
    
    # Here we end the session if any.
    set res [::hooks::run quitAppHook]
    if {$res eq "stop"} {
	return 0
    }
    
    # If we used 'Edit/Revert To/Application Defaults' be sure to reset...
    set prefs(firstLaunch) 0
    
    # Get dialog window geometries.
    set prefs(winGeom) [list]
    foreach {key value} [array get prefs winGeom,*] {
	regexp {winGeom,(.*)$} $key match winkey
	lappend prefs(winGeom) $winkey $value
    }
    
    # Same for pane positions.
    set prefs(paneGeom) [list]
    foreach {key value} [array get prefs paneGeom,*] {
	regexp {paneGeom,(.*)$} $key match winkey
	lappend prefs(paneGeom) $winkey $value
    }
    set prefs(sashPos) [list]
    foreach {key value} [array get prefs sashPos,*] {
	regexp {sashPos,(.*)$} $key match winkey
	lappend prefs(sashPos) $winkey $value
    }
         
    # Save to the preference file and quit...
    ::PrefUtils::SaveToFile
    
    file delete $this(pidFile)
        
    # Cleanup. Beware, no windows with open movies must exist here!
    catch {file delete -force $this(tmpPath)}
    exit
}

#-------------------------------------------------------------------------------