MainTableFunctions.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // MainTableFunctions.cpp: implementation of the CMainTableFunctions class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "cp_main.h"
  6. #include "MainTableFunctions.h"
  7. #include "Tokenizer.h"
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char THIS_FILE[]=__FILE__;
  11. #define new DEBUG_NEW
  12. #endif
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. CMainTableFunctions::CMainTableFunctions()
  17. {
  18. }
  19. CMainTableFunctions::~CMainTableFunctions()
  20. {
  21. }
  22. void CMainTableFunctions::LoadAcceleratorKeys(CAccels& accels, CppSQLite3DB &db)
  23. {
  24. try
  25. {
  26. CppSQLite3Query q = db.execQuery(_T("SELECT lID, lShortCut FROM Main WHERE lShortCut > 0"));
  27. CAccel a;
  28. while(q.eof() == false)
  29. {
  30. a.Cmd = q.getIntField(_T("lID"));
  31. a.Key = q.getIntField(_T("lShortCut"));
  32. accels.AddAccel(a);
  33. q.nextRow();
  34. }
  35. }
  36. CATCH_SQLITE_EXCEPTION
  37. }
  38. CString CMainTableFunctions::GetDisplayText(int nMaxLines, const CString &OrigText)
  39. {
  40. CString text = OrigText;
  41. // assign tabs to 2 spaces (rather than the default 8)
  42. text.Replace(_T("\t"), _T(" "));
  43. if(g_Opt.m_bDescShowLeadingWhiteSpace)
  44. return text;
  45. // else, remove the leading indent from every line.
  46. // get the lines
  47. CString token;
  48. CStringArray tokens;
  49. CTokenizer tokenizer(text,"\r\n");
  50. for(int nLines=0; nLines < nMaxLines && tokenizer.Next(token); nLines++)
  51. {
  52. tokens.Add(token);
  53. }
  54. // remove each line's indent
  55. TCHAR chFirst;
  56. CString line;
  57. int count = tokens.GetSize();
  58. text = "";
  59. for(int i=0; i < count; i++)
  60. {
  61. line = tokens.ElementAt(i);
  62. chFirst = line.GetAt(0);
  63. if(chFirst == ' ' || chFirst == '\t')
  64. {
  65. text += "» "; // show indication that the line is modified
  66. line.TrimLeft();
  67. text += line;
  68. }
  69. else
  70. text += line;
  71. text += "\n";
  72. }
  73. return text;
  74. }