Pārlūkot izejas kodu

Added options to move clips up/down/top

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@796 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 10 gadi atpakaļ
vecāks
revīzija
3c3d6d4f51
9 mainītis faili ar 481 papildinājumiem un 143 dzēšanām
  1. 3 0
      ActionEnums.h
  2. 5 1
      CP_Main.rc
  3. 184 32
      Clip.cpp
  4. 2 1
      Clip.h
  5. 1 1
      MainFrm.cpp
  6. 1 0
      QListCtrl.cpp
  7. 270 106
      QPasteWnd.cpp
  8. 11 1
      QPasteWnd.h
  9. 4 1
      Resource.h

+ 3 - 0
ActionEnums.h

@@ -44,6 +44,9 @@ public:
 		EXPORT_TO_GOOGLE_TRANSLATE,
 		EXPORT_TO_BITMAP_FILE,
 		SAVE_CURRENT_CLIPBOARD,
+		MOVE_CLIP_UP,
+		MOVE_CLIP_DOWN,
+		MOVE_CLIP_TOP,
 
 	};
 };

+ 5 - 1
CP_Main.rc

@@ -302,8 +302,12 @@ BEGIN
             MENUITEM "Remove Hot Key",              32822,MFT_STRING,MFS_ENABLED
             MENUITEM "Remove Quick Paste",          32856,MFT_STRING | MFT_RIGHTJUSTIFY,MFS_ENABLED
         END
-        POPUP "Sticky Clips",                   65535,MFT_STRING,MFS_ENABLED
+        POPUP "Clip Order",                     65535,MFT_STRING,MFS_ENABLED
         BEGIN
+            MENUITEM "Move To Top",                 ID_CLIPORDER_MOVETOTOP,MFT_STRING,MFS_ENABLED
+            MENUITEM "Move Up",                     ID_CLIPORDER_MOVEUP,MFT_STRING,MFS_ENABLED
+            MENUITEM "Move Down",                   ID_CLIPORDER_MOVEDOWN,MFT_STRING,MFS_ENABLED
+            MENUITEM MFT_SEPARATOR
             MENUITEM "Make Top Sticky Clip",        ID_STICKYCLIPS_MAKETOPSTICKYCLIP,MFT_STRING,MFS_ENABLED
             MENUITEM "Make Last Sticky Clip",       ID_STICKYCLIPS_MAKELASTSTICKYCLIP,MFT_STRING,MFS_ENABLED
             MENUITEM "Remove Sticky Setting",       ID_STICKYCLIPS_REMOVESTICKYSETTING,MFT_STRING,MFS_ENABLED

+ 184 - 32
Clip.cpp

@@ -783,52 +783,204 @@ bool CClip::AddToDataTable()
 	return true;
 }
 
