Browse Source

update last paste time when multiple clips are selected

Scott Brogden 8 years ago
parent
commit
ec68550ea8
7 changed files with 97 additions and 54 deletions
  1. 3 3
      CP_Main.cpp
  2. 1 1
      CP_Main.h
  3. 1 1
      DittoSetup/BuildDitto.bld
  4. 3 0
      Misc.h
  5. 64 34
      ProcessPaste.cpp
  6. 1 1
      ProcessPaste.h
  7. 24 14
      QPasteWnd.cpp

+ 3 - 3
CP_Main.cpp

@@ -557,18 +557,18 @@ void CCP_MainApp::RefreshView()
 	}
 }
 
-void CCP_MainApp::RefreshClipAfterPaste(int clipId)
+void CCP_MainApp::RefreshClipAfterPaste(int clipId, int updateFlags)
 {
 	CQPasteWnd *pWnd = QPasteWnd();
 	if(pWnd)
 	{
 		if(m_bAsynchronousRefreshView)
 		{
-			pWnd->PostMessage(WM_RELOAD_CLIP_AFTER_PASTE, clipId, 0);
+			pWnd->PostMessage(WM_RELOAD_CLIP_AFTER_PASTE, clipId, updateFlags);
 		}
 		else
 		{
-			pWnd->SendMessage(WM_RELOAD_CLIP_AFTER_PASTE, clipId, 0);
+			pWnd->SendMessage(WM_RELOAD_CLIP_AFTER_PASTE, clipId, updateFlags);
 		}
 	}
 }

+ 1 - 1
CP_Main.h

@@ -103,7 +103,7 @@ public:
 	CClipTypes* LoadTypesFromDB(); // returns a "new" allocated object
 	void ReloadTypes();
 	void RefreshView(); // refreshes the view if it is visible
-	void RefreshClipAfterPaste(int clipId);
+	void RefreshClipAfterPaste(int clipId, int updateFlags);
 	void OnCopyCompleted( long lLastID, int count = 1 );
 	void OnPasteCompleted();
 

+ 1 - 1
DittoSetup/BuildDitto.bld

@@ -476,7 +476,7 @@ var sc_security="b3f57099";
 		</step>
 		<step action='Git'>
 			<Command>log</Command>
-			<Options>--pretty=format:"%%ad %%s" --date=short   --since=2016-03-18</Options>
+			<Options>--pretty=format:"%%ad %%s" --date=short   --since=2017-02-10</Options>
 			<WorkDir>%workDir%</WorkDir>
 			<buildfailsteps type='11'>0</buildfailsteps>
 			<indent type='3'>2</indent>

+ 3 - 0
Misc.h

@@ -13,6 +13,9 @@
 #define VK_MOUSE_RIGHT_CLICK 0x03
 #define VK_MOUSE_MIDDLE_CLICK 0x04
 
+#define UPDATE_AFTER_PASTE_SELECT_CLIP 0x1
+#define UPDATE_AFTER_PASTE_REFRESH_VISIBLE 0x2
+
 
 //Handle foreign keyboards pressing ALT_GR (right alt), this simulates a control press
 //http://compgroups.net/comp.os.programmer.win32/alt-gr-key-and-left-ctrl/2840252

+ 64 - 34
ProcessPaste.cpp

@@ -87,18 +87,19 @@ void CProcessPaste::MarkAsPasted()
 	Log(_T("start of MarkAsPasted"));
 
 	CClipIDs& clips = GetClipIDs();
