--[[ Feature: Add a toggle button to the left of "Add Address Manually" + global hotkey Ctrl+Shift+K Behaviour: Both the button and hotkey perform expand/collapse toggle (state synchronised) Ver 1.0.0 ]] local mainForm = getMainForm() if not mainForm then return end local refButton = mainForm.ComponentByName['btnAddAddressManually'] if not refButton then return end local parent = refButton.Parent if not parent then return end -- Clear old button if btnToggleHide ~= nil then btnToggleHide.destroy() btnToggleHide = nil end -- Button dimensions local BTN_WIDTH = 250 local BTN_HEIGHT_OFFSET = 13 -- Create button (initially hidden) btnToggleHide = createButton(parent) btnToggleHide.Parent = parent btnToggleHide.Width = BTN_WIDTH btnToggleHide.Height = refButton.Height + BTN_HEIGHT_OFFSET btnToggleHide.Font.Size = refButton.Font.Size btnToggleHide.ShowHint = true btnToggleHide.Visible = false -- Marker constants local MARK_HIDE = "|moH" local MARK_ALWAYS = "|moAH" -- Check if any markers exist local function hasMarkers() local addrList = getAddressList() if not addrList then return false end for i = 0, addrList.Count - 1 do local rec = addrList.getMemoryRecord(i) local desc = rec.Description or "" if desc:find(MARK_HIDE) or desc:find(MARK_ALWAYS) then return true end end return false end -- Update button caption local function updateButtonCaption() if hasMarkers() then btnToggleHide.Caption = "Collapse records" btnToggleHide.Hint = "Click to restore and collapse previously hidden records" else btnToggleHide.Caption = "Show records" btnToggleHide.Hint = "Click to expand all collapsed records (group headers with hidden children)" end end -- Positioning function local function positionButton() if not btnToggleHide or not refButton then return end local refLeft = refButton.Left local refTop = refButton.Top local newLeft = refLeft - btnToggleHide.Width - 5 if newLeft < 0 then newLeft = 0 end btnToggleHide.Left = newLeft btnToggleHide.Top = refTop btnToggleHide.Visible = true end -- Delayed creation local initTimer = createTimer(nil, false) initTimer.Interval = 200 initTimer.OnTimer = function() initTimer.Enabled = false initTimer.destroy() positionButton() updateButtonCaption() btnToggleHide.BringToFront() if parent.Repaint then parent.Repaint() end end initTimer.Enabled = true -- Window resize listener local oldResize = mainForm.OnResize mainForm.OnResize = function(sender) if oldResize then oldResize(sender) end positionButton() end -- ★★★ Core toggle function (shared by button and hotkey) ★★★ local function toggleHideRecords() local addrList = getAddressList() if not addrList or addrList.Count == 0 then showMessage("Address list is empty.") return end if hasMarkers() then -- Markers exist → perform collapse for i = 0, addrList.Count - 1 do local rec = addrList.getMemoryRecord(i) local desc = rec.Description or "" local opt = rec.Options or "" if desc:find(MARK_HIDE) then rec.Description = desc:gsub(MARK_HIDE, "") rec.Options = opt .. "moHideChildren" rec.Collapsed = true end if desc:find(MARK_ALWAYS) then rec.Description = desc:gsub(MARK_ALWAYS, "") rec.Options = opt .. "moAlwaysHideChildren" rec.Collapsed = true end end --showMessage("Collapsed all hidden records.") else -- No markers → perform expand local count = 0 for i = 0, addrList.Count - 1 do local rec = addrList.getMemoryRecord(i) local opt = rec.Options or "" local desc = rec.Description or "" local modified = false if opt:find("moHideChildren") then rec.Description = desc .. MARK_HIDE rec.Options = opt:gsub("moHideChildren", "") rec.Collapsed = false modified = true end if opt:find("moAlwaysHideChildren") then rec.Description = desc .. MARK_ALWAYS rec.Options = rec.Options:gsub("moAlwaysHideChildren", "") rec.Collapsed = false modified = true end if modified then count = count + 1 end end --showMessage(string.format("Expanded %d hidden record(s).", count)) end updateButtonCaption() end -- Bind button click btnToggleHide.OnClick = toggleHideRecords -- ★★★ Register global hotkey (Ctrl+Shift+K) ★★★ local hotkey = createHotkey( function() if btnToggleHide and btnToggleHide.Visible then toggleHideRecords() -- Directly call the core function, not via button end end, { VK_CONTROL, VK_SHIFT, 0x4B } -- 0x4B = K ) -- Optional: save hotkey to a global variable for debugging or destruction -- _G.hotkey_toggle = hotkey --print("auto_hide_toggle loaded (with hotkey Ctrl+Shift+K).") --[[ Hotkey notes Virtual key code: 0x4B is the 'K' key. Modifiers: VK_CONTROL and VK_SHIFT represent Ctrl and Shift. To change the shortcut, modify 0x4B or the modifier list accordingly (e.g., VK_CONTROL, 0x4B for Ctrl+K). ]]