File: ExampleSourceViewer_8C_source.html

package info (click to toggle)
witty 3.2.1-2%2Bdeb7u1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 70,436 kB
  • sloc: cpp: 117,095; ansic: 77,999; xml: 7,564; sh: 1,037; perl: 208; makefile: 144; java: 86; sql: 14
file content (441 lines) | stat: -rw-r--r-- 53,405 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Wt examples: /home/koen/project/wt/public-git/wt/examples/wt-homepage/ExampleSourceViewer.C Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Wt examples
   &#160;<span id="projectnumber">3.2.1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">/home/koen/project/wt/public-git/wt/examples/wt-homepage/ExampleSourceViewer.C</div>  </div>
</div>
<div class="contents">
<a href="ExampleSourceViewer_8C.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2009 Emweb bvba</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * See the LICENSE file for terms of use.</span>
<a name="l00005"></a>00005 <span class="comment"> */</span>
<a name="l00006"></a>00006 
<a name="l00007"></a>00007 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00008"></a>00008 <span class="preprocessor">#include &lt;stdlib.h&gt;</span>
<a name="l00009"></a>00009 <span class="preprocessor">#include &lt;algorithm&gt;</span>
<a name="l00010"></a>00010 
<a name="l00011"></a>00011 <span class="preprocessor">#include &lt;Wt/WApplication&gt;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &lt;Wt/WContainerWidget&gt;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;Wt/WEnvironment&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;Wt/WLineEdit&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;Wt/WGridLayout&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;Wt/WHBoxLayout&gt;</span>
<a name="l00017"></a>00017 <span class="preprocessor">#include &lt;Wt/WPushButton&gt;</span>
<a name="l00018"></a>00018 <span class="preprocessor">#include &lt;Wt/WTable&gt;</span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &lt;Wt/WText&gt;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;Wt/WTreeView&gt;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;Wt/WVBoxLayout&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;Wt/WViewWidget&gt;</span>
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 <span class="preprocessor">#include &lt;boost/filesystem/operations.hpp&gt;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;boost/filesystem/exception.hpp&gt;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;boost/filesystem/convenience.hpp&gt;</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include &lt;boost/algorithm/string.hpp&gt;</span>
<a name="l00028"></a>00028 
<a name="l00029"></a>00029 <span class="preprocessor">#include &quot;<a class="code" href="ExampleSourceViewer_8h.html">ExampleSourceViewer.h</a>&quot;</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include &quot;<a class="code" href="FileItem_8h.html">FileItem.h</a>&quot;</span>
<a name="l00031"></a>00031 
<a name="l00032"></a>00032 <span class="keyword">using namespace </span>Wt; 
<a name="l00033"></a>00033 <span class="keyword">namespace </span>fs = boost::filesystem;
<a name="l00034"></a>00034 
<a name="l00035"></a>00035 <span class="comment">// Same as p.filename() in latest boost::filesystem</span>
<a name="l00036"></a><a class="code" href="ExampleSourceViewer_8C.html#a90d62aee81b34c117b8f494a54bee4d4">00036</a> <span class="keyword">static</span> std::string <a class="code" href="ExampleSourceViewer_8C.html#a90d62aee81b34c117b8f494a54bee4d4">filename</a>(<span class="keyword">const</span> fs::path&amp; p)
<a name="l00037"></a>00037 {
<a name="l00038"></a>00038 <span class="preprocessor">#if BOOST_FILESYSTEM_VERSION &lt; 3</span>
<a name="l00039"></a>00039 <span class="preprocessor"></span>  <span class="keywordflow">return</span> p.empty() ? std::string() : *--p.end();
<a name="l00040"></a>00040 <span class="preprocessor">#else</span>
<a name="l00041"></a>00041 <span class="preprocessor"></span>  <span class="keywordflow">return</span> p.empty() ? std::string() : (*--p.end()).<span class="keywordtype">string</span>();
<a name="l00042"></a>00042 <span class="preprocessor">#endif</span>
<a name="l00043"></a>00043 <span class="preprocessor"></span>}
<a name="l00044"></a>00044 
<a name="l00045"></a>00045 <span class="comment">// Same as p.stem() in latest boost::filesystem</span>
<a name="l00046"></a><a class="code" href="ExampleSourceViewer_8C.html#a2fb90126657b786f14062b06f995583c">00046</a> <span class="keyword">static</span> std::string <a class="code" href="ExampleSourceViewer_8C.html#a2fb90126657b786f14062b06f995583c">stem</a>(<span class="keyword">const</span> fs::path&amp; p)
<a name="l00047"></a>00047 {
<a name="l00048"></a>00048   std::string fn = <a class="code" href="ExampleSourceViewer_8C.html#a90d62aee81b34c117b8f494a54bee4d4">filename</a>(p);
<a name="l00049"></a>00049   std::size_t pos = fn.find(<span class="charliteral">&#39;.&#39;</span>);
<a name="l00050"></a>00050   <span class="keywordflow">if</span> (pos == std::string::npos)
<a name="l00051"></a>00051     <span class="keywordflow">return</span> fn;
<a name="l00052"></a>00052   <span class="keywordflow">else</span>
<a name="l00053"></a>00053     <span class="keywordflow">return</span> fn.substr(0, pos);
<a name="l00054"></a>00054 }
<a name="l00055"></a>00055 
<a name="l00056"></a>00056 <span class="comment">// Should be same as p.parent_path() in latest boost::filesystem</span>
<a name="l00057"></a>00057 <span class="comment">// This is not entirely according to fs::path::parent_path() in 1.39.0</span>
<a name="l00058"></a><a class="code" href="ExampleSourceViewer_8C.html#ae19c9a4a8bd0a5e02a00d6e17707a342">00058</a> fs::path <a class="code" href="ExampleSourceViewer_8C.html#ae19c9a4a8bd0a5e02a00d6e17707a342">parent_path</a>(<span class="keyword">const</span> fs::path&amp; p)
<a name="l00059"></a>00059 {
<a name="l00060"></a>00060   std::string fn = <a class="code" href="ExampleSourceViewer_8C.html#a90d62aee81b34c117b8f494a54bee4d4">filename</a>(p);
<a name="l00061"></a>00061   std::string path = p.string();
<a name="l00062"></a>00062 
<a name="l00063"></a>00063   <span class="keywordflow">return</span> path.substr(0, path.length() - fn.length() - 1);
<a name="l00064"></a>00064 }
<a name="l00065"></a>00065 
<a name="l00066"></a><a class="code" href="ExampleSourceViewer_8C.html#acb92ccbf2405b113c0b8b66cec63aaae">00066</a> <span class="keyword">static</span> <span class="keywordtype">bool</span> <a class="code" href="ExampleSourceViewer_8C.html#acb92ccbf2405b113c0b8b66cec63aaae">comparePaths</a>(<span class="keyword">const</span> fs::path&amp; p1, <span class="keyword">const</span> fs::path&amp; p2)
<a name="l00067"></a>00067 {
<a name="l00068"></a>00068   <span class="keywordflow">return</span> <a class="code" href="ExampleSourceViewer_8C.html#a90d62aee81b34c117b8f494a54bee4d4">filename</a>(p1) &gt; <a class="code" href="ExampleSourceViewer_8C.html#a90d62aee81b34c117b8f494a54bee4d4">filename</a>(p2);
<a name="l00069"></a>00069 }
<a name="l00070"></a>00070 
<a name="l00071"></a><a class="code" href="classExampleSourceViewer.html#a3ab5978077589e8dbf6d8cfdb6da36d4">00071</a> <a class="code" href="classExampleSourceViewer.html#a3ab5978077589e8dbf6d8cfdb6da36d4" title="Constructor.">ExampleSourceViewer::ExampleSourceViewer</a>(<span class="keyword">const</span> std::string&amp; deployPath,
<a name="l00072"></a>00072                                          <span class="keyword">const</span> std::string&amp; examplesRoot,
<a name="l00073"></a>00073                                          <span class="keyword">const</span> std::string&amp; examplesType)
<a name="l00074"></a>00074   : deployPath_(deployPath),
<a name="l00075"></a>00075     examplesRoot_(examplesRoot),
<a name="l00076"></a>00076     examplesType_(examplesType)
<a name="l00077"></a>00077 {
<a name="l00078"></a>00078   wApp-&gt;internalPathChanged().connect
<a name="l00079"></a>00079     (<span class="keyword">this</span>, &amp;<a class="code" href="classExampleSourceViewer.html#a8aeb783e81242455f97f83d259919a20">ExampleSourceViewer::handlePathChange</a>);
<a name="l00080"></a>00080 
<a name="l00081"></a>00081   <a class="code" href="classExampleSourceViewer.html#a8aeb783e81242455f97f83d259919a20">handlePathChange</a>();
<a name="l00082"></a>00082 }
<a name="l00083"></a>00083 
<a name="l00084"></a><a class="code" href="classExampleSourceViewer.html#a8aeb783e81242455f97f83d259919a20">00084</a> <span class="keywordtype">void</span> <a class="code" href="classExampleSourceViewer.html#a8aeb783e81242455f97f83d259919a20">ExampleSourceViewer::handlePathChange</a>()
<a name="l00085"></a>00085 {
<a name="l00086"></a>00086   <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html">WApplication</a> *app = wApp;
<a name="l00087"></a>00087 
<a name="l00088"></a>00088   <span class="keywordflow">if</span> (app-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#aed54bd83339bc80b3cffba9067ab1e39">internalPathMatches</a>(<a class="code" href="classExampleSourceViewer.html#a49e72c4bc9714e8fdf9fad810f0d79b1">deployPath_</a>)) {
<a name="l00089"></a>00089     std::string example = app-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WApplication.html#a95e6b5e4dc9084d45e166264b10b3c46">internalPathNextPart</a>(<a class="code" href="classExampleSourceViewer.html#a49e72c4bc9714e8fdf9fad810f0d79b1">deployPath_</a>);
<a name="l00090"></a>00090 
<a name="l00091"></a>00091     <span class="keywordflow">if</span> (example.find(<span class="stringliteral">&quot;..&quot;</span>) != std::string::npos
<a name="l00092"></a>00092         || example.find(<span class="charliteral">&#39;/&#39;</span>) != std::string::npos
<a name="l00093"></a>00093         || example.find(<span class="charliteral">&#39;\\&#39;</span>) != std::string::npos)
<a name="l00094"></a>00094       <a class="code" href="classExampleSourceViewer.html#a04710b0af789b12346a22a2f7ba2bccf">setExample</a>(<span class="stringliteral">&quot;INVALID_DIR&quot;</span>, <span class="stringliteral">&quot;INVALID&quot;</span>);
<a name="l00095"></a>00095     <span class="keywordflow">else</span>
<a name="l00096"></a>00096       <a class="code" href="classExampleSourceViewer.html#a04710b0af789b12346a22a2f7ba2bccf">setExample</a>(<a class="code" href="classExampleSourceViewer.html#a7e33f7d49055157d7d26d036f91d2891">examplesRoot_</a> + example, example);
<a name="l00097"></a>00097   }
<a name="l00098"></a>00098 }
<a name="l00099"></a>00099 
<a name="l00100"></a><a class="code" href="classExampleSourceViewer.html#a04710b0af789b12346a22a2f7ba2bccf">00100</a> <span class="keywordtype">void</span> <a class="code" href="classExampleSourceViewer.html#a04710b0af789b12346a22a2f7ba2bccf">ExampleSourceViewer::setExample</a>(<span class="keyword">const</span> std::string&amp; exampleDir,
<a name="l00101"></a>00101                                      <span class="keyword">const</span> std::string&amp; example)
<a name="l00102"></a>00102 {
<a name="l00103"></a>00103   <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html#a608f748cbdda763f1a11556ddad9fbe1">clear</a>();
<a name="l00104"></a>00104 
<a name="l00105"></a>00105   <span class="keywordtype">bool</span> exists = <span class="keyword">false</span>;
<a name="l00106"></a>00106   <span class="keywordflow">try</span> {
<a name="l00107"></a>00107     exists = fs::exists(exampleDir);
<a name="l00108"></a>00108   } <span class="keywordflow">catch</span> (std::exception&amp;) {
<a name="l00109"></a>00109   }
<a name="l00110"></a>00110 
<a name="l00111"></a>00111   <span class="keywordflow">if</span> (!exists) {
<a name="l00112"></a>00112     <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html#a2cfe66d9b62940f889e99538a9f478d2">addWidget</a>(<span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html">WText</a>(<span class="stringliteral">&quot;No such example: &quot;</span> + exampleDir));
<a name="l00113"></a>00113     <span class="keywordflow">return</span>;
<a name="l00114"></a>00114   }
<a name="l00115"></a>00115 
<a name="l00116"></a>00116   <a class="code" href="classExampleSourceViewer.html#a09d648f3a6b7aa3ebeeac775f8a197cc">model_</a> = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItemModel.html">WStandardItemModel</a>(0, 1, <span class="keyword">this</span>);
<a name="l00117"></a>00117   <span class="keywordflow">if</span> (<a class="code" href="classExampleSourceViewer.html#a7aaeb2ded7907e864f3ea804f19307cd">examplesType_</a> == <span class="stringliteral">&quot;CPP&quot;</span>) {
<a name="l00118"></a>00118     <a class="code" href="classExampleSourceViewer.html#ae10b86e9ea10445cb5f4cac95e168c82">cppTraverseDir</a>(<a class="code" href="classExampleSourceViewer.html#a09d648f3a6b7aa3ebeeac775f8a197cc">model_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItemModel.html#a5fdc79e8100020d98a77ad3543019477">invisibleRootItem</a>(), exampleDir);
<a name="l00119"></a>00119   } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="classExampleSourceViewer.html#a7aaeb2ded7907e864f3ea804f19307cd">examplesType_</a> == <span class="stringliteral">&quot;JAVA&quot;</span>) {
<a name="l00120"></a>00120     <a class="code" href="classExampleSourceViewer.html#abdf6cba77785ba83e5cb04b78d7f9532">javaTraverseDir</a>(<a class="code" href="classExampleSourceViewer.html#a09d648f3a6b7aa3ebeeac775f8a197cc">model_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItemModel.html#a5fdc79e8100020d98a77ad3543019477">invisibleRootItem</a>(), exampleDir);
<a name="l00121"></a>00121   }
<a name="l00122"></a>00122 
<a name="l00123"></a>00123   WApplication::instance()-&gt;setTitle(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html#aa651f107ec7cf080faef6c435705fc44">tr</a>(<span class="stringliteral">&quot;srcview.title.&quot;</span> + example));
<a name="l00124"></a>00124   <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html">WText</a> *title = 
<a name="l00125"></a>00125     <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html">WText</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWidget.html#aa651f107ec7cf080faef6c435705fc44">tr</a>(<span class="stringliteral">&quot;srcview.title.&quot;</span> + <a class="code" href="classExampleSourceViewer.html#a7aaeb2ded7907e864f3ea804f19307cd">examplesType_</a> + <span class="stringliteral">&quot;.&quot;</span> + example));
<a name="l00126"></a>00126   title-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WText.html#a3491e55f74027b49aaf8cd25369bc0e4">setInternalPathEncoding</a>(<span class="keyword">true</span>);
<a name="l00127"></a>00127 
<a name="l00128"></a>00128   <a class="code" href="classExampleSourceViewer.html#a548859a1b20480151f542ebbcc82e5d0">exampleView_</a> = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WTreeView.html">WTreeView</a>();
<a name="l00129"></a>00129   <a class="code" href="classExampleSourceViewer.html#a548859a1b20480151f542ebbcc82e5d0">exampleView_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WTreeView.html#a4d0967483ed31b26a16a5c7620cb5d7c">setHeaderHeight</a>(0);
<a name="l00130"></a>00130   <a class="code" href="classExampleSourceViewer.html#a548859a1b20480151f542ebbcc82e5d0">exampleView_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WTreeView.html#a482314306c8404d7ed941fd986e32623">resize</a>(300, WLength::Auto);
<a name="l00131"></a>00131   <a class="code" href="classExampleSourceViewer.html#a548859a1b20480151f542ebbcc82e5d0">exampleView_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemView.html#ae1c86a0f37f97f63aed3b00fd8ffad7c">setSortingEnabled</a>(<span class="keyword">false</span>);
<a name="l00132"></a>00132   <a class="code" href="classExampleSourceViewer.html#a548859a1b20480151f542ebbcc82e5d0">exampleView_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WTreeView.html#a390300f766472476e6a0df5aefaa2ef0">setModel</a>(<a class="code" href="classExampleSourceViewer.html#a09d648f3a6b7aa3ebeeac775f8a197cc">model_</a>);
<a name="l00133"></a>00133   <a class="code" href="classExampleSourceViewer.html#a548859a1b20480151f542ebbcc82e5d0">exampleView_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WTreeView.html#add40d3e05352ae094f6fe2b9c879c2c7">expandToDepth</a>(1);
<a name="l00134"></a>00134   <a class="code" href="classExampleSourceViewer.html#a548859a1b20480151f542ebbcc82e5d0">exampleView_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemView.html#af6fcd9761e2f7a3b497d3563c849d320">setSelectionMode</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#a74b3f7eb1689a3cbf0ea514ffd20bccca4fd3c5ba6ce5289a1e732d85f002882a">SingleSelection</a>);
<a name="l00135"></a>00135   <a class="code" href="classExampleSourceViewer.html#a548859a1b20480151f542ebbcc82e5d0">exampleView_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WTreeView.html#a48f74194ae6bd63c08a6ff76ecb3e39c">setAlternatingRowColors</a>(<span class="keyword">false</span>);
<a name="l00136"></a>00136   <a class="code" href="classExampleSourceViewer.html#a548859a1b20480151f542ebbcc82e5d0">exampleView_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemView.html#ada37ffbe2d470dd227c8714645f150f0">selectionChanged</a>().<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1Signal.html#a15d1150af031537b492674ee651bf4a3">connect</a>
<a name="l00137"></a>00137     (<span class="keyword">this</span>, &amp;<a class="code" href="classExampleSourceViewer.html#a7f10a65267869bb570fec25bc19348ac" title="Displayed the currently selected file.">ExampleSourceViewer::showFile</a>);
<a name="l00138"></a>00138 
<a name="l00139"></a>00139   <a class="code" href="classExampleSourceViewer.html#aefc329bfd3d8f7ae11c3f452a5744ab9">sourceView_</a> = <span class="keyword">new</span> <a class="code" href="classSourceView.html" title="View class for source code.">SourceView</a>(<a class="code" href="classFileItem.html#ae072fe0aa9a614bfc39a9f59cf987771">FileItem::FileNameRole</a>, 
<a name="l00140"></a>00140                                <a class="code" href="classFileItem.html#ae1dbc221110c06627765b421c30df2ab">FileItem::ContentsRole</a>,
<a name="l00141"></a>00141                                <a class="code" href="classFileItem.html#aa8d601340669b5628a8bac8e35ccd936">FileItem::FilePathRole</a>);
<a name="l00142"></a>00142   <a class="code" href="classExampleSourceViewer.html#aefc329bfd3d8f7ae11c3f452a5744ab9">sourceView_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#afd3a3b359681111460a93d13979d17dd">setStyleClass</a>(<span class="stringliteral">&quot;source-view&quot;</span>);
<a name="l00143"></a>00143 
<a name="l00144"></a>00144   <span class="comment">/*</span>
<a name="l00145"></a>00145 <span class="comment">   * Expand path to first file, to show something in the source viewer</span>
<a name="l00146"></a>00146 <span class="comment">   */</span>
<a name="l00147"></a>00147   <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html">WStandardItem</a> *w = <a class="code" href="classExampleSourceViewer.html#a09d648f3a6b7aa3ebeeac775f8a197cc">model_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItemModel.html#a32d755ace793c2110b0fa5d650a0d577">item</a>(0);
<a name="l00148"></a>00148   <span class="keywordflow">do</span> {
<a name="l00149"></a>00149     <a class="code" href="classExampleSourceViewer.html#a548859a1b20480151f542ebbcc82e5d0">exampleView_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WTreeView.html#a49566dd5cc8d1d0d95bad4783dd4e11a">setExpanded</a>(w-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html#a8afc6170ff2544d385823795b4dded37">index</a>(), <span class="keyword">true</span>);
<a name="l00150"></a>00150     <span class="keywordflow">if</span> (w-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html#a0b025885afc1500285359821f52bb531">rowCount</a>() &gt; 0)
<a name="l00151"></a>00151       w = w-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html#a874247b52596f31126882ee8ea53d3ca">child</a>(0);
<a name="l00152"></a>00152     <span class="keywordflow">else</span> {
<a name="l00153"></a>00153       <a class="code" href="classExampleSourceViewer.html#a548859a1b20480151f542ebbcc82e5d0">exampleView_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemView.html#a4423d5412ff1b4bc67f0a8f443f12136">select</a>(w-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html#a8afc6170ff2544d385823795b4dded37">index</a>(), <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#a1ec974261fb0e2b80498473dcb6c91eda5317beeb399a97e111e7c99dee9161d5">Select</a>);
<a name="l00154"></a>00154       w = 0;
<a name="l00155"></a>00155     }
<a name="l00156"></a>00156   } <span class="keywordflow">while</span> (w);
<a name="l00157"></a>00157 
<a name="l00158"></a>00158   <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WVBoxLayout.html">WVBoxLayout</a> *topLayout = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WVBoxLayout.html">WVBoxLayout</a>();
<a name="l00159"></a>00159   topLayout-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WBoxLayout.html#a7c1ec58e25d0b7add93f5f4342844db6">addWidget</a>(title, 0, <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#ab8f772c69bc8180c31f9e4f4593b143fa58fe5182bd266132c59718c6d30945a9">AlignTop</a> | <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/namespaceWt.html#ab8f772c69bc8180c31f9e4f4593b143fa18cdf9d975a5a41afa182aabfde0de88">AlignJustify</a>);
<a name="l00160"></a>00160 
<a name="l00161"></a>00161   <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WHBoxLayout.html">WHBoxLayout</a> *gitLayout = <span class="keyword">new</span> <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WHBoxLayout.html">WHBoxLayout</a>();
<a name="l00162"></a>00162   gitLayout-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WBoxLayout.html#a7c1ec58e25d0b7add93f5f4342844db6">addWidget</a>(<a class="code" href="classExampleSourceViewer.html#a548859a1b20480151f542ebbcc82e5d0">exampleView_</a>, 0);
<a name="l00163"></a>00163   gitLayout-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WBoxLayout.html#a7c1ec58e25d0b7add93f5f4342844db6">addWidget</a>(<a class="code" href="classExampleSourceViewer.html#aefc329bfd3d8f7ae11c3f452a5744ab9">sourceView_</a>, 1);
<a name="l00164"></a>00164   topLayout-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WBoxLayout.html#a062d26b432841995a0be7b7d7aac6413">addLayout</a>(gitLayout, 1);
<a name="l00165"></a>00165   gitLayout-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WBoxLayout.html#a00bdfb4d442bd8e8ad9c33b72692763f">setResizable</a>(0);
<a name="l00166"></a>00166 
<a name="l00167"></a>00167   <span class="comment">/*</span>
<a name="l00168"></a>00168 <span class="comment">   * FIXME, in plain HTML mode, we should set a minimum size to the source</span>
<a name="l00169"></a>00169 <span class="comment">   * view, and remove this in enableAjax() ?</span>
<a name="l00170"></a>00170 <span class="comment">   */</span>
<a name="l00171"></a>00171   <span class="comment">// sourceView_-&gt;setHeight(&quot;100%&quot;);</span>
<a name="l00172"></a>00172 
<a name="l00173"></a>00173   <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WContainerWidget.html#a1c84e0ffe330d4798f0ce217f75be08c">setLayout</a>(topLayout);
<a name="l00174"></a>00174   <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#afd3a3b359681111460a93d13979d17dd">setStyleClass</a>(<span class="stringliteral">&quot;maindiv&quot;</span>);
<a name="l00175"></a>00175 }
<a name="l00176"></a>00176 
<a name="l00177"></a>00177 <span class="comment">/*</span>
<a name="l00178"></a>00178 <span class="comment"> * Return the companion implementation/header file for a C++ source file.</span>
<a name="l00179"></a>00179 <span class="comment"> */</span>
<a name="l00180"></a><a class="code" href="ExampleSourceViewer_8C.html#a0c61a4a8c171f6b23a9fc3872c2e9e5d">00180</a> <span class="keyword">static</span> fs::path <a class="code" href="ExampleSourceViewer_8C.html#a0c61a4a8c171f6b23a9fc3872c2e9e5d">getCompanion</a>(<span class="keyword">const</span> fs::path&amp; path) 
<a name="l00181"></a>00181 {
<a name="l00182"></a>00182   std::string ext = fs::extension(path);
<a name="l00183"></a>00183 
<a name="l00184"></a>00184   <span class="keywordflow">if</span> (ext == <span class="stringliteral">&quot;.h&quot;</span>)
<a name="l00185"></a>00185     <span class="keywordflow">return</span> <a class="code" href="ExampleSourceViewer_8C.html#ae19c9a4a8bd0a5e02a00d6e17707a342">parent_path</a>(path) / (<a class="code" href="ExampleSourceViewer_8C.html#a2fb90126657b786f14062b06f995583c">stem</a>(path) + <span class="stringliteral">&quot;.C&quot;</span>);
<a name="l00186"></a>00186   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ext == <span class="stringliteral">&quot;.C&quot;</span> || ext == <span class="stringliteral">&quot;.cpp&quot;</span>)
<a name="l00187"></a>00187     <span class="keywordflow">return</span> <a class="code" href="ExampleSourceViewer_8C.html#ae19c9a4a8bd0a5e02a00d6e17707a342">parent_path</a>(path) / (<a class="code" href="ExampleSourceViewer_8C.html#a2fb90126657b786f14062b06f995583c">stem</a>(path) + <span class="stringliteral">&quot;.h&quot;</span>);
<a name="l00188"></a>00188   <span class="keywordflow">else</span>
<a name="l00189"></a>00189     <span class="keywordflow">return</span> fs::path();
<a name="l00190"></a>00190 }
<a name="l00191"></a>00191 
<a name="l00192"></a><a class="code" href="classExampleSourceViewer.html#ae10b86e9ea10445cb5f4cac95e168c82">00192</a> <span class="keywordtype">void</span> <a class="code" href="classExampleSourceViewer.html#ae10b86e9ea10445cb5f4cac95e168c82">ExampleSourceViewer::cppTraverseDir</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html">WStandardItem</a>* parent, 
<a name="l00193"></a>00193                                          <span class="keyword">const</span> fs::path&amp; path)
<a name="l00194"></a>00194 {
<a name="l00195"></a>00195   <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">char</span> *supportedFiles[] = {
<a name="l00196"></a>00196     <span class="stringliteral">&quot;.C&quot;</span>, <span class="stringliteral">&quot;.cpp&quot;</span>, <span class="stringliteral">&quot;.h&quot;</span>, <span class="stringliteral">&quot;.css&quot;</span>, <span class="stringliteral">&quot;.xml&quot;</span>, <span class="stringliteral">&quot;.png&quot;</span>, <span class="stringliteral">&quot;.gif&quot;</span>, <span class="stringliteral">&quot;.csv&quot;</span>, <span class="stringliteral">&quot;.ico&quot;</span>, 0
<a name="l00197"></a>00197   };
<a name="l00198"></a>00198 
<a name="l00199"></a>00199   <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a>* dir = <span class="keyword">new</span> <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a>(<span class="stringliteral">&quot;/icons/yellow-folder-open.png&quot;</span>, <a class="code" href="ExampleSourceViewer_8C.html#a90d62aee81b34c117b8f494a54bee4d4">filename</a>(path),
<a name="l00200"></a>00200                                <span class="stringliteral">&quot;&quot;</span>);
<a name="l00201"></a>00201   parent-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html#abd54c7797f40c036b38300ba9cdf69b5">appendRow</a>(dir);
<a name="l00202"></a>00202   parent = dir;
<a name="l00203"></a>00203   <span class="keywordflow">try</span> {
<a name="l00204"></a>00204     std::set&lt;fs::path&gt; paths;
<a name="l00205"></a>00205 
<a name="l00206"></a>00206     fs::directory_iterator end_itr;
<a name="l00207"></a>00207     <span class="keywordflow">for</span> (fs::directory_iterator i(path); i != end_itr; ++i) 
<a name="l00208"></a>00208       paths.insert(*i);
<a name="l00209"></a>00209 
<a name="l00210"></a>00210     std::vector&lt;FileItem*&gt; classes, files;
<a name="l00211"></a>00211     std::vector&lt;fs::path&gt; dirs;
<a name="l00212"></a>00212 
<a name="l00213"></a>00213     <span class="keywordflow">while</span> (!paths.empty()) {
<a name="l00214"></a>00214       fs::path p = *paths.begin();
<a name="l00215"></a>00215       paths.erase(p);
<a name="l00216"></a>00216 
<a name="l00217"></a>00217       <span class="comment">// skip symbolic links and other files</span>
<a name="l00218"></a>00218       <span class="keywordflow">if</span> (fs::is_symlink(p))
<a name="l00219"></a>00219         <span class="keywordflow">continue</span>;
<a name="l00220"></a>00220 
<a name="l00221"></a>00221       <span class="comment">// skip files with an extension we do not want to handle</span>
<a name="l00222"></a>00222       <span class="keywordflow">if</span> (fs::is_regular(p)) {
<a name="l00223"></a>00223         std::string ext = fs::extension(p);
<a name="l00224"></a>00224         <span class="keywordtype">bool</span> supported = <span class="keyword">false</span>;
<a name="l00225"></a>00225         <span class="keywordflow">for</span> (<span class="keyword">const</span> <span class="keywordtype">char</span> **s = supportedFiles; *s != 0; ++s)
<a name="l00226"></a>00226           <span class="keywordflow">if</span> (*s == ext) {
<a name="l00227"></a>00227             supported = <span class="keyword">true</span>;
<a name="l00228"></a>00228             <span class="keywordflow">break</span>;
<a name="l00229"></a>00229           }
<a name="l00230"></a>00230         
<a name="l00231"></a>00231         <span class="keywordflow">if</span> (!supported)
<a name="l00232"></a>00232           <span class="keywordflow">continue</span>;
<a name="l00233"></a>00233       }
<a name="l00234"></a>00234 
<a name="l00235"></a>00235       <span class="comment">// see if we have one file of a class (.C, .h)</span>
<a name="l00236"></a>00236       fs::path companion = <a class="code" href="ExampleSourceViewer_8C.html#a0c61a4a8c171f6b23a9fc3872c2e9e5d">getCompanion</a>(p);
<a name="l00237"></a>00237       <span class="keywordflow">if</span> (!companion.empty()) {
<a name="l00238"></a>00238         std::set&lt;fs::path&gt;::iterator it_companion = paths.find(companion);
<a name="l00239"></a>00239  
<a name="l00240"></a>00240           <span class="keywordflow">if</span> (it_companion != paths.end()) {
<a name="l00241"></a>00241             std::string className = <a class="code" href="ExampleSourceViewer_8C.html#a2fb90126657b786f14062b06f995583c">stem</a>(p);
<a name="l00242"></a>00242             <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WWebWidget.html#a6cd1b8a84c7aaf72e5d44cb47ae90e9c">escapeText</a>(className);
<a name="l00243"></a>00243             std::string label = <span class="stringliteral">&quot;&lt;i&gt;class&lt;/i&gt; &quot;</span> + className;
<a name="l00244"></a>00244 
<a name="l00245"></a>00245             <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a> *classItem = 
<a name="l00246"></a>00246               <span class="keyword">new</span> <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a>(<span class="stringliteral">&quot;/icons/cppclass.png&quot;</span>, label, std::string());
<a name="l00247"></a>00247             classItem-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html#aedf80dfed644a525e5d726a4b6e74b94">setFlags</a>(classItem-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html#a81bc3d55f8117f5c80edcb3c9c6b871a">flags</a>() | <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/group__modelview.html#gga1d77c4de293aebfacbdde124de06b8b0a8ce71c5a5f185d9097b4bd596c71315e">ItemIsXHTMLText</a>);
<a name="l00248"></a>00248 
<a name="l00249"></a>00249             <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a> *header = <span class="keyword">new</span> <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a>(<span class="stringliteral">&quot;/icons/document.png&quot;</span>, <a class="code" href="ExampleSourceViewer_8C.html#a90d62aee81b34c117b8f494a54bee4d4">filename</a>(p),
<a name="l00250"></a>00250                                             p.string());
<a name="l00251"></a>00251             <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a> *cpp = <span class="keyword">new</span> <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a>(<span class="stringliteral">&quot;/icons/document.png&quot;</span>,
<a name="l00252"></a>00252                                          <a class="code" href="ExampleSourceViewer_8C.html#a90d62aee81b34c117b8f494a54bee4d4">filename</a>(*it_companion),
<a name="l00253"></a>00253                                          (*it_companion).string());
<a name="l00254"></a>00254             classItem-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html#abd54c7797f40c036b38300ba9cdf69b5">appendRow</a>(header);
<a name="l00255"></a>00255             classItem-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html#abd54c7797f40c036b38300ba9cdf69b5">appendRow</a>(cpp);
<a name="l00256"></a>00256           
<a name="l00257"></a>00257             classes.push_back(classItem);
<a name="l00258"></a>00258             paths.erase(it_companion);
<a name="l00259"></a>00259           } <span class="keywordflow">else</span> {
<a name="l00260"></a>00260             <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a> *file = <span class="keyword">new</span> <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a>(<span class="stringliteral">&quot;/icons/document.png&quot;</span>, <a class="code" href="ExampleSourceViewer_8C.html#a90d62aee81b34c117b8f494a54bee4d4">filename</a>(p),
<a name="l00261"></a>00261                                           p.string());
<a name="l00262"></a>00262             files.push_back(file);
<a name="l00263"></a>00263           }
<a name="l00264"></a>00264       } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (fs::is_directory(p)) {
<a name="l00265"></a>00265         dirs.push_back(p);
<a name="l00266"></a>00266       } <span class="keywordflow">else</span> {
<a name="l00267"></a>00267         <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a> *file = <span class="keyword">new</span> <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a>(<span class="stringliteral">&quot;/icons/document.png&quot;</span>, <a class="code" href="ExampleSourceViewer_8C.html#a90d62aee81b34c117b8f494a54bee4d4">filename</a>(p),
<a name="l00268"></a>00268                                       p.string());
<a name="l00269"></a>00269         files.push_back(file);
<a name="l00270"></a>00270       }
<a name="l00271"></a>00271     }
<a name="l00272"></a>00272 
<a name="l00273"></a>00273     std::sort(dirs.begin(), dirs.end(), <a class="code" href="ExampleSourceViewer_8C.html#acb92ccbf2405b113c0b8b66cec63aaae">comparePaths</a>);
<a name="l00274"></a>00274 
<a name="l00275"></a>00275     <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; classes.size(); i++)
<a name="l00276"></a>00276       parent-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html#abd54c7797f40c036b38300ba9cdf69b5">appendRow</a>(classes[i]);
<a name="l00277"></a>00277 
<a name="l00278"></a>00278     <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; files.size(); i++)
<a name="l00279"></a>00279       parent-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html#abd54c7797f40c036b38300ba9cdf69b5">appendRow</a>(files[i]);
<a name="l00280"></a>00280 
<a name="l00281"></a>00281     <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; dirs.size(); i++)
<a name="l00282"></a>00282       <a class="code" href="classExampleSourceViewer.html#ae10b86e9ea10445cb5f4cac95e168c82">cppTraverseDir</a>(parent, dirs[i]);
<a name="l00283"></a>00283   } <span class="keywordflow">catch</span> (fs::filesystem_error&amp; e) {
<a name="l00284"></a>00284     std::cerr &lt;&lt; e.what() &lt;&lt; std::endl;
<a name="l00285"></a>00285   }
<a name="l00286"></a>00286 }
<a name="l00287"></a>00287 
<a name="l00288"></a><a class="code" href="classExampleSourceViewer.html#a23473a614f1d14bfc3a1bf2c9e688712">00288</a> <span class="keywordtype">void</span> <a class="code" href="classExampleSourceViewer.html#a23473a614f1d14bfc3a1bf2c9e688712">ExampleSourceViewer::javaTraversePackages</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html">WStandardItem</a> *parent,
<a name="l00289"></a>00289                                                <span class="keyword">const</span> fs::path&amp; srcPath,
<a name="l00290"></a>00290                                                <span class="keyword">const</span> std::string packageName)
<a name="l00291"></a>00291 {
<a name="l00292"></a>00292   fs::directory_iterator end_itr;
<a name="l00293"></a>00293 
<a name="l00294"></a>00294   <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a> *packageItem = 0;
<a name="l00295"></a>00295   <span class="keywordflow">for</span> (fs::directory_iterator i(srcPath); i != end_itr; ++i) {
<a name="l00296"></a>00296     fs::path p = *i;
<a name="l00297"></a>00297     <span class="keywordflow">if</span> (fs::is_regular(p)) {
<a name="l00298"></a>00298       <span class="keywordflow">if</span> (!packageItem) {
<a name="l00299"></a>00299         packageItem = <span class="keyword">new</span> <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a>(<span class="stringliteral">&quot;/icons/package.png&quot;</span>, packageName, <span class="stringliteral">&quot;&quot;</span>);
<a name="l00300"></a>00300         parent-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html#abd54c7797f40c036b38300ba9cdf69b5">appendRow</a>(packageItem);
<a name="l00301"></a>00301       }
<a name="l00302"></a>00302 
<a name="l00303"></a>00303       <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a> *file = <span class="keyword">new</span> <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a>(<span class="stringliteral">&quot;/icons/javaclass.png&quot;</span>, <a class="code" href="ExampleSourceViewer_8C.html#a90d62aee81b34c117b8f494a54bee4d4">filename</a>(p),
<a name="l00304"></a>00304                                     p.string());
<a name="l00305"></a>00305       packageItem-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html#abd54c7797f40c036b38300ba9cdf69b5">appendRow</a>(file);
<a name="l00306"></a>00306     }
<a name="l00307"></a>00307   }
<a name="l00308"></a>00308 
<a name="l00309"></a>00309   <span class="keywordflow">for</span> (fs::directory_iterator i(srcPath); i != end_itr; ++i) {
<a name="l00310"></a>00310     fs::path p = *i;
<a name="l00311"></a>00311     <span class="keywordflow">if</span> (fs::is_directory(p)) {  
<a name="l00312"></a>00312       std::string pn = packageName;
<a name="l00313"></a>00313       <span class="keywordflow">if</span> (!pn.empty())
<a name="l00314"></a>00314         pn += <span class="stringliteral">&quot;.&quot;</span>;
<a name="l00315"></a>00315       pn += <a class="code" href="ExampleSourceViewer_8C.html#a90d62aee81b34c117b8f494a54bee4d4">filename</a>(p);
<a name="l00316"></a>00316 
<a name="l00317"></a>00317       <a class="code" href="classExampleSourceViewer.html#a23473a614f1d14bfc3a1bf2c9e688712">javaTraversePackages</a>(parent, p, pn);
<a name="l00318"></a>00318     }
<a name="l00319"></a>00319   }
<a name="l00320"></a>00320 }
<a name="l00321"></a>00321 
<a name="l00322"></a><a class="code" href="classExampleSourceViewer.html#abdf6cba77785ba83e5cb04b78d7f9532">00322</a> <span class="keywordtype">void</span> <a class="code" href="classExampleSourceViewer.html#abdf6cba77785ba83e5cb04b78d7f9532">ExampleSourceViewer::javaTraverseDir</a>(<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html">WStandardItem</a>* parent, 
<a name="l00323"></a>00323                                           <span class="keyword">const</span> fs::path&amp; path)
<a name="l00324"></a>00324 {
<a name="l00325"></a>00325   <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a>* dir = <span class="keyword">new</span> <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a>(<span class="stringliteral">&quot;/icons/yellow-folder-open.png&quot;</span>, <a class="code" href="ExampleSourceViewer_8C.html#a90d62aee81b34c117b8f494a54bee4d4">filename</a>(path),
<a name="l00326"></a>00326                                <span class="stringliteral">&quot;&quot;</span>);
<a name="l00327"></a>00327   parent-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html#abd54c7797f40c036b38300ba9cdf69b5">appendRow</a>(dir);
<a name="l00328"></a>00328   parent = dir;
<a name="l00329"></a>00329 
<a name="l00330"></a>00330   std::vector&lt;fs::path&gt; files, dirs;
<a name="l00331"></a>00331 
<a name="l00332"></a>00332   fs::directory_iterator end_itr;
<a name="l00333"></a>00333   <span class="keywordflow">for</span> (fs::directory_iterator i(path); i != end_itr; ++i) {
<a name="l00334"></a>00334     fs::path p = *i;
<a name="l00335"></a>00335     <span class="keywordflow">if</span> (fs::is_directory(p)) {
<a name="l00336"></a>00336       <span class="keywordflow">if</span> (<a class="code" href="ExampleSourceViewer_8C.html#a90d62aee81b34c117b8f494a54bee4d4">filename</a>(p) == <span class="stringliteral">&quot;src&quot;</span>) {
<a name="l00337"></a>00337         <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a>* dir = <span class="keyword">new</span> <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a>(<span class="stringliteral">&quot;/icons/package-folder-open.png&quot;</span>,
<a name="l00338"></a>00338                                      <a class="code" href="ExampleSourceViewer_8C.html#a90d62aee81b34c117b8f494a54bee4d4">filename</a>(p), <span class="stringliteral">&quot;&quot;</span>);
<a name="l00339"></a>00339         parent-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html#abd54c7797f40c036b38300ba9cdf69b5">appendRow</a>(dir);
<a name="l00340"></a>00340         <a class="code" href="classExampleSourceViewer.html#a23473a614f1d14bfc3a1bf2c9e688712">javaTraversePackages</a>(dir, p, <span class="stringliteral">&quot;&quot;</span>);
<a name="l00341"></a>00341       } <span class="keywordflow">else</span>
<a name="l00342"></a>00342         dirs.push_back(p);
<a name="l00343"></a>00343     } <span class="keywordflow">else</span> {
<a name="l00344"></a>00344       files.push_back(p);
<a name="l00345"></a>00345     }
<a name="l00346"></a>00346   }
<a name="l00347"></a>00347 
<a name="l00348"></a>00348   std::sort(dirs.begin(), dirs.end(), <a class="code" href="ExampleSourceViewer_8C.html#acb92ccbf2405b113c0b8b66cec63aaae">comparePaths</a>);
<a name="l00349"></a>00349   std::sort(files.begin(), files.end(), <a class="code" href="ExampleSourceViewer_8C.html#acb92ccbf2405b113c0b8b66cec63aaae">comparePaths</a>);
<a name="l00350"></a>00350 
<a name="l00351"></a>00351   <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; dirs.size(); i++)
<a name="l00352"></a>00352     <a class="code" href="classExampleSourceViewer.html#abdf6cba77785ba83e5cb04b78d7f9532">javaTraverseDir</a>(parent, dirs[i]);
<a name="l00353"></a>00353 
<a name="l00354"></a>00354   <span class="keywordflow">for</span> (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> i = 0; i &lt; files.size(); i++) {
<a name="l00355"></a>00355     <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a> *file = <span class="keyword">new</span> <a class="code" href="classFileItem.html" title="WStandardItem which stores a file.">FileItem</a>(<span class="stringliteral">&quot;/icons/document.png&quot;</span>, <a class="code" href="ExampleSourceViewer_8C.html#a90d62aee81b34c117b8f494a54bee4d4">filename</a>(files[i]),
<a name="l00356"></a>00356                                   files[i].<span class="keywordtype">string</span>());
<a name="l00357"></a>00357     parent-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WStandardItem.html#abd54c7797f40c036b38300ba9cdf69b5">appendRow</a>(file);
<a name="l00358"></a>00358   }
<a name="l00359"></a>00359 }
<a name="l00360"></a>00360 
<a name="l00363"></a><a class="code" href="classExampleSourceViewer.html#a7f10a65267869bb570fec25bc19348ac">00363</a> <span class="keywordtype">void</span> <a class="code" href="classExampleSourceViewer.html#a7f10a65267869bb570fec25bc19348ac" title="Displayed the currently selected file.">ExampleSourceViewer::showFile</a>() {
<a name="l00364"></a>00364   <span class="keywordflow">if</span> (<a class="code" href="classExampleSourceViewer.html#a548859a1b20480151f542ebbcc82e5d0">exampleView_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemView.html#afde08bb75862592d81dc93f30ed7dcd6">selectedIndexes</a>().empty())
<a name="l00365"></a>00365     <span class="keywordflow">return</span>;
<a name="l00366"></a>00366 
<a name="l00367"></a>00367   <a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WModelIndex.html">WModelIndex</a> selected = *<a class="code" href="classExampleSourceViewer.html#a548859a1b20480151f542ebbcc82e5d0">exampleView_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemView.html#afde08bb75862592d81dc93f30ed7dcd6">selectedIndexes</a>().begin();
<a name="l00368"></a>00368 
<a name="l00369"></a>00369   <span class="comment">// expand a folder when clicked</span>
<a name="l00370"></a>00370   <span class="keywordflow">if</span> (<a class="code" href="classExampleSourceViewer.html#a548859a1b20480151f542ebbcc82e5d0">exampleView_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemView.html#abd583faed8e2fc3936d1b5545c4bbf84">model</a>()-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WAbstractItemModel.html#ab0709a8f71fd5df882f29bb29fd055f0">rowCount</a>(selected) &gt; 0
<a name="l00371"></a>00371       &amp;&amp; !<a class="code" href="classExampleSourceViewer.html#a548859a1b20480151f542ebbcc82e5d0">exampleView_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WTreeView.html#a48eac450ec46ac1eea41822bfd227e9b">isExpanded</a>(selected))
<a name="l00372"></a>00372     <a class="code" href="classExampleSourceViewer.html#a548859a1b20480151f542ebbcc82e5d0">exampleView_</a>-&gt;<a class="codeRef" doxygen="wt.tags:../../reference/html" href="../../reference/html/classWt_1_1WTreeView.html#a49566dd5cc8d1d0d95bad4783dd4e11a">setExpanded</a>(selected, <span class="keyword">true</span>);
<a name="l00373"></a>00373 
<a name="l00374"></a>00374   <span class="comment">// (for a file,) load data in source viewer</span>
<a name="l00375"></a>00375   <a class="code" href="classExampleSourceViewer.html#aefc329bfd3d8f7ae11c3f452a5744ab9">sourceView_</a>-&gt;<a class="code" href="classSourceView.html#a10f2b88b0b8ea6b9563077e7958bc4d0" title="Sets the model index.">setIndex</a>(selected);
<a name="l00376"></a>00376 }
</pre></div></div>
</div>
<hr size="1"><address style="text-align: right; margin: 3px"><small>
Generated on Fri Mar 30 2012 for <a href="http://www.webtoolkit.eu/wt">the
C++ Web Toolkit (Wt)</a> by&nbsp;<a
href="http://www.doxygen.org/index.html"><img src="doxygen.png"
alt="doxygen" border="0" style="vertical-align: middle; display:
inline-block; height: 2em"></a> 1.7.5.1</small></address>
</body>
</html>