Lister Extension

I would not use traditional outline of the script presentation: description, code, comments. First, there are three scripts partially collaborating. Second, some of the scripts' functions require the PowerPro configuration setup.


1. Foreword: Batch File Viewing

For those who don't know: after selecting some files and pressing a specific hotkey (Shift+F3 by default) you can open Lister in "batch" mode, navigating forward with "n" (next) key, and backward with "p" (previous) key.

This function is a perfect one of Lister, but when the number of files viewed is great, their treatment becomes troublesome.

For example, to delete the file currently loaded in Lister, we should do the following:

Are there any problems? Yes, there are. Here are some of them:

Presented scripts and configuration setup are devoted to solve at least some of the probems described.


2. PowerPro Configuration: Keys and Window Classes

All windows you see on the screen (and even those you don't see) have so-called classes. For example, class of the Total Commander file panel is TMyListBox, class of the Lister window is TLister. It's the class that I shall concentrate upon.

PowerPro can assign specific operations to specific keys in specific windows. At describing the Local Menu script I mentioned that this menu is convenient to be invoked by the F2 key. To reach this, I changed the PowerPro configuration. As a result, local menu is dispayed only if: 1) file _local.bar exists in the current directory or its (grand)parent; 2) class of active window is TTOTAL_CMD (Total Commander window class). For example, F2 key is used in file comment window to save comment. In spite of the _local.bar presence, the window class is TMemo, that is, the second condition is not met. Therefore, F2 leads to saving comment rather than to invoking the local menu.

The same logics can be used at the Lister extension. My scripts would work only if: 1) the described key is pressed; 2) current window belongs to the TLister class. So as to change the PowerPro configuration:

Window that appears looks like that on the screenshot:
  1. In the "Key/Mouse" list pick insert;
  2. In the "Blank..." field type c=TLister;
  3. In the "Enter command..." list pick *Script;
  4. In the "Script action" list pick RunFile;
  5. In the "Enter file name..." type
    D:\Utils\PowerPro\scripts\XLister=ins
    

    where D:\Utils\PowerPro\ is the PowerPro installation path, XLister - name of the XLister script (see below). Extension is not specified!

    String ins is passed to the script. Note the equality char (=) between the script name and the string!

Sence of filling dialog box fields is as follows:

  1. At pressing key insert,
  2. if the class (c) of active window is (=) Lister's class (TLister), then
  3. run *Script,
  4. from the file (RunFile),
  5. located in directory D:\Utils\PowerPro\scripts\ and named XLister, and pass the value equal (=) to ins.

Other keys are assigned as the table shows:

 "Key/Mouse" field   Value 
delete del
insert ins
g Green
y Yellow
r Red
k copy
o open
t name
z comment

Other fields must be the same as in the example (or on the screenshot). Use the "Clone" button and change these two fields only.

Some Lister plugins allow not only to view, but also to edit files. In this case letter keys can cause problems. If you use such plugins, it could be handy to check one (for instance, "Ctrl") or more checkboxes (see top line of the screenshot above). For example, after checking "Ctrl" and other things being equal, you'll have to press "Ctrl+G" rather than "G".


3. XLister script

Title XLister
File Name XLister.txt
Description Handle keys pressed in Lister
Author Vochomurka
Parameters -
Plugins Called win, childwin, file, clip
Icon -
Version 2.1
Updated on 16.06.2014

local Hand = win.handle("c=TLister")
local Text = childwin.gettext(Hand)
local From = index(Text, "[")
local To = index(Text, "]")
local Name = select(Text, From + 1, To - 1)
local i, State

if(not validpath(Name))
	quit

if(x9 == "del") do
	file.delete(Name)
elseif(x9 == "ins") do
	for(i = 0; i < Counter; i++)
		if(index(Name, v[i])) do
			State = win.sendmessage(TMLB, 0x0185, 0, i)
			if(State == -1) do
				messagebox("ok error", "Sending message failed", "XLister Script")
				quit
			else
				break
			endif
		endif
	endfor
