ultimatepp/uppsrc/ide/Browser/Template.cpp
cxl f1c9e4d210 Removed Common directory, T++ stylesheets replaced by templates
git-svn-id: svn://ultimatepp.org/upp/trunk@341 f0d560ea-af0d-0410-9eb7-867de7ffcac7
2008-08-16 13:50:40 +00:00

59 lines
1.5 KiB
C++

#include "Browser.h"
void TopicEditor::ListTemplates(Vector<String>& path, Vector<String>& name)
{
Vector<String> ud = GetUppDirs();
for(int i = 0; i < ud.GetCount(); i++) {
String nest = ud[i];
String tmpl = AppendFileName(nest, "$.tpp");
FindFile ff(AppendFileName(tmpl, "*.tpp"));
while(ff) {
if(ff.IsFile()) {
path.Add(AppendFileName(tmpl, ff.GetName()));
name.Add(GetFileTitle(ff.GetName()) + " (in " + GetFileTitle(nest) + ")");
}
ff.Next();
}
}
IndexSort(name, path);
}
String TopicEditor::ChooseTemplate(const char *title)
{
WithTemplateListLayout<TopWindow> dlg;
CtrlLayoutOKCancel(dlg, title);
Vector<String> path, name;
ListTemplates(path, name);
dlg.list.AddIndex();
dlg.list.AddColumn();
for(int i = 0; i < path.GetCount(); i++)
dlg.list.Add(path[i], name[i]);
dlg.list.GoBegin();
if(dlg.Execute() != IDOK)
return Null;
return dlg.list.GetKey();
}
void TopicEditor::ApplyStylesheet()
{
if(!topic.IsCursor())
return;
String t = ChooseTemplate("Apply template stylesheet");
if(t.GetCount())
editor.ApplyStylesheet(ParseQTF(LoadFile(t)));
}
void TopicEditor::ApplyStylesheetGroup()
{
String t = ChooseTemplate("Apply template stylesheet to current group");
if(IsNull(t))
return;
RichText ss = ParseQTF(LoadFile(t));
int c = topic.GetCursor();
Progress pi("Applying stylesheet");
for(int i = 0; i < topic.GetCount(); i++) {
topic.SetCursor(i);
editor.ApplyStylesheet(ss);
}
topic.SetCursor(c);
}