4 ; Warn the user about saving a document
6 ; © 1994-1998 Straylight
9 ;----- Licensing note -------------------------------------------------------
11 ; This file is part of Straylight's Sapphire library.
13 ; Sapphire is free software; you can redistribute it and/or modify
14 ; it under the terms of the GNU General Public License as published by
15 ; the Free Software Foundation; either version 2, or (at your option)
18 ; Sapphire is distributed in the hope that it will be useful,
19 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ; GNU General Public License for more details.
23 ; You should have received a copy of the GNU General Public License
24 ; along with Sapphire. If not, write to the Free Software Foundation,
25 ; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ;----- Standard Header ------------------------------------------------------
34 ;----- External dependencies ------------------------------------------------
43 GET sapphire:xfer.saveAs
45 ;----- Main code ------------------------------------------------------------
47 AREA |Sapphire$$Code|,CODE,READONLY
51 ; On entry: R0 == estimated size of data
52 ; R1 == file type of the data
53 ; R2 == pointer to name of the file
54 ; R3 == pointer to handler block
55 ; R4 == value to pass to handlers in R10
56 ; R5 == value to pass to handlers in R12
57 ; R6 == flags (in bottom two bits)
61 ; Use: Displays a warning box allowing the user to save a modified
62 ; document. The flags in R6 are as follows:
64 ; Bit 0 File is safe; don't give a warning
65 ; Bit 1 File's name is sensible; display it in the warning
67 ; The handler block is the same as that passed to saveAs (q.v.)
68 ; with an extra entry point on the very beginning, which is
69 ; expected to remove the document from memory. This entry
70 ; point is not passed any arguments except for R10 and R12.
72 ; In order for the system to work, you must call various
73 ; saveWarn routines from your saveAs entry points:
75 ; saveWarn_saved from saEntry__success
76 ; saveWarn_close from saEntry__closed
81 STMFD R13!,{R0-R5,R12,R14} ;Save some registers
82 WSPACE sw__wSpace ;Find my workspace address
84 ; --- Save some data in workspace ---
86 MOV R0,#0 ;Clear flags word now
87 STMIA R12,{R0,R3-R5} ;Save values in workspace
89 ; --- Work out whether we need to warn the user ---
91 TST R6,#1 ;Is the file safe?
92 BNE %80saveWarn ;Yes -- just trash it then
94 ; --- Give the user a warning ---
96 TST R6,#2 ;Is the file sensibly named?
97 ADREQ R0,sw__noName ;No -- point to general msg
98 ADRNE R0,sw__named ;Yes -- point to name msg
99 BL msgs_lookup ;Translate the message
100 BLNE str_buffer ;Get a nice string buffer
101 BLNE str_subst ;And substitute the name
103 ADR R1,sw__warnBlk ;Point to button definition
104 BL warning ;Ask the big question
105 BCC %50saveWarn ;If not `Save...' skip on
107 ; --- User wants to try to save the file ---
109 LDMIA R13,{R0-R5} ;Load saveAs arguments
110 ADD R3,R3,#4 ;Point past our entry point
111 MOV R14,#swFlag__saving ;Just about to open save box
112 STR R14,sw__flags ;Save this flags word
113 BL saveAs ;Try to save the file
114 BVC %90saveWarn ;If it's OK, return
116 MOV R14,#0 ;Clear the saving flag
117 STR R14,sw__flags ;Save the flags again
118 MOV R1,#1 ;Display error with 1 button
119 BL errorBox ;Tell user we failed
120 B %90saveWarn ;And now return to caller
122 ; --- User chose `Cancel' or `Discard' ---
124 50saveWarn CMP R0,#1 ;Did we choose `Discard'?
125 BNE %90saveWarn ;No -- then do nothing at all
127 80saveWarn BL sw__discard ;Discard the document
129 90saveWarn LDMFD R13!,{R0-R5,R12,PC}^ ;And return to caller
131 sw__noName DCB "swSDC0",0
132 sw__named DCB "swSDC1",0
134 sw__warnBlk BUTTON "swSAVE"
141 ; --- sw__discard ---
147 ; Use: Discards the document.
151 STMFD R13!,{R0,R10,R12,R14} ;Save some registers
152 LDMIB R12,{R0,R10,R12} ;Load user call arguments
153 MOV R14,PC ;Set up return address
154 MOV PC,R0 ;Call discard routine
155 LDMFD R13!,{R0,R10,R12,PC}^ ;And return to caller
159 ; --- saveWarn_saved ---
165 ; Use: Informs saveWarn that the document has been saved. If
166 ; saveWarn is not operating, this call is ignored. You should
167 ; only call this routine if the document is *safe*, rather than
168 ; RAM transferred to another application, for example.
170 EXPORT saveWarn_saved
173 STMFD R13!,{R12,R14} ;Save some registers
174 WSPACE sw__wSpace ;Find my workspace
175 LDR R14,sw__flags ;Load the flags word
176 ORR R14,R14,#swFlag__saved ;Say that it's been saved
177 STR R14,sw__flags ;Save the flags back
178 LDMFD R13!,{R12,PC}^ ;And return to caller
182 ; --- saveWarn_close ---
188 ; Use: Informs saveWarn that the save dialogue box has been closed.
189 ; If the document is now saved, then it is removed from
192 EXPORT saveWarn_close
195 STMFD R13!,{R12,R14} ;Save some registers
196 WSPACE sw__wSpace ;Find my workspace
197 LDR R14,sw__flags ;Load the flags word
198 CMP R14,#3 ;Are both bits set?
199 BLEQ sw__discard ;Yes -- discard the document
200 MOVEQ R14,#0 ;Clear the flags
201 STREQ R14,sw__flags ;And save them back
202 LDMFD R13!,{R12,PC}^ ;And return to caller
208 ;----- Workspace ------------------------------------------------------------
213 sw__flags # 4 ;Various useful flags
214 sw__table # 4 ;Address of client's table
215 sw__R10 # 4 ;Value to pass in R10
216 sw__R12 # 4 ;Value to pass in R12
218 sw__wSize EQU {VAR}-sw__wStart
220 swFlag__saving EQU (1<<0) ;We have a save box open
221 swFlag__saved EQU (1<<1) ;User has saved the document
223 AREA |Sapphire$$LibData|,CODE,READONLY
230 ;----- That's all, folks ----------------------------------------------------