-void CClip::MoveUp()
+void CClip::MoveUp(int parentId)
 {
-	if (m_stickyClipOrder == INVALID_STICKY)
+	try
 	{
-		CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, clipOrder FROM Main Where clipOrder > %f ORDER BY clipOrder ASC LIMIT 1"), m_clipOrder);
-		if (q.eof() == false)
+		//In a group, not a sticky
+		if(parentId > -1 && m_stickyClipGroupOrder == INVALID_STICKY)
 		{
-			int idAbove = q.getIntField(_T("lID"));
-			double orderAbove = q.getFloatField(_T("clipOrder"));
-
-			CppSQLite3Query q2 = theApp.m_db.execQueryEx(_T("SELECT lID, clipOrder FROM Main Where clipOrder > %f ORDER BY clipOrder ASC LIMIT 1"), orderAbove);
-			if (q2.eof() == false)
-			{ 
-				int idTwoAbove = q2.getIntField(_T("lID"));
-				double orderTwoAbove = q2.getFloatField(_T("clipOrder"));
-			
-				m_clipOrder = orderAbove + (orderTwoAbove - orderAbove) / 2.0;
+			CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, clipGroupOrder FROM Main Where lParentID = %d AND stickyClipGroupOrder == -(2147483647) AND clipGroupOrder > %f ORDER BY clipGroupOrder ASC LIMIT 1"), parentId, m_clipGroupOrder);
+			if (q.eof() == false)
+			{
+				int idAbove = q.getIntField(_T("lID"));
+				double orderAbove = q.getFloatField(_T("clipGroupOrder"));
+
+				CppSQLite3Query q2 = theApp.m_db.execQueryEx(_T("SELECT lID, clipGroupOrder FROM Main Where lParentID = %d AND clipGroupOrder > %f AND stickyClipGroupOrder == -(2147483647) ORDER BY clipGroupOrder ASC LIMIT 1"), parentId, orderAbove);
+				if (q2.eof() == false)
+				{ 
+					int idTwoAbove = q2.getIntField(_T("lID"));
+					double orderTwoAbove = q2.getFloatField(_T("clipGroupOrder"));
+
+					m_clipGroupOrder = orderAbove + (orderTwoAbove - orderAbove) / 2.0;
+				}
+				else
+				{
+					m_clipGroupOrder = orderAbove + 1;
+				}
 			}
-			else
+		}
+		// main group, not a sticky
+		else if(parentId <= -1 && m_stickyClipOrder == INVALID_STICKY)
+		{
+			CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, clipOrder FROM Main Where clipOrder > %f AND stickyClipOrder == -(2147483647) ORDER BY clipOrder ASC LIMIT 1"), m_clipOrder);
+			if (q.eof() == false)
 			{
-				m_clipOrder = orderAbove + 1;
+				int idAbove = q.getIntField(_T("lID"));
+				double orderAbove = q.getFloatField(_T("clipOrder"));
+
+				CppSQLite3Query q2 = theApp.m_db.execQueryEx(_T("SELECT lID, clipOrder FROM Main Where clipOrder > %f AND stickyClipOrder == -(2147483647) ORDER BY clipOrder ASC LIMIT 1"), orderAbove);
+				if (q2.eof() == false)
+				{ 
+					int idTwoAbove = q2.getIntField(_T("lID"));
+					double orderTwoAbove = q2.getFloatField(_T("clipOrder"));
+
+					m_clipOrder = orderAbove + (orderTwoAbove - orderAbove) / 2.0;
+				}
+				else
+				{
+					m_clipOrder = orderAbove + 1;
+				}
+			}
+		}
+		//In a group, a sticky clip
+		else if(parentId > -1 && m_stickyClipGroupOrder != INVALID_STICKY)
+		{
+			CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, stickyClipGroupOrder FROM Main Where lParentID = %d AND stickyClipGroupOrder <> -(2147483647) AND stickyClipGroupOrder > %f ORDER BY stickyClipGroupOrder ASC LIMIT 1"), parentId, m_stickyClipGroupOrder);
+			if (q.eof() == false)
+			{
+				int idAbove = q.getIntField(_T("lID"));
+				double orderAbove = q.getFloatField(_T("stickyClipGroupOrder"));
+
+				CppSQLite3Query q2 = theApp.m_db.execQueryEx(_T("SELECT lID, stickyClipGroupOrder FROM Main Where lParentID = %d AND stickyClipGroupOrder <> -(2147483647) AND stickyClipGroupOrder > %f ORDER BY stickyClipGroupOrder ASC LIMIT 1"), parentId, orderAbove);
+				if (q2.eof() == false)
+				{
+					int idTwoAbove = q2.getIntField(_T("lID"));
+					double orderTwoAbove = q2.getFloatField(_T("stickyClipGroupOrder"));
+
+					m_stickyClipGroupOrder = orderAbove + (orderTwoAbove - orderAbove) / 2.0;
+				}
+				else
+				{
+					m_stickyClipGroupOrder = orderAbove + 1;
+				}
+			}
+		}
+		//not in a group, a sticky clip
+		else if(parentId <= -1 && m_stickyClipOrder != INVALID_STICKY)
+		{
+			CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, stickyClipOrder FROM Main Where stickyClipOrder <> -(2147483647) AND stickyClipOrder > %f ORDER BY stickyClipOrder ASC LIMIT 1"), m_stickyClipOrder);
+			if (q.eof() == false)
+			{
+				int idAbove = q.getIntField(_T("lID"));
+				double orderAbove = q.getFloatField(_T("stickyClipOrder"));
+
+				CppSQLite3Query q2 = theApp.m_db.execQueryEx(_T("SELECT lID, stickyClipOrder FROM Main Where stickyClipOrder <> -(2147483647) AND stickyClipOrder > %f ORDER BY stickyClipOrder ASC LIMIT 1"), orderAbove);
+				if (q2.eof() == false)
+				{
+					int idTwoAbove = q2.getIntField(_T("lID"));
+					double orderTwoAbove = q2.getFloatField(_T("stickyClipOrder"));
+
+					m_stickyClipOrder = orderAbove + (orderTwoAbove - orderAbove) / 2.0;
+				}
+				else
+				{
+					m_stickyClipOrder = orderAbove + 1;
+				}
 			}
 		}
 	}
-	else 
+	CATCH_SQLITE_EXCEPTION
+}
+
+void CClip::MoveDown(int parentId)
+{
+	try
 	{
-		CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, stickyClipOrder FROM Main Where stickyClipOrder > %f ORDER BY clipOrder ASC LIMIT 1"), m_stickyClipOrder);
-		if (q.eof() == false)
+		//In a group, not a sticky
+		if(parentId > -1 && m_stickyClipGroupOrder == INVALID_STICKY)
 		{
-			int idAbove = q.getIntField(_T("lID"));
-			double orderAbove = q.getFloatField(_T("stickyClipOrder"));
+			CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, clipGroupOrder FROM Main Where lParentID = %d AND clipGroupOrder < %f AND stickyClipGroupOrder = -(2147483647) ORDER BY clipGroupOrder DESC LIMIT 1"), parentId, m_clipGroupOrder);
+			if (q.eof() == false)
+			{
+				int idBelow = q.getIntField(_T("lID"));
+				double orderBelow = q.getFloatField(_T("clipGroupOrder"));
+
+				CppSQLite3Query q2 = theApp.m_db.execQueryEx(_T("SELECT lID, clipGroupOrder FROM Main Where lParentID = %d AND clipGroupOrder < %f AND stickyClipGroupOrder = -(2147483647) ORDER BY clipGroupOrder DESC LIMIT 1"), parentId, orderBelow);
+				if (q2.eof() == false)
+				{ 
+					int idTwoBelow = q2.getIntField(_T("lID"));
+					double orderTwoBelow = q2.getFloatField(_T("clipGroupOrder"));
 
-			CppSQLite3Query q2 = theApp.m_db.execQueryEx(_T("SELECT lID, stickyClipOrder FROM Main Where stickyClipOrder > %f ORDER BY clipOrder ASC LIMIT 1"), orderAbove);
-			if (q2.eof() == false)
+					m_clipGroupOrder = orderBelow + (orderTwoBelow - orderBelow) / 2.0;
+				}
+				else
+				{
+					m_clipGroupOrder = orderBelow - 1;
+				}
+			}
+		}
+		// main group, not a sticky
+		else if(parentId <= -1 && m_stickyClipOrder == INVALID_STICKY)
+		{
+			CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, clipOrder FROM Main Where clipOrder < %f AND stickyClipOrder = -(2147483647) ORDER BY clipOrder DESC LIMIT 1"), m_clipOrder);
+			if (q.eof() == false)
 			{
-				int idTwoAbove = q2.getIntField(_T("lID"));
-				double orderTwoAbove = q2.getFloatField(_T("stickyClipOrder"));
+				int idBelow = q.getIntField(_T("lID"));
+				double orderBelow = q.getFloatField(_T("clipOrder"));
+
+				CppSQLite3Query q2 = theApp.m_db.execQueryEx(_T("SELECT lID, clipOrder FROM Main Where clipOrder < %f AND stickyClipOrder = -(2147483647) ORDER BY clipOrder DESC LIMIT 1"), orderBelow);
+				if (q2.eof() == false)
+				{ 
+					int idTwoBelow = q2.getIntField(_T("lID"));
+					double orderTwoBelow = q2.getFloatField(_T("clipOrder"));
 
-				m_stickyClipOrder = orderAbove + (orderTwoAbove - orderAbove) / 2.0;
+					m_clipOrder = orderBelow + (orderTwoBelow - orderBelow) / 2.0;
+				}
+				else
+				{
+					m_clipOrder = orderBelow - 1;
+				}
 			}
-			else
+		}
+		//In a group, a sticky clip
+		else if(parentId > -1 && m_stickyClipGroupOrder != INVALID_STICKY)
+		{
+			CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, stickyClipGroupOrder FROM Main Where lParentID = %d AND stickyClipGroupOrder <> -(2147483647) AND stickyClipGroupOrder < %f ORDER BY stickyClipGroupOrder DESC LIMIT 1"), parentId, m_stickyClipGroupOrder);
+			if (q.eof() == false)
+			{
+				int idBelow = q.getIntField(_T("lID"));
+				double orderBelow = q.getFloatField(_T("stickyClipGroupOrder"));
+
+				CppSQLite3Query q2 = theApp.m_db.execQueryEx(_T("SELECT lID, stickyClipGroupOrder FROM Main Where lParentID = %d AND stickyClipGroupOrder <> -(2147483647) AND stickyClipGroupOrder < %f ORDER BY stickyClipGroupOrder DESC LIMIT 1"), parentId, orderBelow);
+				if (q2.eof() == false)
+				{
+					int idTwoBelow = q2.getIntField(_T("lID"));
+					double orderTwoBelow = q2.getFloatField(_T("stickyClipGroupOrder"));
+
+					m_stickyClipGroupOrder = orderBelow + (orderTwoBelow - orderBelow) / 2.0;
+				}
+				else
+				{
+					m_stickyClipGroupOrder = orderBelow - 1;
+				}
+			}
+		}
+		//not in a group, a sticky clip
+		else if(parentId <= -1 && m_stickyClipOrder != INVALID_STICKY)
+		{
+			CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, stickyClipOrder FROM Main Where stickyClipOrder <> -(2147483647) AND stickyClipOrder < %f ORDER BY stickyClipOrder DESC LIMIT 1"), m_stickyClipOrder);
+			if (q.eof() == false)
 			{
-				m_stickyClipOrder = orderAbove + 1;
+				int idBelow = q.getIntField(_T("lID"));
+				double orderBelow = q.getFloatField(_T("stickyClipOrder"));
+
+				CppSQLite3Query q2 = theApp.m_db.execQueryEx(_T("SELECT lID, stickyClipOrder FROM Main Where stickyClipOrder <> -(2147483647) AND stickyClipOrder < %f ORDER BY stickyClipOrder DESC LIMIT 1"), orderBelow);
+				if (q2.eof() == false)
+				{
+					int idTwoBelow = q2.getIntField(_T("lID"));
+					double orderTwoBelow = q2.getFloatField(_T("stickyClipOrder"));
+
+					m_stickyClipOrder = orderBelow + (orderTwoBelow - orderBelow) / 2.0;
+				}
+				else
+				{
+					m_stickyClipOrder = orderBelow - 1;
+				}
 			}
 		}
 	}
+	CATCH_SQLITE_EXCEPTION
 }
 
 void CClip::MakeStickyTop(int parentId)
@@ -877,7 +1029,7 @@ double CClip::GetNewTopSticky(int parentId, int clipId)
 	{
 		if (parentId < 0)
 		{
-			CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT stickyClipOrder, mText FROM Main ORDER BY stickyClipOrder DESC LIMIT 1"));
+			CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT stickyClipOrder, mText FROM Main WHERE stickyClipOrder <> -(2147483647) ORDER BY stickyClipOrder DESC LIMIT 1"));
 			if (q.eof() == false)
 			{
 				existingMaxOrder = q.getFloatField(_T("stickyClipOrder"));
@@ -887,7 +1039,7 @@ double CClip::GetNewTopSticky(int parentId, int clipId)
 		}
 		else
 		{
-			CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT stickyClipGroupOrder, mText FROM Main WHERE lParentID = %d ORDER BY stickyClipGroupOrder DESC LIMIT 1"), parentId);
+			CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT stickyClipGroupOrder, mText FROM Main WHERE lParentID = %d AND stickyClipGroupOrder <> -(2147483647) ORDER BY stickyClipGroupOrder DESC LIMIT 1"), parentId);
 			if (q.eof() == false)
 			{
 				existingMaxOrder = q.getFloatField(_T("stickyClipGroupOrder"));
@@ -915,7 +1067,7 @@ double CClip::GetNewLastSticky(int parentId, int clipId)
 	{
 		if (parentId < 0)
 		{
-			CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT stickyClipOrder, mText FROM Main WHERE stickyClipOrder <> -10000000 ORDER BY stickyClipOrder LIMIT 1"));
+			CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT stickyClipOrder, mText FROM Main WHERE stickyClipOrder <> -(2147483647) ORDER BY stickyClipOrder LIMIT 1"));
 			if (q.eof() == false)
 			{
 				existingMaxOrder = q.getFloatField(_T("stickyClipOrder"));
@@ -925,7 +1077,7 @@ double CClip::GetNewLastSticky(int parentId, int clipId)
 		}
 		else
 		{
-			CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT stickyClipGroupOrder, mText FROM Main WHERE lParentID = %d ORDER BY stickyClipGroupOrder LIMIT 1"), parentId);
+			CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT stickyClipGroupOrder, mText FROM Main WHERE lParentID = %d AND stickyClipGroupOrder <> -(2147483647) ORDER BY stickyClipGroupOrder LIMIT 1"), parentId);
 			if (q.eof() == false)
 			{
 				existingMaxOrder = q.getFloatField(_T("stickyClipGroupOrder"));

+ 2 - 1
Clip.h

@@ -139,7 +139,8 @@ public:
 	void RemoveStickySetting(int parentId);
 	BOOL LoadMainTable(int id);
 	DWORD GenerateCRC();
-	void MoveUp();
+	void MoveUp(int parentId);
+	void MoveDown(int parentId);
 
 	CStringW GetUnicodeTextFormat();
 	CStringA GetCFTextTextFormat();

+ 1 - 1
MainFrm.cpp

@@ -1272,7 +1272,7 @@ LRESULT CMainFrame::OnShowMsgWindow(WPARAM wParam, LPARAM lParam)
 
 	::SetWindowPos(m_pPopupWindow->m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
 
-	SetTimer(CLOSE_POPUP_MSG_WND, 2000, 0);
+	SetTimer(CLOSE_POPUP_MSG_WND, 2500, 0);
 
 	delete pMsg;
 	return TRUE;

+ 1 - 0
QListCtrl.cpp

@@ -276,6 +276,7 @@ BOOL CQListCtrl::SetListPos( int index )
 	RemoveAllSelection();
 	SetCaret(index);
 	SetSelection(index);
+	ListView_SetSelectionMark(m_hWnd, index);
 	EnsureVisible(index,FALSE);
 
 	return TRUE;

+ 270 - 106
QPasteWnd.cpp

@@ -233,6 +233,12 @@ ON_COMMAND(ID_MENU_WILDCARDSEARCH, &CQPasteWnd::OnMenuWildcardsearch)
 ON_COMMAND(ID_MENU_SAVECURRENTCLIPBOARD, &CQPasteWnd::OnMenuSavecurrentclipboard)
 ON_UPDATE_COMMAND_UI(ID_MENU_SAVECURRENTCLIPBOARD, &CQPasteWnd::OnUpdateMenuSavecurrentclipboard)
 ON_MESSAGE(NM_MOVE_TO_GROUP, OnListMoveSelectionToGroup)
+ON_COMMAND(ID_CLIPORDER_MOVEUP, &CQPasteWnd::OnCliporderMoveup)
+ON_UPDATE_COMMAND_UI(ID_CLIPORDER_MOVEUP, &CQPasteWnd::OnUpdateCliporderMoveup)
+ON_COMMAND(ID_CLIPORDER_MOVEDOWN, &CQPasteWnd::OnCliporderMovedown)
+ON_UPDATE_COMMAND_UI(ID_CLIPORDER_MOVEDOWN, &CQPasteWnd::OnUpdateCliporderMovedown)
+ON_COMMAND(ID_CLIPORDER_MOVETOTOP, &CQPasteWnd::OnCliporderMovetotop)
+ON_UPDATE_COMMAND_UI(ID_CLIPORDER_MOVETOTOP, &CQPasteWnd::OnUpdateCliporderMovetotop)
 END_MESSAGE_MAP()
 
 
@@ -2027,29 +2033,10 @@ void CQPasteWnd::OnMakeTopStickyClip()
 				clip.MakeStickyTop(theApp.m_GroupID);
 				clip.ModifyMainTable();
 
-				std::vector<CMainTable>::iterator iter = m_listItems.begin();
-				while (iter != m_listItems.end())
-				{
-					if (iter->m_lID == id)
-					{
-						if (theApp.m_GroupID > 0)
-						{
-							iter->m_stickyClipGroupOrder = clip.m_stickyClipGroupOrder;
-						}
-						else
-						{
-							iter->m_stickyClipOrder = clip.m_stickyClipOrder;							
-						}
-						sort = true;
-						break;
-					}
-					iter++;
-				}
+				sort = SyncClipDataToArrayData(clip);
 			}
 		}
-
-			//theApp.m_FocusID = id;
-
+		
 		if(sort)
 		{
 			if (theApp.m_GroupID > 0)
@@ -2061,7 +2048,7 @@ void CQPasteWnd::OnMakeTopStickyClip()
 				std::sort(m_listItems.begin(), m_listItems.end(), CMainTable::SortDesc);
 			}
 
-			//SelectFocusID();
+			SelectIds(IDs);
 
 			m_lstHeader.RefreshVisibleRows();
 			m_lstHeader.RedrawWindow();
@@ -2071,8 +2058,6 @@ void CQPasteWnd::OnMakeTopStickyClip()
 
 void CQPasteWnd::OnMakeLastStickyClip()
 {
-//	OnMoveClipUp();
-//	return;
 	ARRAY IDs;
 	m_lstHeader.GetSelectionItemData(IDs);
 
@@ -2088,83 +2073,10 @@ void CQPasteWnd::OnMakeLastStickyClip()
 				clip.MakeStickyLast(theApp.m_GroupID);
 				clip.ModifyMainTable();
 
-				std::vector<CMainTable>::iterator iter = m_listItems.begin();
-				while (iter != m_listItems.end())
-				{
-					if (iter->m_lID == id)
-					{
-						if (theApp.m_GroupID > 0)
-						{
-							iter->m_stickyClipGroupOrder = clip.m_stickyClipGroupOrder;
-						}
-						else
-						{
-							iter->m_stickyClipOrder = clip.m_stickyClipOrder;							
-						}
-						sort = true;
-						break;
-					}
-					iter++;
-				}
-			}
-		}
-
-		//theApp.m_FocusID = id;
-
-		if (sort)
-		{
-			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);
-			}
-
-			//SelectFocusID();
-
-			m_lstHeader.RefreshVisibleRows();
-			m_lstHeader.RedrawWindow();
-		}
-	}
-}
-
-void CQPasteWnd::OnMoveClipUp()
-{
-	ARRAY IDs;
-	m_lstHeader.GetSelectionItemData(IDs);
-
-	if (IDs.GetCount() > 0)
-	{
-		bool sort = false;
-		for (int i = IDs.GetCount() - 1; i >= 0; i--)
-		{
-			int id = IDs[i];
-			CClip clip;
-			if (clip.LoadMainTable(id))
-			{
-				clip.MoveUp();
-				clip.ModifyMainTable();
-
-				std::vector<CMainTable>::iterator iter = m_listItems.begin();
-				while (iter != m_listItems.end())
-				{
-					if (iter->m_lID == id)
-					{
-						iter->m_clipOrder = clip.m_clipOrder;
-						iter->m_stickyClipOrder = clip.m_stickyClipOrder;
-						
-						sort = true;
-						break;
-					}
-					iter++;
-				}
+				sort = SyncClipDataToArrayData(clip);
 			}
 		}
-
-		//theApp.m_FocusID = id;
-
+		
 		if (sort)
 		{
 			if (theApp.m_GroupID > 0)
@@ -2176,7 +2088,7 @@ void CQPasteWnd::OnMoveClipUp()
 				std::sort(m_listItems.begin(), m_listItems.end(), CMainTable::SortDesc);
 			}
 
-			//SelectFocusID();
+			SelectIds(IDs);
 
 			m_lstHeader.RefreshVisibleRows();
 			m_lstHeader.RedrawWindow();
@@ -2765,6 +2677,16 @@ bool CQPasteWnd::DoAction(DWORD actionId)
 		break;
 	case ActionEnums::SAVE_CURRENT_CLIPBOARD:
 		ret = DoSaveCurrentClipboard();
+		break;
+	case ActionEnums::MOVE_CLIP_DOWN:
+		ret = DoMoveClipDown();
+		break;
+	case ActionEnums::MOVE_CLIP_UP:
+		ret = DoMoveClipUp();
+		break;
+	case ActionEnums::MOVE_CLIP_TOP:
+		ret = DoMoveClipTOP();
+		break;
 	}
 
 	return ret;
@@ -3608,6 +3530,139 @@ bool CQPasteWnd::DoSaveCurrentClipboard()
 	return true;
 }
 
+bool CQPasteWnd::DoMoveClipDown()
+{
+	ARRAY IDs;
+	m_lstHeader.GetSelectionItemData(IDs);
+
+	if (IDs.GetCount() > 0)
+	{
+		bool sort = false;
+		for (int i = IDs.GetCount() - 1; i >= 0; i--)
+		{
+			int id = IDs[i];
+			CClip clip;
+			if (clip.LoadMainTable(id))
+			{
+				clip.MoveDown(theApp.m_GroupID);
+				clip.ModifyMainTable();
+
+				sort = SyncClipDataToArrayData(clip);
+			}
+		}
+		
+		if (sort)
+		{
+			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);
+			}
+
+			SelectIds(IDs);
+
+			m_lstHeader.RefreshVisibleRows();
+			m_lstHeader.RedrawWindow();
+		}
+	}
+
+	return true;
+}
+
+bool CQPasteWnd::DoMoveClipUp()
+{
+	ARRAY IDs;
+	m_lstHeader.GetSelectionItemData(IDs);
+
+	if (IDs.GetCount() > 0)
+	{
+		bool sort = false;
+		for (int i = 0; i < IDs.GetCount(); i++)
+		{
+			int id = IDs[i];
+			CClip clip;
+			if (clip.LoadMainTable(id))
+			{
+				clip.MoveUp(theApp.m_GroupID);
+				clip.ModifyMainTable();
+
+				sort = SyncClipDataToArrayData(clip);
+			}
+		}
+		
+		if (sort)
+		{
+			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);
+			}
+
+			SelectIds(IDs);
+
+			m_lstHeader.RefreshVisibleRows();
+			m_lstHeader.RedrawWindow();
+		}
+	}
+
+	return true;
+}
+
+bool CQPasteWnd::DoMoveClipTOP()
+{
+	ARRAY IDs;
+	m_lstHeader.GetSelectionItemData(IDs);
+
+	if (IDs.GetCount() > 0)
+	{
+		bool sort = false;
+		for (int i = 0; i < IDs.GetCount(); i++)
+		{
+			int id = IDs[i];
+			CClip clip;
+			if (clip.LoadMainTable(id))
+			{
+				if (theApp.m_GroupID > 0)
+				{
+					clip.MakeLatestGroupOrder();
+				}
+				else
+				{
+					clip.MakeLatestOrder();
+				}
+				clip.ModifyMainTable();
+
+				sort = SyncClipDataToArrayData(clip);
+			}
+		}
+		
+		if (sort)
+		{
+			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);
+			}
+			
+			SelectIds(IDs);
+
+			m_lstHeader.RefreshVisibleRows();
+			m_lstHeader.RedrawWindow();
+		}
+	}
+
+	return true;
+}
+
 bool CQPasteWnd::DoExportToBitMapFile()
 {
 	bool ret = false;
@@ -3813,9 +3868,19 @@ void CQPasteWnd::GetDispInfo(NMHDR *pNMHDR, LRESULT *pResult)
                             cs += "G";
                         }
 
