[TC 9.51] SELECTFILES dosn't always work with %M

Please report only one bug per message!

Moderators: white, Hacker, petermad, Stefan2

Post Reply
User avatar
petermad
Power Member
Power Member
Posts: 14700
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

[TC 9.51] SELECTFILES dosn't always work with %M

Post by *petermad »

SELECTFILES doesn't work with %M or "%M" if used in an em_command and there is spaces in the file name.

To reproduce:
1. Have the same directory opened in both panels.
2. Put this command in the usercmd.ini file:

Code: Select all

[em_goto_item_opositepanel1]
cmd=SELECTFILES
param="%M"
3. Make this button:

Code: Select all

TOTALCMD#BAR#DATA
em_goto_item_opositepanel1

wcmicons.dll,19
Mark file with the name of the active file in the opposite panel - if it exists


-1
4. Put the cursor on a file with NO spaces in the name and switch to the opposite panel.
5. Click the button - The file with the same name of the active file in the opposite panel is marked.
6. Put the cursor on a file WITH a space in the name and switch to the opposite panel.
7. Click the button - You get the message "No matches found!" - not expected
______________________

8. Now make this button:

Code: Select all

TOTALCMD#BAR#DATA
SELECTFILES
"%M"
wcmicons.dll,19
Mark file with the name of the active file in the opposite panel - if it exists


-1
9. Put the cursor on a file WITH a space in the name and switch to the opposite panel.
10. Click the button - Now the file with the same name of the active file in the opposite panel is marked - as expected
______________________

11. Now put this command in the usercmd.ini file:

Code: Select all

[em_goto_item_opositepanel2]
cmd=SELECTFILEST
param=%N
12. Make this button:

Code: Select all

TOTALCMD#BAR#DATA
em_goto_item_opositepanel2

wcmicons.dll,19
Mark file with the name of the active file in the opposite panel - if it exists


-1
13. Put the cursor on a file WITH a space in the name and switch to the opposite panel.
14. Click the button - Now the file with the same name of the active file in the opposite panel is marked - as expected

______________________

If I in em_goto_item_opositepanel1 change

Code: Select all

param="%M"
to

Code: Select all

param="?%M"
to prompt the parameters - then the button from 3. does work also for files with space in the name - peculiar

______________________

If I in em_goto_item_opositepanel2 change

Code: Select all

param=%N
to

Code: Select all

param="%N"
then then the button from 12. still work also for files with space in the name.

But if I change it to:

Code: Select all

param=?"%N"
to prompt the parameters - then the button from 12. does NOT work for files with space in the name - but gives the message: "No matches found!" - not expected
Last edited by petermad on 2021-03-12, 10:39 UTC, edited 2 times in total.
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.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
elgonzo
Power Member
Power Member
Posts: 866
Joined: 2013-09-04, 14:07 UTC

Re: [TC 9.51] SELECTFILES dosn't always work with %M

Post by *elgonzo »

Your command [em_goto_item_opositepanel1] with SELECTFILES "%M" works for me. Did you perhaps mistakenly set the cursor on a directory instead of a file? UPDATE: See next post

What i find kinda funny is that for SELECTFILES "%M" you'll have to use double-quotes, whereas for SELECTFILEST %N one can omit double quotes (or must omit -- i don't know why my test experience diverged from your test results). Reminds me once again of all the other silly fun one can have with TC's command parameters.
Last edited by elgonzo on 2021-01-15, 15:39 UTC, edited 5 times in total.
Begrudgingly back to Windows... now 11... sigh... but i have no nerve for Linux desktop anymore...
User avatar
elgonzo
Power Member
Power Member
Posts: 866
Joined: 2013-09-04, 14:07 UTC

Re: [TC 9.51] SELECTFILES dosn't always work with %M

Post by *elgonzo »

I found out why my test experience differed. I used the command browser to create the commands. When looking into the usercmd.ini, i noticed that the command browser saved the commands as follows (with [em_goto_item_opositepanel2] having been defined in the command browser with %N using double-quotes):

Code: Select all

[em_goto_item_opositepanel1]
button=
cmd=SELECTFILES
param=""%M""

[em_goto_item_opositepanel2]
button=
cmd=SELECTFILEST
param=""%N""
Note the double double-quotes. :o :twisted:

