ソースを参照

Added menu option to fixup order of sticky clips. Found an issue with assigning sticky clips that would cause wacky ordering, this will fix that.

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@797 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 10 年 前
コミット
3b8fd133de
7 ファイル変更78 行追加6 行削除
  1. 1 0
      CP_Main.rc
  2. 64 0
      DatabaseUtilities.cpp
  3. 3 0
      DatabaseUtilities.h
  4. 6 4
      MainFrm.cpp
  5. 1 0
      MainFrm.h
  6. 1 1
      Misc.cpp
  7. 2 1
      Resource.h

+ 1 - 0
CP_Main.rc

@@ -177,6 +177,7 @@ BEGIN
         MENUITEM SEPARATOR
         MENUITEM "Global Hot Keys",             ID_FIRST_GLOBALHOTKEYS
         MENUITEM "Delete Clip Data",            ID_FIRST_DELETECLIPDATA
+        MENUITEM "Fixup Sticky Clip Order",     ID_FIRST_FIXUPSTICKYCLIPORDER
         MENUITEM SEPARATOR
         MENUITEM "Import Clip(s)",              ID_FIRST_IMPORT
         MENUITEM "New Clip",                    ID_FIRST_NEWCLIP

+ 64 - 0
DatabaseUtilities.cpp

@@ -221,6 +221,66 @@ BOOL OpenDatabase(CString csDB)
 	return FALSE;
 }
 
+void ReOrderStickyClips(int parentID, CppSQLite3DB &db)
+{
+	try
+	{
+		Log(StrF(_T("Start of ReOrderStickyClips, ParentId %d"), parentID));
+
+		//groups where created with 0 in these fields, fix them up if they are 0
+		if(parentID == -1)
+		{
+			db.execDMLEx(_T("Update Main Set stickyClipOrder = -(2147483647) where bIsGroup = 1 AND stickyClipOrder = 0"));
+			db.execDMLEx(_T("Update Main Set stickyClipGroupOrder = -(2147483647) where bIsGroup = 1 AND stickyClipGroupOrder = 0"));			
+		}
+
+		CppSQLite3Query qGroup = db.execQueryEx(_T("SELECT lID, mText FROM Main WHERE bIsGroup = 1 AND lParentID = %d"), parentID);
+
+		if (qGroup.eof() == false)
+		{
+			while (!qGroup.eof())
+			{
+				//Get all sticky clips at the top level or group
+				CString sql = StrF(_T("SELECT lID FROM Main WHERE stickyClipOrder <> -(2147483647) AND lParentID = %d ORDER BY stickyClipOrder DESC"), parentID);
+				if (parentID > -1)
+				{
+					sql = StrF(_T("SELECT lID FROM Main WHERE stickyClipGroupOrder <> -(2147483647) AND lParentID = %d ORDER BY stickyClipGroupOrder DESC"), parentID);
+				}
+
+				CppSQLite3Query qSticky = db.execQueryEx(sql);
+
+				int order = 1;
+
+				if (qSticky.eof() == false)
+				{
+					while (!qSticky.eof())
+					{
+						//set the new order
+						if (parentID > -1)
+						{
+							db.execDMLEx(_T("Update Main Set stickyClipGroupOrder = %d where lID = %d"), order, qSticky.getIntField(_T("lID")));
+						}
+						else
+						{
+							db.execDMLEx(_T("Update Main Set stickyClipOrder = %d where lID = %d"), order, qSticky.getIntField(_T("lID")));
+						}
+
+						qSticky.nextRow();
+						order--;
+					}
+				}				
+
+				ReOrderStickyClips(qGroup.getIntField(_T("lID")), db);
+
+				qGroup.nextRow();
+			}
+		}
+
+		Log(StrF(_T("End of ReOrderStickyClips, ParentId %d"), parentID));
+	}
+	CATCH_SQLITE_EXCEPTION
+}
+
 BOOL ValidDB(CString csPath, BOOL bUpgrade)
 {
 	CDittoPopupWindow *popUpMsg = NULL;
@@ -446,6 +506,8 @@ BOOL ValidDB(CString csPath, BOOL bUpgrade)
 	}
 	CATCH_SQLITE_EXCEPTION_AND_RETURN(FALSE)
 
+	
+
 	if(popUpMsg != NULL &&
 		IsWindow(popUpMsg->m_hWnd))
 	{
@@ -457,6 +519,8 @@ BOOL ValidDB(CString csPath, BOOL bUpgrade)
 	return TRUE;                                                     
 }
 
