@@ -79,7 +79,7 @@ Function request($title : Text; $value : Text; $labelOk : Text; $labelCancel : T
7979
8080 var $formName := "D_Request"
8181
82- If (Is macOS:C1572)
82+ If (Is macOS:C1572) // & False
8383
8484 var $winRef := Open form window:C675 ($formName ; Sheet form window:K39:12 )
8585
@@ -98,13 +98,100 @@ Function request($title : Text; $value : Text; $labelOk : Text; $labelCancel : T
9898 End if
9999
100100 DIALOG:C40 ("D_Request" ; $formData )
101+ CLOSE WINDOW:C154 ($winRef )
101102
102103 If (Bool:C1537 (OK))
103104
104105 return $formData .value
105106
106107 End if
107108
109+ // === === === === === === === === === === === === === === === === === === === === === === === === === === === ===
110+ Function newStyleSheetName ($name : Text; $doc : Object; $type : Integer) : Text
111+
112+ $name := $name || Localized string:C991 ("requestPlaceHolder" )
113+ $type := Count parameters:C259>= 3 ? $type : wk type paragraph:K81:191
114+
115+ var $title := Localized string:C991 ("requestTitle" )
116+ var $okTitle := Localized string:C991 ("requestCreateLabel" )
117+ var $cancelTitle := Localized string:C991 ("requestCancelLabel" )
118+ var $placeHolder := Localized string:C991 ("StyleSheetPlaceHolder" )
119+
120+ Repeat
121+
122+ $name := This:C1470 .request ($title ; $name ; $okTitle ; $cancelTitle ; $placeHolder )
123+
124+ If (OK= 0)
125+
126+ return
127+
128+ End if
129+
130+ var $result := This:C1470 .validateStyleSheetName ($name ; $doc )
131+
132+ If ($result .success )
133+
134+ return $name
135+
136+ Else
137+
138+ Case of
139+
140+ // ______________________________________________________
141+ : ($result .error = "exists" )
142+
143+ ALERT:C41 (Replace string:C233 (Localized string:C991 ("aStylesheetWithThatNameAlreadyExists." ); "{name}" ; $name ))
144+
145+ // ______________________________________________________
146+ : ($result .error = "invalid" )
147+
148+ ALERT:C41 (Localized string:C991 ("invalidStyleSheetName" ))
149+
150+ // ______________________________________________________
151+ : ($result .error = "empty" )
152+
153+ ALERT:C41 (Localized string:C991 ("nameIsMandatory" ))
154+
155+ // ______________________________________________________
156+ End case
157+ End if
158+ Until ($result .success )
159+
160+ // === === === === === === === === === === === === === === === === === === === === === === === === === === === ===
161+ Function validateStyleSheetName ($name : Text; $doc : Object; $type : Integer) : Object
162+
163+ Case of
164+
165+ // ______________________________________________________
166+ : (Length:C16 ($name )= 0) // Empty name
167+
168+ return {success: False:C215 ; error: "empty" }
169+
170+ // ______________________________________________________
171+ : (Position:C15 ("section" ; $name )= 1)\
172+ | (Not:C34 (This:C1470 ._styleSheetNameFollowsRules ($name )))
173+
174+ return {success: False:C215 ; error: "invalid" }
175+
176+ // ______________________________________________________
177+ : ($doc= Null:C1517) // Just verify the validity
178+
179+ return {success: True:C214 }
180+
181+ // ______________________________________________________
182+ Else
183+
184+ // Verify for uniqueness in the document regardless of the type
185+ var $styleSheets := WP Get style sheets:C1655 ($doc ; Count parameters:C259>= 3 ? $type : wk type paragraph:K81:191 )
186+ var $unique := $styleSheets .query ("name= :1" ; $name ).first ()= Null :C1517
187+
188+ return $unique \
189+ ? {success: True:C214 }\
190+ : {success: False:C215 ; error: "exists" }
191+
192+ // ______________________________________________________
193+ End case
194+
108195 // === === === === === === === === === === === === === === === === === === === === === === === === === === === ===
109196Function normalizeStyleSheetName ($name : Text; $doc : Object; $type : Integer) : Text
110197
@@ -141,7 +228,7 @@ The style sheet name must comply with the following rules:
141228
142229 For ($i; 1; Length:C16 ($name ); 1)
143230
144- var $char := Substring :C12 ( $name ; $i ; 1 )
231+ var $char := $name [[$i]]
145232 var $code := Character code:C91 ($char )
146233
147234 If ($i= 1)
@@ -173,7 +260,7 @@ The style sheet name must comply with the following rules:
173260 End if
174261
175262 // The name must be unique within the document
176- var $allStyleSheets := WP Get style sheets:C1655 ($doc ; $type # 0 ? $type : wk type paragraph:K81:191 )
263+ var $allStyleSheets := WP Get style sheets:C1655 ($doc ; Count parameters:C259 >= 3 ? $type : wk type paragraph:K81:191 )
177264
178265 While ($allStyleSheets.query ("name= :1" ; $normalized ).first ()# Null:C1517)
179266
@@ -183,6 +270,59 @@ The style sheet name must comply with the following rules:
183270
184271 return $normalized
185272
273+ // === === === === === === === === === === === === === === === === === === === === === === === === === === === ===
274+ Function _styleSheetNameFollowsRules ($name : Text) : Boolean
275+
276+ /*
277+
278+ The style sheet name must comply with the following rules:
279+
280+ - it must start with a letter
281+ - it can then contain alphanumeric characters, space characters, "-" characters or unicode characters >= 128
282+
283+ */
284+
285+ $name := Trim:C1853 ($name )
286+
287+ var $i : Integer
288+
289+ For ($i; 1; Length:C16 ($name ); 1)
290+
291+ var $char := $name [[$i]]
292+ var $code := Character code:C91 ($char )
293+
294+ If ($i= 1)
295+
296+ // First character = letter or Unicode character >= 128
297+ If ($code>= 128)\
298+ || Match regex:C1019 ("[A-Za-z]" ; $char ; 1 ; * )
299+
300+ continue
301+
302+ Else
303+
304+ return
305+
306+ End if
307+
308+ Else
309+
310+ // Next: alnum, space, “-”, Unicode >=128
311+ If ($code>= 128)\
312+ || Match regex:C1019 ("[A-Za-z0-9 -]" ; $char ; 1 ; * )
313+
314+ continue
315+
316+ Else
317+
318+ return
319+
320+ End if
321+ End if
322+ End for
323+
324+ return True:C214
325+
186326 // === === === === === === === === === === === === === === === === === === === === === === === === === === === ===
187327Function duplicateStyleSheet ($source : Object; $name : Text; $doc : Object)
188328
0 commit comments