MergeBars

Title MergeBars
File Name MergeBars.txt
Description Merge two button bars into one
Author Vochomurka
Parameters "%P%N", "%T%M"
Parameter 1: first bar name
Parameter 2: second bar name
(bars can be exchanged at the script execution)
Plugins Called win, miscplugin, file, osd, ini, vec
Icon
Version 1.3
Updated on 08.09.2006
Scripts Called LoadBar

args First, Second
local mpDlgText, Result, Key, Number, i, Buttons1, Buttons2
local Path = "path_to_TC\"
local Target = Path ++ "_temp.bar"
local Bars = Path ++ "*.bar"
local mpDlgCaption = "Wrong Parameter"
local mpIcon = "WARNING"

if(file.isfolder(First)) do
	mpDlgText = "First bar is " ++ First ++ "\nIt must be a file rather than a folder"
	if(MiscPlugin.MessageBox(2, "&Quit", "&Pick file") == "&Quit")
		quit

	First = pickfile(file.listfiles(Bars, 0), "Pick First Bar File")
	if(not First)
		quit

endif

if(file.type(First) != "bar") do
	mpDlgText = "First bar is " ++ First ++ "\nIt should have the BAR extension."
	if(MiscPlugin.MessageBox(2, "&Continue", "&Pick file") == "&Pick file") do
		First = pickfile(file.listfiles(Bars, 0), "Pick First Bar File")
		if(not First)
			quit

	endif
endif

if(file.isfolder(Second)) do
	mpDlgText = "Second bar is " ++ Second ++ "\nIt must be a file rather than a folder"
	if(MiscPlugin.MessageBox(2, "&Quit", "&Pick file") == "&Quit")
		quit

	Second = pickfile(file.listfiles(Bars, 0), "Pick Second Bar File")
	if(not Second)
		quit

endif

if(file.type(Second) != "bar") do
	mpDlgText = "Second bar is " ++ Second ++ "\It should have the BAR extension."
	if(MiscPlugin.MessageBox(2, "&Continue", "&Pick file") == "&Pick file") do
		Second = pickfile(file.listfiles(Bars, 0), "Pick Second Bar File")
		if(not Second)
			quit

	endif
endif

@start

mpDlgText = "Second bar " ++ Second ++ " will be appended to the First bar " ++ First
mpDlgText = mpDlgText ++ "\n\n(Choose 'Exchange' to exchange First with Second)"
mpDlgCaption = "Merge Bars"
mpIcon = "INFORMATION"
Result = MiscPlugin.MessageBox(1, "&Go!", "E&xchange", "&Cancel")

if(Result == "&Cancel") do
	quit
elseif(Result == "E&xchange") do
	mpDlgText = First
	First = Second
	Second = mpDlgText
	jump start
endif

osd.show("Wait...", "INFINITE", "48", "Arial Cyr", "-1", "255 000 000")

if(not file.copy(First, Target)) do
	mpDlgText = "Failure copying " ++ First ++ " to " ++ Result
	messagebox("ok error", mpDlgText, "FILE plugin error #1")
	quit
endif

Buttons1 = ini.get(First, "Buttonbar", "Buttoncount")
if(ini_status != "OK") do
	messagebox("ok error", ini_status, "INI plugin error #1")
	quit
endif

Buttons2 = ini.get(Second, "Buttonbar", "Buttoncount")
if(ini_status != "OK") do
	messagebox("ok error", ini_status, "INI plugin error #2")
	quit
endif

Result = ini.set(Target, "Buttonbar", "Buttoncount", Buttons1 + Buttons2)
if(Result != "OK") do
	messagebox("ok error", Result, "INI plugin error #3")
	quit
endif

v = vec.createfromwords("button cmd param Bars menu iconic")
if(v == 0) do
	messagebox("ok error", "Failure creating vector", "VEC plugin Error")
	quit
endif

for(i = 1; i <= Buttons2; i++)
	Number = i + Buttons1
	for(j = 0; j <= 5; j++)
		Key = v[j] ++ i
		if(ini.check_exists(Second, "Buttonbar", Key) == 3) do
			mpDlgText = ini.get(Second, "Buttonbar", Key)
			Key = v[j] ++ Number
			Result = ini.set(Target, "Buttonbar", Key, mpDlgText)
			if(Result != "OK") do
				messagebox("ok error", Result, "INI plugin error #5")
				quit
			endif
		endif
	endfor
endfor

vec.destroy(v)
vec.unload
ini.unload
osd.unload

mpDlgText = "First bar " ++ First ++ " and Second bar " ++ Second
mpDlgText = mpDlgText ++ "\nare successfully merged in " ++ Target
mpDlgCaption = "Congratulations!"
mpIcon = "QUESTION"
mpDlgText = mpDlgText
Result = MiscPlugin.MessageBox(1, "&Open Bar", "to &First", "to &Second", "&to...", "&Quit")

if(Result == "&Open Bar") do
;LoadBar - name of script LoadBar
	runfile.LoadBar(Target)
elseif(Result == "to &First") do
	Result = file.move(Target, First)
		if(not Result) do
			mpDlgText = "Failure renaming " ++ Target ++ " to " ++ First
			messagebox("ok error", mpDlgText, "FILE plugin error #2")
			quit
		endif
elseif(Result == "to &Second") do
	Result = file.move(Target, Second)
		if(not Result) do
			mpDlgText = "Failure renaming " ++ Target ++ " to " ++ Second
			messagebox("ok error", mpDlgText, "FILE plugin error #3")
			quit
		endif
elseif(Result == "&to...") do
@NewName
	Key = inputcancel("New name for bar")
	Key = Path ++ Key ++ ".bar"
	if(not file.validpath(Key)) do
		mpDlgText = "File " ++ Key ++ " already exists! Overwrite?"
		if(messagebox("yesno warning", mpDlgText, "Warning") == 7)
			jump NewName

	endif
	if(not file.move(Target, Key)) do
		mpDlgText = "Failure renaming " ++ Target ++ " to " ++ Key
		messagebox("ok error", mpDlgText, "FILE plugin error #4")
		quit
	endif
endif

Comments:

Suppose we have to copy/move a button from one button bar to another.

It should be considered that the "open bar" operation takes at least 5 mouse clicks. So, the whole procedure to copy only one button takes at least 12 right and left clicks. It is not a problem if you need to copy/move one button only. But if you would like to transfer two or more buttons, executing the above procedure can provoke a saint!

There is another way to transfer a button - by editing the *.bar file directly. Perhaps somebody does it. But he/she must be very careful correcting numbers in key names. Any smallest error can have grave consequences.

Script presented merges two button bars yielding one with the _temp.bar name.

Before running the script it is recommended to position cursor in both Total Commander panels on one and another button bar files. But it is not necessary: you can put cursor only on one of button bars or even not care about panels: if the file extension is not bar, then after running the script you could pick both files in dialog boxes.

After the new bar is successfully created, the script proposes the following options:


All Scripts Total Commander TotalCmd.net PowerPro