Button2Clip

Title Button2Clip
File Name Button2Clip.txt
Description List all button bars. Copy any button image to the clipboard
Author Vochomurka
Parameters "1" (to generate report; or nothing)
Plugins Called vec, win, file, ini, clip
Icon
Version 1.1
Updated on 03.03.15
args Stat
static Config = pprofolder ++ "scripts\ini\Button2Clip.ini"
static Height = ini.get(Config, "General", "Height")
static BB = "Buttonbar"
static BC = "Buttoncount"
static CR = esc(?+\r+, ?+\+)
local i
flag clear 1

if(Ctrl || Stat)
	flag set 1

local D = cl.Create("Dirs", 1)
local Cols = ini.enum_sections(Config) 

if(pproflag(1)) do
	local Rep = pprofolder ++ "ButtonBars.ini"
	local fh = file.open(Rep)

	if(fh <= 0) do
		messagebox("ok error", "File not created", "FILE plugin error #1")
		quit
	endif

	file.close(fh)
	local Bars, Buttons, Counter, j, Temp

	for each line i in Cols
		if(i != "General") do
			.@Read(i)
		else
			.@Read()
		endif

		Counter = v.length
		Bars += Counter
		for(j = 0; j < Counter; j++)
			Temp = ini.get(v[j], BB, BC)
			ini.set(Rep, i, v[j], Temp)
			Buttons += Temp
		endfor
		ini.set(Rep, "Summary", "Bars", Bars) 
		ini.set(Rep, "Summary", "Buttons", Buttons)
	endfor

	Temp = "File " ++ Rep ++ " created" ++ CR ++ CR ++ "Bars: " ++ Bars ++ CR ++ "Buttons: " ++ Buttons
	messagebox("ok", Temp, "Button2Clip script")
	quit
endif

for each line i in Cols
	if(i != "General") do
		D.Insert(0)
		D.AddLeft(0, cb("@Read", i))
		D.SetLabel(0, i)
	endif
endfor

D.Insert(0)
D.AddLeft(0, cb("@Read"))
D.SetLabel(0, "Main Bars")

*menu show Dirs

local Bs = cl.Create("Bars", 1)
Bs.NewProperties("tooltips")

local Number = v.length

for(i = Number - 1; i >= 0; i--)
	Bs.Insert(0)
	Bs.AddLeft(0, cb("@Left", i))
	Temp = file.name(v[i])
	Bs.SetLabel(0, Temp)
	Temp = ini.get(v[i], BB, BC)
	Bs.SetTooltip(0, v[i] ++ "/" ++ Temp ++ " buttons")
endfor

Cols = Number/Height

for(i = 1; i <= Cols; i++)
	Bs.Insert(i*Height)
	Bs.AddLeft(i*Height, "Format NewColumnLine")
endfor

*menu show Bars
quit all

;;**************************************
Function Read(Sec)

local Path
local Mask = "*.bar"
local Temp, Str, List, Elem, Counter
static v

if(not Sec) do
	local hh = win.handle("c=TTOTAL_CMD")
	Path = file.folder(win.exepath(hh))
	Temp = file.listfiles(Path ++ "\" ++ Mask)
	v = vec.createfromlines(Temp)

	if(v <= 0)
		messagebox("ok error", "Vector not created", "VEC plugin error #1")

	quit
endif

v = vec.create(1, 1)

if(v <= 0) do
	messagebox("ok error", "Vector not created", "VEC plugin error #2")
	quit
endif

Str = ini.enum_keys(Config, Sec)

for each line Temp in Str
	Elem = ini.get(Config, Sec, Temp)
	List = file.listfiles(Elem ++ Mask)
	for each line Elem in List
		v[Counter] = Elem
		Counter++
	endfor
endfor

quit

;;**************************************
Function Left(i)
static B = cl.Create("Bar", 1)
B.NewProperties("Tooltips iconsize: 16")
local Source = v[i]
static Items = ini.get(Source, BB, BC)
local i, Pars, Str, Counter

for(i = Items; i >= 1; i--)
	B.Insert(0)
	Str = "TOTALCMD#BAR#DATA" ++ CR

	if(ini.check_exists(Source, BB, "cmd" ++ i) == 2) do
		B.AddLeft(0, "Format Separator")
		continue
	endif

	Temp = ini.get(Source, BB, "cmd" ++ i)
	if(Temp == -2) do
		B.AddLeft(0, "Format NewColumnLine")
		Counter = 0
		continue
	else
		B.AddMiddle(0, Temp)
		Str ++= Temp ++ CR
	endif

	Temp = ini.get(Source, BB, "cmd" ++ i)

	if(ini.check_exists(Source, BB, "param" ++ i) == 3)
		B.AddRight(0, ini.get(Source, BB, "param" ++ i))

	Str ++= B.GetRightCmd(0) ++ CR
	Temp = ini.get(Source, BB, "button" ++ i)
	B.SetIcon(0, Temp, 0)
	Str ++= Temp ++ CR
	Temp = ini.get(Source, BB, "menu" ++ i)
	B.SetLabel(0, Temp)
	Str ++= Temp ++ CR
	B.AddLeft(0, cb("@Clip", i))

	Temp = B.GetRightCmd(0)
	if(ini.check_exists(Source, BB, "path" ++ i) == 3)
		B.AddRight(0, Temp, ini.get(Source, BB, "path" ++ i))

	Str ++= B.GetRightParam(0)
	B.SetTooltip(0, Str)

	if(Counter > Height) do
		B.Insert(0)
		B.AddLeft(0, "Format NewColumnLine")
		Counter = 0
	else
		Counter++
	endif
endfor

*menu show Bar

quit
;;**************************************
Function Clip(Num)
local Str = B.GetTooltip(Num - 1)
clip.set(Str)

Comments

I have 74 button bars, some local ones, many obsolete, auxiliary and draft bars. Total number of buttons counts 1581. So, the problem to find the specific button becomes complicated. But I have to do this very often - at accomplishing some work I use temporarily one (or two) buttons. When the work is done, these buttons are deleted.

The script presented allows to find any button with some mouse clicks, and put its image to the clipboard. Only thing that is needed - position the mouse cursor over the free space on main (default) bar, press right mouse button and select "Paste". The same buttonbar image can be posted to the forum.

Paths to panels are in the configuration file. Sections and keys can be edited, added and deleted. Path to all main bars is supposed to be %COMMANDER_PATH%. Value of the Height key must be found according to the font size and screen resolution: the more height, the more menu lines on the screen.

Auxiliary function of script is a report about all button bars and number of buttons in them. To generate this report, execute the script with the "1" parameter, or just hold the Ctrl key at its start.


Main Page Total Commander PowerPro