Browse Source

set group order when moving clip to group

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@579 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 14 years ago
parent
commit
861b335331
3 changed files with 43 additions and 10 deletions
  1. 24 4
      Clip.cpp
  2. 1 0
      Clip.h
  3. 18 6
      ClipIds.cpp

+ 24 - 4
Clip.cpp

@@ -707,16 +707,36 @@ bool CClip::AddToDataTable()
 // old times can happen on fast copies (<1 sec).
 void CClip::MakeLatestTime()
 {
+	m_clipOrder = GetNewOrder(-1);
+}
+
+int CClip::GetNewOrder(int parentId)
+{
+	int newOrder = 0;
 	try
 	{
-		CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT clipOrder FROM Main ORDER BY clipOrder DESC LIMIT 1"));			
-		if(q.eof() == false)
+		if(parentId < 0)
+		{
+			CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT clipOrder FROM Main ORDER BY clipOrder DESC LIMIT 1"));			
+			if(q.eof() == false)
+			{
+				double order = q.getFloatField(_T("clipOrder"));
+				newOrder = order + 1;
+			}
+		}
+		else
 		{
-			double order = q.getFloatField(_T("clipOrder"));
-			m_clipOrder = order + 1;
+			CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT clipGroupOrder FROM Main WHERE lParentID = %d ORDER BY clipOrder DESC LIMIT 1"), parentId);			
+			if(q.eof() == false)
+			{
+				double order = q.getFloatField(_T("clipGroupOrder"));
+				newOrder = order + 1;
+			}
 		}
 	}
 	CATCH_SQLITE_EXCEPTION
+
+	return newOrder;
 }
 
 BOOL CClip::LoadMainTable(int id)

+ 1 - 0
Clip.h

@@ -135,6 +135,7 @@ public:
 	// Fills "types" with all Types in the db for the given Clip ID
 	static void LoadTypes(int id, CClipTypes& types);
 
+	static int GetNewOrder(int parentId);
 	
 protected:
 	bool AddToMainTable();

+ 18 - 6
ClipIds.cpp

@@ -183,13 +183,25 @@ BOOL CClipIDs::MoveTo(long lParentID, double dFirst, double dIncrement)
 	try
 	{
 		INT_PTR count = GetSize();
-		for(int i = 0; i < count; i++)
+		for(int i = count-1; i >= 0; i--)
 		{
-			CString sql = StrF(_T("UPDATE Main SET lParentID = %d ")
-								_T("WHERE lID = %d AND lID <> %d;"), 
-								lParentID,
-								ElementAt(i),
-								lParentID);
+			CString sql;
+
+			if(lParentID > 0)
+			{
+				sql = StrF(_T("UPDATE Main SET lParentID = %d, clipGroupOrder = %d WHERE lID = %d AND lID <> %d;"), 
+							lParentID,
+							CClip::GetNewOrder(lParentID),
+							ElementAt(i),
+							lParentID);
+			}
+			else
+			{
+				sql = StrF(_T("UPDATE Main SET lParentID = %d WHERE lID = %d AND lID <> %d;"), 
+							lParentID,
+							ElementAt(i),
+							lParentID);
+			}
 
 			theApp.m_db.execDMLEx(sql);
 		}