Code Monkey home page Code Monkey logo

Comments (26)

morat523035 avatar morat523035 commented on May 26, 2024 1

Here is how to select the inbox folder for the current account.

(function () {
  var selectedFolder = window.gFolderDisplay.displayedFolder;
  var inboxFolder = selectedFolder.rootFolder.getFolderWithFlags(window.Components.interfaces.nsMsgFolderFlags.Inbox);
  var sentMailFolder = selectedFolder.rootFolder.getFolderWithFlags(window.Components.interfaces.nsMsgFolderFlags.SentMail);
  var allMailFolder = selectedFolder.rootFolder.getFolderWithFlags(window.Components.interfaces.nsMsgFolderFlags.Archive);
  var trashFolder = selectedFolder.rootFolder.getFolderWithFlags(window.Components.interfaces.nsMsgFolderFlags.Trash);
  window.gFolderTreeView.selectFolder(inboxFolder);
})();

from tbkeys.

morat523035 avatar morat523035 commented on May 26, 2024 1

@williamgrimes

Remember to include window objects in custom commands.

Troubleshooting...

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

from tbkeys.

wshanks avatar wshanks commented on May 26, 2024

For quick switch to another folder by name, you can use nostalgy. It defines its own shortcuts, so you have to be careful not to define conflicting ones between tbkeys and nostalgy since there isn't a unified interface for managing the shortcuts of both.

There might be a commands for moving up and down in the folder pane. We would need to look through the source code for that. I think it might be implemented as a generic tree view with actions for up/down and without named "next folder item" commands though.

from tbkeys.

morat523035 avatar morat523035 commented on May 26, 2024

Here are code snippets for collapseFolder, expandFolder, folderDown, folderUp.

http://teramako.hatenadiary.org/entry/20070427/p1

The treeBoxObject has been removed.

http://developer.thunderbird.net/add-ons/updating/tb68/changes#nsitreeboxobject-nsitreecolumn-nsitreeview

Here is a code snippet to go to the next folder beginning with the letter pressed.

http://forums.mozillazine.org/viewtopic.php?p=8528905#p8528905

from tbkeys.

JoshuaCrewe avatar JoshuaCrewe commented on May 26, 2024

At the risk of being off topic, I did find a way to navigate folders using this extension. It works in a different way than @tommyalatalo describes in the OP. The reason for posting here is I struggled a bit to get something working but kept coming back here for information.

Here is what I have working so far :

    "g i": "window.gFolderTreeView.selectFolder(window.MailUtils.getExistingFolder('imap://[email protected]/INBOX'), true);",
    "g s": "window.gFolderTreeView.selectFolder(window.MailUtils.getExistingFolder('imap://[email protected]/INBOX/Sent'), true);",
    "g a": "window.gFolderTreeView.selectFolder(window.MailUtils.getExistingFolder('imap://[email protected]/INBOX/Archive'), true);",

    "m i": "window.MsgMoveMessage(window.MailUtils.getExistingFolder('imap://[email protected]/INBOX'))",
    "d": "window.MsgMoveMessage(window.MailUtils.getExistingFolder('imap://[email protected]/INBOX/Trash'))",

I am quite aware of the downsides to this implementation :

  • The paths are hard coded
  • The solution is not very robust only really working for one account

I prefer the key bindings to the folder up and down paradigm but it is limited to the number of folders you have. I only have about three folders and only use one account so I can work with this.

What would make it better is if the path of the folders could be got programmatically. Something like getCurrentAccountPath() would be neater. These actions in combination with a folder search UI would be all the functionality I would need to make this flow workable. At the moment I don't know if I am sticking with TB but am looking to stick around and hopefully solve some of these problems. If I get anywhere, a PR for examples would be a good addition to the README I think. Are PRs welcome ?

Resources I found helpful :
https://hg.mozilla.org/comm-central/file/tip/mail/modules/MailUtils.jsm for what is available on the MailUtils object.

from tbkeys.

JoshuaCrewe avatar JoshuaCrewe commented on May 26, 2024

@morat523035 thanks for sharing. I am unclear how to use functions which one has defined themselves. is there a location where we can define functions and then call them from the json object?

