Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CP_Main.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 61 additions & 3 deletions src/AdvGeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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()


Expand Down Expand Up @@ -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 change: 1 addition & 0 deletions src/AdvGeneral.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ class CAdvGeneral : public CDialogEx
afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point);
virtual BOOL PreTranslateMessage(MSG* pMsg);
afx_msg void OnBnClickedButtonNextMatch();
afx_msg void OnBnClickedButtonCopyScripts2();
};
8 changes: 7 additions & 1 deletion src/MoveToGroupDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand All @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion src/MoveToGroupDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -36,6 +36,7 @@ class CMoveToGroupDlg : public CDialog
protected:

int m_nSelectedGroup;
CString m_windowTitle;

// Generated message map functions
//{{AFX_MSG(CMoveToGroupDlg)
Expand Down
57 changes: 3 additions & 54 deletions src/sqlite/CppSQLite3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
// }
}


Expand All @@ -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
}
}

Expand Down Expand Up @@ -214,23 +198,15 @@ 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
}


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
}


Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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)
{
Expand All @@ -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
}


Expand All @@ -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
}


Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
6 changes: 1 addition & 5 deletions src/sqlite/CppSQLite3.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down