elseif(x9 == "Green" || x9 == "Yellow" || x9 == "Red") do
	Text = scriptfolder ++ "\FileLists\" ++ x9 ++ ".tfl"
	State = file.open(Text, "a")
	if(State <= 0) do
		messagebox("ok error", "File not opened", "FILE plugin error")
		quit
	endif

	file.writeline(State, Name)
	file.close(State)
elseif(x9 == "copy") do
	clip.set(Name)
elseif(x9 == "name") do
	messagebox("ok", file.nametype(Name), "XLister script")
elseif(x9 == "open") do
	file.doverb(Name, "open")
elseif(x9 == "comment") do
	local Path = file.folder(Name) ++ "\"
	State = file.nametype(Name)
;Sub_Descript_ion - name of script Sub_Descript_ion;
	From = runfile.Subs\Sub_Descript_ion(Path, State, "", "g")
	if(From == "ERROR: no comment file") do
		Text = input("Input comment for file " ++ Name)
	else
		Text = inputdefault(From, "Current comment: " ++ From)
		if(not Text)
			Text = From
					
	endif
	runfile.Subs\Sub_Descript_ion(Path, State, Text, "s")
endif

Comments:

The Xlister script should not be used as a usual script by its direct execution! Button or hotkey is neither used to run it! This script is executed automatically and implicitly if: 1) the key described in the PowerPro configuration is pressed, and 2) active window has the TLister class.

Explicit script execution is useless and can cause unpredictable results!

Path to the script must correspond to that in the PowerPro configuration (D:\Utils\PowerPro\scripts\ in the above example).

Subdirectory d:\Utils\PowerPro\scripts\FileLists\ must be created by user before the script execution (see comment in the script code).


3. ABLV script

Title Advanced Batch Lister View
File Name (*.txt) ABLV.txt
Description Create the list of files selected and start their batch viewing
Author Vochomurka
Parameter ("%L")
Plugins Called win, childwin, file, tc, vec, ini
Icon
Version 3.0
Updated on 16.06.2014
args List
local hwnd = win.handle("c=TTOTAL_CMD")
local Panel = ifelse(tc.active(hwnd) == "left", 8, 7)
;;If wincmd.ini is not in Windows directory, indicate its path implicitly: 
local Config = env("WINDIR") ++ "\wincmd.ini"
local Str, i, Hand, Tabs, j, Ind, Temp, Buttons
global TMLB = childwin.handle(hwnd, "TMyListBox", Panel)
global Counter = win.sendmessage(TMLB, 0x0190, 0, 0)
local Total = win.sendmessage(TMLB, 0x018B, 0, 0)

if(not Counter) do
	messagebox("ok error", "At least two files must be selected", "ABLV Script")
	quit
endif

if(Counter != Total) do
	Panel = ifelse(Panel == 8, 12, 19)
	Tabs = childwin.handle(hwnd, Panel)
	i = win.sendmessage(Tabs, 4868, 0, 0)
	win.postmessage(hwnd, 0x400+51, 501, 0)
	wait.for(1500, activewindow("c=TFindFile"))
	*keys {del}
	Hand = win.handle("c=TFindFile")
	Str = win.childhandlelist(Hand, "c=TButton")
	static v = vec.createfromwords(Str)

	if(v <= 0) do
		messagebox("ok error", "Failure creating vector", "VEC plugin Error #2")
		quit
	endif

	Buttons = v.length
	Str = .ABLV@TL(0)
	for(j = 1; j < Buttons; j++)
		if(win.parent(v[j]) != Hand)
			continue

		Temp = .ABLV@TL(j)
		if(Temp < Str) do
			Str = Temp
			Ind = j
		endif

	endfor
	Str = v[Ind]
	win.sendmessage(Str, 0x00F5, 0, 0)

	for(not win.gettext(win.childhandlelist(Hand, "c=TMyPanel")))
	endfor

	Str = .ABLV@BL(0)
	Ind = 0

	for(j = 1; j < Buttons; j++)
		Temp = .ABLV@BL(j)
		if(Temp > Str) do
			Str = Temp
			Ind = j
		endif

	endfor
	Str = v[Ind]
	win.sendmessage(Str, 0x00F5, 0, 0)
	wait.for(1000, i != win.sendmessage(Tabs, 4868, 0, 0))
	win.sendmessage(hwnd, 0x400+51, 523, 0)