(By the way, defining the command parameter %N in the second user command with double-quotes in the command browser, which leads to the double pair of double-quotes in usercmd.ini as shown here, won't work with file names containing spaces.)

The double pair of double-quotes can also be seen in the command definitions of the toolbar buttons in your respective .BAR file.



After editing the usercmd.ini manually, with %M in [em_goto_item_opositepanel1] using only a single pair of double-quotes - to match my usercmd.ini entries exactly like you have described:

Code: Select all

[em_goto_item_opositepanel1]
button=
cmd=SELECTFILES
param="%M"
i could reproduce your issue with %M.

And, for completeness sake: Doing the same for [em_goto_item_opositepanel2] - using a single pair of double-quotes for %N in command definition in the usercmd.ini - still keeps [em_goto_item_opositepanel2] working.
Begrudgingly back to Windows... now 11... sigh... but i have no nerve for Linux desktop anymore...
User avatar
ghisler(Author)
Site Admin
Site Admin
Posts: 48005
Joined: 2003-02-04, 09:46 UTC
Location: Switzerland
Contact:

Re: [TC 9.51] SELECTFILES dosn't always work with %M

Post by *ghisler(Author) »

I have analyzed this now: When reading from INI files, Windows removes double quotes from an item, e.g.
param="%M" -> %M
param=""%M"" -> "%M"

The double quotes are needed here, though, because SELECTFILES can accept multiple file names. e.g.
SELECTFILES file.txt "file 2.txt"
Without the double quotes, it would break it into multiple parts, e.g.
SELECTFILES file.txt file 2.txt
>
file.txt
file
2.txt

Therefore if you edit ini or bar files yourself, add extra double quotes to items surrounded by double quotes.
Author of Total Commander
https://www.ghisler.com
User avatar
elgonzo
Power Member
Power Member
Posts: 866
Joined: 2013-09-04, 14:07 UTC

Re: [TC 9.51] SELECTFILES dosn't always work with %M

Post by *elgonzo »

2ghisler(Author)
are you aware of the difference in quotation requirements between %N and %M, regardless of double-quote escaping in the INI files?
%M needs quotes whereas %N must not be quoted when files with spaces are involved.

Do you intend to improve documentation in TC's next release regarding these differences in quoting requirements?
(If not, i am thinking of opening a new topic in the bug forum about this issue for tracking purposes...)

As a side note: i am hesitant to suggest a fix making the behavior of %M and %N equivalent. While i would consider this difference in behavior between %N and %M a bug/unintended behavior, fixing it now would be a breaking change, breaking already existing toolbar button definitions and/or user commands.
Last edited by elgonzo on 2021-01-24, 14:50 UTC, edited 2 times in total.
Begrudgingly back to Windows... now 11... sigh... but i have no nerve for Linux desktop anymore...
User avatar
petermad
Power Member
Power Member
Posts: 14700
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: [TC 9.51] SELECTFILES dosn't always work with %M

Post by *petermad »

While i would consider this difference in behavior between %N and %M a bug/unintended behavior, fixing it now would be a breaking change, breaking already existing toolbar button definitions and/or user commands.
I think is is possible to make %M work the same way as %N regarding quotes and still keeping backwards compatability also handling ""%M"" like %N and "%N"
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.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
User avatar
elgonzo
Power Member
Power Member
Posts: 866
Joined: 2013-09-04, 14:07 UTC

Re: [TC 9.51] SELECTFILES dosn't always work with %M

Post by *elgonzo »

petermad wrote: 2021-01-24, 12:51 UTC I think is is possible to make %M work the same way as %N regarding quotes and still keeping backwards compatability also handling ""%M"" like %N and "%N"
Just to make sure, i was not referring to the escaping of double-quotes within the INI files, but about the parameters themselves functionally being quoted in the parameter string, as in such quotes being part of the commandline argument passed to the invoked program. (I edited my previous post to make it clearer that i was not speaking about the INI file content.)

I guess, one way to maintain backwards compatibility when executing a button or user command, is letting TC parse the parameter string for occurences of %M and detect whether it is surrounded by double-quotes. If %M is surrounded by double-quotes, %M should work as of now (not double-quoting any file name). If %M is not surrounded by double-quoted, it should adapt the behavior of %N (automatically including double-quotes for file names with spaces or other special character sequences such as &&). Though, i am not 100% certain that such a context-sensitive switching of the behavior of %M wouldn't break some unusual parameter strings some users might have defined where "%M" is not a stand-alone argument (such as the following paramer string, including the double-quotes: "X:\Some\Hardcoded\Path\%M", for instance).
Begrudgingly back to Windows... now 11... sigh... but i have no nerve for Linux desktop anymore...
User avatar
petermad
Power Member
Power Member
Posts: 14700
Joined: 2003-02-05, 20:24 UTC
Location: Denmark
Contact:

Re: [TC 9.51] SELECTFILES dosn't always work with %M

Post by *petermad »

I guess, one way to maintain backwards compatibility when executing a button or user command, is letting TC parse the parameter string for occurences of %M and detect whether it is surrounded by double-quotes. If %M is surrounded by double-quotes, %M should work as of now (not double-quoting any file name). If %M is not surrounded by double-quoted, it should adapt the behavior of %N (automatically including double-quotes for file names with spaces or other special character sequences such as &&). Though, i am not 100% certain that such a context-sensitive switching of the behavior of %M wouldn't break some unusual parameter strings some users might have defined where "%M" is not a stand-alone argument (such as the following paramer string, including the double-quotes: "X:\Some\Hardcoded\Path\%M", for instance).
I agree - I couldn't have said it better myself.
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.50b4 on Android 6 & 13
Try: TC Extended Menus | TC Languagebar | TC Dark Help | PHSM-Calendar
Post Reply