Skip to content

Commit

Permalink
Release Search action by command ID or name v2.0.3 (#1389)
Browse files Browse the repository at this point in the history
Internal code cleanup
  • Loading branch information
cfillion authored May 12, 2024
1 parent 1e9da9d commit 1a804fc
Showing 1 changed file with 69 additions and 72 deletions.
141 changes: 69 additions & 72 deletions Development/cfillion_Search action by command ID or name.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
-- @description Search action by command ID or name
-- @author cfillion
-- @version 2.0.2
-- @changelog Enable ReaImGui's backward compatibility shims
-- @version 2.0.3
-- @changelog Internal code cleanup
-- @link Forum thread https://forum.cockos.com/showthread.php?t=226107
-- @screenshot https://i.imgur.com/yqkvZvf.gif
-- @donation https://www.paypal.com/cgi-bin/webscr?business=T3DEWBQJAV7WL&cmd=_donations&currency_code=CAD
-- @donation https://reapack.com/donate

dofile(reaper.GetResourcePath() ..
'/Scripts/ReaTeam Extensions/API/imgui.lua')('0.7')

local FLT_MIN, FLT_MAX = reaper.ImGui_NumericLimits_Float()
local SCRIPT_NAME = ({reaper.get_action_context()})[2]:match("([^/\\_]+)%.lua$")
local SCRIPT_NAME = select(2, reaper.get_action_context()):match("([^/\\_]+)%.lua$")
local AL_SECTIONS = {
{ id=0, name='Main' },
{ id=100, name='Main (alt recording)' },
Expand All @@ -20,10 +16,13 @@ local AL_SECTIONS = {
{ id=32063, name='Media Explorer' },
}

local ctx = reaper.ImGui_CreateContext(SCRIPT_NAME)
local font = reaper.ImGui_CreateFont('sans-serif', 13)
reaper.ImGui_AttachFont(ctx, font)
package.path = reaper.ImGui_GetBuiltinPath() .. '/?.lua'
local ImGui = require 'imgui' '0.9'
local font = ImGui.CreateFont('sans-serif', 13)
local ctx = ImGui.CreateContext(SCRIPT_NAME)
ImGui.Attach(ctx, font)

local FLT_MIN, FLT_MAX = ImGui.NumericLimits_Float()
local section, commandId, actionName = AL_SECTIONS[1], '', ''

local function iterateActions()
Expand Down Expand Up @@ -58,18 +57,18 @@ end
local function form()
local rv

reaper.ImGui_TableSetupColumn(ctx, '', reaper.ImGui_TableColumnFlags_WidthFixed())
reaper.ImGui_TableSetupColumn(ctx, '', reaper.ImGui_TableColumnFlags_WidthStretch())
ImGui.TableSetupColumn(ctx, '', ImGui.TableColumnFlags_WidthFixed)
ImGui.TableSetupColumn(ctx, '', ImGui.TableColumnFlags_WidthStretch)

reaper.ImGui_TableNextRow(ctx)
reaper.ImGui_TableNextColumn(ctx)
reaper.ImGui_AlignTextToFramePadding(ctx)
reaper.ImGui_Text(ctx, 'Section:')
reaper.ImGui_TableNextColumn(ctx)
reaper.ImGui_SetNextItemWidth(ctx, -FLT_MIN)
if reaper.ImGui_BeginCombo(ctx, '##section', section.name) then
ImGui.TableNextRow(ctx)
ImGui.TableNextColumn(ctx)
ImGui.AlignTextToFramePadding(ctx)
ImGui.Text(ctx, 'Section:')
ImGui.TableNextColumn(ctx)
ImGui.SetNextItemWidth(ctx, -FLT_MIN)
if ImGui.BeginCombo(ctx, '##section', section.name) then
for _, s in ipairs(AL_SECTIONS) do
if reaper.ImGui_Selectable(ctx, s.name, s.id == section.id) then
if ImGui.Selectable(ctx, s.name, s.id == section.id) then
section = s
local oldName = actionName
findById()
Expand All @@ -79,83 +78,81 @@ local function form()
end
end
end
reaper.ImGui_EndCombo(ctx)
ImGui.EndCombo(ctx)
end

reaper.ImGui_TableNextRow(ctx)
reaper.ImGui_TableNextColumn(ctx)
reaper.ImGui_AlignTextToFramePadding(ctx)
reaper.ImGui_Text(ctx, 'Command ID:')
reaper.ImGui_TableNextColumn(ctx)
reaper.ImGui_SetNextItemWidth(ctx, -FLT_MIN)
rv, commandId = reaper.ImGui_InputText(ctx, '##command_id', commandId)
ImGui.TableNextRow(ctx)
ImGui.TableNextColumn(ctx)
ImGui.AlignTextToFramePadding(ctx)
ImGui.Text(ctx, 'Command ID:')
ImGui.TableNextColumn(ctx)
ImGui.SetNextItemWidth(ctx, -FLT_MIN)
rv, commandId = ImGui.InputText(ctx, '##command_id', commandId)
if rv then findById() end

reaper.ImGui_TableNextRow(ctx)
reaper.ImGui_TableNextColumn(ctx)
reaper.ImGui_AlignTextToFramePadding(ctx)
reaper.ImGui_Text(ctx, 'Action name:')
reaper.ImGui_TableNextColumn(ctx)
reaper.ImGui_SetNextItemWidth(ctx, -FLT_MIN)
rv, actionName = reaper.ImGui_InputText(ctx, '##action_name', actionName)
ImGui.TableNextRow(ctx)
ImGui.TableNextColumn(ctx)
ImGui.AlignTextToFramePadding(ctx)
ImGui.Text(ctx, 'Action name:')
ImGui.TableNextColumn(ctx)
ImGui.SetNextItemWidth(ctx, -FLT_MIN)
rv, actionName = ImGui.InputText(ctx, '##action_name', actionName)
if rv then findByName() end
end

local function buttons()
local found = #commandId > 0 and #actionName > 0
reaper.ImGui_BeginDisabled(ctx, not found)
if reaper.ImGui_Button(ctx, 'Copy command ID') then
reaper.ImGui_SetClipboardText(ctx, commandId)
ImGui.BeginDisabled(ctx, not found)
if ImGui.Button(ctx, 'Copy command ID') then
ImGui.SetClipboardText(ctx, commandId)
end
reaper.ImGui_SameLine(ctx)
if reaper.ImGui_Button(ctx, 'Copy action name') then
reaper.ImGui_SetClipboardText(ctx, actionName)
ImGui.SameLine(ctx)
if ImGui.Button(ctx, 'Copy action name') then
ImGui.SetClipboardText(ctx, actionName)
end
if not found and (#commandId > 0 or #actionName > 0) then
reaper.ImGui_SameLine(ctx)
reaper.ImGui_AlignTextToFramePadding(ctx)
reaper.ImGui_Text(ctx, 'Action not found.')
ImGui.SameLine(ctx)
ImGui.AlignTextToFramePadding(ctx)
ImGui.Text(ctx, 'Action not found.')
end
reaper.ImGui_EndDisabled(ctx)
ImGui.EndDisabled(ctx)
end

local function loop()
reaper.ImGui_PushFont(ctx, font)
reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_WindowBg(), 0xffffffff)
ImGui.PushFont(ctx, font)
ImGui.PushStyleColor(ctx, ImGui.Col_WindowBg, 0xffffffff)

reaper.ImGui_SetNextWindowSize(ctx, 442, 131, reaper.ImGui_Cond_FirstUseEver())
local visible, open = reaper.ImGui_Begin(ctx, SCRIPT_NAME, true)
ImGui.SetNextWindowSize(ctx, 442, 131, ImGui.Cond_FirstUseEver)
local visible, open = ImGui.Begin(ctx, SCRIPT_NAME, true)
if visible then
reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Border(), 0x2a2a2aff)
reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Button(), 0xdcdcdcff)
reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_ButtonActive(), 0x787878ff)
reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_ButtonHovered(), 0xdcdcdcff)
reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_FrameBg(), 0xffffffff)
reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_HeaderHovered(), 0x96afe1ff)
reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_PopupBg(), 0xffffffff)
reaper.ImGui_PushStyleColor(ctx, reaper.ImGui_Col_Text(), 0x2a2a2aff)
reaper.ImGui_PushStyleVar(ctx, reaper.ImGui_StyleVar_FrameBorderSize(), 1)

