Skip to content

Commit 37e1f85

Browse files
committed
github:19997 - work on #21267
1 parent aa4e09d commit 37e1f85

16 files changed

Lines changed: 324 additions & 66 deletions

File tree

Project/Sources/Classes/_wp.4dm

Lines changed: 143 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
// === === === === === === === === === === === === === === === === === === === === === === === === === === === ===
109196
Function 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
// === === === === === === === === === === === === === === === === === === === === === === === === === === === ===
187327
Function duplicateStyleSheet($source : Object; $name : Text; $doc : Object)
188328

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
WP_StylesheetAdd
1+
WP_StylesheetAdd

Project/Sources/Methods/WP_GetStyleSheet.4dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//%attributes = {"invisible":true}
2-
var $type:=WP_GetStylesheetType
2+
var $type:=getSelectedStyleSheetType
33

44
Case of
55

Project/Sources/Methods/WP_GetStyleSheets.4dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//%attributes = {"invisible":true}
22
var $document : Object:=Form:C1466.selection[wk owner:K81:168]
3-
var $type:=WP_GetStylesheetType
3+
var $type:=getSelectedStyleSheetType
44
var $c:=WP Get style sheets:C1655($document; $type)
55

66
var $namesArrayPtr:=OBJECT Get pointer:C1124(Object named:K67:5; "stylesheet_Names")

Project/Sources/Methods/WP_StylesheetAdd.4dm

Lines changed: 69 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -37,84 +37,104 @@ RELEASE MENU:C978($menu)
3737

3838
If (Length:C16($choice)=0)
3939

40-
return
40+
return // <NOTHING MORE TO DO>
4141

4242
End if
4343

4444
// MARK:- Action
45-
var $title:=Localized string:C991("requestTitle")
46-
var $default:=Localized string:C991("requestPlaceHolder")
47-
var $okTitle:=Localized string:C991("requestCreateLabel")
48-
var $cancelTitle:=Localized string:C991("requestCancelLabel")
49-
var $placeHolder:=Localized string:C991("StyleSheetPlaceHolder")
45+
var $new:=$choice="new"
46+
var $newFromSelection:=$choice="newFromSelection"
47+
var $duplicate:=Position:C15("duplicate_"; $choice)=1
48+
49+
var $type:=getSelectedStyleSheetType/* 0 = Paragraph, 1 = Font, 6 = List */
5050

5151
Case of
5252