-						if (m_listItems[pItem->iItem].m_stickyClipOrder != INVALID_STICKY)
+						if (theApp.m_GroupID > 0)
 						{
-							cs += "Sticky";
+							if (m_listItems[pItem->iItem].m_stickyClipGroupOrder != INVALID_STICKY)
+							{
+								cs += "Sticky";
+							}
+						}
+						else
+						{
+							if (m_listItems[pItem->iItem].m_stickyClipOrder != INVALID_STICKY)
+							{
+								cs += "Sticky";
+							}
 						}
 
                         // attached to a group
@@ -4025,15 +4090,16 @@ void CQPasteWnd::OnGetToolTipText(NMHDR *pNMHDR, LRESULT *pResult)
         CString cs;
 
         int id = m_lstHeader.GetItemData(pInfo->lItem);
-        CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, mText, lDate, lShortCut, clipOrder, clipGroupOrder, stickyClipOrder, lDontAutoDelete, QuickPasteText, lastPasteDate, globalShortCut FROM Main WHERE lID = %d"), id);
+        CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, mText, lDate, lShortCut, clipOrder, clipGroupOrder, stickyClipOrder, stickyClipGroupOrder, lDontAutoDelete, QuickPasteText, lastPasteDate, globalShortCut FROM Main WHERE lID = %d"), id);
         if(q.eof() == false)
         {
             cs = q.getStringField(1);
             cs += "\n\n";
-
             #ifdef _DEBUG
-                cs += StrF(_T("(Index = %d) (DB ID = %d) (Seq = %f) (Group Seq = %f) (Sticky Seq = %f)\n"), pInfo->lItem, q.getIntField(_T("lID")), 
-													q.getFloatField(_T("clipOrder")), q.getFloatField(_T("clipGroupOrder")), q.getFloatField(_T("stickyClipOrder")));
+                cs += StrF(_T("(Index = %d) (DB ID = %d) (Seq = %f) (Group Seq = %f) (Sticky Seq = %f) (Sticky Group Seq = %f)\n"), 
+								pInfo->lItem, q.getIntField(_T("lID")), 
+													q.getFloatField(_T("clipOrder")), q.getFloatField(_T("clipGroupOrder")), 
+													q.getFloatField(_T("stickyClipOrder")), q.getFloatField(_T("stickyClipGroupOrder")));
             #endif 
 
             COleDateTime time((time_t)q.getIntField(_T("lDate")));
@@ -4939,3 +5005,101 @@ void CQPasteWnd::OnUpdateMenuSavecurrentclipboard(CCmdUI *pCmdUI)
 
 	UpdateMenuShortCut(pCmdUI, ActionEnums::SAVE_CURRENT_CLIPBOARD);
 }
