No BSD License  

Highlights from
fitpath

image thumbnail
from fitpath by Erik Newton
Gracefully truncate a file path to fit into uicontrols.

demo.m
% Demo script for fitpath.m
%
% Example:
%   demo
%
% Will bring up the demonstration GUI. Click on the button, browse for a file with
% a long path and see it truncated in the GUI. Don't worry it won't do anything
% with the actual file.

%=================================================================================
%
%        AUTHOR: Erik Newton (Newtek Software Ltd)
%
%           WEB: www.newteksoftware.co.uk
%
%	Copyright Newtek Software Ltd 2006
%
% This function is free for all use, but please leave in my credit.
% Check out more tutorials & functions at our website.
%
%==================================================================================

h_figure = figure(...
   'Name','fitpath demo', ...
   'MenuBar','none', ...
   'NumberTitle','Off', ...
   'Position',[50 50 260 30], ...
   'Resize','Off');

LABEL_BACK = get(h_figure,'Color');

% Init filename
uicontrol(h_figure, ...
   'BackgroundColor',LABEL_BACK, ...
   'Position', [5 5 30 18], ...
   'Horizontal', 'Right', ...
   'String','File:', ...
   'Style','text');
h_filename = uicontrol(h_figure, ...
   'BackgroundColor',LABEL_BACK, ...
   'Position',[35 5 200 18], ...
   'Horizontal', 'Left', ...
   'Style','text', ...
   'Tag','InitFilename');
uicontrol(h_figure, ...
   'Position', [235 5 20 18], ...
   'Horizontal', 'Center', ...
   ...'Callback', '[init_file,new_path]=uigetfile; set(h_filename,''string'',fullfile(new_path,init_file));', ...
   'Callback', '[init_file,new_path]=uigetfile; fitpath(h_filename,fullfile(new_path,init_file));', ...
   'String','...', ...
   'TooltipString', 'Select file.', ...
   'Style','PushButton');

%==================================================================================

Contact us at files@mathworks.com