EditFileComments

Title EditFileComments
File Name EditFileComments.txt
Description Edit descriptions for group of files
Author Vochomurka
Parameters -
Plugins Called file, win, clip, vec
Icon
Version 4.0
Updated on 15.11.2017
static hwnd = win.handle("c=TTOTAL_CMD")
local ActivePanel = win.sendmessage(hwnd, 0x400+50, 1000, 0)
static Counter = win.sendmessage(hwnd, 0x400+50, 1004 + ActivePanel, 0)
local Current = win.sendmessage(hwnd, 0x400+50, 1006 + ActivePanel, 0)
static Updir = win.sendmessage(hwnd, 0x400+50, 1008 + ActivePanel, 0)
static Slash = "\"
static ENFC = "ERROR: no comment file"
static CurPath = file.folder(win.gettext(win.sendmessage(hwnd, 0x400+50, 8 + ActivePanel, 0))) ++ Slash

if(!Current && Updir) do
;Sub_Descript_ion - name of script Sub_Descript_ion;
	local DirComment = .Subs\Sub_Descript_ion(CurPath, "..", 0, "g")
	if(DirComment == ENFC)
		DirComment = ""

	flag clear 1
else
	if(Counter < 2) do
		win.postmessage(hwnd, 0x400+51, 2700, 0)
		quit
	endif

	flag set 1
	clip.save
	clip.clear
	win.sendmessage(hwnd, 0x400+51, 2018, 0)
	wait.for(clip.get)
	static List = clip.get
	clip.clear
	wait.for(!clip.get)
	clip.load
endif

local RadioButtons = 3
static Active = 3
static Quote = ?+"+
static EFCS = "'EditFileComments' script"
static R = cl.Create("Radio", 1)
local Width = 150
static Off = "e:\Storage\Graphics\Icons\Visual Basic\MISC13.ICO"
static On = "e:\Storage\Graphics\Icons\Visual Basic\MISC14.ICO"
local CS = "@ChangeState"
static T = "Text"
static EndComment = esc(?+\x04+, ?+\+) ++ esc(?+\xC2+, ?+\+)
local i

R.Insert(0)
R.SetLabel(0, ?+*control button center "Close"+)
R.AddLeft(0, "*bar close Radio")

R.Insert(0)
R.SetLabel(0, ?+*control button center "OK"+)
R.AddLeft(0, cb("@OK"))

R.Insert(0)
R.SetLabel(0, ?+*control button autocheckbox "\ is a newline char"+)
R.SetId(0, "Newline")
R.SetHeight(0, 30)

R.Insert(0)
R.SetLabel(0, "Instead")
R.AddLeft(0, cb(CS, 3))

R.Insert(0)
R.SetLabel(0, "After")
R.AddLeft(0, cb(CS, 2))

R.Insert(0)
R.SetLabel(0, "Before")
R.AddLeft(0, cb(CS, 1))
R.SetId(0, "Radio1")

R.Insert(0)
R.SetLabel(0, "*control edit left autohscroll clientedge")
R.SetId(0, T)

if(pproflag(1)) do
	R.Insert(0)
	local Text = "List " ++ Counter ++ " files..."
	R.SetLabel(0, "*control button " ++ Quote ++ Text ++ Quote)
	R.AddLeft(0, cb("@FileList"))
endif

R.SetWidth(0, Width)

static Radio1 = R.GetIdIndex("Radio1")

R.SetProperties("Format=barsize samesize flat vertical border iconsize: 16 topmost 3DFrame No3DColor")

for(i = Radio1; i <= Radio1 + RadioButtons; i++)
	R.SetIcon(i, Off)
	R.SetEnabled(i, 0)
endfor

R.SetIcon(Radio1 + RadioButtons - 1, On)

R.show

win.setfocus(R.GetCtrlHandle(R.GetIdIndex(T)))

if(DirComment)
	R.SetCtrlValue(T, DirComment)

quit
//=================================================
Function ChangeState(Num)
R.SetIcon(Active + Radio1 - 1, Off)
R.SetIcon(Num + Radio1 - 1, On)
Active = Num
R.show
quit
//=================================================
Function OK
local Result, Item, Path, Name
local Str = R.GetCtrlValue(T)
local NewLine = R.GetCtrlValue("NewLine")
local v = vec.createfromwords("b a s")

R.close

if(not Str) do
	Item = "Comment string is empty. Delete old comments?"
	Result = messagebox("yesnocancel question", Item, EFCS)
	if(Result == 7) do
		R.show
	elseif(Result == 0) do
		quit
	endif
endif

if(find(Str, Slash) != -1 && NewLine)
	Str = replacechars(Str, Slash, "\n") ++ EndComment

local Par = ifelse(Result == 6, "d", v[Active - 1])

if(pproflag(1)) do
	for each line Item in List
		Result = file.isfolder(Item)
		Path = file.folder(remove(Item, -1*Result)) ++ Slash
		Name = file.nametype(remove(Item, -1*Result))
		.Subs\Sub_Descript_ion(Path, Name, Str, Par)
	endfor
else
	.Subs\Sub_Descript_ion(CurPath, "..", Str, Par)
endif

wait.for(50)
win.setfocus(hwnd)
win.sendmessage(hwnd, 0x400+51, 540, 0)
quit
//=================================================
Function FileList
local Item, Text, Mess, i, FiF
static TabChar = esc(?+\t+, ?+\+)
static CR = esc(?+\r+, ?+\+)

for(i = 1; i <= Counter; i++)
	Item = line(List, i)
	FiF = file.isfolder(Item)
	Path = file.folder(remove(Item, -1*FiF)) ++ Slash
	Name = file.nametype(remove(Item, -1*FiF))
	Text = .Subs\Sub_Descript_ion(Path, Name, 0, "g")
	Mess ++= i ++ ": " ++ TabChar ++ Item

	if(Text && Text != ENCF)
		Mess ++= CR ++ TabChar ++ "Comment: " ++ TabChar ++ Text

	Mess ++= CR
endfor

Mess = replacechars(Mess, EndComment, "")
Mess = replacechars(Mess, "\n", CR ++ repeat(TabChar, 3))
Mess = remove(Mess, -1)

messagebox("ok information", Mess, EFCS)

quit

Comments:

This script for Total Commander 7.0 and older.

One day it was required to edit descriptions for several files rather than for one. I was amazed to learn that Total Commander doesn't give such opportunity. I think it's an annoying defect, but it can be eliminated by means of PowerPro.

The script is developed in such a way that if there is no group selected, then the cm_EditComment command is executed. Thus, it is a good idea to assign the Ctrl+Z hotkey to the script. If you will never have the necessity to edit many descriptions, you will not learn the difference between running the script and the command. But, if you ever have such need, I will be glad to help you with my script.

So, when some files are selected, the following dialog window appears:

Upper button informs about the total number of files selected (4 on the screenshot). After pressing the button the detailed information about files will be shown.

Type the comment in the edit box below, or leave it empty. In the latter case the comments, if any, for selected files will be deleted after confirmation. In the "Location..." dropdown list you can choose where to put the new comment relative to the old one (if any) – before, after or instead (default).

The "\ is a newline char" flag allows to set multiline comments. If this flag is set, then the backslash character in the comment body is treated as a newline character.

One more function of the script – editing the comment for the whole directory. This comment is displayed in the popup window when hovering the mouse over the updir line (the ".." line on top of the file list). Total Commander does not provide any means to edit this comment. Moreover, this feature is undocumented.

To edit directory comment, place cursor on updir and run the script. Of course, there will be no "List…" button in this dialog box.


Main Page Total Commander PowerPro