Преглед изворни кода

Added advanced option to renumber clip to whole numbers

Scott Brogden пре 1 недеља
родитељ
комит
eb03c2c6eb
8 измењених фајлова са 78 додато и 65 уклоњено
  1. 2 1
      CP_Main.rc
  2. 1 0
      resource.h
  3. 61 3
      src/AdvGeneral.cpp
  4. 1 0
      src/AdvGeneral.h
  5. 7 1
      src/MoveToGroupDlg.cpp
  6. 2 1
      src/MoveToGroupDlg.h
  7. 3 54
      src/sqlite/CppSQLite3.cpp
  8. 1 5
      src/sqlite/CppSQLite3.h

+ 2 - 1
CP_Main.rc

@@ -1266,11 +1266,12 @@ BEGIN
     EDITTEXT        IDC_EDIT_ADV_FILTER,7,7,351,14,ES_AUTOHSCROLL | ES_WANTRETURN
     CONTROL         "",IDC_MFCPROPERTYGRID1,"MfcPropertyGrid",0x100,7,25,376,194
     PUSHBUTTON      "Compact and Repair Database",IDC_BT_COMPACT_AND_REPAIR,7,251,108,11
-    PUSHBUTTON      "On Copy Scripts",IDC_BUTTON_COPY_SCRIPTS,7,224,108,11
+    PUSHBUTTON      "Reset Group Order",IDC_BUTTON_COPY_SCRIPTS,7,224,108,11
     PUSHBUTTON      "On Paste Scripts",IDC_BUTTON_PASTE_SCRIPTS,7,237,108,11
     DEFPUSHBUTTON   "OK",IDOK,280,251,50,11
     PUSHBUTTON      "Cancel",IDCANCEL,333,250,50,12
     PUSHBUTTON      ">",IDC_BUTTON_NEXT_MATCH,359,7,24,14
+    PUSHBUTTON      "Reset Clip Order",IDC_BUTTON_COPY_SCRIPTS2,122,224,108,11
 END
 
 IDD_SCRIPT_EDITOR DIALOGEX 0, 0, 435, 324

+ 1 - 0
resource.h

@@ -337,6 +337,7 @@
 #define IDC_CHECK_CLIP_TITLE            1042
 #define IDC_CHECK_SHIFT_1               1042
 #define IDC_CHECK_ACTIVE                1042
+#define IDC_BUTTON_COPY_SCRIPTS2        1042
 #define IDC_PLAY_SOUND_2                1043
 #define IDC_CHECK_MOVE_CLIPS_ON_PASTE   1043
 #define IDC_CHECK_CREATE_DATE           1043

+ 61 - 3
src/AdvGeneral.cpp

@@ -7,9 +7,8 @@
 #include "afxdialogex.h"
 #include "ScriptEditor.h"
 #include "DimWnd.h"
-
-
-// CAdvGeneral dialog
+#include "MoveToGroupDlg.h"
+#include "SQlite/CppSQLite3.h"
 
 IMPLEMENT_DYNAMIC(CAdvGeneral, CDialogEx)
 
@@ -41,6 +40,7 @@ BEGIN_MESSAGE_MAP(CAdvGeneral, CDialogEx)
 	ON_WM_NCLBUTTONDOWN()
 	ON_EN_CHANGE(IDC_EDIT_ADV_FILTER, &CAdvGeneral::OnEnChangeAdvFilter)
 	ON_BN_CLICKED(IDC_BUTTON_NEXT_MATCH, &CAdvGeneral::OnBnClickedButtonNextMatch)
+	ON_BN_CLICKED(IDC_BUTTON_COPY_SCRIPTS2, &CAdvGeneral::OnBnClickedButtonCopyScripts2)
 END_MESSAGE_MAP()
 
 
@@ -1184,3 +1184,61 @@ void CAdvGeneral::OnBnClickedButtonNextMatch()
 {
 	Search(true);	
 }
+
+void CAdvGeneral::OnBnClickedButtonCopyScripts2()
+{
+	CDimWnd dimmer(this);
+
+	CMoveToGroupDlg dlg(this, _T("Select group to reset clip order"));
+
+	const auto ret = dlg.DoModal();
+	if (ret == IDOK)
+	{
+		CWaitCursor wait;
+
+		const int groupID = dlg.GetSelectedGroup();
+
+		CString reOrderSql = R"(
+
+			WITH OrderedRows AS(
+				SELECT
+					rowid AS original_rowid,
+					ROW_NUMBER() OVER(ORDER BY {orderField} ASC) AS rn
+				FROM
+					Main
+				WHERE lParentID = {parentID}
+			)
+			--Update the main table using the CTE results
+			UPDATE 
+				Main
+			SET {orderField} = (
+					SELECT rn
+					FROM OrderedRows
+					WHERE OrderedRows.original_rowid = Main.rowid
+				)
+			WHERE lParentID = {parentID}
+		)";
+
+		if (groupID == -1)
+		{
+			reOrderSql.Replace(_T("{orderField}"), _T("clipOrder"));
+
+			//reorder all clip
+			reOrderSql.Replace(_T("WHERE lParentID = {parentID}"), _T(""));
+		}
+		else
+		{
+			reOrderSql.Replace(_T("{parentID}"), std::to_wstring(groupID).c_str());
+			reOrderSql.Replace(_T("{orderField}"), _T("clipGroupOrder"));
+		}
+
+		try
+		{
+			theApp.m_db.execDML(reOrderSql);
+		}
+		catch (CppSQLite3Exception& e)
+		{
+			MessageBox(e.errorMessage());
+		}
+	}
+}

