No BSD License  

Highlights from
SHORTSTOOL: Browse through User Shortcut Toolbar

image thumbnail
from SHORTSTOOL: Browse through User Shortcut Toolbar by Md Rezaul Karim
To extend the desktop facilities such as shortcuts and command history browsing when JAVA ...

shortstool(varargin)
function varargout = shortstool(varargin)
%SHORTSTOOL Browse through User Shortcut Toolbar
% Purpose: 
%    To extend the desktop facilities such as shortcuts and command history browsing when JAVA Vitrual machine is not running
%    Works with compiled standalone version/gui
%    Sometimes useful, if you are the one like me who often run MATLAB in NODESKTOP/NOJVM mode for final execution of code, but miss
%    the desktop feature badly. Since as I know, java can't be turned on or off in the same matlab session.
% You could look at my shortcuts.xml file, and you will be surprised to see how extensively I use the new Shortcuts toolbar feature
% Shortcut file means shortcuts.xml in preference directory
% History file means history.m in the preference directory (assume history is on)
% Since it takes little time to process the shortcuts.xml file,
% the listbox data is saved as shortcutsxml.mat and history.mat respectively
% If the above two files are availble in the preference or matlab path, shortcuts.xml is not process further (reads directly
% from shortcutsxml.mat). Contrary, since it takes almost no time to process the history file, the history.mat file is
% created each time
% However, you can update the listbox manually by running commands from the "Shortcuts" uimenu
% For processing xml file, I used xml2struct (Copyright: Jonas Almeida, almeidaj@musc.edu, 19 May 2003, MAT4NAT Tbox)
%     as xml2structr with very little modifications. I added herein, but you could download it from the file exchange seperately from (XML4MAT v2.0)
%          http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=6268&objectType=file
% For the fisr time, it takes little time to load since it process the shortcuts.xml for the first time. When you close
% (first time), you will be prompted to choose the directory to save the processed shortcutsxml.mat file for subsequent
% operation. If you dont save settings to shortcutsxml.mat, it will process the shortcuts.xml on the next startup...
% Save Data Option Only Saves Shortcuts from shortcuts.xml (not from history.m)
% shortstool also works with Standalone version, provided that you include shortcutsxml.mat and history.mat during
% compilation along with shortstool.m
% Right click on the menu listbox item will display selected contents to command window, as well as will copy them to
%    clipboard if java is present
% Double click on the selected item will run the contents in the base workspace (same as RUN pushbutton)
% Use reload button, if to update contents from the history.m file
%
% See also: CREATESHORTCUTSXMLMAT, SAVEHISTORY
% Copyright: Md Rezaul Karim, 2005. Kyoto University, Japan
%  
% ------------ About "shortstool" -------- 
%  
% Author            : Md Rezaul Karim 
% E-mail            : kalosada@gmail.com 
% Author's homepage : http://www.angelfire.com/film/rezaul 
% Date              : 11-Aug-2005 17:41:50  
% Revision          : 3.00  
% Developed using   : 7.0.4.365 (R14) Service Pack 2 
% Filename          : shortstool.m 
%  
% ------------------------------------ 

% Begin initialization code - DO NOT EDIT
% persistent labelf callbackf
% global labelf callbackf
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @shortstool_OpeningFcn, ...
    'gui_OutputFcn',  @shortstool_OutputFcn, ...
    'gui_LayoutFcn',  @shortstool_LayoutFcn, ...
    'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    try
        gui_mainfcn(gui_State, varargin{:});
    catch
        msgbox(lasterr)
    end
end
% End initialization code - DO NOT EDIT


% --- Executes just before shortstool is made visible.
function shortstool_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to shortstool (see VARARGIN)

% Choose default command line output for shortstool
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes shortstool wait for user response (see UIRESUME)
% uiwait(handles.figure1);
ft1 = findobj(handles.figure1,'Label','Shortcuts');
if isempty(ft1),
    EFGMMenu2 = uimenu(handles.figure1,'Label','Shortcuts');
    h31 = EFGMMenu2;
    h32 = uimenu(...
        'Parent',h31,...
        'Callback','createshortcutsxmlmat',...
        'Enable','on',...
        'Label','Update listbox from Shortcut.xml',...
        'Tag','rezamat',...
        'Behavior',get(0,'defaultuimenuBehavior'));
    h33 = uimenu(...
        'Parent',h31,...
        'Callback','savehistory',...
        'Label','Update listbox from history.m',...
        'Tag','rezahlp',...
        'Behavior',get(0,'defaultuimenuBehavior'));
