#include <tmplmngr.h>
Public Member Functions | |
CTemplateManager () | |
Initialise the manager. | |
~CTemplateManager () | |
Destroys the manager. | |
BOOL | Init () |
Initialise the manger. | |
bool | GetTemplateMenuName (UINT32 ordNumberOfTemplate, String_256 *pStrPathOfFile) |
Return the name to use in the New menu in pStrNameOfFile for the template with ordinal ordNumberOfTemplate. | |
bool | GetTemplateFilename (UINT32 ordNumberOfTemplate, String_256 *pStrPathOfFile) |
Return the path to template with ordinal ordNumberOfTemplate in pStrNameOfFile. | |
Static Public Member Functions | |
static String_256 & | GetTemplatesPath () |
To find out the user's preference for a path to the template file. | |
static void | SetTemplatesPath (String_256 &strToSet) |
To set the default templates path. | |
static PathName | GetDefaultAnimationTemplate () |
As above. | |
static void | SetDefaultAnimationTemplate (const String_256 &strPath) |
static PathName | GetDefaultDrawingTemplate () |
As above. | |
static void | SetDefaultDrawingTemplate (const String_256 &strPath) |
Private Types | |
typedef std::map< String_256, bool > | CTemplateList |
Private Member Functions | |
void | GetTemplateList (CTemplateList *pList, const String_256 &strTemplatePath, bool fLocal) |
INTERNAL - Fill the list of templates with all templates in specified directory, marking each with specified user local flag. | |
Static Private Attributes | |
static String_256 | m_TemplatesPath = TEXT("") |
The path to load the templates from and save the templates to. Defaults to blank which means alongside the exe. | |
static String_256 | m_LocalTemplatesPath = TEXT("") |
static String_256 | ms_strDefaultAnimationTemplate = _T("") |
The path to the default animation template. By default, this is the EXE path with "\templates\animation.xar" added to the end. | |
static String_256 | ms_strDefaultDrawingTemplate = _T("") |
The path to the default drawing template. By default, this is the EXE path with "\templates\drawing.xar" added to the end. |
Definition at line 114 of file tmplmngr.h.
|
Definition at line 141 of file tmplmngr.h. |
|
Initialise the manager.
Definition at line 167 of file tmplmngr.cpp.
|
|
Destroys the manager.
Definition at line 188 of file tmplmngr.cpp.
|
|
As above.
Definition at line 356 of file tmplmngr.cpp. 00357 { 00358 PathName pathToReturn=ms_strDefaultAnimationTemplate; 00359 00360 return pathToReturn; 00361 }
|
|
As above.
Definition at line 378 of file tmplmngr.cpp. 00379 { 00380 PathName pathToReturn=ms_strDefaultDrawingTemplate; 00381 00382 return pathToReturn; 00383 }
|
|
Return the path to template with ordinal ordNumberOfTemplate in pStrNameOfFile.
Definition at line 508 of file tmplmngr.cpp. 00509 { 00510 // Fill the list with all templates (user local, begin second will over-write system ones) 00511 CTemplateList setSortFilename; 00512 GetTemplateList( &setSortFilename, m_TemplatesPath, false ); 00513 GetTemplateList( &setSortFilename, m_LocalTemplatesPath, true ); 00514 00515 // If the template with ordinal doesn't exist, fail 00516 if( ordNumberOfTemplate > UINT32(setSortFilename.size()) ) 00517 return false; 00518 00519 // Get enbry for template 00520 CTemplateList::iterator iter = setSortFilename.begin(); 00521 for( UINT32 i = 1; i < ordNumberOfTemplate; ++i, ++iter ) 00522 { /*Do nothing!*/ } 00523 00524 // Pre-pend the path to the template 00525 PathName pathTemplates = iter->second ? m_LocalTemplatesPath : m_TemplatesPath; 00526 pathTemplates.SetFileNameAndType( iter->first ); 00527 00528 *pStrNameOfFile = pathTemplates.GetPath(); 00529 TRACEUSER( "jlh92", _T("Final(%d) = %s\n"), ordNumberOfTemplate, PCTSTR(*pStrNameOfFile) ); 00530 00531 return true; 00532 }
|
|
INTERNAL - Fill the list of templates with all templates in specified directory, marking each with specified user local flag.
Definition at line 403 of file tmplmngr.cpp. 00404 { 00405 // Don't bother with any of this is directory is invalid 00406 if( !wxDir::Exists( (PCTSTR)strTemplatePath ) ) 00407 return; 00408 00409 //Now search that path for templates 00410 //Start by setting the leaf name to *.xar 00411 String_256 strSearchFilename( _R(IDS_NEWTEMPLATES_DEFAULTTEMPLATEEXTENSION) ); 00412 00413 // Get the default entry names 00414 String_256 strPathOfDrawingTemplate = CTemplateManager::GetDefaultDrawingTemplate().GetPath(FALSE); 00415 strPathOfDrawingTemplate.SwapChar( _T('_'), _T(' ') ); 00416 String_256 strPathOfAnimationTemplate = CTemplateManager::GetDefaultAnimationTemplate().GetPath(FALSE); 00417 strPathOfAnimationTemplate.SwapChar( _T('_'), _T(' ') ); 00418 String_256 strPathOfFile; 00419 00420 TRACEUSER( "jlh92", _T("DefPath = %s, %s\n"), PCTSTR(strPathOfDrawingTemplate), 00421 PCTSTR(strPathOfAnimationTemplate) ); 00422 00423 // Build system template path 00424 PathName pathTemplates( strTemplatePath ); 00425 pathTemplates.SetFileNameAndType( strSearchFilename ); 00426 PathName pathOfFile( pathTemplates ); 00427 String_256 strTemplates = pathTemplates.GetPath( FALSE ); 00428 00429 //And search the path for xar files that are 00430 //NOT the default animation or drawing templates 00431 String_256 strNameOfFile; 00432 if( FileUtil::StartFindingFiles( &strTemplates ) ) 00433 { 00434 while( FileUtil::FindNextFile( &strNameOfFile ) ) 00435 { 00436 pathOfFile.SetFileNameAndType( strNameOfFile ); 00437 strPathOfFile = pathOfFile.GetFileName(TRUE); 00438 00439 if( 0 != strPathOfFile.CompareTo( strPathOfDrawingTemplate, FALSE ) && 00440 0 != strPathOfFile.CompareTo( strPathOfAnimationTemplate, FALSE ) ) 00441 { 00442 (*pList)[strPathOfFile] = fLocal; 00443 TRACEUSER( "jlh92", _T("Curr = %s\n"), PCTSTR(strPathOfFile) ); 00444 } 00445 } 00446 FileUtil::StopFindingFiles(); 00447 } 00448 00449 // Don't allow any errors set while searching to propagate outside this scope 00450 Error::ClearError(); 00451 }
|
|
Return the name to use in the New menu in pStrNameOfFile for the template with ordinal ordNumberOfTemplate.
Definition at line 470 of file tmplmngr.cpp. 00471 { 00472 // Fill the list with all templates (user local, begin second will over-write system ones) 00473 CTemplateList setSortFilename; 00474 GetTemplateList( &setSortFilename, m_TemplatesPath, false ); 00475 GetTemplateList( &setSortFilename, m_LocalTemplatesPath, true ); 00476 00477 // If the template with ordinal doesn't exist, fail 00478 if( ordNumberOfTemplate > UINT32(setSortFilename.size()) ) 00479 return false; 00480 00481 // Get enbry for template 00482 CTemplateList::iterator iter = setSortFilename.begin(); 00483 for( UINT32 i = 1; i < ordNumberOfTemplate; ++i, ++iter ) 00484 { /*Do nothing!*/ } 00485 00486 *pStrNameOfFile = iter->first; 00487 TRACEUSER( "jlh92", _T("Final(%d) = %s\n"), ordNumberOfTemplate, PCTSTR(*pStrNameOfFile) ); 00488 00489 return true; 00490 }
|
|
To find out the user's preference for a path to the template file.
Definition at line 312 of file tmplmngr.cpp. 00313 { 00314 // Add a trailing slash if it hasn't got one 00315 SGLibOil::AppendSlashIfNotPresent(&m_LocalTemplatesPath); 00316 00317 return m_LocalTemplatesPath; 00318 }
|
|
Initialise the manger.
Definition at line 210 of file tmplmngr.cpp. 00211 { 00212 //Graham 20/10/97 00213 if (Camelot.DeclareSection( _T("NewTemplates"), 10)) 00214 { 00215 Camelot.DeclarePref( _T("NewTemplates"), _T("DefaultAnimationFile"), &ms_strDefaultAnimationTemplate); 00216 Camelot.DeclarePref( _T("NewTemplates"), _T("DefaultDrawingFile"), &ms_strDefaultDrawingTemplate); 00217 } 00218 00219 if (ms_strDefaultAnimationTemplate==String_256(_T(""))) 00220 { 00221 String_256 strNameOfAnimationTemplate( _R(IDS_NEWTEMPLATES_DEFAULTANIMATIONFILE) ); 00222 String_256 strPathOfTemplate( GetTemplatesPath() ); 00223 strPathOfTemplate += strNameOfAnimationTemplate; 00224 00225 ms_strDefaultAnimationTemplate=strPathOfTemplate; 00226 00227 TRACEUSER( "jlh92", _T("DefAnimTempl = %s\n"), PCTSTR(ms_strDefaultAnimationTemplate) ); 00228 } 00229 00230 if( ms_strDefaultDrawingTemplate == String_256( _T("") ) || 00231 0 == camStrcmp( ms_strDefaultDrawingTemplate, _T("default.xar") ) ) 00232 { 00233 ms_strDefaultDrawingTemplate=String_256(_R(IDS_DEFAULTDOCNAME)); 00234 00235 PORTNOTETRACE("other","CTemplateManager::Init - remove code to setup paths"); 00236 #if !defined(EXCLUDE_FROM_XARALX) 00237 //Then assume it's the exe path with \templates\drawing.xar on the end 00238 TCHAR Pathname[MAX_PATH]; 00239 00240 if(GetModuleFileName(NULL, Pathname, MAX_PATH) == 0) //Should be in the winoil really 00241 return FALSE; 00242 00243 // Put the path name into a string 00244 String_256 strPathOfExe(Pathname); 00245 PathName pathPathOfExe(strPathOfExe); 00246 00247 strPathOfExe = pathPathOfExe.GetLocation(TRUE); 00248 00249 //And add "templates\" to the end 00250 String_256 strTemplatesDirectory(_R(IDS_NEWTEMPLATES_RELATIVEPATH)); 00251 String_256 strNameOfDrawingTemplate(_R(IDS_DEFAULTDOCNAME)); 00252 00253 String_256 strPathOfTemplate=strPathOfExe; 00254 strPathOfTemplate+=strTemplatesDirectory; 00255 strPathOfTemplate+=strNameOfDrawingTemplate; 00256 00257 ms_strDefaultDrawingTemplate=strPathOfTemplate; 00258 #endif 00259 } 00260 00261 // As the preference system is up, declare our preference to it 00262 // This is the pathname that the templates should be loaded from and saved to 00263 // If blank, the default, then it should use the exe path 00264 GetApplication()->DeclareSection(TEXT("Templates"), 2); 00265 GetApplication()->DeclarePref(TEXT("Templates"), TEXT("Path"), &m_TemplatesPath); 00266 GetApplication()->DeclarePref(TEXT("Templates"), TEXT("LocalPath"), &m_LocalTemplatesPath); 00267 00268 //Graham 21/10/97: If it is blank, then we should use the 00269 //exe path with "\templates\" on the end 00270 if( m_TemplatesPath.IsEmpty() || !SGLibOil::DirExists( m_TemplatesPath ) ) 00271 { 00272 // Put the path name into a string 00273 m_TemplatesPath = CCamApp::GetResourceDirectory(); 00274 00275 //And add "templates\" to the end 00276 String_256 strRelativePath(_R(IDS_NEWTEMPLATES_RELATIVEPATH)); 00277 00278 m_TemplatesPath+=strRelativePath; 00279 00280 #if defined(_DEBUG) 00281 if( !SGLibOil::DirExists( m_TemplatesPath ) ) 00282 m_TemplatesPath = _T("/usr/share/xaralx/Templates/"); 00283 #endif 00284 } 00285 00286 if( m_LocalTemplatesPath.IsEmpty() || !SGLibOil::DirExists( m_LocalTemplatesPath ) ) 00287 { 00288 wxString strHome( ::wxGetHomeDir() ); 00289 m_LocalTemplatesPath = (PCTSTR)strHome; 00290 m_LocalTemplatesPath += _T("/.xaralx/templates/"); 00291 } 00292 00293 TRACEUSER( "jlh92", _T("Using %s as template store\n"), PCTSTR(m_TemplatesPath) ); 00294 return TRUE; 00295 }
|
|
Definition at line 130 of file tmplmngr.h. 00130 { ms_strDefaultAnimationTemplate = strPath; }
|
|
Definition at line 132 of file tmplmngr.h. 00132 { ms_strDefaultDrawingTemplate = strPath; }
|
|
To set the default templates path.
Definition at line 333 of file tmplmngr.cpp. 00334 { 00335 m_LocalTemplatesPath = strToSet; 00336 00337 // Add a trailing slash if it hasn't got one 00338 SGLibOil::AppendSlashIfNotPresent(&m_LocalTemplatesPath); 00339 }
|
|
Definition at line 136 of file tmplmngr.h. |
|
The path to load the templates from and save the templates to. Defaults to blank which means alongside the exe. Preference: Path Section: Templates Range: 0 .. 256 characters
Definition at line 135 of file tmplmngr.h. |
|
The path to the default animation template. By default, this is the EXE path with "\templates\animation.xar" added to the end. Preference: DefaultAnimationTemplate Section: Templates Range: String
Definition at line 138 of file tmplmngr.h. |
|
The path to the default drawing template. By default, this is the EXE path with "\templates\drawing.xar" added to the end. Preference: DefaultDrawingTemplate Section: Templates Range: String
Definition at line 139 of file tmplmngr.h. |