So, I semi answered my own question, but not with the answer that I really want. This is passable as a workaround, but not desireable. The reasons this still sucks are:
- cannot use "undo"
- have to set a separate menu to get keyboard shortcut to function, but that will be removed in future release, and it sticks that extra menu on your diagram toolstip
- extra menu, not under the "format" section where it should be
- cannot right click and hit single button or series of buttons because you can't apply a quick key letter to context menu items.
But, if you're like me and really don't want to use the toolstrip and like the context menu route, this works for now.
Create custom context menu with keyboard shortcuts by generating an sl_customization (see this help here for referece)
function sl_customization(cm)
% register custom menu functions
cm.addCustomMenuFcn('Simulink:ContextMenu',@getMyMenuItems)
cm.addCustomMenuFcn('Simulink:DiagramMenu',@getMyMenuItems) % This is here to make keyboard shortucts work
end
%% Define the custom menu function for sizes
function schemaFcns = getMyMenuItems(callbackInfo)
% Make it context dependant, and only show if multiple blocks selected
if length(find_system(gcs,'FindAll','on','SearchDepth',1,'Type','block','Selected','on')) > 2
schemaFcns = {@matchSizeMenu, ...
@matchHeightMenu, ...
@matchWidthMenu};
else
schemaFcns = {};
end
end
% Menu Schema for match size
function schema = matchSizeMenu(callbackInfo)
schema = sl_action_schema;
schema.label = 'Match Block Size';
schema.userdata = 'size';
schema.callback = @matchSize;
schema.accelerator = 'Ctrl+Alt+S'; % This works because the "DiagramMenu" above, but help says "to be removed"
end
% Menu Schema for match height
function schema = matchHeightMenu(callbackInfo)
schema = sl_action_schema;
schema.label = 'Match Block Height';
schema.userdata = 'height';
schema.callback = @matchSize;
schema.accelerator = 'Ctrl+Alt+H';
end
% Menu Schema for match width
function schema = matchWidthMenu(callbackInfo)
schema = sl_action_schema;
schema.label = 'Match Block Width';
schema.userdata = 'width';
schema.callback = @matchSize;
schema.accelerator = 'Ctrl+Alt+W';
end
% Function to match the size of the selected blocks based on the calling menu
function matchSize(callbackInfo)
% Get the selected block position
pos = get(gcbh,'Position');
sz = [pos(3)-pos(1), pos(4)-pos(2)]; % get the block size
% Find the rest of the selected blocks in this current subsystem
blks = find_system(gcs,'FindAll','on','SearchDepth',1,'Type','block','Selected','on');
blks(blks==get_param(gcs,'Handle')) = []; % Drop the parent block (not sure if always first, so find it)
% Check to see if multiple blocks selected
if length(blks) > 1
% Find the position of the selected blocks
pos = get(blks,'Position');
% Loop over the block positions updating to new ones
for n = 1:length(blks)
this = pos{n};
% adjust about the middle
md = [this(3)-this(1),this(4)-this(2)]./2 + [this(1), this(2)];
% Switch the callback type
switch callbackInfo.userdata
case 'size'
this(1) = md(1) - sz(1)/2;
this(3) = md(1) + sz(1)/2;
this(2) = md(2) - sz(2)/2;
this(4) = md(2) + sz(2)/2;
case 'height'
this(2) = md(2) - sz(2)/2;
this(4) = md(2) + sz(2)/2;
case 'width'
this(1) = md(1) - sz(1)/2;
this(3) = md(1) + sz(1)/2;
end
% Restore the updated position
pos{n} = this;
end
% Set the blocks to the new positions all at once
set(blks,{'Position'},pos);
end
end