end


% --- Outputs from this function are returned to the command line.
function varargout = shortstool_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

% labelf(1)
% callbackf

if ~isappdata(0,'labelfu')
    %if isdeployed,error('shortstool uses xml_load, which can''t be run in complied mode');end
    if ~isdeployed
        xmll = which('shortcutsxml.mat');
        if isempty(xmll)
            setdira = prefdir;
            if isempty(setdira),delete(handles.figure1);return,end
            setdir = char(setdira);
            xmll = fullfile(setdir,'shortcutsxml.mat');
            %if ~exist(xmll, 'file'),disp('The Default Shortcut File ''shortcuts.xml'' is not Found!');delete(handles.figure1);return,end
        end
        %{
        if exist(xmll,'file')% == 2
        %xmll = which('shortcutsxml.mat');
        a=dir(xmll);an = datenum(a.date);
        xml = which('shortcuts.xml');
        if isempty(xml)
        setdira = prefdir;
        if isempty(setdira),delete(handles.figure1);return,end
        setdir = char(setdira);
        xml = fullfile(setdir,'shortcuts.xml');
        if ~exist(xml, 'file'),disp('The Default Shortcut File ''shortcuts.xml'' is not Found!');delete(handles.figure1);return,end
        end
        if isempty(xml),disp('The Default Shortcut File ''shortcuts.xml'' is not Found!');delete(handles.figure1);return,end
        b=dir(xml);bn = datenum(b.date);
        if an >=bn
        load(xmll);
        tui = 1;
        if ~exist('labelfu','var'),tui = 0;else,setappdata(0,'labelfu',labelfu);end
        else,
        tui = 0;
        end
        else
        tui = 0;
        end
        %}
        if exist(xmll,'file')% == 2
            load(xmll);
            tui = 1;
            if ~exist('labelfu','var'),tui = 0;else,setappdata(0,'labelfu',labelfu);end
        else
            tui = 0;
        end

        if tui == 0
            xml = which('shortcuts.xml');
            if isempty(xml)
                setdira = prefdir;
                if isempty(setdira),delete(handles.figure1);return,end
                setdir = char(setdira);
                xml = fullfile(setdir,'shortcuts.xml');
                if ~exist(xml, 'file'),disp('The Default Shortcut File ''shortcuts.xml'' is not Found!');delete(handles.figure1);return,end
            end
            if isempty(xml),disp('The Default Shortcut File ''shortcuts.xml'' is not Found!');delete(handles.figure1);return,end
            %xml='C:\Download\xmltoolbox\shortcuts.xml';
            disp('Processing Shortcuts.xml File for the Current MATLAB Session. Please wait....')
            %a=xml_load(xml);
            a = xml2structr(xml);
            at = {a.title};
            af = {a.FAVORITECATEGORY};
            labelf = {};
            callbackf = {};
            for i = 1:length(at)
                titlea = at{i};
                FAVORITECATEGORYa = af{i};
                namea = {FAVORITECATEGORYa.name};
                if isfield(FAVORITECATEGORYa,'FAVORITE')
                    FAVORITEa = {FAVORITECATEGORYa.FAVORITE};
                    for j = 1:length(FAVORITEa)
                        labela = FAVORITEa{j}.label;
                        callbacka = FAVORITEa{j}.callback;
                        labelf{end+1,1} = labela;
                        callbackf{end+1,1} = callbacka;
                    end
                end
            end
            setappdata(0,'labelfu',[labelf callbackf]);
            labelfu = [labelf callbackf];
            disp('Done...')
        end
    else
        if exist('shortcutsxml.mat','file'),load('shortcutsxml.mat');else,disp('The shortcutsxml.mat file is NOT found!');delete(handles.figure1);return,end
        if ~exist('labelfu','var'),disp('Variable labelfu is NOT found in the shortcutsxml.mat!');delete(handles.figure1);return,else,setappdata(0,'labelfu',labelfu);end
    end
else
    labelfu = getappdata(0,'labelfu');
end

set(handles.figure1,'userdata',labelfu)
set(handles.listbox1,'String',labelfu(:,1))

