MainTableFunctions.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 "shared/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. {
  27. CppSQLite3Query q = db.execQuery(_T("SELECT lID, lShortCut FROM Main WHERE lShortCut > 0"));
  28. CAccel a;
  29. while(q.eof() == false)
  30. {
  31. a.Cmd = q.getIntField(_T("lID"));
  32. a.Key = q.getIntField(_T("lShortCut"));
  33. a.RefId = CHotKey::PASTE_OPEN_CLIP;
  34. accels.AddAccel(a);
  35. q.nextRow();
  36. }
  37. }
  38. {
  39. CppSQLite3Query q2 = db.execQuery(_T("SELECT lID, MoveToGroupShortCut FROM Main WHERE MoveToGroupShortCut > 0"));
  40. CAccel a2;
  41. while(q2.eof() == false)
  42. {
  43. a2.Cmd = q2.getIntField(_T("lID"));
  44. a2.Key = q2.getIntField(_T("MoveToGroupShortCut"));
  45. a2.RefId = CHotKey::MOVE_TO_GROUP;
  46. accels.AddAccel(a2);
  47. q2.nextRow();
  48. }
  49. }
  50. }
  51. CATCH_SQLITE_EXCEPTION
  52. }
  53. CString CMainTableFunctions::GetDisplayText(int nMaxLines, const CString &OrigText)
  54. {
  55. CString text = OrigText;
  56. // assign tabs to 2 spaces (rather than the default 8)
  57. text.Replace(_T("\t"), _T(" "));
  58. if(g_Opt.m_bDescShowLeadingWhiteSpace)
  59. return text;
  60. // else, remove the leading indent from every line.
  61. // get the lines
  62. CString token;
  63. CStringArray tokens;
  64. CTokenizer tokenizer(text,"\r\n");
  65. for(int nLines=0; nLines < nMaxLines && tokenizer.Next(token); nLines++)
  66. {
  67. tokens.Add(token);
  68. }
  69. // remove each line's indent
  70. TCHAR chFirst;
  71. CString line;
  72. INT_PTR count = tokens.GetSize();
  73. text = "";
  74. for(int i=0; i < count; i++)
  75. {
  76. line = tokens.ElementAt(i);
  77. chFirst = line.GetAt(0);
  78. if(chFirst == ' ' || chFirst == '\t')
  79. {
  80. text += "» "; // show indication that the line is modified
  81. line.TrimLeft();
  82. text += line;
  83. }
  84. else
  85. text += line;
  86. text += "\n";
  87. }
  88. return text;
  89. }