5353
//________________________________________________________________________________
54-
: ($choice="new")\
55-
| ($choice="newFromSelection")
56-
57-
Repeat
58-
59-
var $newName:=cs:C1710._wp.me.request($title; $default; $okTitle; $cancelTitle; $placeHolder)
60-
61-
If ($newName="section@")
62-
63-
ALERT:C41(Localized string:C991("nameError"))
64-
65-
End if
66-
Until (($newName#"section@") & ($newName#"")) | (OK=0)
54+
: ($new || $newFromSelection)
6755

68-
//________________________________________________________________________________
69-
: ($choice="duplicate_@")
56+
var $name:=cs:C1710._wp.me.newStyleSheetName(Localized string:C991("requestPlaceHolder"); Form:C1466.document; $type)
57+
var $success:=Length:C16($name)>0
7058

71-
var $source : Object:=$styleSheets[Num:C11(Delete string:C232($choice; 1; 10))]
72-
var $sourceName : Text:=$source.name
73-
$newName:=cs:C1710._wp.me.normalizeStyleSheetName($source.name; Form:C1466.document)
74-
$newName:=cs:C1710._wp.me.request($title; $newName; $okTitle; $cancelTitle; $placeHolder)
75-
76-
//________________________________________________________________________________
77-
End case
78-
79-
If (Bool:C1537(OK)) // resuls of Request
80-
81-
var $typeStylesheet:=WP_GetStylesheetType/* 0 = Paragraph, 1 = Font, 6 = List */
82-
83-
// Just in case the user refuses the "x" added at the end…
84-
$newName:=cs:C1710._wp.me.normalizeStyleSheetName($newName; Form:C1466.document)
85-
86-
var $to : Object:=$source.levelCount#Null:C1517\
87-
? WP New style sheet:C1650(Form:C1466.document; $typeStylesheet; $newName; $source.levelCount)\
88-
: WP New style sheet:C1650(Form:C1466.document; $typeStylesheet; $newName)
89-
90-
Case of
59+
If (Not:C34($success))
9160

92-
//________________________________________________________________________________
93-
: ($choice="newFromSelection")
61+
return // <NOTHING MORE TO DO>
9462

95-
var $attributes:=WP_GetStyleAttributesByType($typeStylesheet) // collection of attributes according to stylesheet TYPE
63+
End if
64+
65+
If ($newFromSelection)
9666

9767
Case of
9868

9969
//┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
100-
: ($typeStylesheet=wk type default:K81:190)
70+
: ($type=wk type default:K81:190)
10171

10272
var $from : Object:=Form:C1466.selection
10373

10474
//┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
105-
: ($typeStylesheet=wk type paragraph:K81:191)
75+
: ($type=wk type paragraph:K81:191)
10676

10777
$from:=WP Paragraph range:C1346(Form:C1466.selection)
78+
var $styleSheet : Object
79+
WP Get attributes:C1345($from; wk style sheet:K81:63; $styleSheet)
10880

10981
//┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅┅
11082
End case
83+
End if
84+
85+
//________________________________________________________________________________
86+
: ($duplicate)
87+
88+
var $source : Object:=$styleSheets[Num:C11(Delete string:C232($choice; 1; 10))]
89+
$name:=cs:C1710._wp.me.newStyleSheetName($source.name; Form:C1466.document; $type)
90+
$success:=Length:C16($name)>0
91+
92+
If (Not:C34($success))
93+
94+
return // <NOTHING MORE TO DO>
11195

112-
WP_StylesheetSetAttributes({list: $attributes; from: $from; to: $to; remove: True:C214})
96+
End if
97+
98+
//________________________________________________________________________________
99+
End case
100+
101+
// Ensure that the name is unique & valid
102+
$name:=cs:C1710._wp.me.normalizeStyleSheetName($name; Form:C1466.document)
103+
$success:=Length:C16($name)>0
104+
105+
If ($success)
106+
107+
/* 📌 Requirement #21267
108+
109+
When the selected paragraph has a listStyleType applied to it (not necessarily a style sheet),
110+
the “New style sheet based on selection” button shall create a multi-level list of 1 level based on the style
111+
112+
*/
113+
// Normal $styleSheet.type=1; listStyleType=0; listLevelCount=null
114+
// listStyleType &
115+
116+
If ($styleSheet.listStyleType#Null:C1517)
117+
118+
var $to:=WP New style sheet:C1650(Form:C1466.document; $type; $name; 1)
119+
120+
Else
121+
122+
$to:=($styleSheet.listLevelCount#Null:C1517) || ($source.listLevelCount#Null:C1517)\
123+
? WP New style sheet:C1650(Form:C1466.document; $type; $name; $styleSheet.listLevelCount || $source.listLevelCount)\
124+
: WP New style sheet:C1650(Form:C1466.document; $type; $name)
125+
126+
End if
127+
128+
Case of
129+
130+
//________________________________________________________________________________
131+
: ($newFromSelection)
113132

114-
WP SET ATTRIBUTES:C1342(Form:C1466.selection; wk style sheet:K81:63; $to) // As an object
133+
WP_StylesheetSetAttributes({list: WP_GetStyleAttributesByType($type); from: $from; to: $to; remove: True:C214})
134+
WP SET ATTRIBUTES:C1342(Form:C1466.selection; wk style sheet:K81:63; $to)
115135

116136
//________________________________________________________________________________
117-
: ($choice="duplicate_@")
137+
: ($duplicate)
118138

119139
$from:=WP Get style sheet:C1656(Form:C1466.document; $source.name)
120140
WP_StylesheetCopyAttributes({from: $from; to: $to})

Project/Sources/Methods/WP_StylesheetRemove.4dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ If ($stylesheetName="normal") | ($stylesheetName="")
2727

2828
Else
2929

30-
$stylesheetType:=WP_GetStylesheetType // wk type default or wk type paragraph
30+
$stylesheetType:=getSelectedStyleSheetType // wk type default or wk type paragraph
3131

3232

3333
//CONFIRM(".Delete style sheet \""+$stylesheetName+"\"?";".delete";".cancel")
3434
//If (ok=1) // cancel = 1, delete = 0
3535
// //ALERT(".Style sheet can't be delete yet…")
3636
//WP DELETE STYLE SHEET(Form.document;$stylesheetName)
3737
//WP_GetStyleSheets // refresh
38-
//End if
38+
//End if
3939
//SET TIMER(-1)
4040

4141
$menu:=Create menu:C408

Project/Sources/Methods/WP_StylesheetUpdate.4dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//%attributes = {"invisible":true}
2-
var $stylesheetType:=WP_GetStylesheetType // Paragraph, char, picture, table, row or cell
2+
var $stylesheetType:=getSelectedStyleSheetType // Paragraph, char, picture, table, row or cell
33

44
var $ptrListbox:=OBJECT Get pointer:C1124(Object named:K67:5; "LB_StyleSheets")
55
var $ptrStylesheetNames:=OBJECT Get pointer:C1124(Object named:K67:5; "stylesheet_Names")
File renamed without changes.

0 commit comments

Comments
 (0)