image thumbnail

Pre-R2012b Zoom Keyboard Shortcuts

by

 

26 Jun 2013 (Updated )

Enables use of r, v, 1, anf f as keyboard shortcut keys for zooming in Simulink

sl_customization(cm)
% Mike Anthony
% Copyright (c) 2013, The MathWorks, Inc.
% All rights reserved.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are
% met:
%
%     * Redistributions of source code must retain the above copyright
%       notice, this list of conditions and the following disclaimer.
%     * Redistributions in binary form must reproduce the above copyright
%       notice, this list of conditions and the following disclaimer in
%       the documentation and/or other materials provided with the distribution
%     * Neither the name of the The MathWorks, Inc. nor the names
%       of its contributors may be used to endorse or promote products derived
%       from this software without specific prior written permission.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% POSSIBILITY OF SUCH DAMAGE.
%
% Place this file somewhere on your MATLAB path and run the command
% sl_refresh_customizations
%
function sl_customization(cm)

    %% Register custom menu function.
    cm.addCustomMenuFcn('Simulink:ViewMenu', @getMyMenuItems);
end

%% Define the custom menu function.
function schemaFcns = getMyMenuItems(callbackInfo)
    schemaFcns = {@getCustomSubMenu};
end
function schema = getCustomSubMenu(callbackInfo)
    schema = sl_container_schema;
    schema.label = 'Retro Zoom';
    schema.state = 'Enabled'; %Enabled, Disabled, Hidden
    schema.childrenFcns = {@ZoomInSchema, @ZoomOutSchema, @NormalZoomSchema, @FitZoomSchema};
end

%% Define the schema function for Zoom In
function schema = ZoomInSchema(callbackInfo)
    schema = sl_action_schema;
    schema.label = 'Retro Zoom In';
    schema.userdata = 'Retro Zoom In';
    schema.accelerator = 'r';
    schema.callback = @ZoomInCallback;
end

function ZoomInCallback(callbackInfo)
    z = get_param(gcs,'ZoomFactor');
    z = num2str(round(str2num(z)*1.25)); % 25% zoom in factor
    set_param(gcs,'ZoomFactor',z);
    Simulink.scrollToVisible(gcb);
end

%% Define the custom menu function for Zoom Out
function schema = ZoomOutSchema(callbackInfo)
    schema = sl_action_schema;
    schema.label = 'Retro Zoom Out';
    schema.userdata = 'Retro Zoom Out';
    schema.accelerator = 'v';
    schema.callback = @ZoomOutCallback;
end

function ZoomOutCallback(callbackInfo)
    z = get_param(gcs,'ZoomFactor');
    z = num2str(round(str2num(z)*0.75)); % 25% zoom out factor
    set_param(gcs,'ZoomFactor',z);
end

%% Define the custom menu function for Zoom 100%
function schema = NormalZoomSchema(callbackInfo)
    schema = sl_action_schema;
    schema.label = 'Retro Normal View (100%)';
    schema.userdata = 'Retro Normal View (100%)';
    schema.accelerator = '1';
    schema.callback = @NormalZoomCallback;
end

function NormalZoomCallback(callbackInfo)
    set_param(gcs,'ZoomFactor','100');
end

%% Define the custom menu function for Zoom 100%
function schema = FitZoomSchema(callbackInfo)
    schema = sl_action_schema;
    schema.label = 'Retro Normal View (100%)';
    schema.userdata = 'Retro Normal View (100%)';
    schema.accelerator = 'f';
    schema.callback = @FitZoomCallback;
end

function FitZoomCallback(callbackInfo)
    set_param(gcs,'ZoomFactor','1000');
    Simulink.scrollToVisible(gcb);
end

Contact us