wshanks / tbkeys

Custom keybindings for Thunderbird
Other
199 stars 14 forks source link

Adding ToggleMessageTag #117

Open AlternNO opened 1 year ago

AlternNO commented 1 year ago

I would like to assign keys to certain tags (I have more than 9 tags). I asked at stackoverflow and got a helpful answer. But I can't get it to work.

Since I'm supposed to use eval I should just the code provided there, with nothing in front like cmd or func, is that correct? This is among the things I tried.

"q": "ToggleMessageTag(MailServices.tags.getKeyForTag('business'), true);",

Since this is not working (nothing happens when I hit q) I guess I have to add some more code, but what? I hope you may help me, thanks for a great addon!

I'm using tbkeys 2.2.0 from 10th of November 2022.

morat523035 commented 1 year ago

Remember to include window objects in custom commands.

window.ToggleMessageTag(window.MailServices.tags.getKeyForTag('business'), true);

Tips http://forums.mozillazine.org/viewtopic.php?p=14872763#p14872763

Are you using tbkey or tbkeys-lite?

You cannot run arbitrary javascript with tbkeys-lite.

You can use the cmd shorthand and func shorthand with tbkeys and tbkeys-lite.

Use the cmd shorthand for calling a command using the goDoCommand method.

For example, "cmd:cmd_nextMsg" is the same as "window.goDoCommand('cmd_nextMsg');".

Use the func shorthand for calling a function on the window object without a parameter.

For example, "func:MsgNewMessage" is the same as "window.MsgNewMessage();".

There is a tbkeys.xpi link on the releases page.

Install tbkeys http://github.com/wshanks/tbkeys#install

AlternNO commented 1 year ago

I was sure I tested window.Toggle etc earlier today and it didn't work, but now it worked, so I guess I had a misspell or something! Thank you very much! Also thank you for the additional information, it was very useful :-)

I'm using tbkeys 2.2.0 from 10th of November 2022.

AndyM48 commented 1 year ago

Sorry but I cannot make this work for the existing tags. For example I would like to bind "i" to the Important tag, but this does not work for me: "i": "window.ToggleMessageTag(MailServices.tags.getKeyForTag('Important'), true);", Can someone tell me what am I doing wrong?

morat523035 commented 1 year ago

Try this:

// Thunderbird 102
window.ToggleMessageTag(window.MailServices.tags.getKeyForTag('Important'), true);

// Thunderbird 115
window.gTabmail.currentAbout3Pane.mailContextMenu._toggleMessageTag(window.MailServices.tags.getKeyForTag('Important'), true);

About new mail front end http://developer.thunderbird.net/thunderbird-development/codebase-overview/mail-front-end http://developer.thunderbird.net/add-ons/updating/tb115/adapt-to-changes-in-thunderbird-103-115

AndyM48 commented 1 year ago

Thunderbird 115

Tried this: "i": "window.gTabmail.currentAbout3Pane.mailContextMenu._toggleMessageTag(window.MailServices.tags.getKeyForTag('Important'), true);", but it did not work. Have I done it wrong?

morat523035 commented 1 year ago

Are you using tbkey or tbkeys-lite?

You cannot run arbitrary javascript with tbkeys-lite. There is a tbkeys.xpi link on the GitHub releases page.

Try running the following code snippets in the console as a test.

i.e. Menu Bar > Tools > Developer Tools > Error Console

window.alert(window.MailServices.tags.getKeyForTag('Important'));
window.gTabmail.currentAbout3Pane.mailContextMenu._toggleMessageTag(window.MailServices.tags.getKeyForTag('Important'), true);

The first code results in the $label1 string for me since I'm using the default tags.

The second code adds the Important tag to the selected message.

The second code doesn't remove the Important tag if I run the second code again.

AndyM48 commented 1 year ago

I am using tbkeys, not tbkeys-lite Running your code snippets in the console has the same results as you. So why doesn't this add the tag to the current message (actually tbkeys baulks at saving it!) "i": "window.gTabmail.currentAbout3Pane.mailContextMenu._toggleMessageTag(window.MailServices.tags.getKeyForTag('Important'), true);",

AndyM48 commented 1 year ago

There is an error shown in the console which may be relevant: 2023-11-10_15-41

AndyM48 commented 1 year ago

I think I have it working now, not sure what is different, however as you say, it does not toggle.

Thanks for your help