- for (i = 0; i < noTemplates; i++)
- {
- if (templates[i]->IsVisible())
- {
- strings[n] = (wxChar *)templates[i]->m_description.c_str();
- data[n] = (wxChar *)templates[i];
- n ++;
- }
- }
- if (n == 0)
- {
- delete[] strings;
- delete[] data;
- return (wxDocTemplate *) NULL;
- }
- else if (n == 1)
- {
- wxDocTemplate *temp = (wxDocTemplate *)data[0];
- delete[] strings;
- delete[] data;
- return temp;
- }
+ for (i = 0; i < noTemplates; i++)
+ {
+ if (templates[i]->IsVisible())
+ {
+ strings.Add(templates[i]->m_description);
+ if (!sort)
+ {
+ data[n] = templates[i];
+ n ++;
+ }
+ }
+ } // for
+
+ if (sort)
+ {
+ // Yes, this will be slow, but template lists
+ // are typically short.
+ int j;
+ n = strings.Count();
+ for (i = 0; i < n; i++)
+ {
+ for (j = 0; j < noTemplates; j++)
+ {
+ if (strings[i] == templates[j]->m_description)
+ data[i] = templates[j];
+ }
+ }
+ }
+
+ wxDocTemplate *theTemplate;
+
+ switch ( n )
+ {
+ case 0:
+ // no visible templates, hence nothing to choose from
+ theTemplate = NULL;
+ break;