DetectColorFilter

Title DetectColorFilter
File Name DetectColorFilter.txt
Description Determine which color filter(s) is/are used for the current file/directory
Author Vochomurka
Parameters ("%P", "%N")
Plugins Called win, childwin, ini, tc, osd, vec, clip, file
Icon
Version 2.0
Updated on 08.06.2009
args Path, Obj
local hwnd = win.handle("c=TTOTAL_CMD")
local Config = "path\wincmd.ini"
local ColorKeys = ini.enum_keys(Config, "Colors")
local Counter = line(ColorKeys, 0)
local Panel = ifelse(tc.active(hwnd) == "left", 8, 7)
local TMLB = childwin.handle(hwnd, "TMyListBox", Panel)
local i, j, OneKey, Str

v = vec.create(0, 1)
if(not v) do
	messagebox("ok error", "Vector not created", "VEC plugin error #1")
	quit
endif 

for(i = 1; i <= Counter; i++)
	OneKey = line(ColorKeys, i)
	if(index(OneKey, "ColorFilter") != 0 && revindex(OneKey, "Color") == 1) do
		OneKey = ini.get(Config, "Colors", OneKey)
		vec.insert(v, vec.length(v), OneKey)
	endif
endfor

Counter = vec.length(v)
if(not Counter) do
	Str = "No color filter is specified in configuration"
	messagebox("ok warning", Str, "DetectColorFilter Script")
	vec.destroy(v)
	quit
endif

w = vec.create(0, 1)
if(not w) do
	messagebox("ok error", "Vector not created", "VEC plugin error #2")
	quit
endif 

win.sendmessage(hwnd, 0x400+51, 524, 0)
ColorKeys = clip.get

if(file.isfolder(Path ++ Obj)) do
	Obj ++= "\"
	flag set 1
else
	flag clear 1
endif

for(i = 0; i < Counter; i++)
	osd.show(i + 1 ++ " / " ++ Counter, "INFINITE", "30", "Arial", "-1", "255 000 000") 
	for(win.class(win.getfocus()) != "TMyListBox")
	endfor
	win.postmessage(hwnd, 0x400+51, 521, 0)
	for(win.class(win.getfocus()) == "TMyListBox")
	endfor
	OneKey = win.getfocus()
	for(win.class(OneKey) != "Edit")
		OneKey = win.getfocus()
	endfor
	win.settext(OneKey, v[i])
	keys {enter}
	for(win.class(OneKey) == "Edit")
		OneKey = win.getfocus()
	endfor
	OneKey = win.getfocus()
	win.sendmessage(OneKey, 245, 0, 0)
	for(win.class(win.getfocus()) == "Button")
		win.sendmessage(win.getfocus(), 245, 0, 0)
	endfor
	OneKey = win.sendmessage(TMLB, 0x0190, 0, 0)
	if(OneKey) do
		clip.clear
		win.postmessage(hwnd, 0x400+51, 2017, 0)
		wait.for(clip.get)
		Str = clip.get
		for(j = 1; j <= OneKey; j++)
			if(line(Str, j) == Obj) do
				Panel = ini.get(Config, "Colors", "ColorFilter" ++ i + 1)
				vec.insert(w, 0, Panel)
			endif
		endfor
		win.postmessage(hwnd, 0x400+51, 524, 0)
	endif
endfor

osd.hide()
clip.set(ColorKeys)

Panel = vec.length(w)
if(not Panel) do
	Str = "Are you really sure the file/directory " ++ Obj ++ " is colored?"
	messagebox("ok warning", Str, "No appropriate color filter found")
	vec.destroy(v)
	vec.destroy(w)
	quit
endif

OneKey = Panel ++ " color filters found for "
OneKey = OneKey ++ ifelse(pproflag(1), "directory ", "file ") ++ Obj
Str = ""

for(i = Panel - 1; i >= 0; i--)
	for(j = 1; j <= Counter; j++)
		if(v[j - 1] == w[i]) do
			Str = Str ++ "Color filter #" ++ j ++ ": "
			Str = Str ++ remove(w[i], 1) ++ esc(?+\n+, ?+\+)
		endif
	endfor
endfor

messagebox("ok information", Str, OneKey)
vec.destroy(v)
vec.destroy(w)

Comments:

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

This script for Total Commander 7.0 and older.

One of ways to distinguish files/directories is to preset a so-called color filter (Configuration\Color\Define colors by file type). Such filter can be very complex basing on name, extension, date, content plugin data, etc. Unfortunately, Total Commander does not allow to learn the color filter name(s) for specific file. It could be a problem especially if there are many color filters. Moreover, a single file can meet criteria of some filters at once. In this case the filter priority matters.

Place the cursor on the file/directory of interest and run the script. If in the current panel there was some selection, it will be lost. It would be a good idea not to switch to other applications until any dialog box is displayed. All color filters applicable for the current file will be listed with their priorities.


All Scripts Total Commander TotalCmd.net PowerPro