+
+
+bool CQPasteWnd::SyncClipDataToArrayData(CClip &clip)
+{
+	int row = 0;
+	bool found = false;
+	std::vector<CMainTable>::iterator iter = m_listItems.begin();
+	while (iter != m_listItems.end())
+	{
+		if (iter->m_lID == clip.ID())
+		{
+			iter->m_clipOrder = clip.m_clipOrder;			
+			iter->m_clipGroupOrder = clip.m_clipGroupOrder;
+
+			iter->m_stickyClipOrder = clip.m_stickyClipOrder;
+			iter->m_stickyClipGroupOrder = clip.m_stickyClipGroupOrder;
+			
+			found = true;
+			break;
+		}
+		iter++;
+		row++;
+	}
+
+	return found;
+}
+
+bool CQPasteWnd::SelectIds(ARRAY &ids)
+{
+	int row = 0;
+	bool found = false;
+	std::vector<CMainTable>::iterator iter = m_listItems.begin();
+	while (iter != m_listItems.end())
+	{
+		if(ids.Find(iter->m_lID))
+		{
+			if(found == false)
+			{
+				m_lstHeader.SetListPos(row);
+			}
+			else
+			{
+				m_lstHeader.SetSelection(row);
+			}
+
+			found = true;
+		}
+		iter++;
+		row++;
+	}
+
+	return found;
+}
+
+void CQPasteWnd::OnCliporderMoveup()
+{
+	DoAction(ActionEnums::MOVE_CLIP_UP);
+}
+
+void CQPasteWnd::OnUpdateCliporderMoveup(CCmdUI *pCmdUI)
+{
+	if (!pCmdUI->m_pMenu)
+	{
+		return;
+	}
+
+	UpdateMenuShortCut(pCmdUI, ActionEnums::MOVE_CLIP_UP);
+}
+
+void CQPasteWnd::OnCliporderMovedown()
+{
+	DoAction(ActionEnums::MOVE_CLIP_DOWN);
+}
+
+void CQPasteWnd::OnUpdateCliporderMovedown(CCmdUI *pCmdUI)
+{
+	if (!pCmdUI->m_pMenu)
+	{
+		return;
+	}
+
+	UpdateMenuShortCut(pCmdUI, ActionEnums::MOVE_CLIP_DOWN);
+}
+
+void CQPasteWnd::OnCliporderMovetotop()
+{
+	DoAction(ActionEnums::MOVE_CLIP_TOP);
+}
+
+void CQPasteWnd::OnUpdateCliporderMovetotop(CCmdUI *pCmdUI)
+{
+	if (!pCmdUI->m_pMenu)
+	{
+		return;
+	}
+
+	UpdateMenuShortCut(pCmdUI, ActionEnums::MOVE_CLIP_TOP);
+}