function listbox1_Callback(hObject, eventdata, handles)
labelfu = get(handles.figure1,'userdata');
% set(listbox1,'String',A(1))
% a = get(handles.listbox1,'String');
b = get(handles.listbox1,'Value');
c  = labelfu{b(1),2};
for i = 2:length(b)
    c  = [c ',' labelfu{b(i),2}];
end
%c
set(handles.text1,'String',c);
set(handles.pushbutton1,'userdata',c);
set(handles.listbox1,'TooltipString',c);

get(handles.figure1,'SelectionType');

if strcmp(get(handles.figure1,'SelectionType'),'open')
    pushbutton1_Callback(hObject, eventdata, handles)
end
% evalin('base',c)
% if strcmp(get(handles.listbox1,'SelectionType'),'open')
%     fprintfr([tempdir 'hizitmp.m'],c,'%c')
%['run(''' tempdir 'hizitmp.m'')']
%     eval(['run(''' tempdir 'hizitmp.m'')'])
%     deleter([tempdir 'hizitmp.m'])
% end

function listbox1_CreateFcn(hObject, eventdata, handles)

% Hint: listbox controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end




function pushbutton1_Callback(hObject, eventdata, handles)
c = get(handles.pushbutton1,'userdata');
if isempty(c),return,end
% evalin('base',c)
try
    evalin('base',c)
    %rezamatupdate
    set(handles.text3,'String','MATLAB Shortcut Browser');
    set(handles.text3,'ToolTipString','Ready For Next Command');
catch
    set(handles.text3,'String',lasterr);
    set(handles.text3,'ToolTipString',lasterr);
end




function pushbutton3_Callback(hObject, eventdata, handles)
labelfu = get(handles.figure1,'userdata');
dirn = uigetdir; if dirn == 0,return,end
save([dirn '\shortcutsxml.mat'],'labelfu')



function runnn_Callback(hObject, eventdata, handles)
% pushbutton1_Callback(hObject, eventdata, handles)
c = get(handles.pushbutton1,'userdata');
if isempty(c),return,end
% fprintf('%c',c)
try
    if usejava('jvm')
        clipboard('copy',c)
        disp(c)
    else
        disp(c)
    end
catch
    set(handles.text3,'String',lasterr);
    set(handles.text3,'ToolTipString',lasterr);
end

% if isjvm
%     clipbcopy(c)
%     disp(c)
% else
%     disp(c)
% end
% clipbcopy(c)
% commandwindow
% clipbpaste

function quit_Callback(hObject, eventdata, handles)
xmll = which('shortcutsxml.mat');
if isempty(xmll)
    setdira = prefdir;
    if isempty(setdira),delete(handles.figure1);return,end
    setdir = char(setdira);
    xmll = fullfile(setdir,'shortcutsxml.mat');
    %if ~exist(xmll, 'file'),disp('The Default Shortcut File ''shortcuts.xml'' is not Found!');delete(handles.figure1);return,end
end
if ~exist(xmll,'file')
    pushbutton3_Callback(hObject, eventdata, handles)
end
delete(handles.figure1)
% closereq




