Splitting of parameter %L%a results?

Here you can propose new features, make suggestions etc.

Moderators: white, Hacker, petermad, Stefan2

sirksel
Junior Member
Junior Member
Posts: 71
Joined: 2013-04-24, 10:24 UTC

Splitting of parameter %L%a results?

Post by *sirksel »

I understand that %L%a appends the selected target files to the file list created by %L which would ordinarily just contain the source files. I read that this is because you can have only one list file present per command.

Do any of you have a best practice or batch file text or what not to unambiguously re-split the file list between source and target files? Originally, I was thinking I would just parse by line, and look for different initial characters to indicate a change in path. It appears that that would have complications. For example, I'm noticing that when there's nothing selected on the source file side, it just begins with the target list. I guess that's to be expected. (I should also note that I'm currently using the %Y parameter to pass a blank list file when nothing is selected.)

Also, I'm not sure how this would work if a source or target side contained search results or a zip file or what not, but I haven't tested that yet. This complication is less important to me than just getting it to work with a standard file pane.

I just wanted to be sure I wasn't missing a command switch or some undocumented feature, before I write some parsing batch file. Also, I figured this must have been done before, so maybe one of you has a solution you're already using for this? Many thanks for the help!
Fla$her
Power Member
Power Member
Posts: 2390
Joined: 2020-01-18, 04:03 UTC

Re: Splitting of parameter %L%a results?

Post by *Fla$her »

%a was entered only because of the synchronization tool, and there are separate lists only for output to the command line: %P%S and %T%R.
A batch file for splitting will not help. You need something more serious like AHK, AutoIt, etc. It's not so difficult there. It's enough to get the number of selected list items in the active panel to find out which element to count from for the target panel. If necessary, I can demonstrate.

I've been wanting TC to support lists for both panels at the same time for a long time.
Overquoting is evil! πŸ‘Ž
sirksel
Junior Member
Junior Member
Posts: 71
Joined: 2013-04-24, 10:24 UTC

Re: Splitting of parameter %L%a results?

Post by *sirksel »

2Fla$her

Thank you. Yes, I was going to try it in AHKv2. I just figured there must be a way with switches in TC that I was missing. In 10+ years using TC, I can't believe I've never attempted writing something that required full lists from both panels. I'm sure I thought of it 100 times but just never had time to write them! :)

You are so nice to offer to help with a demonstration. I don't need all the code, as I can probably write most of it. If you can just give me the line or TC param that detects the number of items selected in the source panel. I was going to try to look for changes in directory names, but your way is much better. Can you give me a hint? Many thanks!
sirksel
Junior Member
Junior Member
Posts: 71
Joined: 2013-04-24, 10:24 UTC

Re: Splitting of parameter %L%a results?

Post by *sirksel »

Mr. Ghisler,

As I'm trying to write this code referenced above to split the source/target file list, I'm noticing an easy change that could be made (I think?) to make it so this could be handled in a batch file alone. I know a lot of folks have asked for the ability to send separate source and target file lists. That would be great, but there are probably reasons you haven't adopted it, including the time it would take to do make such a change. But as a stopgap, would it be hard to simply include a blank line between the two lists if %L%a is specified?

Unless I'm thinking about it wrong, it seems like this wouldn't even be a breaking change for people's scripts because FOR %%G and the like would just ignore the blank line and continue iteration, correct? So if one wanted source/target lists separately, one could just search for the blank line and break the file there, and then run two separate FOR %%G loops.

As an implementation detail, if only the target had selected files, and the source did not, Line 1 of the file would be blank. If only the source had files, and the target did not, the file would end with an extra linefeed. If neither had a selection, the file would contain exactly one blank line.

What do you think? Do others think this would be a good stopgap, or would this mess up existing scripts people are running? Many thanks!
Fla$her
Power Member
Power Member
Posts: 2390
Joined: 2020-01-18, 04:03 UTC

Re: Splitting of parameter %L%a results?

Post by *Fla$her »

sirksel wrote: ↑2024-05-25, 23:50 UTC Can you give me a hint? Many thanks!
I am writing in AHK 1.1, so I can give the code in it. But there is a problem. I found a bug:
if there is no mark in the target panel, then the list item under the cursor in it is not written to a temp file.

Code: Select all