+
+
 BOOL BackupDB(CString dbPath, CString prefix, CDittoPopupWindow **popUpMsg)
 {
 	if ((*popUpMsg) == NULL)

+ 3 - 0
DatabaseUtilities.h

@@ -10,6 +10,7 @@
 #endif // _MSC_VER > 1000
 
 #include "DittoPopupWindow.h"
+#include "sqlite/CppSQLite3.h"
 
 #define DEFAULT_DB_NAME "Ditto.db"
 #define ERROR_OPENING_DATABASE	2
@@ -31,6 +32,8 @@ BOOL EnsureDirectory(CString csPath);
 
 BOOL BackupDB(CString dbPath, CString prefix, CDittoPopupWindow **popUpMsg);
 
+void ReOrderStickyClips(int parentID, CppSQLite3DB &db);
+
 //BOOL CopyDownDatabase();
 //BOOL CopyUpDatabase();
 

+ 6 - 4
MainFrm.cpp

@@ -17,6 +17,7 @@
 #include "GlobalClips.h"
 #include "OptionsSheet.h"
 #include "DeleteClipData.h"
+#include "DatabaseUtilities.h"
 
 #ifdef _DEBUG
     #define new DEBUG_NEW
@@ -67,6 +68,7 @@ IMPLEMENT_DYNAMIC(CMainFrame, CFrameWnd)
 	ON_MESSAGE(WM_REOPEN_DATABASE, &CMainFrame::OnReOpenDatabase)
 	ON_MESSAGE(WM_SHOW_MSG_WINDOW, &CMainFrame::OnShowMsgWindow)
 	ON_MESSAGE(WM_SHOW_DITTO_GROUP, &CMainFrame::OnShowDittoGroup)
+	ON_COMMAND(ID_FIRST_FIXUPSTICKYCLIPORDER, &CMainFrame::OnFirstFixupstickycliporder)
 	END_MESSAGE_MAP()
 
 	static UINT indicators[] = 
@@ -1293,7 +1295,7 @@ LRESULT CMainFrame::OnShowDittoGroup(WPARAM wParam, LPARAM lParam)
 	return TRUE;
 }
 
-
-
-
-
+void CMainFrame::OnFirstFixupstickycliporder()
+{
+	ReOrderStickyClips(-1, theApp.m_db);
+}

+ 1 - 0
MainFrm.h

@@ -131,4 +131,5 @@ DECLARE_MESSAGE_MAP()public:
 	afx_msg LRESULT OnReOpenDatabase(WPARAM wParam, LPARAM lParam);
 	afx_msg LRESULT OnShowMsgWindow(WPARAM wParam, LPARAM lParam);
 	afx_msg LRESULT OnShowDittoGroup(WPARAM wParam, LPARAM lParam);
+	afx_msg void OnFirstFixupstickycliporder();
 };

+ 1 - 1
Misc.cpp

@@ -707,7 +707,7 @@ long NewGroupID(int parentID, CString text)
 
 		CString cs;
 
-		cs.Format(_T("insert into Main (lDate, mText, lDontAutoDelete, bIsGroup, lParentID) values(%d, '%s', %d, 1, %d);"),
+		cs.Format(_T("insert into Main (lDate, mText, lDontAutoDelete, bIsGroup, lParentID, stickyClipOrder, stickyClipGroupOrder) values(%d, '%s', %d, 1, %d, -(2147483647), -(2147483647));"),
 							(int)time.GetTime(),
 							text,
 							(int)time.GetTime(),

+ 2 - 1
Resource.h

@@ -514,6 +514,7 @@
 #define ID_CLIPORDER_MOVEUP             32906
 #define ID_CLIPORDER_MOVEDOWN           32907
 #define ID_CLIPORDER_MOVETOTOP          32908
+#define ID_FIRST_FIXUPSTICKYCLIPORDER   32909
 
 // Next default values for new objects
 // 
@@ -521,7 +522,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_3D_CONTROLS                     1
 #define _APS_NEXT_RESOURCE_VALUE        240
-#define _APS_NEXT_COMMAND_VALUE         32909
+#define _APS_NEXT_COMMAND_VALUE         32910
 #define _APS_NEXT_CONTROL_VALUE         2127
 #define _APS_NEXT_SYMED_VALUE           101
 #endif