function checkbox1_Callback(hObject, eventdata, handles)
if get(handles.checkbox1,'Value') == 1
    set(handles.checkbox2,'Value',0);
    if ~isappdata(0,'labelfu')
        %if isdeployed,error('shortstool uses xml_load, which can''t be run in complied mode');end
        if ~isdeployed
            xmll = which('shortcutsxml.mat');
            if isempty(xmll)
                setdira = prefdir;
                if isempty(setdira),delete(handles.figure1);return,end
                setdir = char(setdira);
                xmll = fullfile(setdir,'shortcutsxml.mat');
                %if ~exist(xmll, 'file'),disp('The Default Shortcut File ''shortcuts.xml'' is not Found!');delete(handles.figure1);return,end
            end
            %{
            if exist(xmll,'file')% == 2
            %xmll = which('shortcutsxml.mat');
            a=dir(xmll);an = datenum(a.date);
            xml = which('shortcuts.xml');
            if isempty(xml)
            setdira = prefdir;
            if isempty(setdira),delete(handles.figure1);return,end
            setdir = char(setdira);
            xml = fullfile(setdir,'shortcuts.xml');
            if ~exist(xml, 'file'),disp('The Default Shortcut File ''shortcuts.xml'' is not Found!');delete(handles.figure1);return,end
            end
            if isempty(xml),disp('The Default Shortcut File ''shortcuts.xml'' is not Found!');delete(handles.figure1);return,end
            b=dir(xml);bn = datenum(b.date);
            if an >=bn
            load(xmll);
            tui = 1;
            if ~exist('labelfu','var'),tui = 0;else,setappdata(0,'labelfu',labelfu);end
            else,
            tui = 0;
            end
            else
            tui = 0;
            end
            %}
            if exist(xmll,'file')% == 2
                load(xmll);
                tui = 1;
                if ~exist('labelfu','var'),tui = 0;else,setappdata(0,'labelfu',labelfu);end
            else
                tui = 0;
            end

            if tui == 0
                xml = which('shortcuts.xml');
                if isempty(xml)
                    setdira = prefdir;
                    if isempty(setdira),delete(handles.figure1);return,end
                    setdir = char(setdira);
                    xml = fullfile(setdir,'shortcuts.xml');
                    if ~exist(xml, 'file'),disp('The Default Shortcut File ''shortcuts.xml'' is not Found!');delete(handles.figure1);return,end
                end
                if isempty(xml),disp('The Default Shortcut File ''shortcuts.xml'' is not Found!');delete(handles.figure1);return,end
                %xml='C:\Download\xmltoolbox\shortcuts.xml';
                disp('Processing Shortcuts.xml File for the Current MATLAB Session. Please wait....')
                %a=xml_load(xml);
                a = xml2structr(xml);
                at = {a.title};
                af = {a.FAVORITECATEGORY};
                labelf = {};
                callbackf = {};
                for i = 1:length(at)
                    titlea = at{i};
                    FAVORITECATEGORYa = af{i};
                    namea = {FAVORITECATEGORYa.name};
                    if isfield(FAVORITECATEGORYa,'FAVORITE')
                        FAVORITEa = {FAVORITECATEGORYa.FAVORITE};
                        for j = 1:length(FAVORITEa)
                            labela = FAVORITEa{j}.label;
                            callbacka = FAVORITEa{j}.callback;
                            labelf{end+1,1} = labela;
                            callbackf{end+1,1} = callbacka;
                        end
                    end
                end
                setappdata(0,'labelfu',[labelf callbackf]);
                labelfu = [labelf callbackf];
                disp('Done...')
            end
        else
            if exist('shortcutsxml.mat','file'),load('shortcutsxml.mat');else,disp('The shortcutsxml.mat file is NOT found!');delete(handles.figure1);return,end
            if ~exist('labelfu','var'),disp('Variable labelfu is NOT found in the shortcutsxml.mat!');delete(handles.figure1);return,else,setappdata(0,'labelfu',labelfu);end
        end
    else
        labelfu = getappdata(0,'labelfu');
    end
    set(handles.figure1,'userdata',labelfu)
    set(handles.listbox1,'String',labelfu(:,1))
    set(handles.listbox1,'Value',1)
    set(handles.text1,'String',labelfu{1,2});
    set(handles.pushbutton1,'userdata',labelfu{1,2});
    set(handles.listbox1,'TooltipString',labelfu{1,2});
    set(handles.text3,'String','MATLAB Shortcut Browser');
    set(handles.text3,'ToolTipString','Ready For Next Command');
    %else
    %    set(handles.checkbox1,'Value') == 1
end

function checkbox2_Callback(hObject, eventdata, handles)
if get(handles.checkbox2,'Value') == 1
    set(handles.checkbox1,'Value',0);
    if ~isappdata(0,'labelfuhis')
        %if isdeployed,error('shortstool uses xml_load, which can''t be run in complied mode');end
        if ~isdeployed
            %{
            xmll = which('history.mat');
            if isempty(xmll)
                setdira = prefdir;
                if isempty(setdira),return,end
                setdir = char(setdira);
                xmll = fullfile(setdir,'history.mat');
                %if ~exist(xmll, 'file'),disp('The Default Shortcut File ''shortcuts.xml'' is not Found!');delete(handles.figure1);return,end
            end
            if exist(xmll,'file')% == 2
                load(xmll);
                tui = 1;
                if ~exist('labelfuhis','var'),tui = 0;else,setappdata(0,'labelfuhis',labelfuhis);end
            else
                tui = 0;
            end
            %}
            tui = 0;
            if tui == 0
                xml = which('history.m');
                if isempty(xml)
                    setdira = prefdir;
                    if isempty(setdira),return,end
                    setdir = char(setdira);
                    xml = fullfile(setdir,'history.m');
                    if ~exist(xml, 'file'),disp('The Default history File ''history.m'' is not Found!');return,end
                end
                if isempty(xml),disp('The Default history File ''history.m'' is not Found!');return,end
                xml = savehistory('',prefdir);
                load(xml);
                setappdata(0,'labelfuhis',labelfuhis);
            end
        else
            if exist('history.mat','file'),load('history.mat');else,disp('The history.mat file is NOT found!');return,end
            if ~exist('labelfuhis','var'),disp('Variable labelfuhis is NOT found in the history.mat!');return,else,setappdata(0,'labelfuhis',labelfuhis);end
        end
    else
        labelfuhis = getappdata(0,'labelfuhis');
    end
    set(handles.figure1,'userdata',labelfuhis)
    set(handles.listbox1,'String',labelfuhis(:,1))
    set(handles.listbox1,'Value',1)
    set(handles.text1,'String',labelfuhis{1,2});
    set(handles.pushbutton1,'userdata',labelfuhis{1,2});
    set(handles.listbox1,'TooltipString',labelfuhis{1,2});
    set(handles.text3,'String','MATLAB Shortcut Browser');
    set(handles.text3,'ToolTipString','Ready For Next Command');