+ 11 - 1
QPasteWnd.h

@@ -238,11 +238,16 @@ public:
 	bool DoExportToGoogleTranslate();
 	bool DoExportToBitMapFile();
 	bool DoSaveCurrentClipboard();
+	bool DoMoveClipDown();
+	bool DoMoveClipUp();
+	bool DoMoveClipTOP();
 
 	void UpdateMenuShortCut(CCmdUI *pCmdUI, DWORD action);
 
 	bool ShowProperties(int id, int row);
 	bool DeleteClips(CClipIDs &IDs, ARRAY &Indexs);
+	bool SyncClipDataToArrayData(CClip &clip);
+	bool SelectIds(ARRAY &ids);
 
     // Generated message map functions
 protected:
@@ -382,7 +387,6 @@ protected:
 	afx_msg void OnMakeLastStickyClip();
 	afx_msg void OnRemoveStickySetting();
 	afx_msg void OnElevateAppToPasteIntoElevatedApp();
-	afx_msg void OnMoveClipUp();
 	
 public:
 	afx_msg void OnQuickoptionsShowintaskbar();
@@ -403,4 +407,10 @@ public:
 	afx_msg void OnMenuWildcardsearch();
 	afx_msg void OnMenuSavecurrentclipboard();
 	afx_msg void OnUpdateMenuSavecurrentclipboard(CCmdUI *pCmdUI);