+ 1 - 0
src/AdvGeneral.h

@@ -40,4 +40,5 @@ public:
 	afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point);
 	virtual BOOL PreTranslateMessage(MSG* pMsg);
 	afx_msg void OnBnClickedButtonNextMatch();
+	afx_msg void OnBnClickedButtonCopyScripts2();
 };

+ 7 - 1
src/MoveToGroupDlg.cpp

@@ -17,13 +17,14 @@ static char THIS_FILE[] = __FILE__;
 // CMoveToGroupDlg dialog
 
 
-CMoveToGroupDlg::CMoveToGroupDlg(CWnd* pParent /*=NULL*/)
+CMoveToGroupDlg::CMoveToGroupDlg(CWnd* pParent /*=NULL*/, CString windowTitle /*= _T("")*/)
 	: CDialog(CMoveToGroupDlg::IDD, pParent)
 {
 	//{{AFX_DATA_INIT(CMoveToGroupDlg)
 		// NOTE: the ClassWizard will add member initialization here
 	//}}AFX_DATA_INIT
 	m_nSelectedGroup = -1;
+	m_windowTitle = windowTitle;
 }
 
 
@@ -50,6 +51,11 @@ END_MESSAGE_MAP()
 BOOL CMoveToGroupDlg::OnInitDialog() 
 {
 	CDialog::OnInitDialog();
+
+	if(!m_windowTitle.IsEmpty())
+	{
+		SetWindowText(m_windowTitle);
+	}
 	
 	m_Tree.m_selectedFolderID = m_nSelectedGroup;
 	m_Tree.SetNotificationWndEx(m_hWnd);

+ 2 - 1
src/MoveToGroupDlg.h

@@ -14,7 +14,7 @@ class CMoveToGroupDlg : public CDialog
 {
 // Construction
 public:
-	CMoveToGroupDlg(CWnd* pParent = NULL);   // standard constructor
+	CMoveToGroupDlg(CWnd* pParent = NULL, CString windowTitle = _T(""));   // standard constructor
 
 // Dialog Data
 	//{{AFX_DATA(CMoveToGroupDlg)
@@ -36,6 +36,7 @@ public:
 protected:
 
 	int m_nSelectedGroup;
+	CString m_windowTitle;
 
 	// Generated message map functions
 	//{{AFX_MSG(CMoveToGroupDlg)

+ 3 - 54
src/sqlite/CppSQLite3.cpp

@@ -52,22 +52,10 @@ CppSQLite3Exception::CppSQLite3Exception(const int nErrCode,
 									bool bDeleteMsg/*=true*/) :
 									mnErrCode(nErrCode)
 {
-#ifdef _UNICODE
 	swprintf(mpszErrMess, _T("%s[%d]: %s"),
 								errorCodeAsString(nErrCode),
 								nErrCode,
 								szErrMess ? szErrMess : _T(""));
-#else
-	sprintf(mpszErrMess, "%s[%d]: %s",
-								errorCodeAsString(nErrCode),
-								nErrCode,
-								szErrMess ? szErrMess : "");
-#endif
-
-//	if (bDeleteMsg && szErrMess)
-//	{
-//		sqlite3_free(szErrMess);
-//	}
 }
 
 									
@@ -78,11 +66,7 @@ CppSQLite3Exception::CppSQLite3Exception(const CppSQLite3Exception&  e) :
 
 	if(e.mpszErrMess)
 	{
-#ifdef _UNICODE
 		swprintf(mpszErrMess, _T("%s"), e.mpszErrMess);
-#else
-		sprintf(mpszErrMess, "%s", e.mpszErrMess);
-#endif
 	}
 }
 
@@ -214,11 +198,7 @@ const TCHAR* CppSQLite3Query::fieldValue(int nField)
 								DONT_DELETE_MSG);
 	}
 
-#ifdef _UNICODE
 	return (const TCHAR*)sqlite3_column_text16(mpVM, nField);
-#else
-	return (const TCHAR*)sqlite3_column_text(mpVM, nField);
-#endif
 }
 
 