end



function pushbutton4_Callback(hObject, eventdata, handles)
if isappdata(0,'labelfu'),rmappdata(0,'labelfu');end
if isappdata(0,'labelfuhis'),rmappdata(0,'labelfuhis');end
% set(handles.figure1,'CloseRequestFcn','closereq');
set(handles.figure1,'CloseRequestFcn','');
% close(handles.figure1);
delete(handles.figure1)
shortstool



% --- Creates and returns a handle to the GUI figure. 
function h1 = shortstool_LayoutFcn(policy)
% policy - create a new figure or use a singleton. 'new' or 'reuse'.

persistent hsingleton;
if strcmpi(policy, 'reuse') & ishandle(hsingleton)
    h1 = hsingleton;
    return;
end

appdata = [];
appdata.GUIDEOptions = struct(...
    'active_h', [], ...
    'taginfo', struct(...
    'figure', 2, ...
    'listbox', 2, ...
    'text', 4, ...
    'pushbutton', 5, ...
    'checkbox', 3), ...
    'override', 1, ...
    'release', 13, ...
    'resize', 'none', ...
    'accessibility', 'off', ...
    'mfile', 1, ...
    'callbacks', 1, ...
    'singleton', 1, ...
    'syscolorfig', 1, ...
    'blocking', 0, ...
    'lastSavedFile', 'D:\shortstool.m');
appdata.lastValidTag = 'figure1';
appdata.GUIDELayoutEditor = [];

h1 = figure(...
'PaperUnits',get(0,'defaultfigurePaperUnits'),...
'CloseRequestFcn','shortstool(''quit_Callback'',gcbo,[],guidata(gcbo))',...
'Color',[0.87843137254902 0.866666666666667 0.831372549019608],...
'Colormap',[0 0 0.5625;0 0 0.625;0 0 0.6875;0 0 0.75;0 0 0.8125;0 0 0.875;0 0 0.9375;0 0 1;0 0.0625 1;0 0.125 1;0 0.1875 1;0 0.25 1;0 0.3125 1;0 0.375 1;0 0.4375 1;0 0.5 1;0 0.5625 1;0 0.625 1;0 0.6875 1;0 0.75 1;0 0.8125 1;0 0.875 1;0 0.9375 1;0 1 1;0.0625 1 1;0.125 1 0.9375;0.1875 1 0.875;0.25 1 0.8125;0.3125 1 0.75;0.375 1 0.6875;0.4375 1 0.625;0.5 1 0.5625;0.5625 1 0.5;0.625 1 0.4375;0.6875 1 0.375;0.75 1 0.3125;0.8125 1 0.25;0.875 1 0.1875;0.9375 1 0.125;1 1 0.0625;1 1 0;1 0.9375 0;1 0.875 0;1 0.8125 0;1 0.75 0;1 0.6875 0;1 0.625 0;1 0.5625 0;1 0.5 0;1 0.4375 0;1 0.375 0;1 0.3125 0;1 0.25 0;1 0.1875 0;1 0.125 0;1 0.0625 0;1 0 0;0.9375 0 0;0.875 0 0;0.8125 0 0;0.75 0 0;0.6875 0 0;0.625 0 0;0.5625 0 0],...
'DockControls','off',...
'IntegerHandle','off',...
'InvertHardcopy',get(0,'defaultfigureInvertHardcopy'),...
'MenuBar','none',...
'Name','Shortcut Browser',...
'NextPlot','new',...
'NumberTitle','off',...
'PaperOrientation',get(0,'defaultfigurePaperOrientation'),...
'PaperPosition',[0.25 2.5 8 6],...
'PaperPositionMode',get(0,'defaultfigurePaperPositionMode'),...
'PaperSize',[8.267716 11.692913],...
'PaperType',get(0,'defaultfigurePaperType'),...
'Position',[1224 428 255 433],...
'Resize','off',...
'WindowStyle','normal',...
'HandleVisibility','off',...
'Tag','figure1',...
'UserData',[],...
'Behavior',get(0,'defaultfigureBehavior'),...
'Visible','on',...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'listbox1';

h2 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'BackgroundColor',[1 1 1],...
'Callback','shortstool(''listbox1_Callback'',gcbo,[],guidata(gcbo))',...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'Max',10,...
'Position',[0.0196078431372549 0.0669745958429561 0.592156862745098 0.879907621247113],...
'String','',...
'Style','listbox',...
'Value',1,...
'CreateFcn', {@local_CreateFcn, 'shortstool(''listbox1_CreateFcn'',gcbo,[],guidata(gcbo))', appdata} ,...
'Tag','listbox1',...
'Behavior',get(0,'defaultuicontrolBehavior'));

