MCPcopy Create free account
hub / github.com/AutoHotkey/AutoHotkey / TV_AddModifyDelete

Method TV_AddModifyDelete

source/script2.cpp:16033–16305  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16031
16032
16033ResultType GuiControlType::TV_AddModifyDelete(ResultToken &aResultToken, int aID, int aFlags, ExprTokenType *aParam[], int aParamCount)
16034// TV.Add():
16035// Returns the HTREEITEM of the item on success, zero on failure.
16036// Parameters:
16037// 1: Text/name of item.
16038// 2: Parent of item.
16039// 3: Options.
16040// TV.Modify():
16041// Returns the HTREEITEM of the item on success (to allow nested calls in script, zero on failure or partial failure.
16042// Parameters:
16043// 1: ID of item to modify.
16044// 2: Options.
16045// 3: New name.
16046// Parameters for TV.Delete():
16047// 1: ID of item to delete (if omitted, all items are deleted).
16048{
16049 GuiControlType &control = *this;
16050 auto mode = BuiltInFunctionID(aID);
16051 LPTSTR buf = _f_number_buf; // Resolve macro early for maintainability.
16052
16053 if (mode == FID_TV_Delete)
16054 {
16055 // If param #1 is present but is zero, for safety it seems best not to do a delete-all (in case a
16056 // script bug is so rare that it is never caught until the script is distributed). Another reason
16057 // is that a script might do something like TV.Delete(TV.GetSelection()), which would be desired
16058 // to fail not delete-all if there's ever any way for there to be no selection.
16059 _o_return(SendMessage(control.hwnd, TVM_DELETEITEM, 0
16060 , ParamIndexIsOmitted(0) ? NULL : (LPARAM)ParamIndexToInt64(0)));
16061 }
16062
16063 // Since above didn't return, this is TV.Add() or TV.Modify().
16064 TVINSERTSTRUCT tvi; // It contains a TVITEMEX, which is okay even if MSIE pre-4.0 on Win95/NT because those OSes will simply never access the new/bottommost item in the struct.
16065 bool add_mode = (mode == FID_TV_Add); // For readability & maint.
16066 HTREEITEM retval;
16067
16068 // Suppress any events raised by the changes made below:
16069 control.attrib |= GUI_CONTROL_ATTRIB_SUPPRESS_EVENTS;
16070
16071 LPTSTR options;
16072 if (add_mode) // TV.Add()
16073 {
16074 tvi.hParent = ParamIndexIsOmitted(1) ? NULL : (HTREEITEM)ParamIndexToInt64(1);
16075 tvi.hInsertAfter = TVI_LAST; // i.e. default is to insert the new item underneath the bottommost sibling.
16076 options = ParamIndexToOptionalString(2, buf);
16077 retval = 0; // Set default return value.
16078 }
16079 else // TV.Modify()
16080 {
16081 // NOTE: Must allow hitem==0 for TV.Modify, at least for the Sort option, because otherwise there would
16082 // be no way to sort the root-level items.
16083 tvi.item.hItem = (HTREEITEM)ParamIndexToInt64(0); // Load-time validation has ensured there is a first parameter for TV.Modify().
16084 // For modify-mode, set default return value to be "success" from this point forward. Note that
16085 // in the case of sorting the root-level items, this will set it to zero, but since that almost
16086 // always succeeds and the script rarely cares whether it succeeds or not, adding code size for that
16087 // doesn't seem worth it:
16088 retval = tvi.item.hItem; // Set default return value.
16089 if (aParamCount < 2) // In one-parameter mode, simply select the item.
16090 {

Callers

nothing calls this directly

Calls 7

omit_leading_whitespaceFunction · 0.85
StrChrAnyFunction · 0.85
ATOIFunction · 0.85
IsNumericFunction · 0.85
ATOI64Function · 0.85
ValueErrorMethod · 0.80
BuiltInFunctionIDEnum · 0.70

Tested by

no test coverage detected