;β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
; Splitting the list of active and target panel items
; Parameter: %a%WF ( or any equivalent of %a%.. )
;β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”β€”
#NoEnv
#NoTrayIcon
ListLines, Off
SetBatchLines,-1

If !%0%
   ExitApp

List = %1%

SendMessage, 1074, 1000, 0,, A
Act = % ErrorLevel
Trg := Act = 1?2:1

; The number of selected items in the active panel
aSelCount := GetSelItemsCount(Act)

; The number of selected items in the target panel
tSelCount := GetSelItemsCount(Trg)

FileRead, Text, % List

; Getting lists with a limit of 65536 selected items in one panel:
ActList = % StrSplit(RegExReplace(Text, "(\V+\R){" . aSelCount . "}\K.+"), "`r`n`r`n")[1]
TrgList = % RegExReplace(Text, "^(\V+\R){" . aSelCount . "}")
MsgBox, 262208, % " Selected items in active panel", % ActList
MsgBox, 262208, % " Selected items in target panel", % TrgList

ArrList := StrSplit(Text, "`r`n")

; Listing the active panel list items
Loop
   MsgBox, 262208, % " Listing the active panel list items", % A_Index . ". " . ArrList[A_Index]
Until A_Index = aSelCount

; Listing the target panel list items
Loop
   MsgBox, 262208, % " Listing the target panel list items", % A_Index . ". " . ArrList[A_Index + aSelCount]
Until A_Index = tSelCount

GetSelItemsCount(pNum) {
   SendMessage, 1074, 1004+pNum, 0,, A
   SelCount := % ErrorLevel
   If Not SelCount {
      SendMessage, 1074, 1008+pNum, 0,, A
      If ErrorLevel {
         SendMessage, 1074, 1006+pNum, 0,, A
         SelCount := % ErrorLevel > 0 ? 1 : 0
      } Else
         SelCount = 1
   }
   Return % SelCount
}
Overquoting is evil! πŸ‘Ž
sirksel
Junior Member
Junior Member
Posts: 71
Joined: 2013-04-24, 10:24 UTC

Re: Splitting of parameter %L%a results?

Post by *sirksel »

2Fla$her

Thank you SOOO much for the code. You didn't have to do all that. Very kind of you. I'm re-writing in v2 now to put in my library. I'll post what I come up with here too, in case there are others who read this who end up needing v2. A few quick questions:

1. How did you know the correct message numbers (e.g., 1074) and the right wParams (e.g., 1000, 1004+x, 1006+x, 1008+x)? Is there a reference somewhere? I'd like to find others.

2. For example, from another application, I currently get the current source and target dirs of the running TC instance by switching to the TC window, sending keys to copy the source/target dirs, reading the clipboard, and then switching back to the other window. Is there a way to get the current source/target dirs with SendMessage? That would be amazing! And much more efficient...

3. I'm also trying to replicate the bug you mentioned. To replicate, I understand the target must have no selection. Then, in the source panel, is the file not written (that should be) the one that is selected/marked, but is also under the cursor? Can you see it when you look at the temp file itself, before the AHK processing, or is this an issue with the way the SendMessage works? I was watching just the temp file written and I'm having trouble replicating the issue. I figured I just wasn't doing something right.

Thanks so much for the help. You are the best!
Fla$her
Power Member
Power Member
Posts: 2390
Joined: 2020-01-18, 04:03 UTC

Re: Splitting of parameter %L%a results?

Post by *Fla$her »