appdata = [];
appdata.lastValidTag = 'text1';

h3 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'Position',[0.623529411764706 0.284064665127021 0.352941176470587 0.517321016166282],...
'String','',...
'Style','text',...
'Tag','text1',...
'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'text2';

h4 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'FontWeight','bold',...
'ForegroundColor',[0.501960784313725 0 0],...
'Position',[0.192156862745097 0.951501154734411 0.211764705882353 0.0369515011547344],...
'String','Menu',...
'Style','text',...
'Tag','text2',...
'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'text3';

h5 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',9,...
'ForegroundColor',[0 0 1],...
'Position',[0.0117647058823529 0.0023094688221709 0.956862745098038 0.0600461893764434],...
'String','MATLAB Shortcut Browser',...
'Style','text',...
'Tag','text3',...
'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'pushbutton1';

h6 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'Callback','shortstool(''pushbutton1_Callback'',gcbo,[],guidata(gcbo))',...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'FontWeight','bold',...
'ForegroundColor',[0.250980392156863 0 0.501960784313725],...
'Position',[0.690196078431373 0.207852193995381 0.254901960784314 0.0623556581986143],...
'String','RUN',...
'Tag','pushbutton1',...
'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'pushbutton3';

h7 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'Callback','shortstool(''pushbutton3_Callback'',gcbo,[],guidata(gcbo))',...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'Position',[0.686274509803921 0.829099307159353 0.231372549019608 0.0554272517321016],...
'String','Save Data',...
'TooltipString','Save Shortcut Information To be used in Compiled Application or Later',...
'Tag','pushbutton3',...
'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'runnn';

