UI selection?
Hi, Is it possible to detect the currently account in the UI and also selected transactions from the UI? From what I can tell it's not possible. The Account seems to be kind of available through parsing the current window.
Keyboard shortcuts
Generic
| ? | Show this help |
|---|---|
| ESC | Blurs the current field |
Comment Form
| r | Focus the comment reply box |
|---|---|
| ^ + ↩ | Submit the comment |
You can use Command ⌘ instead of Control ^ on Mac
1 Posted by Stuart Beesley ... on 04 Feb, 2026 09:09 AM
Yes. I’ll look and send later.
2 Posted by Stuart Beesley ... on 04 Feb, 2026 05:36 PM
It's actually very simple.. Hooks were added for MD2024 to do this. In python:
(using getFirstMainFrame() is slightly hacky and is not a supported API call as such, but getSelectedTxns() is certainly there to be used and you can backtrack the account from the list of selected txns).
There is also a way to hook into the right click selected txns within a register if you want to do that?
3 Posted by Jim on 05 Feb, 2026 02:08 AM
Thanks! Yes, sure right-click selected may come in handy. Is there any documentation on what was added? I don't see this in the apidoc.
4 Posted by Stuart Beesley ... on 05 Feb, 2026 07:32 AM
Are you using java?
5 Posted by chiang.jim on 05 Feb, 2026 03:41 PM
I use both, but for this UI stuff, yes Java
6 Posted by Stuart Beesley ... on 05 Feb, 2026 03:46 PM
I ask as the context menu hook method is totally different between Java and python extensions.
7 Posted by Stuart Beesley ... on 05 Feb, 2026 11:23 PM
OK, here is the java hook.. It's easy - after you have gotten your head around it..
Your extension's Main must be extending
FeatureModuleYou will need the following, and you may have to compile against the live jar - see what works:
Now override:
getActionsForContext(context:MDActionContext):List<Action>In conceptual terms, everytime a context menu is triggered, all extensions get their
getActionsForContextmethod called. They must return a list ofActions. If not overridden, then the superclass method is called returning an empty list. This call must return quickly to not lag the UI.This method must quickly interrogate the contents of
MDActionContextand determine what it can do. It then builds a list ofActions with names that appear on the context menu, and a callback that gets called if clicked... A kotlin example below:No, it's not documented... Let me know how you get on?
8 Posted by Stuart Beesley ... on 07 Feb, 2026 10:34 AM
?
9 Posted by Jim on 07 Feb, 2026 06:18 PM
Yup, it's working!
Did a bit of digging around. Is there any reason not to use:
txns = mdGui.getSelectedTxns();
acc = mdGui.getCurrentAccount();
for retreiving currently selected txns? I had been using the method in post 2 with polling, but this seems much clearner
10 Posted by Stuart Beesley ... on 07 Feb, 2026 06:32 PM
txns = mdGui.getSelectedTxns();is fineacc = mdGui.getCurrentAccount();is NOT fine - this is not the selected account. This is the top level account book...For some reason
mdGui.getSelectedAccount()was removed in the past so you have to use what I said....11 Posted by Jim on 07 Feb, 2026 07:15 PM
From my testing mdGui.getCurrentAccount() does return the current account (not the root book)...?
12 Posted by Stuart Beesley ... on 07 Feb, 2026 07:30 PM
I misspoke, but I still maintain it is NOT returning the currently selected account (in the GUI sidebar)..
What does this return in Developer console for you?
It returns the ROOT account (top) level of the account book.. So yes, it's an account, but it has nothing to do with the currently selected account in the GUI sidebar.
13 Posted by Jim on 07 Feb, 2026 10:28 PM
I'm a bit confused....In Java, it seems to return the current sidebar account, but in python it seems to always return the root account. Does that make any sense?
I noticed I can use getFirstMainFrame() and the md:account:select even together. Is there an event for txn selection?
14 Posted by Stuart Beesley ... on 07 Feb, 2026 10:34 PM
No, these are the events:
15 Posted by Stuart Beesley ... on 07 Feb, 2026 10:46 PM
Nope - what you are seeing makes no sense to me... Can you send me the actual code? How are you getting the ui? Is it something like this:
16 Posted by Jim on 07 Feb, 2026 10:51 PM
it's
17 Posted by Stuart Beesley ... on 07 Feb, 2026 11:11 PM
Well, there are only two definitions of getCurrentAccount() in MD, the one in UI points to the one in Main, and this one gets the root account.
So you are saying that in java when you call
mdGUI().getCurrentAccount().getAccountType()- you get something other than ROOT?Are you running in an IDE? Can you double-click to decompile and open getCurrentAccount()
18 Posted by Jim on 08 Feb, 2026 03:12 AM
My apologies, I had some fallback code that was 'hiding' the output, so you're absolutely right, its always the root account.
19 Posted by Jim on 08 Feb, 2026 03:31 AM
So at this point the getFirstMainFrame() method seems the most robust for me. I've noticed if I use the getSelectedTxns() and then backtrack the account from the selected txn, it may be incorrect or ambigious. If there is 1 selected txn and it happens to be a transfer, I may get the account on the other side of the transfer. If there are more than1 txn selected I may get multiple accounts (if there are transfers). Tthe getFirstMainFrame method seems to be the only reliable method.
The other method I have is ((JFrame)window).getTitle() and then parsing the text which is pretty hacky but works.
20 Posted by Stuart Beesley ... on 08 Feb, 2026 08:25 AM
I think your usage of the account on a txn may be incorrect.. Basically you can do this.
iterate all selected txns, for each call txn.getAccount(). If all are the same account then you can safely use that account, and are probably in an account register. Otherwise, if you get mixed results, then you are probably on a Summary Screen quick search, and yes in this situation you might be looking at either side of the txn...
Further, if you were to call such a (missing) getSelectedTxns() when you were on the Summary Screen, then getSelectedTxns() would return the root account anyway.