source: MML/trunk/applications/m2html/mwizard2.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 30.3 KB
Line 
1function mwizard(file)
2%MWIZARD - M2HTML Graphical User Interface
3%  MWIZARD launches a Matlab GUI front-end to edit parameters
4%  that are then used by M2HTML to generate HTML documentation.
5%  MWIZARD(FILE) allows to specify a mat-file FILE from which
6%  default parameters are extracted and can be updated. 
7%
8%  For more information, please read the M2HTML tutorial and FAQ at:
9%    <http://www.artefact.tk/software/matlab/m2html/>
10%
11%  See also M2HTML
12
13%  Copyright (C) 2004 Guillaume Flandin <Guillaume@artefact.tk>
14%  $Revision: 0.5 $Date: 2004/05/24 20:12:17 $
15
16%  This program is free software; you can redistribute it and/or
17%  modify it under the terms of the GNU General Public License
18%  as published by the Free Software Foundation; either version 2
19%  of the License, or any later version.
20%
21%  This program is distributed in the hope that it will be useful,
22%  but WITHOUT ANY WARRANTY; without even the implied warranty of
23%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24%  GNU General Public License for more details.
25%
26%  You should have received a copy of the GNU General Public License
27%  along with this program; if not, write to the Free Software
28%  Foundation Inc, 59 Temple Pl. - Suite 330, Boston, MA 02111-1307, USA.
29
30%  Suggestions for improvement and fixes are always welcome, although no
31%  guarantee is made whether and when they will be implemented.
32%  Send requests to Guillaume@artefact.tk
33
34error(nargchk(0,1,nargin));
35
36disp('This is a beta version of mwizard.');
37disp('Please use the online version m2html instead.');
38
39h = initWindow;
40
41initOptions(h);
42
43buildWindow(h);
44
45setappdata(h, 'handles', guihandles(h));
46% M. Krauski
47% setappdata(h, 'pwd',     pwd);
48
49if nargin == 0
50        setappdata(h, 'file', '');
51        setappdata(h, 'needsave', 1);
52else
53        setappdata(h, 'file', file);
54        setappdata(h, 'needsave', 0);
55        opt = load(file, 'options');
56        setappdata(h, 'options', opt.options);
57    refreshOptions(h);
58end
59
60set(h, 'HandleVisibility', 'callback');
61
62%===============================================================================
63
64function h = initWindow
65
66h = figure('Resize',      'on',...
67                   'MenuBar',     'none',...
68                   'NumberTitle', 'off',...
69                   'Name',        ':: M2HTML Wizard ::',...
70                   'Position',    [200 200 500 650],...
71                   'Tag',         mfilename);
72                   
73set(h, 'CloseRequestFcn', {@doClose,h});
74
75%===============================================================================
76
77function buildWindow(h)
78
79wincolor = struct('bg',    [0.9 0.9 0.9], ...
80                  'fg',    [0.8 0.8 0.8], ...
81                  'title', [0.8 0.8 0.9]);
82
83set(h, 'Color', wincolor.bg);
84             
85%-------------------------------------------------------------------------------
86%- Menu
87%-------------------------------------------------------------------------------
88
89icons = load(fullfile(fileparts(which(mfilename)),'private', ...
90            'm2htmltoolbarimages.mat'));
91
92uipushtool('CData',icons.newIcon,...
93        'enable','on',...
94        'Separator','off',...
95        'ToolTipString','New File',...
96        'ClickedCallback',{@doNewFile,h},...
97        'Tag','NewTool');
98
99uipushtool('CData',icons.openIcon,...
100        'enable','on',...
101        'Separator','off',...
102        'ToolTipString','Open File',...
103        'ClickedCallback',{@doOpenFile,h},...
104        'Tag','OpenTool');
105
106uipushtool('CData',icons.saveIcon,...
107        'enable','on',...
108        'Separator','off',...
109        'ToolTipString','Save File',...
110        'ClickedCallback',{@doSaveFile,h},...
111        'Tag','SaveTool');
112
113uipushtool('CData',icons.saveAsIcon,...
114        'enable','on',...
115        'Separator','off',...
116        'ToolTipString','Save File As',...
117        'ClickedCallback',{@doSaveAsFile,h},...
118        'Tag','SaveAsTool');
119       
120uipushtool('CData',icons.wheelIcon,...
121        'enable','on',...
122        'Separator','on',...
123        'ToolTipString','Save and Run M2HTML',...
124        'ClickedCallback',{@doRunFile,h},...
125        'Tag','RunTool');
126
127uipushtool('CData',icons.webIcon,...
128        'enable','on',...
129        'Separator','on',...
130        'ToolTipString','Online Tutorial',...
131        'ClickedCallback',...
132                'web(''http://www.artefact.tk/software/matlab/m2html/'')',...
133        'Tag','WebTool');
134
135uipushtool('CData',icons.helpIcon,...
136        'enable','on',...
137        'Separator','off',...
138        'ToolTipString','Help',...
139        'ClickedCallback',{@doHelp,h},...
140        'Tag','HelpTool');
141
142%-------------------------------------------------------------------------------
143%- Title
144%-------------------------------------------------------------------------------
145
146uicontrol('Style','Frame',...
147        'Units','Normalized',...
148        'Position',[0.02,0.92,0.96,0.06],...
149        'BackgroundColor',wincolor.title);
150
151uicontrol('Style','Text',...
152        'Units','Normalized',...
153        'String','M2HTML Wizard',...
154        'FontSize',18,...
155        'HorizontalAlignment','center',...
156        'Position',[0.03,0.93,0.94,0.038],...
157        'BackgroundColor',wincolor.title);
158
159%-------------------------------------------------------------------------------
160%- Input
161%-------------------------------------------------------------------------------
162
163uicontrol('Style','Frame',...
164        'Units','Normalized',...
165        'Position',[0.02,0.74,0.96,0.16],...
166        'BackgroundColor',wincolor.fg);
167       
168uicontrol('Style','Frame',...
169        'Units','Normalized',...
170        'HorizontalAlignment','center',...
171        'Position',[0.02,0.87,0.96,0.03],...
172        'BackgroundColor',wincolor.title);
173       
174uicontrol('Style','Text',...
175        'Units','Normalized',...
176        'String','M-Files Input',...
177        'HorizontalAlignment','left',...
178        'Position',[0.03,0.875,0.94,0.02],...
179        'BackgroundColor',wincolor.title);
180
181uicontrol('Style','Text',...
182        'Units','Normalized',...
183        'String','Root directory:',...
184    'FontAngle','oblique',...
185        'HorizontalAlignment','left',...
186        'Position',[0.04,0.825,0.6,0.03],...
187        'BackgroundColor',wincolor.fg);
188
189% M. Krauski 7/20/04
190% changed and resized control to work with browse push button
191
192% uicontrol('Style','edit',...
193%       'Units','Normalized',...
194%       'Position',[0.21,0.83,0.74,0.03],...
195%       'String',pwd,...
196%       'Enable','inactive',...
197%       'HorizontalAlignment','left',...
198%       'Callback','uigetfile;',...%uigetdir
199%       'BackgroundColor',wincolor.bg,...
200%       'Tag','rootdir');
201
202uicontrol('Style','edit',...
203        'Units','Normalized',...
204        'Position',[0.21,0.83,0.59,0.03],...
205        'String',pwd,... %this will be over written in refreshOptions
206        'Enable','inactive',...
207        'HorizontalAlignment','left',...
208        'BackgroundColor',wincolor.bg,...
209        'Tag','rootdir');
210
211% M. Krauski 7/20/04
212% added control
213uicontrol('Style','pushbutton',...
214        'Units','Normalized',...
215        'Position',[0.81,0.83,0.14,0.03],...
216        'String','Browse...',...
217        'HorizontalAlignment','left',...
218    'Callback',{@doBrowseButton,h},...
219        'BackgroundColor',wincolor.bg,...
220        'Tag','browsebutton');
221
222uicontrol('Style','Text',...
223        'Units','Normalized',...
224        'String','Relative pathes:',...
225        'HorizontalAlignment','left',...
226        'Position',[0.04,0.785,0.6,0.03],...
227        'BackgroundColor',wincolor.fg);
228
229% M. Krauski 7/20/04
230% changed and resized control to work with select push button
231
232% uicontrol('Style','edit',...
233%       'Units','Normalized',...
234%       'Position',[0.21,0.79,0.74,0.03],...
235%       'String','',...
236%       'HorizontalAlignment','left',...
237%       'Callback',{@doSetMfiles,h},...
238%     'CreateFcn',{@doInitMfiles,h},...
239%       'BackgroundColor',wincolor.bg,...
240%       'Tag','mfiles');
241
242uicontrol('Style','edit',...
243        'Units','Normalized',...
244    'Position',[0.21,0.79,0.59,0.03],...
245        'String','',...
246    'Enable','inactive',...
247        'HorizontalAlignment','left',...
248    'CreateFcn',{@doInitMfiles,h},...
249        'BackgroundColor',wincolor.bg,...
250        'Tag','mfiles');
251
252uicontrol('Style','pushbutton',...
253        'Units','Normalized',...
254        'Position',[0.81,0.79,0.14,0.03],...
255        'String','Select...',...
256        'HorizontalAlignment','left',...
257    'Callback',{@doSelectMfiles,h},...
258        'BackgroundColor',wincolor.bg,...
259        'Tag','selectbutton');
260
261uicontrol('Style','CheckBox',...
262        'Units','Normalized',...
263        'Position',[0.04,0.749,0.42,0.032],...
264        'String',' Recursive',...
265        'HorizontalAlignment','left',...
266        'Callback',{@doSetRecursive,h},...
267        'Value',0,...
268        'BackgroundColor',wincolor.bg,...
269        'Tag','recursive');
270
271%-------------------------------------------------------------------------------
272%- Output
273%-------------------------------------------------------------------------------
274
275uicontrol('Style','Frame',...
276        'Units','Normalized',...
277        'Position',[0.02, 0.56,0.96,0.16],...
278        'BackgroundColor',wincolor.fg);
279
280uicontrol('Style','Frame',...
281        'Units','Normalized',...
282        'HorizontalAlignment','center',...
283        'Position',[0.02,0.69,0.96,0.03],...
284        'BackgroundColor',wincolor.title);
285       
286uicontrol('Style','Text',...
287        'Units','Normalized',...
288        'String','HTML Output',...
289        'HorizontalAlignment','left',...
290        'Position',[0.03,0.695,0.94,0.02],...
291        'BackgroundColor',wincolor.title);
292
293uicontrol('Style','Text',...
294        'Units','Normalized',...
295        'String','Output Directory:',...
296        'HorizontalAlignment','left',...
297        'Position',[0.04,0.645,0.6,0.03],...
298        'BackgroundColor',wincolor.fg);
299
300uicontrol('Style','edit',...
301        'Units','Normalized',...
302        'Position',[0.21,0.65,0.74,0.03],...
303        'String','',...
304        'HorizontalAlignment','left',...
305        'Callback',{@doSetOutputDir,h},...
306    'CreateFcn',{@doInitHTMLDir,h},...
307        'BackgroundColor',wincolor.bg,...
308        'Tag','htmldir');
309
310uicontrol('Style','Text',...
311        'Units','Normalized',...
312        'String','HTML Index:',...
313        'HorizontalAlignment','left',...
314        'Position',[0.04,0.605,0.6,0.03],...
315        'BackgroundColor',wincolor.fg);
316
317uicontrol('Style','edit',...
318        'Units','Normalized',...
319        'Position',[0.21,0.61,0.25,0.03],...
320        'String','index',...
321        'HorizontalAlignment','left',...
322        'Callback',{@doSetIndex,h},...
323        'BackgroundColor',wincolor.bg,...
324        'Tag','index');
325
326uicontrol('Style','Text',...
327        'Units','Normalized',...
328        'String','Extension:',...
329        'HorizontalAlignment','left',...
330        'Position',[0.53,0.605,0.3,0.03],...
331        'BackgroundColor',wincolor.fg);
332
333uicontrol('Style','edit',...
334        'Units','Normalized',...
335        'Position',[0.70,0.61,0.25,0.03],...
336        'String','html',...
337        'HorizontalAlignment','left',...
338        'Callback',{@doSetExtension,h},...
339        'BackgroundColor',wincolor.bg,...
340        'Tag','extension');
341
342uicontrol('Style','Text',...
343        'Units','Normalized',...
344        'String','Template:',...
345        'HorizontalAlignment','left',...
346        'Position',[0.04,0.565,0.3,0.03],...
347        'BackgroundColor',wincolor.fg);
348
349uicontrol('Style','popupmenu',...
350        'Units','Normalized',...
351        'Position',[0.21,0.57,0.25,0.03],...
352        'String','',...
353        'HorizontalAlignment','center',...
354        'Callback',{@doSetTemplate,h},...
355        'CreateFcn',{@doInitTpl,h},...
356        'BackgroundColor',wincolor.bg,...
357        'Tag','template');
358
359%-------------------------------------------------------------------------------
360%- Other options
361%-------------------------------------------------------------------------------
362
363uicontrol('Style','Frame',...
364        'Units','Normalized',...
365        'Position',[0.02,0.24,0.96,0.30],...
366        'BackgroundColor',wincolor.fg);
367
368uicontrol('Style','Frame',...
369        'Units','Normalized',...
370        'HorizontalAlignment','center',...
371        'Position',[0.02,0.51,0.96,0.03],...
372        'BackgroundColor',wincolor.title);
373       
374uicontrol('Style','Text',...
375        'Units','Normalized',...
376        'String','Other Options',...
377        'HorizontalAlignment','left',...
378        'Position',[0.03,0.515,0.94,0.02],...
379        'BackgroundColor',wincolor.title);
380
381uicontrol('Style','checkbox',...
382        'Units','Normalized',...
383        'Position',[0.04,0.464,0.42,0.032],...
384        'String',' Include Source Code',...
385        'HorizontalAlignment','left',...
386        'Callback',{@doSetSource,h},...
387        'Value',1,...
388        'TooltipString','Include Source Code of each M-file',...
389        'BackgroundColor',wincolor.bg,...
390        'Tag','source');
391
392uicontrol('Style','checkbox',...
393        'Units','Normalized',...
394        'Position',[0.53,0.464,0.42,0.032],...
395        'String',' Syntax Highlighting',...
396        'HorizontalAlignment','left',...
397        'Callback',{@doSetHighlight,h},...
398        'Value',1,...
399        'TooltipString','Source Code Syntax Highlighting',...
400        'BackgroundColor',wincolor.bg,...
401        'Tag','highlight');
402
403uicontrol('Style','checkbox',...
404        'Units','Normalized',...
405        'Position',[0.04,0.42,0.42,0.032],...
406        'String',' Create Dependency Graphs',...
407        'HorizontalAlignment','left',...
408        'Callback',{@doSetGraph,h},...
409    'CreateFcn',{@doInitGraphs,h},...
410        'Value',0,...
411        'TooltipString','Compute a Dependency Graph using GraphViz',...
412        'BackgroundColor',wincolor.bg,...
413        'Tag','graph');
414
415uicontrol('Style','checkbox',...
416        'Units','Normalized',...
417        'Position',[0.53,0.42,0.42,0.032],...
418        'String',' PHP Search Engine',...
419        'HorizontalAlignment','left',...
420        'Callback',{@doSetSearch,h},...
421        'Value',0,...
422        'TooltipString','Create an Index for a PHP Search Engine',...
423        'BackgroundColor',wincolor.bg,...
424        'Tag','search');
425
426uicontrol('Style','checkbox',...
427        'Units','Normalized',...
428        'Position',[0.04,0.378,0.42,0.032],...
429        'String',' Global Hyperlinks',...
430        'HorizontalAlignment','left',...
431        'Callback',{@doSetGlobal,1},...
432        'Value',0,...
433        'TooltipString','Hypertext links among separate Matlab Directories',...
434        'BackgroundColor',wincolor.bg,...
435        'Tag','globalhypertext');
436
437uicontrol('Style','checkbox',...
438        'Units','Normalized',...
439        'Position',[0.53,0.378,0.42,0.032],...
440        'String',' Downloadable M-files',...
441        'HorizontalAlignment','left',...
442        'Callback',{@doSetDownload,h},...
443        'TooltipString','Add a link to download each M-file separately',...
444        'Value',0,...
445        'BackgroundColor',wincolor.bg,...
446        'Tag','download');
447
448uicontrol('Style','checkbox',...
449        'Units','Normalized',...
450        'Position',[0.04,0.336,0.42,0.032],...
451        'String',' To Do List',...
452        'HorizontalAlignment','left',...
453        'Callback',{@doSetTodo,h},...
454        'TooltipString',['Create a TODO list in each directory summarizing'...
455        ' all the ''% TODO %'' lines found in Matlab code'],...
456        'Value',0,...
457        'BackgroundColor',wincolor.bg,...
458        'Tag','todo');
459
460uicontrol('Style','checkbox',...
461        'Units','Normalized',...
462        'Position',[0.53,0.336,0.42,0.032],...
463        'String',' Verbose Mode',...
464        'HorizontalAlignment','left',...
465        'Callback',{@doSetVerbose,h},...
466        'TooltipString','Verbose mode',...
467        'Value',1,...
468        'BackgroundColor',wincolor.bg,...
469        'Tag','verbose');
470
471uicontrol('Style','checkbox',...
472        'Units','Normalized',...
473        'Position',[0.04,0.294,0.42,0.032],...
474        'String',' Save M-files Parsing',...
475        'HorizontalAlignment','left',...
476        'Callback',{@doSetSaveAsMat,h},...
477        'TooltipString',['Save current state after M-files parsing in '...
478        '''m2html.mat'' in the Output directory'],...
479        'Value',0,...
480        'BackgroundColor',wincolor.bg,...
481        'Tag','save');
482
483uicontrol('Style','Text',...
484        'Units','Normalized',...
485        'String','Load File:',...
486        'HorizontalAlignment','left',...
487        'Position',[0.53,0.289,0.3,0.03],...
488        'BackgroundColor',wincolor.fg);
489
490uicontrol('Style','edit',...
491        'Units','Normalized',...
492        'Position',[0.70,0.294,0.25,0.03],...
493        'String','',...
494        'HorizontalAlignment','left',...
495        'Callback',{@doSetLoadMat,h},...
496        'TooltipString',['Load a previously saved MAT file '...
497        'to generate HTML files once again'],...
498        'BackgroundColor',wincolor.bg,...
499        'Tag','load');
500
501uicontrol('Style','Text',...
502        'Units','Normalized',...
503        'String','Tabs Length:',...
504        'HorizontalAlignment','left',...
505        'Position',[0.04,0.247,0.3,0.03],...
506        'BackgroundColor',wincolor.fg);
507
508uicontrol('Style','edit',...
509        'Units','Normalized',...
510        'Position',[0.21,0.252,0.25,0.03],...
511        'String','4',...
512        'HorizontalAlignment','right',...
513        'Callback',{@doSetTabs,h},...
514        'TooltipString',['Replace horizontal tabs in source code '...
515        'by N white space characters'],...
516        'BackgroundColor',wincolor.bg,...
517        'Tag','tabs');
518
519uicontrol('Style','Text',...
520        'Units','Normalized',...
521        'String','Nb Columns:',...
522    'FontAngle','oblique',...
523        'HorizontalAlignment','left',...
524        'Position',[0.53,0.247,0.3,0.03],...
525        'BackgroundColor',wincolor.fg);
526
527uicontrol('Style','edit',...
528        'Units','Normalized',...
529        'Position',[0.70,0.252,0.25,0.03],...
530        'String','4',...
531        'HorizontalAlignment','right',...
532        'Callback',{@doSetNbColumns,h},...
533        'TooltipString','Number of columns for M-files output - not available',...
534    'Enable','inactive',...
535        'BackgroundColor',wincolor.bg,...
536        'Tag','column');
537
538
539%-------------------------------------------------------------------------------
540%- Space available
541%-------------------------------------------------------------------------------
542
543% uicontrol('Style','Frame',...
544%       'Units','Normalized',...
545%       'Position',[0.02,0.07,0.96,0.14],...
546%       'BackgroundColor',wincolor.fg);
547
548% simulate a frame using an axes
549% http://www.mathworks.com/support/solutions/data/1-15P9E.html
550axes('Color',wincolor.fg,...
551    'XTick',[],'YTick',[],...
552    'Units','Normalized',...
553    'Box','on',...
554    'Position',[0.02,0.07,0.9585,0.14]);
555
556uicontrol('Style','Frame',...
557        'Units','Normalized',...
558        'HorizontalAlignment','center',...
559        'Position',[0.02,0.19,0.96,0.03],...
560        'BackgroundColor',wincolor.title);
561
562uicontrol('Style','Text',...
563        'Units','Normalized',...
564        'String','M2HTML status',...
565        'HorizontalAlignment','left',...
566        'Position',[0.03,0.195,0.94,0.02],...
567        'BackgroundColor',wincolor.title);
568
569uicontrol('Style','Text',...
570        'Units','Normalized',...
571        'String','Click on the wheel in the toolbar to launch M2HTML...',...
572        'HorizontalAlignment','left',... % center
573        'Position',[0.12,0.135,0.76,0.02],...
574    'Visible','on',...
575        'BackgroundColor',wincolor.fg,...
576        'Tag','textmisc');
577
578axes('XLim',[0 100],...
579    'YLim',[0 1],...
580    'Box','on', ...
581    'Units','Normalized',...
582    'Position',[0.07,0.09,0.86,0.03],...
583    'XTickMode','manual',...
584    'YTickMode','manual',...
585    'layer','top',...
586    'XTick',[],...
587    'YTick',[],...
588    'XTickLabelMode','manual',...
589    'XTickLabel',[],...
590    'YTickLabelMode','manual',...
591    'Visible','on',...
592    'YTickLabel',[],...
593    'Color',wincolor.bg);
594
595x = 0; % between 0 and 100
596xpatch = [0 x x 0];
597ypatch = [0 0 1 1];
598 
599p = patch(xpatch,ypatch,'r',...
600    'EdgeColor','r',...
601    'Visible','on',...
602    'EraseMode','none',...
603        'Tag','waitbarmisc');
604 
605l = line([100 0 0 100 100], [0 0 1 1 0], ...
606    'EraseMode','none', ...
607    'Visible','on',...
608    'Color',get(gca,'XColor'));
609 
610% for i=10:5:100
611%     set(p,'Xdata',[0 i i 0]); pause(0.02);
612% end
613% set(p,'EraseMode','normal');
614% set(p,'Xdata',[0 0 0 0]);
615% set(p,'EraseMode','none');
616
617%-------------------------------------------------------------------------------
618%- Footnote
619%-------------------------------------------------------------------------------
620
621uicontrol('Style','Frame',...
622        'Units','Normalized',...
623        'Position',[0.02,0.02,0.96,0.03],...
624        'BackgroundColor',[0.8 0.8 0.9]);
625
626uicontrol('Style','Text',...
627        'Units','Normalized',...
628        'String',['M2HTML © 2004 Guillaume Flandin <Guillaume@artefact.tk>'],...
629        'HorizontalAlignment','right',...
630        'Position',[0.03,0.025,0.94,0.02],...
631        'BackgroundColor',[0.8 0.8 0.9]);
632
633%===============================================================================
634
635function doClose(fig,evd,h)
636        status = doCheckSave(h);
637        if status
638                delete(h);
639        end
640       
641function doNewFile(fig,evd,h)
642        status = doCheckSave(h);
643        if status
644                initOptions(h);
645                setappdata(h, 'needsave', 1);
646                % refresh options in GUI...
647        refreshOptions(h);
648        end
649
650function doOpenFile(fig,evd,h)
651        status = doCheckSave(h);
652        if status
653                [filename, pathname] = uigetfile('*.mat','Open File');
654                if ~(isequal(filename,0)|isequal(pathname,0))
655                        opt = load(fullfile(pathname,filename),'options');
656                        setappdata(h,'options',opt.options);
657                        setappdata(h,'file',fullfile(pathname,filename));
658                end
659        end
660    % refresh options in GUI...
661    refreshOptions(h);
662
663function status = doSaveFile(fig,evd,h)
664        file = getappdata(h,'file');
665        status = 1;
666        if isempty(file)
667                status = doSaveAsFile(fig,evd,h);
668        else
669                options = getappdata(h,'options');
670                save(file, 'options');
671    end
672        setappdata(h,'needsave',0);
673
674function status = doSaveAsFile(fig,evd,h)
675    opt = getappdata(h,'options');
676        [filename, pathname] = uiputfile(strcat(opt.rootdir,filesep,'matlab.mat'),...
677        'Save File as');
678        if ~(isequal(filename,0)|isequal(pathname,0))
679                setappdata(h,'file',fullfile(pathname,filename));
680                status = doSaveFile(fig,evd,h);
681        else
682                status = 0;
683        end
684
685function doRunFile(fig,evd,h)
686        status = doSaveFile(fig,evd,h);
687        if status
688                opt = getappdata(h,'options');
689        file = getappdata(h,'file');
690        r = {'off' 'on'};
691        % opt could be directly given to m2html (no need for file saving)
692        % just need to convert on/off using opt.param = r{opt.param+1}
693                m2html('load',file,'recursive',r{opt.recursive+1});
694        % 'recursive' is specified to force m2html to parse M-files
695        end
696       
697function status = doCheckSave(h)
698        file = getappdata(h,'file');
699        if isempty(file), file = 'Untitled'; end
700        needsave = getappdata(h,'needsave');
701        status = 1;
702        if needsave
703                button = questdlg(sprintf('Save changes to %s?',file),...
704                        'Mwizard','Yes','No','Cancel','Yes');
705                if strcmp(button,'Yes')
706                        status = doSaveFile([],[],h);
707                elseif strcmp(button,'Cancel')
708                        status = 0;
709                end
710        end
711
712function doHelp(fig,evd,h)
713        helpdlg(sprintf(['M2HTML by Guillaume Flandin\n'...
714                'Copyright © 2003-2004\nGuillaume@artefact.tk\n'...
715                '<http://www.artefact.tk/>']),'M2HTML Wizard');
716
717%===============================================================================
718
719%-------------------------------------------------------------------------------
720%- Default parameters
721%-------------------------------------------------------------------------------
722
723function varargout = initOptions(h)
724        options = struct('verbose', 1,...
725                'mFiles', {{''}},...
726                'htmlDir', 'doc',...
727                'recursive', 0,...
728                'source', 1,...
729                'download',0,...
730                'syntaxHighlighting', 1,...
731                'tabs', 4,...
732                'globalHypertextLinks', 0,...
733                'graph', 0,...
734                'todo', 0,...
735                'load', 0,...
736                'save', 0,...
737                'search', 0,...
738                'helptocxml', 0,...
739                'indexFile', 'index',...
740                'extension', '.html',...
741                'template', 'blue',...
742        'rootdir', pwd,...
743                'ignoredDir', {{'.svn' 'cvs'}}, ...
744        'language','english');
745       
746    if nargin == 1,
747            setappdata(h,'options',options);
748    else
749        varargout{1} = options;   
750    end
751
752function refreshOptions(h)
753    opt = getappdata(h,'options');
754    handles = getappdata(h,'handles');
755   
756    doInitTpl(handles.template,    0, h);
757    doInitMfiles(handles.mfiles,   0, h);
758    doInitHTMLDir(handles.htmldir, 0, h)
759   
760    set(handles.recursive,       'Value',  opt.recursive);
761    set(handles.graph,           'Value',  opt.graph); %doInitGraphs(handles.graph,0,h);
762    set(handles.save,            'Value',  opt.save);
763    set(handles.verbose,         'Value',  opt.verbose);
764    set(handles.todo,            'Value',  opt.todo);
765    set(handles.download,        'Value',  opt.download);
766    set(handles.search,          'Value',  opt.search);
767    set(handles.highlight,       'Value',  opt.syntaxHighlighting);
768    set(handles.source,          'Value',  opt.source);
769    set(handles.globalhypertext, 'Value',  opt.globalHypertextLinks);
770   
771    set(handles.index,           'String', opt.indexFile);
772    set(handles.extension,       'String', opt.extension(2:end)); %remove the '.'
773    set(handles.tabs,            'String', num2str(opt.tabs));
774%     if ~strcmp(opt.rootdir, pwd)
775%         warning('[M2HTML] You should ''cd %s'' before...',opt.rootdir);   
776%     end
777    set(handles.rootdir,         'String', opt.rootdir); % need to 'cd' if different...
778    set(handles.column,          'String', num2str(4)); %- not saved... default here
779    if ischar(opt.load)
780        set(handles.load,        'String', opt.load);
781    else
782        set(handles.load,        'String', '');
783    end
784   
785    set(handles.textmisc,        'String', ...
786        'Click on the wheel in the toolbar to launch M2HTML...'); %- not saved... default here
787    set(handles.waitbarmisc,     'EraseMode','normal');
788    set(handles.waitbarmisc,     'Xdata',[0 0 0 0]);
789    set(handles.waitbarmisc,     'EraseMode','none');
790
791
792%-------------------------------------------------------------------------------
793%- CreateFcn Callbacks
794%-------------------------------------------------------------------------------
795
796function doInitHTMLDir(fig,evd,h)
797    opt = getappdata(h,'options');
798    [path,name] = fileparts(opt.htmlDir);
799    if isempty(path)
800        opt.htmlDir = fullfile(opt.rootdir, opt.htmlDir);
801    end
802    set(fig,'String',opt.htmlDir);
803    setappdata(h,'options',opt);
804
805function doInitTpl(fig,evd,h)
806    %- problems when templates are still in full format
807    opt = getappdata(h,'options');
808        d = dir(fullfile(fileparts(which(mfilename)),'templates'));
809        d = {d([d.isdir]).name};
810        d = {d{~ismember(d,{'.' '..'})}};
811        if ~isempty(d)
812                tpl = sprintf('%s|',d{:});
813                set(fig,'String',tpl(1:end-1));
814                i = strmatch(opt.template,d,'exact');
815                if ~isempty(i)
816                        set(fig,'Value',i(1));
817        else
818            %- where is the default template ?
819            warning('[M2HTML] Default template ''%s'' not found.',opt.template);
820            set(fig,'Value',1);
821            opt.template = d{1};
822            setappdata(h,'options',opt);
823            warning('[M2HTML] Using template ''%s'' instead.',opt.template);
824        end
825        else
826                error('[M2HTML] No template found.');
827        end
828
829 function doInitMfiles(fig,evd,h)
830    opt = getappdata(h,'options');
831    if ~isempty(opt.mFiles{1})
832        s = sprintf('''%s'', ',opt.mFiles{:}); s = s(1:end-2);
833        set(fig,'String',['{' s '}']);
834        return;
835    end
836    d = dir(opt.rootdir); d = {d([d.isdir]).name};
837    d = {d{~ismember(d,{'.' '..'})}};
838    if length(d) == 0
839        warning('[M2HTML] No subsequent directory found. Check your cwd.');
840        set(fig,'String',''); %- maybe open a uigetdir ?
841        opt.mFiles = {''};
842    elseif length(d) == 1
843        set(fig,'String',d{1});
844        opt.mFiles = d;
845    else
846        s = sprintf('''%s'', ',d{:}); s = s(1:end-2);
847        set(fig,'String',['{' s '}']);
848        opt.mFiles = d;
849    end
850    setappdata(h,'options',opt);
851   
852function doInitGraphs(fig,evd,h)
853    opt = getappdata(h,'options');
854    [s, w] = system('dot -V');
855    if s
856        disp('GraphViz not installed: Generation of dependency graphs desactivated.');
857        disp('See http://www.graphviz.org/ to get ''dot'' tool.');
858        set(fig,'FontAngle','Oblique','Enable','inactive');
859        set(fig,'Value',0);
860        opt.graph = 0;
861        setappdata(h,'options',opt);
862    else
863        set(fig,'Value',opt.graph);
864    end
865
866
867%===============================================================================
868
869%-------------------------------------------------------------------------------
870%- M-Files Input Callbacks
871%-------------------------------------------------------------------------------
872
873function doBrowseButton(fig,evd,h)
874    opt = getappdata(h,'options');
875    handles = getappdata(h,'handles');
876    d = uigetdir(pwd,'Select the Root directory');
877    if ~d, return; end;
878    opt.rootdir = d;
879    set(handles.rootdir,'String',d);
880   
881    % set mfiles
882    d = dir(opt.rootdir); d = {d([d.isdir]).name};
883    d = {d{~ismember(d,{'.' '..'})}};
884    if length(d) == 0
885        warning('[M2HTML] No subsequent directory found. Check your cwd.');
886        set(handles.mfiles,'String','');
887        opt.mFiles = {''};
888    elseif length(d) == 1
889        set(handles.mfiles,'String',d{1});
890        opt.mFiles = d;
891    else
892        s = sprintf('''%s'', ',d{:}); s = s(1:end-2);
893        set(handles.mfiles,'String',['{' s '}']);
894        opt.mFiles = d;
895    end
896   
897    % set htmldir
898    [path,name] = fileparts(opt.htmlDir);
899    opt.htmlDir = fullfile(opt.rootdir, name);
900    set(handles.htmldir,'String',opt.htmlDir);
901   
902    setappdata(h,'options',opt);
903       
904function doSelectMfiles(fig,evd,h)
905    opt = getappdata(h,'options');
906    handles = getappdata(h,'handles');
907   
908    d = dir(opt.rootdir); d = {d([d.isdir]).name};
909    d = {d{~ismember(d,{'.' '..'})}};
910   
911    [i,v] = listdlg('ListString',d,...
912        'PromptString','Select folder(s):',...
913        'Name',':: M2HTML :: M-files',...
914        'SelectionMode','multiple');
915    if v == 1
916        d = {d{i}};
917        s = sprintf('''%s'', ',d{:}); s = s(1:end-2);
918        set(handles.mfiles,'String',['{' s '}']);
919    end
920    opt.mFiles = d;
921
922    setappdata(h,'options',opt);
923
924function doSetRecursive(fig,evd,h)
925        opt = getappdata(h,'options');
926        opt.recursive = get(fig,'Value');
927        setappdata(h,'options',opt);
928
929%-------------------------------------------------------------------------------
930%- HTML Output Callbacks
931%-------------------------------------------------------------------------------
932
933function doSetOutputDir(fig,evd,h)
934        opt = getappdata(h,'options');
935        opt.htmlDir = get(fig,'String');
936        setappdata(h,'options',opt);
937
938function doSetIndex(fig,evd,h)
939        opt = getappdata(h,'options');
940        opt.indexFile = get(fig,'String');
941        setappdata(h,'options',opt);
942       
943function doSetExtension(fig,evd,h)
944        opt = getappdata(h,'options');
945        e = get(fig,'String');
946        if ~isempty(e) & e(1) ~= '.'
947                e = ['.' e];
948        end
949        opt.extension = e;
950        setappdata(h,'options',opt);
951       
952function doSetTemplate(fig,evd,h)
953    opt = getappdata(h,'options');
954    s = get(fig,'String');
955    v = get(fig,'Value');
956    opt.template = deblank(s(v,:));
957    setappdata(h,'options',opt);
958
959%-------------------------------------------------------------------------------
960%- Options Callbacks
961%-------------------------------------------------------------------------------
962
963function doSetSource(fig,evd,h)
964        opt = getappdata(h,'options');
965        opt.source = get(fig,'Value');
966        setappdata(h,'options',opt);
967
968function doSetHighlight(fig,evd,h)
969        opt = getappdata(h,'options');
970        opt.syntaxHighlighting = get(fig,'Value');
971        setappdata(h,'options',opt);
972
973function doSetGraph(fig,evd,h)
974        opt = getappdata(h,'options');
975        opt.graph = get(fig,'Value');
976        setappdata(h,'options',opt);
977
978function doSetSearch(fig,evd,h)
979        opt = getappdata(h,'options');
980        opt.search = get(fig,'Value');
981        setappdata(h,'options',opt);
982
983function doSetGlobal(fig,evd,h)
984        opt = getappdata(h,'options');
985        opt.globalHypertextLinks = get(fig,'Value');
986        setappdata(h,'options',opt);
987
988function doSetDownload(fig,evd,h)
989        opt = getappdata(h,'options');
990        opt.download = get(fig,'Value');
991        setappdata(h,'options',opt);
992
993function doSetTodo(fig,evd,h)
994        opt = getappdata(h,'options');
995        opt.todo = get(fig,'Value');
996        setappdata(h,'options',opt);
997
998function doSetVerbose(fig,evd,h)
999        opt = getappdata(h,'options');
1000        opt.verbose = get(fig,'Value');
1001        setappdata(h,'options',opt);
1002
1003function doSetSaveAsMat(fig,evd,h)
1004        opt = getappdata(h,'options');
1005        opt.save = get(fig,'Value');
1006        setappdata(h,'options',opt);
1007
1008function doSetLoadMat(fig,evd,h)
1009        opt = getappdata(h,'options');
1010        [fname, pname, findex] = uigetfile('m2html.mat',...
1011        'Load a m2html MAT-file');
1012    if findex
1013        opt.load = fullfile(pname,fname);
1014        set(fig,'String',fullfile(pname,fname));
1015    end
1016        setappdata(h,'options',opt);
1017
1018function doSetTabs(fig,evd,h)
1019        opt = getappdata(h,'options');
1020        t = str2num(get(fig,'String'));
1021        if t >= 0 & length(t) == 1
1022                opt.tabs = t;
1023        else
1024                set(fig,'String',num2str(opt.tabs));
1025        end
1026        setappdata(h,'options',opt);
1027
1028function doSetNbColumns(fig,evd,h)
1029        opt = getappdata(h,'options');
1030        disp 'Not available';
1031        setappdata(h,'options',opt);
1032   
1033%===============================================================================
1034
1035function text2 = shortenText(text, l)
1036
1037    if nargin == 1, l = 64; end
1038    m = length(text);
1039    text2 = text;
1040    if m > l
1041        s = floor((l - 3) / 2);
1042        text2 = [text(1:s) '...' text(end-(l-s-3)+1:end)];
1043    end
Note: See TracBrowser for help on using the repository browser.