Now I'm using the folowing code:(eg: a shortcut named CLC doing clc
when clicked).
************************************************
awtinvoke(com.mathworks.mlwidgets.shortcuts.ShortcutUtils,'addShortcut
ToBottom', 'CLC', 'clc', [], 'Toolbar Shortcuts', [] );
************************************************
Now awtinvoke is an undocumented function and there's no info that I
could find on it.
The Problem :
When the file is run for the first time, with this code in it, a
shortcut named "CLC" is created. But the problem starts from the
second time the file is run... eventhough the shortcut is already
there, it'll try to create another shortcut of same name, but since
there is already one, it'll come up with a window to give the new
shortcut that's about to be created a new name. And once you do that,
there'll be a second shortcut on the tool bar that does the exact
same thing. Now if I run this file a million times, I'll end up
having a million shortcuts which is the problem.
So, How do I check if a shortcut is already there - so that I can use
that to control running the code ?
One possible solution that I can think of is to parse the
shortcuts.xml(in the prefdir) file to check if the shortcut already
exist. I don't know how to implement that though.
Could any of the matlab gurus here shed some light into this.
Also, I don't know java...just mentioned it as I have a hunch that
this might involve java.
Thanks
SJP
Additional info:
I opened the shotcuts.xml file and this is how the CLC shortcut in
the above post look like inside it.
************************************
<FAVORITE>
<label>CLC</label>
<icon><icon>/com/mathworks/mlwidgets/shortcuts/resources/s
hortcut.gif</icon></icon>
<callback>clc</callback>
<editable>true</editable>
</FAVORITE>
************************************
Any suggestions or ideas to actually parse the xml file to look for
the "CLC label inside the xml file would also be helpful.
Thanks
SJP
Sometimes my brain just doesn't turn on.
Here's the solution if anyone's interested.
1)Go to prefdir,
2)open shortcuts.xml like any other file.
3)textread --
xmlData = textread('shortcuts.xml','%s','delimiter','\n');
4)check using regexp - match for "CLC"
5)if found return status 1 else 0
6)create shortcut only if status 0.
** steps 3 and 4, use any other method of your choice.
Hope this helps anyone searching for this in future.
Hi, I tried this to create a shortcut on the MATLAB toolbar
to run a GUI I've created. It works very well, thank you!
However, each time I reopen MATLAB I get the following
error at the command prompt:
Shortcuts.xml file has been regenerated to the default
shortcuts due to a corrupted
shortcuts.xml file. The original file has been saved in
the prefdir as
shortcuts.xml_recovery.
When I open shortcuts.xml the code for my shortcut appears
as the following:
<FAVORITE>
<label>ICPrograms</label>
<icon>/com/mathworks/mlwidgets/shortcuts/resources/shortcut.
gif</icon>
<callback>ICPrograms</callback>
<editable/>
</FAVORITE>
It appears the code is corrupt because of the "editable"
field missing appropriate signatures. (<editable/> does not
look like correct XML code). Any thoughts on why this is
happening?
My .m code looks like this:
shrtCut = awtinvoke
(com.mathworks.mlwidgets.shortcuts.ShortcutUtils,...
'addShortcutToBottom', 'ICPrograms', 'ICPrograms',
[], 'Toolbar Shortcuts', []);
Thanks in advance!
A second thing (i know this is a lot) any way to make the
shortcut label an image as opposed to text? Ive tried using
imread, and setting the shortcut to the image as I do for
pushbuttons on GUIs but that does not appear to work. Any
input would be appreciated. Thanks guys!
-Josh
Does anyone have any suggestions for me about creating the
image on the shortcut? Thanks!
Yair Altman
http://ymasoftware.com
Thank you for the response. However, I need this to work on
any computer. Simply editing the xml code will not do the
trick. Basically, I need to edit the startup.m file where I
create the shortcuts to allow for an image on the shortcut.
Thoughts?
Thanks.
name = 'My New Shortcut'
evalstr = 'disp(''My New Shortcut'')'
iconfile = 'c:\path\to\icon.gif'
isEditable = 'true'
com.mathworks.mlwidgets.shortcuts.ShortcutUtils,'addShortcutToBottom',name,evalstr,iconfile,'Toolbar
Shortcuts',isEditable);
"Josh " <imah...@hotmail.com> wrote in message
<fq984f$6j5$1...@fred.mathworks.com>...
Thank you again! Many points for this solution :)
"Jesse Hopkins" <n...@na.com> wrote in message <fvn5lu$350
$1...@fred.mathworks.com>...
"Jesse Hopkins" <n...@na.com> wrote in message <fvn5lu$350
$1...@fred.mathworks.com>...
Any thoughts? Is it a java:MAC problem? Or something else?
Thanks
All of a sudden, without changing ANYTHING in my startup
file, the shortcuts are no longer being created. Anyone
else having this problem? If you go into your shorcuts.xml
file and delete the xml code that creates the shortcuts and
try to run startup again, does that still create new
shortcuts?
Mine doesnt anymore :( Any thoughts? Thanks in advance!
"Josh " <imah...@hotmail.com> wrote in message <g0cnp3$i57
$1...@fred.mathworks.com>...
"Josh " <imah...@hotmail.com> wrote in message <g0hdaj$e91
$1...@fred.mathworks.com>...