From b984475e491eaac8ed1ecee80e2b36e235a12691 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sat, 27 Aug 2011 03:12:33 +0000 Subject: [PATCH] fixed: index templates and 'change' templates were not cleared when 'reload' function was called so wrong indexes have been assigned git-svn-id: svn://ttmath.org/publicrep/winix/trunk@759 e52654a7-88a9-db11-a3e9-0013d4bc506e --- core/pluginmsg.h | 9 ++++++++ templates/changepatterns.cpp | 6 ++++++ templates/changepatterns.h | 6 ++++++ templates/dir.cpp | 42 ++++++++++++++++-------------------- templates/indexpatterns.cpp | 7 ++++++ templates/indexpatterns.h | 5 +++++ templates/templates.cpp | 6 +++++- 7 files changed, 57 insertions(+), 24 deletions(-) diff --git a/core/pluginmsg.h b/core/pluginmsg.h index aa8595c..2d5b723 100755 --- a/core/pluginmsg.h +++ b/core/pluginmsg.h @@ -105,6 +105,15 @@ // in p1 you have a pointer to the Item struct #define WINIX_FILE_CHANGED 3016 +// here you add your own html templates +// call TemplatesFunctions::patterns.Add(L"file_name.html") +// the method returns an index which you have to remember +// and you can get the template with patterns.Get(index, lang_index) +// it returns a pointer to Ezc::Pattern (or null pointer if the index is wrong) +// the message will be sent too whenever 'reload/templates' winix function is called +// templates you should add only in this message +// in other cases after 'reload' function the indexes would be wrong +#define WINIX_ADD_TEMPLATE 3017 diff --git a/templates/changepatterns.cpp b/templates/changepatterns.cpp index bde033f..36c5442 100755 --- a/templates/changepatterns.cpp +++ b/templates/changepatterns.cpp @@ -100,3 +100,9 @@ Value::iterator v, next; } + +void ChangePatterns::Clear() +{ + pat_tab.clear(); +} + diff --git a/templates/changepatterns.h b/templates/changepatterns.h index 8779ed7..4919fb0 100755 --- a/templates/changepatterns.h +++ b/templates/changepatterns.h @@ -50,6 +50,12 @@ public: void DeleteMarked(); + /* + deleting all patterns + */ + void Clear(); + + private: Patterns * patterns; diff --git a/templates/dir.cpp b/templates/dir.cpp index f502a74..56517e0 100755 --- a/templates/dir.cpp +++ b/templates/dir.cpp @@ -120,6 +120,25 @@ void dir_can_use_mkdir(Info & i) +static std::wstring dir_parents_str; + + +void dir_has_parents(Info & i) +{ + dir_parents_str.clear(); + + for(size_t a=0 ; arequest->dir_tab.size() ; ++a) + { + dir_parents_str += cur->request->dir_tab[a]->url; + dir_parents_str += '/'; + } + + i.res = IsSubString(i.par, dir_parents_str); +} + + + + static std::vector dir_childs_table; static size_t dir_childs_index; // cur->request->id is never 0 and we can start dir_childs_reqid from 0 @@ -365,29 +384,6 @@ void dir_last_has_html_template(Info & i) - static std::wstring dir_parents_str; - - -void dir_has_parents(Info & i) -{ - dir_parents_str.clear(); - - for(size_t a=0 ; arequest->dir_tab.size() ; ++a) - { - dir_parents_str += cur->request->dir_tab[a]->url; - dir_parents_str += '/'; - - } - - i.res = IsSubString(i.par, dir_parents_str); -} - - - - - - - } // namespace TemplatesFunctions diff --git a/templates/indexpatterns.cpp b/templates/indexpatterns.cpp index 1187f81..06820f8 100755 --- a/templates/indexpatterns.cpp +++ b/templates/indexpatterns.cpp @@ -76,3 +76,10 @@ Tab::iterator next; i = next; } } + + + +void IndexPatterns::Clear() +{ + tab.clear(); +} diff --git a/templates/indexpatterns.h b/templates/indexpatterns.h index b6c7005..58d8a87 100755 --- a/templates/indexpatterns.h +++ b/templates/indexpatterns.h @@ -52,6 +52,11 @@ public: void DeleteMarked(); + /* + deleting all patterns + */ + void Clear(); + private: diff --git a/templates/templates.cpp b/templates/templates.cpp index cdb7c07..ebcb87b 100755 --- a/templates/templates.cpp +++ b/templates/templates.cpp @@ -171,7 +171,7 @@ void Templates::CreateFunctions() ezc_functions.Insert("dir_can_remove", dir_can_remove); ezc_functions.Insert("dir_can_use_emacs", dir_can_use_emacs); ezc_functions.Insert("dir_can_use_mkdir", dir_can_use_mkdir); - ezc_functions.Insert("dir_has_parents",dir_has_parents); + ezc_functions.Insert("dir_has_parents", dir_has_parents); ezc_functions.Insert("dir_childs_tab", dir_childs_tab); ezc_functions.Insert("dir_childs_is_parent", dir_childs_is_parent); @@ -680,6 +680,8 @@ using namespace TemplatesFunctions; ReadLocale(); patterns.Clear(); + index_patterns.Clear(); + change_patterns.Clear(); pat_index = patterns.Add(config->templates_index); pat_err_404 = patterns.Add(L"err_404.html"); @@ -689,6 +691,8 @@ using namespace TemplatesFunctions; ReadIndexTemplates(); ReadChangeTemplates(); + plugin.Call(WINIX_ADD_TEMPLATE); + SetHtmlFilter(); log << log3 << "Templates: there are " << patterns.Size() << " patterns"