endif


Panel = file.readall(List)
v = vec.createfromlines(Panel)

Str = ini.get(Config, "Configuration", "Viewertype")

if(Str == "1") do
	keys {F3}
else
	keys +{F3}
endif
quit
;;************************************** 
Function TL(i)
quit(float.divide(win.top(v[i]), win.right(v[i])))
;;************************************** 
Function BL(i)
quit(float.mul(win.top(v[i]), win.right(v[i])))

Comments:

Attention! This script does not work in Total Commander 7.5 pb1 and pb2!

This script for Total Commander 7.0 and older.

Before running this script you should select files as you do before usual batch viewing. If nothing is selected, the error message will be displayed.

Files can be selected either in a usual file panel or in the listbox panel created after file search by pressing "Feed to listbox". If quantity of files selected is great, you should wait some seconds for the Lister window to appear. If there are a few files, the window opens immediately.

If directories are also selected, files in them are included in the list.

So, what are the new opportunities afforded by the ABLV script?

Delete current file. To delete the currently viewed file from disk, just press Del. If you have done this mistakenly, re-save the file through the Lister menu. To delete the file you should not care about where it is located, what its name is, etc.

Copy file name. Pressing "k" you put the full file name to the clipboard.

Open current file. To learn what it means, execute the cm_Associate command (File\Associate with...) for the current file (or another file with the same extension). Or just double-click the file - it will open the associated application with the file loaded. Pressing the "o" will also open the currently viewed file in the associated application.

Display current file name. I use this key, for example, when playing some mp3 files with long paths that do not fit into the small window caption.

File comment. To edit the current file description, you don't need to switch to Total Commander file panels, you can press Z (or usual Ctrl+Z, if you have checked Ctrl in the PowerPro settings window), and you can edit the file comment, if any, or add a new comment otherwise.

Important! All functions described above work both in batch and in single file viewing!

If several Lister windows are open, all their classes are TLister. Do we care about which of files will be deleted or opened? No, we don't but PowerPro does. When you press the Del key, PowerPro deletes exactly the file you are looking at. The same is valid for the "k", "t" and "o" keys.

Unselect current file. Before any batch view is loaded, the group of files must be selected. In other words, the file is always in the "selected" state while viewed in batch mode. The script allows to unselect the file in view exactly the same way as in a file panel - by the Ins key. It's very convenient if you want, for example, to copy some of the files viewed, then you can distinghush them from files that are not supposed to be copied. Without switching to Total Commander, finding the current file in the list, unselectiong it, and then switching back to Lister, you just press Ins, and that's enough to unselect it. After the list is viewed, you can reverse the selection by pressing the grey asterisk key. The group so composed can be copied, deleted, archived, etc.

Make group lists. In the first chapter I gave the example of necessity to select some file group rather than one. These (say, five) groups are destined to be:

  1. Copied to directory XXX;
  2. Copied to directory YYY;
  3. Moved to directory ZZZ;
  4. Deleted;
  5. Archived.

How to do this without the script? Look through the whole list five times, switching to file panels for each file from the same group, unselect it, and then, after the group is ready, perform the required operation... It's an extraordinarily boring job!

The ABLV script allows to make three named groups without switching from the Lister window at all. First three groups described above are assigned to traffic light colors - red, yellow, and green. So as to add the current file to any of these groups, you should press the "r", "y", or "g" keys, respectively. Further, fourth group would not be made explicitly - to delete the current file, you just press Del. Finally, last group would be made by unselecting the current file from the list with the Ins key. Again, you don't care how many files are in each group, where they are located, what their names are, etc. Browsing files with usual "n" and "p" keys, you take decision about the file you are viewing right now: what would you like to do with it? There is no need to switch to Total Commander.

Moreover, if your computer hangs, the "colored" groups already made would not be corrupted because the file name is written to disk immediately after pressing "r", "y", or "g" keys, and the list file is then closed.

