-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathaddToFavorites.m
50 lines (44 loc) · 1.74 KB
/
addToFavorites.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function addToFavorites
% Add "insertSnippet();" to the favorites commands and adds it to the Quick
% Access Toolbar so it can be triggered by a keyboard shortcut (e.g. ALT+1)
manualInstallationRequest = ...
'Please add it manually with a callback copy & pasted from the file "favoriteCallback.txt".';
if verLessThan('matlab','9.3')
f = warndlg([ 'The quick lunch icon can be automatically added only in Matlab 2017b and later. ' manualInstallationRequest ]);
uiwait(f);
return
end
basePath = fileparts(which('insertSnippet.m'));
iconPath = [ basePath filesep 'graphics' filesep ];
iconFileName = 'insertSnippet_16.png';
appName = 'MATLAB Snippets';
appID = getAppID(appName);
if isempty(appID)
f = warndlg([ 'Cannot find the App named "' appName '". Please (re)install it.' ]);
uiwait(f);
return
end
code = { ...
'if exist(''insertSnippet'',''file'')'
' insertSnippet();'
'else'
[' matlab.apputil.run(''' appID ''');'];
'end'
};
code = strjoin(code,sprintf('\n')); %#ok<SPRINTFN>
try
fc = com.mathworks.mlwidgets.favoritecommands.FavoriteCommands.getInstance();
newFavoriteCommand = com.mathworks.mlwidgets.favoritecommands.FavoriteCommandProperties();
newFavoriteCommand.setLabel('Insert Snippet');
newFavoriteCommand.setCategoryLabel('MATLAB SNIPPETS');
newFavoriteCommand.setCode(code);
newFavoriteCommand.setIsOnQuickToolBar(true);
newFavoriteCommand.setIconName(iconFileName);
newFavoriteCommand.setIconPath(iconPath);
fc.addCommand(newFavoriteCommand);
%msgbox('Quick lunch icon successfully added. Try to trigger it by ALT+1.','Matlab Snippets');
catch
f = warndlg(['Adding the quick lunch icon failed. ' manualInstallationRequest]);
uiwait(f);
end
end