2sirksel
1. See here and here WM_USER+50/51.
2. More efficient than %P and %T? Look here for examples with SP and TP.
You can also get headers (but it's not suitable for the target panel with a quick view):

Code: Select all

#NoTrayIcon
SendMessage 1074, 1000, 0,, A
Act := ErrorLevel
Trg := Act = 1?2:1
MsgBox % GetPath(Act) "`n" GetPath(Trg)

GetPath(i) {
   SendMessage 1074, i + 8, 0,, A
   ControlGetText Value,, % "ahk_id " ErrorLevel
   Return RegExReplace(Value, "\\[^\\]+$")
}
3. Deselect using Ctrl+Num- from both panels and place the cursor in them below [..]. Then click the button:

Code: Select all

TOTALCMD#BAR#DATA
%comspec% /q/u/c type
%a%WL>flist.txt
wcmicon2.dll,67
Create a list of selected items

1
After that, flist.txt should appear with only one path instead of two.

You're welcome. )
Overquoting is evil! πŸ‘Ž
sirksel
Junior Member
Junior Member
Posts: 71
Joined: 2013-04-24, 10:24 UTC

Re: Splitting of parameter %L%a results?

Post by *sirksel »

2Fla$her
Thanks so much. I'm working on incorporating your excellent suggestions into my AHK v2 code. Will report back soon.

In the meantime, I'm noticing maybe another bug. For me, even querying 1005 with SendMessage (when another window is active, using "ahk_class TTOTAL_CMD" instead of "A") actually clears the source selection, as an apparent side effect. The target selection remains selected but the source selection becomes unhighlighted as soon as I return to the TC window. The selection count still reports right on the call, and actually, it will report right on multiple calls as long as I don't switch back to the TC window as active. As soon as I do, the source selection is cleared!

Is this happening for you too? It seems like a different bug than the one you were talking about, right? Is the proper etiquette that I should post a separate bug report in the "bugs" forum for this bug or does this topic get moved there?
Fla$her
Power Member
Power Member
Posts: 2390
Joined: 2020-01-18, 04:03 UTC

Re: Splitting of parameter %L%a results?

Post by *Fla$her »

sirksel wrote: ↑2024-05-27, 12:57 UTC I'm noticing maybe another bug.
For such situations, it's necessary to use DetectHiddenWindows On.
sirksel wrote: ↑2024-05-27, 12:57 UTC It seems like a different bug than the one you were talking about, right? Is the proper etiquette that I should ...
... test the proposed button and report the result.
Overquoting is evil! πŸ‘Ž
sirksel
Junior Member
Junior Member
Posts: 71
Joined: 2013-04-24, 10:24 UTC

Re: Splitting of parameter %L%a results?

Post by *sirksel »

2Fla$her

Sorry for my delay. I set this aside because I couldn't get it to work, and I vowed to return to it later. Famous last words...

I'm slightly embarrassed to say that I never use the button bar. I've had it completely disabled for 10+ years, since I use only keyboard. I know some will say I'm crazy because buttons are the best part of TC. I was able to turn the bar back on and was able to add a button, but I'm not sure where in the dialog or vertical.bar file this text is supposed to go. Right now it just contains lines like button1=, cmd1=, iconic1=. I'm going through the forums now to try to re-learn the custom button bar mechanics so I can test the button you suggested.

Also, to make matters worse, I have every keystroke remapped as well. :) So when I get forum tips that are specific keystrokes, I always need to go unbind these keys to see what they originally did. I'm working on this too. I really should keep a separate portable TC installation without any remaps just for testing stuff like this.

Anyhow, the only part of this I've solved for sure was that my "additional bug" of the source selection disappearing was not really a bug. I had some debug AHK code active that appeared to be writing to a file in the Source directory, and *that* change in the source dir's files is what seemed to be making my source selection disappear. Once I disabled those debug file writes from AHK, the issue went away.

I will continue to work on my study of buttons tonight to see if I can get your button tested. Sorry again for the delay -- and THANK YOU again for all the help!
User avatar
petermad
Power Member
Power Member
Posts: 14914
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Splitting of parameter %L%a results?

Post by *petermad »

2sirksel
but I'm not sure where in the dialog or vertical.bar file this text is supposed to go.
You can copy Fla$her's button here above by simply clicking "SELECT ALL" next to "CODE:" - and then right click on TC's button bar and choose "Paste".

I really should keep a separate portable TC installation without any remaps just for testing stuff like this.
You don't need a separate installation for that just start TC with the parameter /i="%COMMANDER_INI_PATH%\alternative.ini" then TC will start as if you just installed it. You could copy your current wincmd.ini to alternative.ini and just remove the [Shortcuts] and [ShortcutsWin] to have a version of TC, just without the keyboard remappings.

You can use this button to start TC with the alternative.ini file:

Code: Select all

TOTALCMD#BAR#DATA
%COMMANDER_EXE%  /N /P /A /i="%COMMANDER_INI_PATH%\alternative.ini"
%Z%X %P%N* %T%M*
%COMMANDER_EXE%
Open copy of Total Commander with Alternative.ini
To make the button:
1. Mark the text in the box here above (click SELECT ALL).
2. Copy it to the ClipBoard (press Ctrl+C).
3. Right click on TC's buttonbar and choose "Paste".
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
hi5
Power Member
Power Member
Posts: 555
Joined: 2012-11-03, 11:35 UTC
Contact:

Re: Splitting of parameter %L%a results?

Post by *hi5 »

sirksel wrote: ↑2024-06-14, 04:35 UTC... I never use the button bar. I've had it completely disabled for 10+ years, since I use only keyboard.
Which is why I hope to see a general keyboard activation option for the button bar one day - similar to the ribbon menus in some programs - viewtopic.php?p=403188#p403188 how it could look after pressing a "show letters shortcut first" https://github.com/hi5/_resources/blob/master/ButtonBarKeyboard.png
F4MiniMenu (Forum) - Open selected file(s) from TC in defined editor(s) - A (minimalistic) clone of F4Menu
Source at GitHub (AutoHotkey). TCSyncComments (copy file comments)
User avatar
petermad
Power Member
Power Member
Posts: 14914
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: Splitting of parameter %L%a results?

Post by *petermad »

2hi5
Which is why I hope to see a general keyboard activation option for the button bar
You can use Atl+Shift+F11 (cm_FocusButtonBar) to activate the buttonbar, and then use the arrow-keys to go to the button you want to activate.

For the vertical buttonbar it is Atl+Shift+F12 (cm_FocusButtonBarVertical).
License #524 (1994)
Danish Total Commander Translator
TC 11.03 32+64bit on Win XP 32bit & Win 7, 8.1 & 10 (22H2) 64bit, 'Everything' 1.5.0.1371a
TC 3.50 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
sirksel
Junior Member
Junior Member
Posts: 71
Joined: 2013-04-24, 10:24 UTC

Re: Splitting of parameter %L%a results?

Post by *sirksel »

2petermad
Thanks for the help with the button bar. I can't believe I didn't know about that paste context menu on the button bar. Guess I'll have to start using buttons... Also, I really like the alternative.ini approach. I've implemented that by your recipe for future testing. Thanks!

2Fla$her
Yes, I was able to confirm just one path, not two listed. Sorry for the delay.
At first, I thought it was because it was writing to the same directory (which was my issue with the AHK script). However, even after changing the output file to another directory, it made no difference. Thanks again for all the help (in both threads).

2hi5
That's a good idea and a nice graphic you made. However, I'm not sure even the accelerator key would convert me from hotkeys. I'm one of the crazy ones who has mapped every combo of C+, A+, S+, CS+, CA+, AS+, and CAS+ for every key on the keyboard in the wincmd.ini of TC. The hotkeys are parallel in structure by function or group of functions, they make great sense to me, and I have no trouble remembering them. As a backup, my menu file has fully categorized cascading menus with the shortcut reminders on them. I still almost never use the menus (even as alt-sequences) and never use the buttons. But for some people, the ribbon approach might be helpful. For me, the alt-sequence menus would be my backup.

(Slightly off topic...) My personal opinion is that the ribbon ruined Office for me, and I've been an extremely heavy/expert user for decades. I much prefer the old-style menus, as the keyboard sequences were much shorter. Seems like it made the occasional user more productive by more explicitly exposing functionality, but the keyboard-jockey expert less productive by exchanging shorter keystrokes and more compact menus for longer/bulkier ones. Not to worry, I've used AHK or add-ins to remap most of the Office suite just so I *don't* have to use the ribbon. But many people do love it. :)
hi5
Power Member
Power Member
Posts: 555
Joined: 2012-11-03, 11:35 UTC
Contact:

Re: Splitting of parameter %L%a results?

Post by *hi5 »

@petermad I know but it is of course tediously slow, the screenshot I posted comes from my AutoHotkey script that overlays those keys, so for me it is as fast as ctrl+k (the AutoHotkey script to overlay the letters) and then pressing one letter, e.g. ctrl+k c to press the third button, after a little while you'll remember the most used ones so you don't even have to look. I mention the ribbon because that is where most people will have seen it - not that I'm a fan of ribbons as such or that I would suggest to introduce ribbons.
F4MiniMenu (Forum) - Open selected file(s) from TC in defined editor(s) - A (minimalistic) clone of F4Menu
Source at GitHub (AutoHotkey). TCSyncComments (copy file comments)
Post Reply