Do you have somewhere you go to to get this information about what objects are available ?

from tbkeys.

wshanks avatar wshanks commented on May 26, 2024

PR's to add to the README are definitely welcome.

I think @morat523035 was suggesting stuffing all of that code into the key binding. I don't completely rule out the option of defining some helper functions in tbkeys code base, but I'd like to limit that as much as possible to keep things maintainable. Perhaps the settings could accept a block of text to be evaluated once that could be used to define functions that could be called in the scope that the shortcut bindings are evaluated in. That would have to be disabled in the lite version.

For working with folders, one option is to use Quick Folder Move and bind to the window.quickmove.openFile() and window.quickmove.openGoto() functions. That just opens the folder selection dialog though. The internals of Quick Folder Move don't have a good entry point for calling a move or go to for a specific folder.

from tbkeys.

morat523035 avatar morat523035 commented on May 26, 2024

Here is a json object using an anonymous function.

{
    "1": "window.alert('example 1');",
    "2": "(function () { var text = 'example 2'; window.alert(text); })();"
}

http://www.javascripttutorial.net/javascript-anonymous-functions/

I like to use the userChromeJS addon to define functions to use in the tbkeys settings.

Example...

http://forums.mozillazine.org/viewtopic.php?p=14900570#p14900570

Tips...

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

from tbkeys.

JoshuaCrewe avatar JoshuaCrewe commented on May 26, 2024

Ahhh I see. Thanks for the added clarification, that is really helpful.

from tbkeys.

wshanks avatar wshanks commented on May 26, 2024

I wasn't familiar with the userChromeJS addon. It would be nice to suggest using that to define larger helper functions in the readme as well.

from tbkeys.

xkonni avatar xkonni commented on May 26, 2024

quickmove

could you elaborate on how to use quickmove?

