1
0

MainTableFunctions.cpp 1.8 KB

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