Skip to content

Commit

Permalink
add spell management to inputDelegate
Browse files Browse the repository at this point in the history
  • Loading branch information
vdelachaux committed Oct 4, 2023
1 parent c9495e8 commit e03a1b3
Show file tree
Hide file tree
Showing 4 changed files with 3,490 additions and 3,303 deletions.
33 changes: 29 additions & 4 deletions Documentation/Classes/inputDelegate.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# input
# inputDelegate

The `inputDelegate` class is intended to handle input widget.

📌 This class inherit from the [`widgetDelegate`](widgetDelegate.md) class
♻️ This class inherit from the [`widgetDelegate`](widgetDelegate.md) class

#### This class is available via the [`formDelegate`](formDelegate.md#objects) class as `input` interface.

Expand All @@ -13,7 +13,7 @@ This.form.input.new("formObjectName")
#### This class can also be instantiated on its own.

```4D
cs. inputDelegate.new({"formObjectName"})
cs.inputDelegate.new({"formObjectName"})
```
If the `formObjectName` parameter is ommited, the constructor use the result of **[OBJECT Get name](https://doc.4d.com/4Dv18R6/4D/18-R6/OBJECT-Get-name.301-5198296.en.html)** ( _Object current_ )

Expand All @@ -29,6 +29,30 @@ All the properties of the extended class, plus:
|**.filter** | The entry filter | `Integer`\* \| `Text`\* | - | <font color="green">X</font>
|**.placeholder** | The placeholder text | `Text`\*\* | - | <font color="green">X</font>
|**.modified** | Modified state of the field after calling the `backup()` function| `Boolean` | **False**
|**.autoSpellcheck** | Auto spellcheck option for the widget| `Boolean` | - | <font color="green">X</font>
|**.dictionary** | Current dictionary \*| `Object` | - |

\* When you read the dictionary property is an object

```4d
Form.input:=cs.inputDelegate.new({"input"})
$dictionary:=Form.input.dictionary
```
```json
{
id: (Integer),
code: (Text),
name: (Text)
}
```

When you write, you pass the `id` or the `code` or the `name`

```4d
Form.input.dictionary:="fr"
```

If the dictionary is not installed, an assert is triggered.

## Functions

Expand All @@ -44,8 +68,9 @@ All the functions of the extended class, plus:
|.**highlighted** () → `Object` | Returns the selection status of the field as a [selection object](#selectionObject).
|.**highlightingStart** () → `Integer` | Returns the start position of currently selected text
|.**highlightingEnd** () → `Integer` | Returns the end position of currently selected text
|**.backup ()** | Stores the current input value.
|**.backup ()** | Stores the current input value\*

\* If the input is instantiated by the `input` interface of the `formDelegate` class, a backup is automatically made during execution of the form.onload() handler.

#### <a name="selectionObject">Selection object</a>

Expand Down
10 changes: 9 additions & 1 deletion Project/Sources/Classes/formDelegate.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,22 @@ Function onLoad()

$widget:=$widgets.query("name = :1"; $key).first()


If ($widget=Null:C1517)\
|| ($page.objects[$key].events=Null:C1517)

continue

End if

// Saving initial value
If (OB Instance of:C1731($widget; cs:C1710.inputDelegate))

//%W-550.2
$widget.backup()
//%W+550.2

End if

For each ($event; $page.objects[$key].events)

$o:=This:C1470._mapEvents.query("e = :1"; $event).pop()
Expand Down
171 changes: 95 additions & 76 deletions Project/Sources/Classes/inputDelegate.4dm
Original file line number Diff line number Diff line change
Expand Up @@ -35,80 +35,7 @@ Function get filter() : Text
// ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==>
Function set filter($filter)

var $separator : Text

If (Value type:C1509($filter)=Is longint:K8:6)\
| (Value type:C1509($filter)=Is real:K8:4) // Predefined formats

Case of

//………………………………………………………………………
: ($filter=Is integer:K8:5)\
| ($filter=Is longint:K8:6)\
| ($filter=Is integer 64 bits:K8:25)

OBJECT SET FILTER:C235(*; This:C1470.name; "&\"0-9;-;+\"")

//………………………………………………………………………
: ($filter=Is real:K8:4)

GET SYSTEM FORMAT:C994(Decimal separator:K60:1; $separator)
OBJECT SET FILTER:C235(*; This:C1470.name; "&\"0-9;"+$separator+";.;-;+\"")

//………………………………………………………………………
: ($filter=Is time:K8:8)

GET SYSTEM FORMAT:C994(Time separator:K60:11; $separator)
OBJECT SET FILTER:C235(*; This:C1470.name; "&\"0-9;"+$separator+";:\"")

//………………………………………………………………………
: ($filter=Is date:K8:7)

GET SYSTEM FORMAT:C994(Date separator:K60:10; $separator)
OBJECT SET FILTER:C235(*; This:C1470.name; "&\"0-9;"+$separator+";/\"")

//………………………………………………………………………
Else

OBJECT SET FILTER:C235(*; This:C1470.name; "") // Text as default

//………………………………………………………………………
End case

Else

$filter:=String:C10($filter)

Case of

//______________________________________________________
: ($filter="email")

OBJECT SET FILTER:C235(*; This:C1470.name; "&\"a-z;0-9;@;.;-;_\"")

//______________________________________________________
: ($filter="url")

OBJECT SET FILTER:C235(*; This:C1470.name; "&\"a-z;0-9;@;.;-;_;:;#;%;/;?;=\"")

//______________________________________________________
: ($filter="noSpaceNorCr")

OBJECT SET FILTER:C235(*; This:C1470.name; "&\"!-ÿ\"")

//______________________________________________________
: ($filter="noCr")

OBJECT SET FILTER:C235(*; This:C1470.name; "&\" -ÿ\"")

//______________________________________________________
Else

OBJECT SET FILTER:C235(*; This:C1470.name; $filter)

//______________________________________________________
End case
End if
This:C1470.setFilter($filter)

// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
Function get placeholder() : Text
Expand Down Expand Up @@ -277,7 +204,38 @@ Function setFilter($filter; $separator : Text) : cs:C1710.inputDelegate

End if

OBJECT SET FILTER:C235(*; This:C1470.name; String:C10($filter))
$filter:=String:C10($filter)

Case of

//______________________________________________________
: ($filter="email")

OBJECT SET FILTER:C235(*; This:C1470.name; "&\"a-z;0-9;@;.;-;_\"")

//______________________________________________________
: ($filter="url")

OBJECT SET FILTER:C235(*; This:C1470.name; "&\"a-z;0-9;@;.;-;_;:;#;%;/;?;=\"")

//______________________________________________________
: ($filter="noSpaceNorCr")

OBJECT SET FILTER:C235(*; This:C1470.name; "&\"!-ÿ\"")

//______________________________________________________
: ($filter="noCr")

OBJECT SET FILTER:C235(*; This:C1470.name; "&\" -ÿ\"")

//______________________________________________________
Else

OBJECT SET FILTER:C235(*; This:C1470.name; $filter)

//______________________________________________________
End case

return This:C1470

// === === === === === === === === === === === === === === === === === === === === === === === === === ===
Expand Down Expand Up @@ -311,4 +269,65 @@ Function setPlaceholder($placeholder : Text) : cs:C1710.inputDelegate
OBJECT SET PLACEHOLDER:C1295(*; This:C1470.name; $t)

return This:C1470


// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
Function get autoSpellcheck() : Boolean

return OBJECT Get auto spellcheck:C1174(*; This:C1470.name)

// ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==>
Function set autoSpellcheck($enabled : Boolean)

OBJECT SET AUTO SPELLCHECK:C1173(*; This:C1470.name; $enabled)

// <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <== <==
Function get dictionary() : Object

This:C1470.$dictionaries:=This:C1470.$dictionaries || This:C1470._getDictionaries()

return This:C1470.$dictionaries.query("id = :1"; SPELL Get current dictionary:C1205).first()

// ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==> ==>
Function set dictionary($dictionary)

This:C1470.$dictionaries:=This:C1470.$dictionaries || This:C1470._getDictionaries()

If (This:C1470.$dictionaries.query("id = :1 OR name = :1 OR code = :1"; $dictionary).pop()=Null:C1517)\
&& (Position:C15("_"; $dictionary)>0)

$dictionary:=Split string:C1554($dictionary; "_")[0]

End if

If (Asserted:C1132(This:C1470.$dictionaries.query("id = :1 OR name = :1 OR code = :1"; $dictionary).pop()#Null:C1517; \
"The dictionary \""+String:C10($dictionary)+"\" isn't installed"))

SPELL SET CURRENT DICTIONARY:C904($dictionary)

End if

// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Function _getDictionaries() : Collection

var $i : Integer
var $c : Collection

ARRAY TEXT:C222($files; 0)
ARRAY TEXT:C222($names; 0)
ARRAY LONGINT:C221($IDs; 0)

SPELL GET DICTIONARY LIST:C1204($IDs; $files; $names)

$c:=[]

For ($i; 1; Size of array:C274($IDs); 1)

$c.push({\
id: $IDs{$i}; \
code: $files{$i}; \
name: $names{$i}\
})

End for

return $c
Loading

0 comments on commit e03a1b3

Please sign in to comment.