e.g. "v": "window.quickmove.openFile()"` does not seem to work

from tbkeys.

morat523035 avatar morat523035 commented on May 26, 2024

@xkonni

Try using a delay. The following code snippet works in the error console.

window.setTimeout(function () { window.quickmove.openFile(); }, 1000);

Quick Folder Move
http://addons.thunderbird.net/thunderbird/addon/12018

from tbkeys.

wshanks avatar wshanks commented on May 26, 2024

For what it's worth, I use "v": "window.quickmove.openFile()". I am not sure why it doesn't work for you. I hope the delay helps.

from tbkeys.

xkonni avatar xkonni commented on May 26, 2024

thank you for your replies!

both commands window.quickmove.openFile() and window.setTimeout(function () { window.quickmove.openFile(); }, 1000); work in the jsconsole, unfortunately both do nothing when added to the settings as:

  • "v": "window.quickmove.openFile()",
  • "v": "window.setTimeout(function () { window.quickmove.openFile(); }, 1000);"

but I can map other existing functions to v, such as:

  • "v": "func:MsgNewMessage",

also tried prefixing them with func: or cmd:, no luck.

so it's not window-manager related.

from tbkeys.

morat523035 avatar morat523035 commented on May 26, 2024

@xkonni

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.

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

from tbkeys.

xkonni avatar xkonni commented on May 26, 2024

@xkonni

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.

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

right. it was tbkeys-lite. sorry for this and thanks for spotting it! all works as expected now!

from tbkeys.

Lantizia avatar Lantizia commented on May 26, 2024

As crazy as this is... (pressing 'f' moves the message to whichever folder is tagged as 'Archive' on the mailbox you're viewing)

"f": "(function () { window.MsgMoveMessage(window.gFolderDisplay.displayedFolder.rootFolder.getFolderWithFlags(window.Components.interfaces.nsMsgFolderFlags.Archive)); })();",

Crazy because although it works, it's entirely pointless as there is already an inbuilt keyboard shortcut for doing this.

Is there a way of looking up not whichever folder is tagged 'Archive'... but instead whichever folder is named 'Filed'.

I tried something like this (which didn't work) but I'm a little out of my depth here, never really having done much with Thuderbird/Firefox extensions...

"f": "(function () { window.MsgMoveMessage(window.gFolderDisplay.displayedFolder.rootFolder.getFolderURL("Filed")); })();",

This would be an excellent way of having mailbox-agnostic single-key shortcuts for moving to popular same-named folders you may have on multiple mailboxes (e.g. 'f' for 'Filed'... 's' for 'Shopping'... etc...)

from tbkeys.

morat523035 avatar morat523035 commented on May 26, 2024

@Lantizia

Show selected folder url:

window.alert(window.gFolderDisplay.displayedFolder.URI);

Move message to given folder url:

(function () {
  var targetUri = 'mailbox://nobody@Local%20Folders/Cowabunga';
  var targetFolder = window.MailUtils.getExistingFolder(targetUri);
  window.MsgMoveMessage(targetFolder);
})();

Examples
http://yandex.com/search/?text=%22MailUtils.getFolderForURI%22+site%3Aforums.mozillazine.org
http://yandex.com/search/?text=%22MailUtils.getExistingFolder%22+site%3Aforums.mozillazine.org

MailUtils.getFolderForURI was renamed to MailUtils.getExistingFolder in Thunderbird 68.

from tbkeys.

Lantizia avatar Lantizia commented on May 26, 2024

Yeah I found similar examples like that already,

But doesn't your solution require an absolute URL that is specific to a mailbox?

My requirement (as I already mentioned) is that this be a mailbox agnostic lookup of a folder (in the root of the mailbox you're viewing) with a specific name.

from tbkeys.

morat523035 avatar morat523035 commented on May 26, 2024

@Lantizia

Here is a contrived example that uses a recursive function. It shows all root folder subfolder urls in a new tab and alerts the "Shopping" folder url for the selected account.

(function () {
  function checkSubFolders(aFolder) {
    if (!aFolder.hasSubFolders) {
      return;
    }
    for (var subFolder of aFolder.subFolders) {
      allFolders.push(subFolder.URI);
      checkSubFolders(subFolder);
    }
  }
  var allFolders = [];
  checkSubFolders(window.gFolderDisplay.displayedFolder.rootFolder);
  var data = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">';
  data += '<html><head><title>Example</title>';
  data += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
  data += '</head><body><pre>' + allFolders.join('\n') + '</pre></body></html>';
  window.document.getElementById('tabmail').openTab('contentTab', {
    url: 'data:text/html;charset=utf-8;base64,' + window.btoa(data),
    background: false,
  });
  for (var i = 0; i < allFolders.length; i++) {
    if (allFolders[i].endsWith('Shopping')) {
      var targetUri = allFolders[i];
      var targetFolder = window.MailUtils.getExistingFolder(targetUri);
      window.alert(targetUri);
      break;
    }
  }
})();

Try testing the code snippet using the error console before creating a keyboard shortcut.

P.S.

There is no helper function available like getFolderWithName.

Reference
http://searchfox.org/comm-esr102/source/mailnews/base/public/nsIMsgFolder.idl

from tbkeys.

morat523035 avatar morat523035 commented on May 26, 2024

@Lantizia

Maybe you can use the descendants property.

(function () {
  for (var folder of window.gFolderDisplay.displayedFolder.rootFolder.descendants) {
    if (folder.name == 'Shopping') {
      window.MsgMoveMessage(folder);
      break;
    }
  }
})();

Reference
http://searchfox.org/comm-esr102/search?q=rootFolder.descendants

from tbkeys.

Cleversn avatar Cleversn commented on May 26, 2024

Hi all,
I have an old code which works under Keyconfig, but not under tbkeys. You assign a letter key, say p, then you can press p followed by the first letter of the folder you want to visit. If anyone updates the code for me, I'll be grateful and it may serve others interested in this thread.

Here is the entry I added to tbkeys, which doesn't work:

"p": "(function () { window.addEventListener('keypress',temp,true); function temp(event) { window.removeEventListener('keypress',temp,true); var tree = document.getElementById'folderTree'); var firstColumn = tree.columns.getFirstColumn(); var letter = String.fromCharCode(event.charCode).toLowerCase(); var i, l; for(i = tree.currentIndex + 1, l = tree.view.rowCount; i < l ; i++) if(tree.view.getCellText(i,firstColumn)[0].toLowerCase() == letter) return tree.view.selection.select(i); for(i = 0, l = tree.currentIndex; i < l ; i++) if(tree.view.getCellText(i,firstColumn)[0].toLowerCase() == letter) tree.view.selection.select(i); })();",

from tbkeys.

morat523035 avatar morat523035 commented on May 26, 2024

@Cleverson

The following code snippet works using the error console. (not tested with tbkeys)

(function () {
  function onWindowKeypress(aEvent) {
    window.removeEventListener('keypress', onWindowKeypress, true);
    var tree = window.document.getElementById('folderTree');
    var firstColumn = tree.columns.getFirstColumn();
    var letter = window.String.fromCharCode(aEvent.charCode).toLowerCase();
    var i, l;
    for (i = tree.currentIndex + 1, l = tree.view.rowCount; i < l ; i++)
      if (tree.view.getCellText(i, firstColumn)[0].toLowerCase() == letter)
        return tree.view.selection.select(i);
    for (i = 0, l = tree.currentIndex; i < l ; i++)
      if (tree.view.getCellText(i, firstColumn)[0].toLowerCase() == letter)
        tree.view.selection.select(i);
  }
  window.addEventListener('keypress', onWindowKeypress, true);
})();

Notice the window objects in the code snippet. Normally the use of the window object is optional, like |document| and |window.document| are equivalent. With tbkeys, |document| would result in a reference error.

Online Multiline to Single Line Converter
http://tools.knowledgewalls.com/online-multiline-to-single-line-converter

from tbkeys.

Cleversn avatar Cleversn commented on May 26, 2024

thanks! Works perfect. I'm Definitely wanting to teach myself some Javascript and related environments.

from tbkeys.

williamgrimes avatar williamgrimes commented on May 26, 2024

Can someone explain why this does not work, using tbkeys to assign a shortcut as a main key binding:

To navigate folders:

"shift+k": "(function (){ let folder = GetFirstSelectedMsgFolder(); if (folder != null) { let index = gFolderTreeView.getIndexOfFolder(folder); if (index != null) folder = gFolderTreeView.getFolderForIndex(index - 1); } if (folder != null) gFolderTreeView.selectFolder(folder); } ) ();"

A similar shortcut can be used to go down e.g. "shift+j",

The JavaScript was lifted from here: https://superuser.com/a/1411903

This works in the Thunderbird error console to go up a folder but not as a tbkeys shortcut:

{
  let folder = GetFirstSelectedMsgFolder();
  if (folder != null) {
    let index = gFolderTreeView.getIndexOfFolder(folder);
    if (index != null)
      folder = gFolderTreeView.getFolderForIndex(index - 1);
  }
  if (folder != null)
    gFolderTreeView.selectFolder(folder);
}

but not as a tbkeys shortcut?!?!

from tbkeys.

williamgrimes avatar williamgrimes commented on May 26, 2024

@morat523035 you are a star ⭐

Adding window did the trick i.e

"shift+j": "(function (){ let folder = window.GetFirstSelectedMsgFolder(); if (folder != null) { let index = window.gFolderTreeView.getIndexOfFolder(folder); if (index != null) folder = window.gFolderTreeView.getFolderForIndex(index + 1); } if (folder != null) window.gFolderTreeView.selectFolder(folder); } ) ();"
"shift+k": "(function (){ let folder = window.GetFirstSelectedMsgFolder(); if (folder != null) { let index = window.gFolderTreeView.getIndexOfFolder(folder); if (index != null) folder = window.gFolderTreeView.getFolderForIndex(index - 1); } if (folder != null) window.gFolderTreeView.selectFolder(folder); } ) ();"

It now works to navigate folders with "shift + k" and "shift + j"

@altosys I think you can close this issue

Also for reference if anyone wants to add vim-like keys to Thunderbird with tbkeys, I found this config now works very well:

https://gist.github.com/williamgrimes/e0622b3336a454926137101ba0456a11

(note use tbkeys not tbkeys-lite)

from tbkeys.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.