+	afx_msg void OnCliporderMoveup();
+	afx_msg void OnUpdateCliporderMoveup(CCmdUI *pCmdUI);
+	afx_msg void OnCliporderMovedown();
+	afx_msg void OnUpdateCliporderMovedown(CCmdUI *pCmdUI);
+	afx_msg void OnCliporderMovetotop();
+	afx_msg void OnUpdateCliporderMovetotop(CCmdUI *pCmdUI);
 };

+ 4 - 1
Resource.h

@@ -511,6 +511,9 @@
 #define ID_MENU_WILDCARDSEARCH          32903
 #define ID_FIRST_SAVECURRENTCLIPBOARD   32904
 #define ID_MENU_SAVECURRENTCLIPBOARD    32905
+#define ID_CLIPORDER_MOVEUP             32906
+#define ID_CLIPORDER_MOVEDOWN           32907
+#define ID_CLIPORDER_MOVETOTOP          32908
 
 // Next default values for new objects
 // 
@@ -518,7 +521,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_3D_CONTROLS                     1
 #define _APS_NEXT_RESOURCE_VALUE        240
-#define _APS_NEXT_COMMAND_VALUE         32906
+#define _APS_NEXT_COMMAND_VALUE         32909
 #define _APS_NEXT_CONTROL_VALUE         2127
 #define _APS_NEXT_SYMED_VALUE           101
 #endif