These list files are named Green.tfl, Yellow.tfl and Red.tfl, and located in the \scripts\FileLists\ subdirectory of the PowerPro path. How these lists can be used?

First, they are ready to be called with the cm_LoadSelectionFromFile command. Second, they can be used as simple lists of certain files, for example, those containing some specific data - in this case do not forget to rename or copy them to another location. But more flexible way is presented by the TreatFileList script.


4. TreatFileList script

Title TreatFileList
File Name (*.txt) TreatFileList.txt
Description Copy, move, or delete files from list
Author Vochomurka
Parameters ("%P", "%T")
Plugins Called file
Icon
Version 1.0
Updated on 23.01.2006
args Source, Target
local Result, List, What, Dest, Clear
local Cap = "Source: " ++ Source ++ ", Target: " ++ Target ++ "'"

Result = Inputdialog("~List=List??Green|Yellow|Red, What=Operation with Files from List??Copy|Move|Delete, Dest=Destination Path (for 'Copy' && 'Move' operations)??Source folder|Target folder, Clear=Clear List File after Treatment Finished??", Cap)

if(Result == 0)
	quit

if(List == "") do
	messagebox("ok error", "List file is not specified", "TreatFileList Script")
	quit
endif

if(What == "") do
	messagebox("ok error", "Operation is not specified", "TreatFileList Script")
	quit
endif

if(What != "Delete" && Dest == "") do
	Cap = "Destination folder is not specified"
	messagebox("ok error", Cap, "TreatFileList Script")
	quit
endif

if(What != "Delete") do
	if(Dest == "Source folder" && file.validpath(Source) != "1") do
		Cap = "Source path '" ++ Source ++ "' is invalid"
		messagebox("ok error", Cap, "TreatFileList Script")
		quit
	endif
	if(Dest == "Target folder" && file.validpath(Target) != "1") do
		Cap = "Target path '" ++ Target ++ "' is invalid"
		messagebox("ok error", Cap, "TreatFileList Script")
		quit
	endif
endif

Target = ifelse(Dest == "Source folder", Source, Target)
Source = scriptfolder ++ "\FileLists\" ++ List ++ ".tfl"

if(file.validpath(Source) != "1") do
	Cap = "List File '" ++ Source ++ "' does not exist"
	messagebox("ok error", Cap, "TreatFileList Script")
	quit
endif

local fh = file.open(Source, "r")

if(fh > 0) do
	for(not(file.eof(fh))) 
		Result = file.readstring(fh)
		if(Result != 0) do
			if(file.validpath(Result) != 1) do
				Cap = "File " ++ Result ++ " does not exist"
				if(messagebox("okcancel warning", Cap, "TreatFileList Script") == 0)
					quit

			endif

			if(What == "Copy") do
				file.copy(Result, Target)
			elseif(What == "Move") do
				file.move(Result, Target)
			elseif(What == "Delete") do
				file.delete(Result)
			endif
		endif

	endfor
else
	messagebox("ok error", "File not opened", "FILE plugin error")
	quit
endif

file.close(fh)

if(Clear == "1")
	file.delete(Source)

Comments:

If files from some list are to be copied or moved, first you should activate the target path in source or target panel. Then run the script and get the same window as that on the screenshot:

Dialog box caption displays paths in both panels. If they are too long to fit, just extend the window with the mouse.

At the subsequent ABLV script execution the new file names added to lists will be appended, they will not replace old names. This property can be used to compose lists of files chosen by different criteria. Thus, if the current list is not needed to be extended, you should check the "Clear List File after Treatment Finished" checkbox.


5. Conclusion

The described scripts and configuration setup allow to extend sufficiently the Lister capabilities, especially at the batch viewing. Any file loaded in Lister can be included in one of three groups, deleted, and unselected. Moreover, its full name can be easily copied to the clipboard. These new possibilities do not interfere with the standard ones. For example, after running the usual batch Lister mode you can run the script for the same group. Therefore, it's a good idea to always run the ABLV script rather than the convenient batch view. All the keys (like "n" and "p") act as usual, but in addition we have some new keys, and new functions.


Main Page Total Commander PowerPro