-	if(clips.GetSize() == 1)
-	{
-		CGetSetOptions::SetTripPasteCount(-1);
-		CGetSetOptions::SetTotalPasteCount(-1);
-
-		MarkAsPastedData* pData = new MarkAsPastedData();
-		pData->clipId = clips.ElementAt(0);
-		pData->pastedFromGroup = m_pastedFromGroup;
+	
+	CGetSetOptions::SetTripPasteCount(-1);
+	CGetSetOptions::SetTotalPasteCount(-1);
 
-		//Moved to a thread because when running from from U3 devices the write is time consuming
-		AfxBeginThread(CProcessPaste::MarkAsPastedThread, (LPVOID)pData, THREAD_PRIORITY_LOWEST);
+	MarkAsPastedData* pData = new MarkAsPastedData();
+	for (int i = 0; i < clips.GetCount(); i++)
+	{
+		pData->ids.Add(clips.ElementAt(i));
 	}
+	pData->pastedFromGroup = m_pastedFromGroup;
+
+	//Moved to a thread because when running from from U3 devices the write is time consuming
+	AfxBeginThread(CProcessPaste::MarkAsPastedThread, (LPVOID)pData, THREAD_PRIORITY_LOWEST);
 
 	Log(_T("End of MarkAsPasted"));
 }
@@ -120,50 +121,79 @@ UINT CProcessPaste::MarkAsPastedThread(LPVOID pParam)
 		MarkAsPastedData* pData = (MarkAsPastedData*)pParam;
 		if(pData)
 		{
-			clipId = pData->clipId;
-			if(g_Opt.m_bUpdateTimeOnPaste)
+			int clipCount = pData->ids.GetCount();
+
+			if(g_Opt.m_bUpdateTimeOnPaste && 
+				clipCount == 1)
 			{
-				try
+				for (int i = 0; i < clipCount; i++)
 				{
-					if(pData->pastedFromGroup)
+					int id = pData->ids.ElementAt(i);
+					try
 					{
-						CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT clipGroupOrder FROM Main ORDER BY clipGroupOrder DESC LIMIT 1"));
-
-						if(q.eof() == false)
+						if (pData->pastedFromGroup)
 						{
-							double latestDate = q.getFloatField(_T("clipGroupOrder"));
-							latestDate += 1;
+							CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT clipGroupOrder FROM Main ORDER BY clipGroupOrder DESC LIMIT 1"));
 
-							Log(StrF(_T("Setting clipId: %d, GroupOrder: %f"), pData->clipId, latestDate));
+							if (q.eof() == false)
+							{
+								double latestDate = q.getFloatField(_T("clipGroupOrder"));
+								latestDate += 1;
 
-							theApp.m_db.execDMLEx(_T("UPDATE Main SET clipGroupOrder = %f where lID = %d;"), latestDate, pData->clipId);
-						}
-					}
-					else
-					{
-						CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT clipOrder FROM Main ORDER BY clipOrder DESC LIMIT 1"));
+								Log(StrF(_T("Setting clipId: %d, GroupOrder: %f"), id, latestDate));
 
-						if(q.eof() == false)
+								theApp.m_db.execDMLEx(_T("UPDATE Main SET clipGroupOrder = %f where lID = %d;"), latestDate, id);
+							}
+						}
+						else
 						{
-							double latestDate = q.getFloatField(_T("clipOrder"));
-							latestDate += 1;
+							CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT clipOrder FROM Main ORDER BY clipOrder DESC LIMIT 1"));
+
+							if (q.eof() == false)
+							{
+								double latestDate = q.getFloatField(_T("clipOrder"));
+								latestDate += 1;
 
-							Log(StrF(_T("Setting clipId: %d, order: %f"), pData->clipId, latestDate));
+								Log(StrF(_T("Setting clipId: %d, order: %f"), id, latestDate));
 
-							theApp.m_db.execDMLEx(_T("UPDATE Main SET clipOrder = %f where lID = %d;"), latestDate, pData->clipId);
+								theApp.m_db.execDMLEx(_T("UPDATE Main SET clipOrder = %f where lID = %d;"), latestDate, id);
+							}
 						}
 					}
+					CATCH_SQLITE_EXCEPTION
 				}
-				CATCH_SQLITE_EXCEPTION
 			}
 
 			try
 			{
-				theApp.m_db.execDMLEx(_T("UPDATE Main SET lastPasteDate = %d where lID = %d;"), (int)CTime::GetCurrentTime().GetTime(), pData->clipId);
+				for (int i = 0; i < clipCount; i++)
+				{
+					int id = pData->ids.ElementAt(i);
+					theApp.m_db.execDMLEx(_T("UPDATE Main SET lastPasteDate = %d where lID = %d;"), (int)CTime::GetCurrentTime().GetTime(), id);
+				}
 			}
 			CATCH_SQLITE_EXCEPTION
 