if reaper.ImGui_BeginTable(ctx, '##layout', 2) then
ImGui.PushStyleColor(ctx, ImGui.Col_Border, 0x2a2a2aff)
ImGui.PushStyleColor(ctx, ImGui.Col_Button, 0xdcdcdcff)
ImGui.PushStyleColor(ctx, ImGui.Col_ButtonActive, 0x787878ff)
ImGui.PushStyleColor(ctx, ImGui.Col_ButtonHovered, 0xdcdcdcff)
ImGui.PushStyleColor(ctx, ImGui.Col_FrameBg, 0xffffffff)
ImGui.PushStyleColor(ctx, ImGui.Col_HeaderHovered, 0x96afe1ff)
ImGui.PushStyleColor(ctx, ImGui.Col_PopupBg, 0xffffffff)
ImGui.PushStyleColor(ctx, ImGui.Col_Text, 0x2a2a2aff)
ImGui.PushStyleVar(ctx, ImGui.StyleVar_FrameBorderSize, 1)

if ImGui.BeginTable(ctx, '##layout', 2) then
form()
reaper.ImGui_EndTable(ctx)
ImGui.EndTable(ctx)
end
reaper.ImGui_Spacing(ctx)
ImGui.Spacing(ctx)
buttons()

reaper.ImGui_PopStyleVar(ctx)
reaper.ImGui_PopStyleColor(ctx, 8)
reaper.ImGui_End(ctx)
ImGui.PopStyleVar(ctx)
ImGui.PopStyleColor(ctx, 8)
ImGui.End(ctx)
end

reaper.ImGui_PopStyleColor(ctx)
reaper.ImGui_PopFont(ctx)
ImGui.PopStyleColor(ctx)
ImGui.PopFont(ctx)

if open and not reaper.ImGui_IsKeyPressed(ctx, reaper.ImGui_Key_Escape()) then
if open and not ImGui.IsKeyPressed(ctx, ImGui.Key_Escape) then
reaper.defer(loop)
else
reaper.ImGui_DestroyContext(ctx)
end
end

loop()
reaper.defer(loop)

0 comments on commit 1a804fc

Please sign in to comment.