Page 2 of 2
Re: assign a Keyboard Shortcut to a User Button
Posted: 04 Feb 2025 11:05
by atisoro
can you help by an example?
Re: assign a Keyboard Shortcut to a User Button
Posted: 04 Feb 2025 19:10
by highend
Show the full script in code tags
Re: assign a Keyboard Shortcut to a User Button
Posted: 04 Feb 2025 20:34
by atisoro
it's too hard for me.
I stop here
Re: assign a Keyboard Shortcut to a User Button
Posted: 05 Feb 2025 21:09
by atisoro
it doesn't matter.
I got hold of the solution.
(with regexreplace)
It works, but it does not take into account the existence of any previously set buttons.
Code: Select all
$newCB = <<<'EOD'
[CustomButtons]
Version=1
Count=1
1=""loader|:ladybug|1|0" load "<xyscripts>.\myscript.xys"; "
[BookmarkButtons]
EOD;
$content = readfile("<xydata>\<xyini>");
$content_new = regexreplace($content, "\[CustomButtons]([\s\S]*?)\[BookmarkButtons]", $newCB);
writefile("<xydata>\<xyini>", $content_new, "o");
#190; //restart
any addition (such as by code addition of CommandButton1 in the toolbar) is welcome
Re: assign a Keyboard Shortcut to a User Button
Posted: 05 Feb 2025 22:06
by highend
toolbar()?
Re: assign a Keyboard Shortcut to a User Button
Posted: 06 Feb 2025 09:57
by atisoro
smoothly add a custom button at the end of active toolbar
Code: Select all
$oldtoolbar = toolbar();
toolbar($oldtoolbar."-,ctb1,".);
Re: assign a Keyboard Shortcut to a User Button
Posted: 06 Feb 2025 10:11
by highend
Can you at least test such things more extensively before posting them?
You're effectively removing the last entry with it^^
Code: Select all
$oldToolbar = toolbar();
if (!regexmatches($oldToolbar, "\bctb1\b")) {
toolbar($oldToolbar . ",ctb1");
}
Re: assign a Keyboard Shortcut to a User Button
Posted: 06 Feb 2025 11:00
by atisoro
actually, I initially tested this code to adds to the first position and I mistakenly assumed that it works correctly (surprisingly, it doesn't)
working code //for first position cbt1
Code: Select all
$oldtoolbar = toolbar();
toolbar("ctb1,-".$oldtoolbar);
my proposals are only at the beginner level, (a few days of juggling the codes), my experience being in VBA and VB.net
in any case, I accept the criticism
Re: assign a Keyboard Shortcut to a User Button
Posted: 06 Feb 2025 11:02
by highend
toolbar("ctb1,-".$oldtoolbar);
Cool, and now you're removing the existing first entry^^
Re: assign a Keyboard Shortcut to a User Button
Posted: 06 Feb 2025 11:21
by atisoro
indeed
your code works flawlessly
Kudos
Code: Select all
$oldToolbar = toolbar();
if (!regexmatches($oldToolbar, "\bctb1\b")) {
toolbar($oldToolbar . ",ctb1");
}
Re: assign a Keyboard Shortcut to a User Button
Posted: 06 Feb 2025 22:54
by highend
And this is a way how it could be really done...
Code: Select all
$script = <<<'#EOD'
"loader|:ladybug|1|0" load "<xyscripts>\myscript.xys";
#EOD;
$script = replace(trim($script, <crlf>), <crlf>, "ΒΆ");
$iniFile = "<xydata>\<xyini>";
$iniContent = readfile($iniFile);
$section = getsectionlist("CustomButtons", $iniFile);
$cntBtns = gettoken(regexmatches($section, "^Count=\d+$"), 2, "=");
$section = regexreplace($section, "^(Version|Count)=\d+(\r?\n|$)");
$btnID = "";
while ($i++ < 64) {
$line = gettoken($section, $i, <crlf>);
// Find an existing but not-populated line or an empty one
if (regexmatches($line, "^\d{1,2}=""""$") || $line == "") {
$btnID = $i;
break;
}
}
end ($btnID == ""), "No free (x of 64) custom button entry found, aborted!";
// Add new / overwrite empty entry and adjust the "Count" if necessary
$newLine = quote($script . <tab 2>);
if ($btnID > $cntBtns) { setkey $btnID, "Count", "CustomButtons", $iniFile, 2; }
setkey $newLine, $btnID, "CustomButtons", $iniFile, 2;
// Restart without saving
#190;
Re: assign a Keyboard Shortcut to a User Button
Posted: 07 Feb 2025 07:55
by atisoro
this is sophisticated far beyond the knowledge of most users (at least mine).
elegant, simple and useful.
Re: assign a Keyboard Shortcut to a User Button
Posted: 12 Feb 2025 11:19
by atisoro
again, a problem in which I ask for your help.
after the code successfully writes to the xyplorer.ini file,

whatever I try, after Exit(saving) or savesettings or save configuration, the changes disappear.

can anything be done?
Re: assign a Keyboard Shortcut to a User Button
Posted: 12 Feb 2025 11:30
by highend
That's why it uses "Restart without saving" at the end^^
Re: assign a Keyboard Shortcut to a User Button
Posted: 12 Feb 2025 12:10
by atisoro
This trick works great.
Thank you.