-			theApp.RefreshClipAfterPaste(pData->clipId);
+			int refreshFlags = 0;
+
+			//if multiple clips are selected then don't change selection
+			if (clipCount == 1)
+			{
+				refreshFlags |= UPDATE_AFTER_PASTE_SELECT_CLIP;
+			}
+
+			for (int i = 0; i < clipCount; i++)
+			{
+				int id = pData->ids.ElementAt(i);
+
+				//refresh the window on the last clip
+				if (i == clipCount - 1)
+				{
+					refreshFlags |= UPDATE_AFTER_PASTE_REFRESH_VISIBLE;
+				}
+
+				theApp.RefreshClipAfterPaste(id, refreshFlags);
+			}			
 
 			delete pData;
 			bRet = TRUE;

+ 1 - 1
ProcessPaste.h

@@ -29,7 +29,7 @@ public:
 
 	struct MarkAsPastedData 
 	{
-		int clipId;
+		CClipIDs ids;
 		bool pastedFromGroup;
 	};
 	

+ 24 - 14
QPasteWnd.cpp

@@ -985,6 +985,7 @@ LRESULT CQPasteWnd::OnReloadClipAfterPaste(WPARAM wParam, LPARAM lParam)
 
 	BOOL foundClip = FALSE;
 	int clipId = (int)wParam;
+	int updateFlags = (int)lParam;
 
 	CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT clipOrder, clipGroupOrder, lastPasteDate FROM Main WHERE lID = %d"), clipId);			
 	if(q.eof() == false)
@@ -998,27 +999,36 @@ LRESULT CQPasteWnd::OnReloadClipAfterPaste(WPARAM wParam, LPARAM lParam)
 		{
 			if(iter->m_lID == clipId)
 			{
-				iter->m_clipOrder = order;
-				iter->m_clipGroupOrder = orderGroup;
 				iter->m_datePasted = lastPasted;
-
-				theApp.m_FocusID = clipId;
-
-				if(theApp.m_GroupID > 0)
-				{
-					std::sort(m_listItems.begin(), m_listItems.end(), CMainTable::GroupSortDesc);
-				}
-				else
+				
+				if (iter->m_clipOrder != order || iter->m_clipGroupOrder != orderGroup)
 				{
-					std::sort(m_listItems.begin(), m_listItems.end(), CMainTable::SortDesc);
+					iter->m_clipOrder = order;
+					iter->m_clipGroupOrder = orderGroup;
+
+					if (theApp.m_GroupID > 0)
+					{
+						std::sort(m_listItems.begin(), m_listItems.end(), CMainTable::GroupSortDesc);
+					}
+					else
+					{
+						std::sort(m_listItems.begin(), m_listItems.end(), CMainTable::SortDesc);
+					}
 				}
 				
 				foundClip = TRUE;
 				
-				SelectFocusID();
+				if (updateFlags & UPDATE_AFTER_PASTE_SELECT_CLIP)
+				{
+					theApp.m_FocusID = clipId;
+					SelectFocusID();
+				}
 
-				m_lstHeader.RefreshVisibleRows();
-				m_lstHeader.RedrawWindow();
+				if (updateFlags & UPDATE_AFTER_PASTE_REFRESH_VISIBLE)
+				{
+					m_lstHeader.RefreshVisibleRows();
+					m_lstHeader.RedrawWindow();
+				}
 
 				break;
 			}