h8 = uicontextmenu(...
'Parent',h1,...
'Callback','shortstool(''runnn_Callback'',gcbo,[],guidata(gcbo))',...
'Tag','runnn',...
'Behavior',get(0,'defaultuicontextmenuBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'checkbox1';

h9 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'Callback','shortstool(''checkbox1_Callback'',gcbo,[],guidata(gcbo))',...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'Position',[0.647058823529412 0.946882217090069 0.270588235294118 0.0369515011547344],...
'String','Shortcuts',...
'Style','checkbox',...
'Value',1,...
'Tag','checkbox1',...
'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'checkbox2';

h10 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'Callback','shortstool(''checkbox2_Callback'',gcbo,[],guidata(gcbo))',...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'Position',[0.725490196078431 0.905311778290993 0.250980392156863 0.0369515011547344],...
'String','History',...
'Style','checkbox',...
'Tag','checkbox2',...
'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

appdata = [];
appdata.lastValidTag = 'pushbutton4';

h11 = uicontrol(...
'Parent',h1,...
'Units','normalized',...
'Callback','shortstool(''pushbutton4_Callback'',gcbo,[],guidata(gcbo))',...
'FontName',get(0,'defaultuicontrolFontName'),...
'FontSize',get(0,'defaultuicontrolFontSize'),...
'Position',[0.650980392156863 0.1270207852194 0.176470588235294 0.0554272517321016],...
'String','Reload',...
'Tag','pushbutton4',...
'Behavior',get(0,'defaultuicontrolBehavior'),...
'CreateFcn', {@local_CreateFcn, '', appdata} );

handles = [ h2 ];
set(handles, 'uicontextmenu', h8);


hsingleton = h1;


% --- Set application data first then calling the CreateFcn. 
function local_CreateFcn(hObject, eventdata, createfcn, appdata)

if ~isempty(appdata)
   names = fieldnames(appdata);
   for i=1:length(names)
       name = char(names(i));
       setappdata(hObject, name, getfield(appdata,name));
   end
end

if ~isempty(createfcn)
   eval(createfcn);
end


% --- Handles default GUIDE GUI creation and callback dispatch
function varargout = gui_mainfcn(gui_State, varargin)


%   GUI_MAINFCN provides these command line APIs for dealing with GUIs
%
%      SHORTSTOOL, by itself, creates a new SHORTSTOOL or raises the existing
%      singleton*.
%
%      H = SHORTSTOOL returns the handle to a new SHORTSTOOL or the handle to
%      the existing singleton*.
%
%      SHORTSTOOL('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in SHORTSTOOL.M with the given input arguments.
%
%      SHORTSTOOL('Property','Value',...) creates a new SHORTSTOOL or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to untitled_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".

%   Copyright 1984-2004 The MathWorks, Inc.
%   $Revision: 1.4.6.10.2.1 $ $Date: 2005/01/14 21:54:21 $

gui_StateFields =  {'gui_Name'
                    'gui_Singleton'
                    'gui_OpeningFcn'
                    'gui_OutputFcn'
                    'gui_LayoutFcn'
                    'gui_Callback'};
gui_Mfile = '';
for i=1:length(gui_StateFields)
    if ~isfield(gui_State, gui_StateFields{i})
        error('Could not find field %s in the gui_State struct in GUI M-file %s', gui_StateFields{i}, gui_Mfile);        
    elseif isequal(gui_StateFields{i}, 'gui_Name')
        gui_Mfile = [gui_State.(gui_StateFields{i}), '.m'];
    end
end

numargin = length(varargin);

if numargin == 0
    % SHORTSTOOL
    % create the GUI
    gui_Create = 1;
elseif isequal(ishandle(varargin{1}), 1) && ispc && iscom(varargin{1}) && isequal(varargin{1},gcbo)
    % SHORTSTOOL(ACTIVEX,...)    
    vin{1} = gui_State.gui_Name;
    vin{2} = [get(varargin{1}.Peer, 'Tag'), '_', varargin{end}];
    vin{3} = varargin{1};
    vin{4} = varargin{end-1};
    vin{5} = guidata(varargin{1}.Peer);
    feval(vin{:});
    return;
elseif ischar(varargin{1}) && numargin>1 && isequal(ishandle(varargin{2}), 1)
    % SHORTSTOOL('CALLBACK',hObject,eventData,handles,...)
    gui_Create = 0;
else
    % SHORTSTOOL(...)
    % create the GUI and hand varargin to the openingfcn
    gui_Create = 1;
end

if gui_Create == 0
    varargin{1} = gui_State.gui_Callback;
    if nargout
        [varargout{1:nargout}] = feval(varargin{:});
    else
        feval(varargin{:});
    end
else
    if gui_State.gui_Singleton
        gui_SingletonOpt = 'reuse';
    else
        gui_SingletonOpt = 'new';
    end
    
    % Open fig file with stored settings.  Note: This executes all component
    % specific CreateFunctions with an empty HANDLES structure.
    
    % Do feval on layout code in m-file if it exists
    if ~isempty(gui_State.gui_LayoutFcn)
        gui_hFigure = feval(gui_State.gui_LayoutFcn, gui_SingletonOpt);
        % openfig (called by local_openfig below) does this for guis without
        % the LayoutFcn. Be sure to do it here so guis show up on screen.
        movegui(gui_hFigure,'onscreen')
    else
        gui_hFigure = local_openfig(gui_State.gui_Name, gui_SingletonOpt);            
        % If the figure has InGUIInitialization it was not completely created
        % on the last pass.  Delete this handle and try again.
        if isappdata(gui_hFigure, 'InGUIInitialization')
            delete(gui_hFigure);
            gui_hFigure = local_openfig(gui_State.gui_Name, gui_SingletonOpt);            
        end
    end
    
    % Set flag to indicate starting GUI initialization
    setappdata(gui_hFigure,'InGUIInitialization',1);

    % Fetch GUIDE Application options
    gui_Options = getappdata(gui_hFigure,'GUIDEOptions');
    
    if ~isappdata(gui_hFigure,'GUIOnScreen')
        % Adjust background color
        if gui_Options.syscolorfig 
            set(gui_hFigure,'Color', get(0,'DefaultUicontrolBackgroundColor'));
        end

        % Generate HANDLES structure and store with GUIDATA. If there is
        % user set GUI data already, keep that also.
        data = guidata(gui_hFigure);
        handles = guihandles(gui_hFigure);
        if ~isempty(handles)
            if isempty(data)
                data = handles;
            else
                names = fieldnames(handles);
                for k=1:length(names)
                    data.(char(names(k)))=handles.(char(names(k)));
                end
            end
        end
        guidata(gui_hFigure, data);
    end
    
    % If user specified 'Visible','off' in p/v pairs, don't make the figure
    % visible.
    gui_MakeVisible = 1;
    for ind=1:2:length(varargin)
        if length(varargin) == ind
            break;
        end
        len1 = min(length('visible'),length(varargin{ind}));
        len2 = min(length('off'),length(varargin{ind+1}));
        if ischar(varargin{ind}) && ischar(varargin{ind+1}) && ...
                strncmpi(varargin{ind},'visible',len1) && len2 > 1
            if strncmpi(varargin{ind+1},'off',len2)
                gui_MakeVisible = 0;
            elseif strncmpi(varargin{ind+1},'on',len2)
                gui_MakeVisible = 1;
            end
        end
    end
    
    % Check for figure param value pairs
    for index=1:2:length(varargin)
        if length(varargin) == index || ~ischar(varargin{index})
            break;
        end
        try set(gui_hFigure, varargin{index}, varargin{index+1}), catch break, end
    end

    % If handle visibility is set to 'callback', turn it on until finished
    % with OpeningFcn
    gui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
    if strcmp(gui_HandleVisibility, 'callback')
        set(gui_hFigure,'HandleVisibility', 'on');
    end
    
    feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
    
    if ishandle(gui_hFigure)
        % Update handle visibility
        set(gui_hFigure,'HandleVisibility', gui_HandleVisibility);
        
        % Make figure visible
        if gui_MakeVisible
            set(gui_hFigure, 'Visible', 'on')
            if gui_Options.singleton 
                setappdata(gui_hFigure,'GUIOnScreen', 1);
            end
        end

        % Done with GUI initialization
        rmappdata(gui_hFigure,'InGUIInitialization');
    end
    
    % If handle visibility is set to 'callback', turn it on until finished with
    % OutputFcn
    if ishandle(gui_hFigure)
        gui_HandleVisibility = get(gui_hFigure,'HandleVisibility');
        if strcmp(gui_HandleVisibility, 'callback')
            set(gui_hFigure,'HandleVisibility', 'on');
        end
        gui_Handles = guidata(gui_hFigure);
    else
        gui_Handles = [];
    end
    
    if nargout
        [varargout{1:nargout}] = feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
    else
        feval(gui_State.gui_OutputFcn, gui_hFigure, [], gui_Handles);
    end
    
    if ishandle(gui_hFigure)
        set(gui_hFigure,'HandleVisibility', gui_HandleVisibility);
    end
end    

function gui_hFigure = local_openfig(name, singleton)

% this application data is used to indicate the running mode of a GUIDE
% GUI to distinguish it from the design mode of the GUI in GUIDE.
setappdata(0,'OpenGuiWhenRunning',1);

% openfig with three arguments was new from R13. Try to call that first, if
% failed, try the old openfig.
try 
    gui_hFigure = openfig(name, singleton, 'auto');
catch
    % OPENFIG did not accept 3rd input argument until R13,
    % toggle default figure visible to prevent the figure
    % from showing up too soon.
    gui_OldDefaultVisible = get(0,'defaultFigureVisible');
    set(0,'defaultFigureVisible','off');
    gui_hFigure = openfig(name, singleton);
    set(0,'defaultFigureVisible',gui_OldDefaultVisible);
end
rmappdata(0,'OpenGuiWhenRunning');

Contact us at files@mathworks.com