Create, modify, copy and delete QM items

Not available in exe.

 

Syntax

int newitem([name] [text] [type|template] [trigger] [folder] [flags])

 

Parameters

name - name.

text - item text.

type - QM item type. Can be: "Macro", "Function", "Menu", "Toolbar", "Autotext", "Member", "Folder", "File Link".

template - name or id of an existing item. Its type and other properties will be applied to the new item.

trigger - encoded trigger string.

folder - name or id of folder where new item must be created.

flags:

0

If item with name exists, create new item with unique name, e.g., "Macro" -> "Macro2".

  • Flags 0 - 3 cannot be used together.
  • QM 2.3.3. Does not make unique name if it is folder.
1

If item with name exists, replace it.

  • Cannot replace folder.
2 If item with name exists, error.
3

If item with name exists, replace its text.

  • The user can Undo if the item is currently open (is in the "Open items" list).
  • Does not replace other properties.
  • Alternatively you can use str.setmacro.
4 Select new item.
8 Let user edit name of new item (if flag 4, and QM window is active).
16 Create at the bottom.
32

Delete item.

  • Other flags (except 64), text and trigger are not used.
  • Not error if item not found. Then the function returns -1.
64 Confirm (with flag 32). Error if user clicks Cancel.

128

(QM 2.3.0)

Temporary. Temporary items disappear when closing file.

  • QM 2.4.0. Creates in the Temp folder, regardless of folder.

 

Remarks

Creates new QM item, or replaces/modifies/deletes existing item. Returns item id.

 

Cannot create/replace/modify/delete items in read-only folders. Cannot replace (flag 1), modify (flag 3) or delete (flag 32) existing item if it is in other folder or has other type, unless item id is used.

 

QM 2.2.0. Can be used encrypted templates. Then the new item also will be encrypted. Also can replace (flag 1), replace text (flag 3) and delete (flag 32) encrypted items. If flag 3 used, and the item already exists, it also must be encrypted.

 

Example

 Execute QM macro code that is stored in file "test.txt". This will create temporary macro with text of file and execute it:
str s.getfile("$desktop$\test.txt")
mac newitem("temp_file_text" s "" "" "\Temp\files" 1)