@@ -226,11 +206,7 @@ const TCHAR* CppSQLite3Query::fieldValue(const TCHAR* szField)
 {
 	int nField = fieldIndex(szField);
 
-#ifdef _UNICODE
 	return (const TCHAR*)sqlite3_column_text16(mpVM, nField);
-#else
-	return (const TCHAR*)sqlite3_column_text(mpVM, nField);
-#endif
 }
 
 
@@ -301,11 +277,7 @@ const TCHAR* CppSQLite3Query::getStringField(int nField, const TCHAR* szNullValu
 	}
 	else
 	{
-#ifdef _UNICODE
 		return (const TCHAR*)sqlite3_column_text16(mpVM, nField);
-#else
-		return (const TCHAR*)sqlite3_column_text(mpVM, nField);
-#endif
 	}
 }
 
@@ -381,11 +353,7 @@ int CppSQLite3Query::fieldIndex(const TCHAR* szField)
 	{
 		for (int nField = 0; nField < mnCols; nField++)
 		{
-#ifdef _UNICODE
 			const TCHAR* szTemp = (const TCHAR*)sqlite3_column_name16(mpVM, nField);
-#else
-			const TCHAR* szTemp = sqlite3_column_name(mpVM, nField);
-#endif
 
 			if(STRCMP(szField, szTemp) == 0)
 			{
@@ -411,11 +379,8 @@ const TCHAR* CppSQLite3Query::fieldName(int nCol)
 								_T("Invalid field index requested"),
 								DONT_DELETE_MSG);
 	}
-#ifdef _UNICODE
+
 	return (const TCHAR*)sqlite3_column_name16(mpVM, nCol);
-#else
-	return sqlite3_column_name(mpVM, nCol);
-#endif
 }
 
 
@@ -430,11 +395,7 @@ const TCHAR* CppSQLite3Query::fieldDeclType(int nCol)
 								DONT_DELETE_MSG);
 	}
 
-#ifdef _UNICODE
 	return (const TCHAR*)sqlite3_column_decltype16(mpVM, nCol);
-#else
-	return sqlite3_column_decltype(mpVM, nCol);
-#endif
 }
 
 
@@ -616,12 +577,8 @@ CppSQLite3Query CppSQLite3Statement::execQuery()
 void CppSQLite3Statement::bind(int nParam, const TCHAR* szValue)
 {
 	checkVM();
-#ifdef _UNICODE
-	int nRes = sqlite3_bind_text16(mpVM, nParam, szValue, -1, SQLITE_TRANSIENT);
-#else
-	int nRes = sqlite3_bind_text(mpVM, nParam, szValue, -1, SQLITE_TRANSIENT);
-#endif
 
+	int nRes = sqlite3_bind_text16(mpVM, nParam, szValue, -1, SQLITE_TRANSIENT);
 	if (nRes != SQLITE_OK)
 	{
 		throw CppSQLite3Exception(nRes,
@@ -828,11 +785,7 @@ bool CppSQLite3DB::DBEncrypted()
 
 void CppSQLite3DB::open(const TCHAR* szFile)
 {
-#ifdef _UNICODE
 	int nRet = sqlite3_open16(szFile, &mpDB);
-#else
-	int nRet = sqlite3_open(szFile, &mpDB);
-#endif
 
 	//sqlite3_exec(mpDB, "PRAGMA rekey=123456", 0, 0, 0);
 	//sqlite3_exec(mpDB, "PRAGMA key=123456", 0, 0, 0);
@@ -1060,14 +1013,10 @@ sqlite3_stmt* CppSQLite3DB::compile(const TCHAR* szSQL)
 	const TCHAR* szTail=0;
 	sqlite3_stmt* pVM;
 
-#ifdef _UNICODE
 	int nRet = sqlite3_prepare16_v2(mpDB, szSQL, -1, &pVM, (const void**)szTail);
-#else
-	int nRet = sqlite3_prepare_v2(mpDB, szSQL, -1, &pVM, &szTail);
-#endif
-
 	if (nRet != SQLITE_OK)
 	{
+		SQLITE3_ERRMSG(mpDB);
 		throw CppSQLite3Exception(nRet, (TCHAR*)szError);
 	}
 

+ 1 - 5
src/sqlite/CppSQLite3.h

@@ -35,11 +35,7 @@
 
 #define CPPSQLITE_ERROR 1000
 
-#ifdef _UNICODE
-	#define SQLITE3_ERRMSG(mpDB) const TCHAR* szError = (const TCHAR*)sqlite3_errmsg16(mpDB)
-#else							
-	#define SQLITE3_ERRMSG(mpDB) const TCHAR* szError = sqlite3_errmsg(mpDB)
-#endif		
+#define SQLITE3_ERRMSG(mpDB) const TCHAR* szError = (const TCHAR*)sqlite3_errmsg16(mpDB)
 
 int sqlite3_encode_binary(const unsigned char *in, int n, unsigned char *out);
 int sqlite3_decode_binary(const unsigned char *in, unsigned char *out);