Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Program to Renumber Toolbar Buttons

Jun
552
4
I maintain the definitions for the buttons in a file. Whenever I add, remove, or change the position of a button in the file, I have to renumber all the buttons. If the numbers are out of order or some are missing, I don't get the toolbar I expect. (I'm not sure why TCMD doesn't do this automatically when reading in the file, but maybe there are cases where one does not want the buttons to be in order with no gaps.)

Today I decided to deal with this and wrote a program in Pascal that processes the file and renumbers all the buttons in order. (Trying to do this in a BTM script seemed to be impossible because of all the special characters in the file.) One can create/edit the file to have lines that that start with just "B=" or "B#=" or "B##=" (# can actually be any character), and the program will renumber them. The program writes its output to a new file, and I use a BTM script to manage testing and renaming.

If anyone is interested, I would be happy to provide the Pascal source code and the EXE file.
 
Re-arranging Toolbar Buttons in TCC 11
Code:
USAGE: BTNSORT.BTM filewithbuttonstosort

Step 1: TCTOOLBAR /w e:\utils\unsorted.ini

Step 2: NOTEPAD unsorted.ini

Step 3: Change the order of the buttons as desired

Step 4: Save the unsorted.ini file, then exit NOTEPAD

BTNSORT unsorted.ini

If all goes well, sorted.ini will be created, with all of your buttons in proper order.

To reset your toolbar with the new arrangement;

TCTOOLBAR /c
TCTOOLBAR /r e:\utils\sorted.ini

Joe
 
Have you tried the @INIREAD and @INIWRITE functions?
Code:
do i=1 to 10 (echo B%i = "%@iniread[c:\tc28\tcmd.ini,Toolbar1,B%i]")
B1 = "1792,32,c:\windows\system32\mspaint.exe,Paint,,,,mspaint.exe"
B2 = "1796,32,C:\Program Files (x86)\XVI32\XVI32.exe,XVI32,,,,"C:\Program Files (x86)\XVI32\XVI32.exe""
B3 = "1540,32,C:\TC27\HxD.exe,HxD,,,,"C:\TC27\HxD.exe""
B4 = "1540,32,C:\Program Files\Docker Toolbox\docker-quickstart-terminal.ico,ICE3 Dev,,S:\LNX\Platform,,"C:\Program Files\Git\bin\bash.exe" --lo
gin -i C:\TC26\startdocker.sh"
B5 = "1540,32,C:\Program Files\Git\usr\bin\bash.exe,Git Bash,,S:\LNX\Platform,,"C:\Program Files\Git\usr\bin\bash.exe" --login -i"
B6 = "1540,32,C:\Program Files\Docker Toolbox\docker-quickstart-terminal.ico,Docker Quickstart,,"C:\Program Files\Docker Toolbox",Use this to pr
une the docker VM,"C:\Program Files\Git\bin\bash.exe" --login -i "C:\Program Files\Docker Toolbox\start.sh""
B7 = ""
B8 = ""
B9 = ""
B10 = ""

Assuming you use a separate file for the buttons, you could do something as simple as this.
Create a file with your entries without the leading 'B##='.
Then iterate over the contents and update the TCMD.INI file.
Code:
set numbtns=%@lines[mybuttonfile.txt]
do i=1 to %numbtns
  echo %@iniwrite[c:\tc28\tcmd.ini,Toolbar1,B%i,%@line[mybuttonfile.txt,%((i-1))]]
enddo
 
I didn't even know the TCTOOLBAR command existed. You can use that instead of @iniwrite.
Code:
set i=1
tctoolbar /c
do l in @mybuttonfile.txt
  tctoolbar default %i 1, %i, %l
  set /a i+=1
enddo
 
set numbtns=%@lines[mybuttonfile.txt] do i=1 to %numbtns echo %@iniwrite[c:\tc28\tcmd.ini,Toolbar1,B%i,%@line[mybuttonfile.txt,%((i-1))]] enddo

That code is not going to work when the lines contain many special characters: '&' and '%' and maybe '>'. I could not figure out a way with SETDOS /X to both allow the BTM to process the material and not stumble over the special characters.
 
Joe Caverly's script has the same problem. Many of my buttons contain lines of the form

esc "pgm_or_script %%@quote[%_selected]" enter

The button definitions could have multiple commands separated by '&' and possibly even redirection. I could not figure out a way to process those lines using TCC functions while leaving the code intact (and wiped out my toolbar file a couple of times before I noticed the damage). Finally, it occurred to me that this processing could be done trivially using a C or Pascal program. With those languages there is no problem with special characters.

By the way, I have multiple tabs in my toolbar, and my program handles that, renumbering each section.
 
I've done similar work.

My general solution is the same for environment variables, aliases, functions, lib-functions and toolbars.

I generate a frozen state (in this case an ini-file) from source. In your script you are unrestrained in your efforts to make your toolbar as 'auto-discovering' and 'dynamic' as possible. Also, you have a single location for documenting all that fanciness. The chore of renumbering toolbars and toolbar-buttons is eliminated in this way. But above all, you minimize the impact on your startup time. Loading the toolbar at startup becomes (and should always be) a single line.
 
I just rewrite the toolbar as needed. But the toolbar i use is in tcmd 8.01, used for launching other apps relevant to a project.
 
My general solution is the same for environment variables, aliases, functions, lib-functions and toolbars.

I generate a frozen state (in this case an ini-file) from source. In your script you are unrestrained in your efforts to make your toolbar as 'auto-discovering' and 'dynamic' as possible. Also, you have a single location for documenting all that fanciness. The chore of renumbering toolbars and toolbar-buttons is eliminated in this way.
I took it as a given that the toolbar data is stored in a file. (Doesn't everyone load aliases, functions, toolbar, etc. from a file at start-up?)

I don't see from what you wrote how renumbering the buttons is eliminated. If I edit the toolbar-defining file (tctoolbar.txt in my case) to exchange two buttons, for example, they have to be renumbered.

Here is the beginning of Toolbar1 in my file.

Code:
[Toolbar1]
Title=Main
B1=257,,RUN,,,"%%@quote[%_selected]" enter
B2=257,,PATH,,,esc "dp %%@quote[%_selected]" enter
B3=257,,CD/UP,,,esc "cd_clip %%@quote[%_selected]" enter
B4=257,,PASTE,,,"%%@quote[%_selected] "
B5=261,,DESC,,,esc "desc %%@quote[%_selected]" enter
B6=257,,EREN,,,esc "eren %%@quote[%_selected]" enter
B7=257,,REN,,,esc "batrun button_ren %%@quote[%_selected]" enter
B8=257,,MOVE,,,esc "batrun button_move %_selected" enter
B9=261,,ED,,,esc "edit %%@quote[%_selected]" enter

If I want to move the PASTE button to position 2 after RUN, the following will not work:

Code:
[Toolbar1]
Title=Main
B1=257,,RUN,,,"%%@quote[%_selected]" enter
B4=257,,PASTE,,,"%%@quote[%_selected] "
B2=257,,PATH,,,esc "dp %%@quote[%_selected]" enter
B3=257,,CD/UP,,,esc "cd_clip %%@quote[%_selected]" enter
B5=261,,DESC,,,esc "desc %%@quote[%_selected]" enter
B6=257,,EREN,,,esc "eren %%@quote[%_selected]" enter
B7=257,,REN,,,esc "batrun button_ren %%@quote[%_selected]" enter
B8=257,,MOVE,,,esc "batrun button_move %_selected" enter
B9=261,,ED,,,esc "edit %%@quote[%_selected]" enter

The buttons have to be renumbered. The same applies if I want to insert a new button.

All of my toolbars start with the same set of basic buttons, so I'm considering extending my renumbering program to allow subroutine references (e.g, "@tbsubs.txt) in the master file to automatically insert the standard set of buttons from the file before renumbering all the toolbars. Right now, if I wanted to make the changes above, I would have to manually edit all seven of my toolbars. Of course, I don't make such changes all that often. Manually renumbering the buttons is more of a nuisance and error-prone.
 
Hi Jay!

There are two ways you can setup e.g. your lists and toolbar definitions: you can run a script that has "ALIAS MyAlias=... " statements in them *or* you execute a script that produces a file that has bare lines in them with the expanded definitions like MyAlias=... i.e. without the ALIAS statements. At startup you can execute the first file - dynamically creating all your definitions - or replace all of that in your TCStart with one line of code: ALIAS /R MyAliases.SAVED The same principle applies to all "lists": environment, aliases, functions, lib-funcs, toolbars and even command- and dir-history lists if you like.

There are many aspects of this method that make it superior to other methods. The most obvious one being speed. Second, you keep all the advantages of a sourcefile. The sometimes lengthy definitions are much more compact and understandable when reviewed from source because you have comments and step-by-step expansion, reuse etc. Of course that slows things down a bit, but that's not relevant since you only incidentally run that script (ones after each change) whereas the startup reuses the 'frozen state' (those '*.SAVED' files) time and again.

In the case of your toolbars frozen state takes the shape of ini-files. You write a batch that writes the toolbar definitions. In it, you're free to do whatever you like, e.g. write a subroutine for 'the same set of buttons' all your toolbars start with. Of course you use a variable as a counter for your buttons. If you want to rearrange your buttons you rearrange your definitions and the numbering is adjusted automatically.

I will attach an example of my source for generating toolbars. It will give you an impression, at least. You cannot execute it as is because it uses some a module that defines some fancy auto-incrementing envars but you can easily work around that.
 
In the case of your toolbars frozen state takes the shape of ini-files. You write a batch that writes the toolbar definitions. In it, you're free to do whatever you like, e.g. write a subroutine for 'the same set of buttons' all your toolbars start with. Of course you use a variable as a counter for your buttons. If you want to rearrange your buttons you rearrange your definitions and the numbering is adjusted automatically.

Just as with aliases, functions, environment variables, and command and directory history, I use the "/r" option of the TCTOOLBAR command to load my toolbar definitions. When the file that is loaded is edited, the buttons need to be numbered correctly. Since I write the definitions in the order that I want the buttons to appear on the toolbars, this means that each toolbar set has to be renumbered whenever new buttons are added or buttons are swapped. Hence the program I wrote.
 
Just as with aliases, functions, environment variables, and command and directory history, I use the "/r" option of the TCTOOLBAR command to load my toolbar definitions. When the file that is loaded is edited, the buttons need to be numbered correctly. Since I write the definitions in the order that I want the buttons to appear on the toolbars, this means that each toolbar set has to be renumbered whenever new buttons are added or buttons are swapped. Hence the program I wrote.

If it does what you want, it's a good solution. Nothing wrong with Pascal if it solves the problem at hand.
 
Back
Top