瀏覽代碼

Double click global short cut key to save selection to that group

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@779 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 10 年之前
父節點
當前提交
64f5f392f5
共有 9 個文件被更改,包括 174 次插入9 次删除
  1. 26 0
      CP_Main.cpp
  2. 7 0
      CP_Main.h
  3. 24 2
      Clip.cpp
  4. 1 0
      Clip.h
  5. 12 0
      CopyThread.cpp
  6. 75 7
      MainFrm.cpp
  7. 3 0
      MainFrm.h
  8. 20 0
      Options.cpp
  9. 6 0
      Options.h

+ 26 - 0
CP_Main.cpp

@@ -107,6 +107,8 @@ CCP_MainApp::CCP_MainApp()
 {
 	theApp.m_activeWnd.TrackActiveWnd(false);
 
+	m_activeGroupId = -1;
+	m_activeGroupStartTime = 0;
 	m_pUacPasteThread = NULL;
 	m_bAppRunning = false;
 	m_bAppExiting = false;
@@ -1106,4 +1108,28 @@ void CCP_MainApp::RefreshShowInTaskBar()
 	{
 		m_pMainFrame->RefreshShowInTaskBar();
 	}
+}
+
+void CCP_MainApp::SetActiveGroupId(int groupId)
+{
+	m_activeGroupId = groupId;
+	m_activeGroupStartTime = GetTickCount();
+}
+
+int CCP_MainApp::GetActiveGroupId()
+{
+	int ret = -1;
+	DWORD maxDiff = CGetSetOptions::GetSaveToGroupTimeoutMS();
+	DWORD diff = GetTickCount() - m_activeGroupStartTime;
+
+	if(m_activeGroupId > -1 &&
+		diff < maxDiff)
+	{
+		ret = m_activeGroupId;
+	}
+
+	m_activeGroupId = -1;
+	m_activeGroupStartTime = 0;
+
+	return ret;
 }

+ 7 - 0
CP_Main.h

@@ -181,6 +181,10 @@ public:
 
 	void RefreshShowInTaskBar();
 
+	void SetActiveGroupId(int groupId);
+	int GetActiveGroupId();
+
+
 public:
 	virtual BOOL InitInstance();
 	virtual int ExitInstance();
@@ -192,4 +196,7 @@ public:
 protected:
 	void ShowCommandLineError(CString csTitle, CString csMessage);
 	CUAC_Thread *m_pUacPasteThread;
+
+	int m_activeGroupId;
+	DWORD m_activeGroupStartTime;
 };

+ 24 - 2
Clip.cpp

@@ -543,6 +543,7 @@ bool CClip::AddToDB(bool bCheckForDuplicates)
 			if(nID >= 0)
 			{
 				MakeLatestOrder();
+				MakeLatestGroupOrder();
 
 				CString sql;
 				
@@ -551,9 +552,21 @@ bool CClip::AddToDB(bool bCheckForDuplicates)
 
 				int ret = theApp.m_db.execDML(sql);
 
+				int groupRet = -1;
+
+				if(m_parentId > -1)
+				{
+					sql.Format(_T("UPDATE Main SET clipGroupOrder = %f where lID = %d;"), 
+						m_clipGroupOrder, nID);
+
+					groupRet = theApp.m_db.execDML(sql);
+				}
+
+
 				m_id = nID;
 
-				Log(StrF(_T("Found duplicate clip in db, Id: %d, crc: %d, NewOrder: %f, Ret: %d, SQL: %s"), nID, m_CRC, m_clipOrder, ret, sql));
+				Log(StrF(_T("Found duplicate clip in db, Id: %d, ParentId: %d crc: %d, NewOrder: %f, GroupOrder %f, Ret: %d, GroupRet: %d, SQL: %s"), 
+										nID, m_parentId, m_CRC, m_clipOrder, m_clipGroupOrder, ret, groupRet, sql));
 
 				return true;
 			}
@@ -667,7 +680,7 @@ bool CClip::AddToMainTable()
 
 		m_id = (long)theApp.m_db.lastRowId();
 
-		Log(StrF(_T("Added clip to main table, Id: %d, Desc: %s, Order: %f, GroupOrder: %f"), m_id, m_Desc, m_clipOrder, m_clipGroupOrder));
+		Log(StrF(_T("Added clip to main table, Id: %d, ParentId: %d Desc: %s, Order: %f, GroupOrder: %f"), m_id, m_parentId, m_Desc, m_clipOrder, m_clipGroupOrder));
 
 		m_LastAddedCRC = m_CRC;
 		m_lastAddedID = m_id;
@@ -920,6 +933,14 @@ void CClip::MakeLatestOrder()
 	m_clipOrder = GetNewOrder(-1, m_id);
 }
 
+void CClip::MakeLatestGroupOrder()
+{
+	if(m_parentId > -1)
+	{
+		m_clipGroupOrder = GetNewOrder(m_parentId, m_id);
+	}
+}
+
 double CClip::GetNewOrder(int parentId, int clipId)
 {
 	double newOrder = 0;
@@ -1267,6 +1288,7 @@ int CClipList::AddToDB(bool bLatestOrder)
 		if(bLatestOrder)
 		{
 			pClip->MakeLatestOrder();
+			pClip->MakeLatestGroupOrder();
 		}
 
 		pClip->m_Time = CTime::GetCurrentTime().GetTime();

+ 1 - 0
Clip.h

@@ -129,6 +129,7 @@ public:
 	bool ModifyMainTable();
 	bool SaveFromEditWnd(BOOL bUpdateDesc);
 	void MakeLatestOrder();
+	void MakeLatestGroupOrder();
 	void MakeStickyTop(int parentId);
 	void MakeStickyLast(int parentId);
 	void RemoveStickySetting(int parentId);

+ 12 - 0
CopyThread.cpp

@@ -61,6 +61,12 @@ void CCopyThread::OnClipboardChange()
 	if(!m_LocalConfig.m_bCopyOnChange)
 		return;
 	
+	int groupId = theApp.GetActiveGroupId();
+	if(groupId > -1)
+	{
+		Log(StrF(_T("LoadFromClipboard - loading clips into groupId: %d"), groupId));
+	}
+
 	CClip* pClip = new CClip;
 
 	CClipTypes* pSupportedTypes = m_LocalConfig.m_pSupportedTypes;
@@ -132,6 +138,12 @@ void CCopyThread::OnClipboardChange()
 		delete pClip;
 		return; // error
 	}
+
+	if(pClip != NULL &&
+		groupId > -1)
+	{
+		pClip->m_parentId = groupId;
+	}
 	
 	if(m_LocalConfig.m_bAsyncCopy)
 		::PostMessage(m_LocalConfig.m_hClipHandler, WM_CLIPBOARD_COPIED, (WPARAM)pClip, 0);

+ 75 - 7
MainFrm.cpp

@@ -85,6 +85,8 @@ CMainFrame::CMainFrame()
 	m_pGlobalClips = NULL;
 	m_pOptions = NULL;
 	m_pDeleteClips = NULL;
+	m_doubleClickGroupId = -1;
+	m_doubleClickGroupStartTime = 0;
 }
 
 CMainFrame::~CMainFrame()
@@ -451,16 +453,51 @@ void CMainFrame::PasteOrShowGroup(int dbId, BOOL updateClipTime, BOOL activeTarg
 {
 	try
 	{
-		if (theApp.EnterGroupID(dbId, FALSE, TRUE))
-		{			
-			theApp.m_activeWnd.TrackActiveWnd(true);
-			
-			StartKeyModifyerTimer();
+		bool isGroup = false;
+		CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT bIsGroup FROM Main WHERE lID = %d"), dbId);
+		if(q.eof() == false)
+		{
+			if(q.getIntField(_T("bIsGroup")) > 0)
+			{
+				isGroup = true;
+			}
+		}
+		
+		if(isGroup)
+		{
+			int maxDiff = CGetSetOptions::GetGroupDoubleClickTimeMS();
+			DWORD diff = GetTickCount() - m_doubleClickGroupStartTime;		
+
+			if(m_doubleClickGroupId == dbId &&
+				diff < maxDiff)
+			{
+				Log(StrF(_T("Second Press of group hot key, group Id: %d, Sending copy to save selection to this group"), dbId));
+				
+				KillTimer(GROUP_DOUBLE_CLICK);
+				m_doubleClickGroupId = -1;
+				m_doubleClickGroupStartTime = 0;
+
+				theApp.SetActiveGroupId(dbId);
+				theApp.m_activeWnd.SendCopy();
+			}
+			else
+			{
+				m_doubleClickGroupId = dbId;
+				m_doubleClickGroupStartTime = GetTickCount();
 
-			m_quickPaste.ShowQPasteWnd(this, false, true, FALSE);
+				int doubleClickTime = CGetSetOptions::GetGroupDoubleClickTimeMS();
+
+				SetTimer(GROUP_DOUBLE_CLICK, doubleClickTime, 0);
+
+				Log(StrF(_T("First Press of group hot key, group Id: %d, timout: %d"), dbId, doubleClickTime));
+			}
 		}
 		else
 		{
+			KillTimer(GROUP_DOUBLE_CLICK);
+			m_doubleClickGroupId = -1;
+			m_doubleClickGroupStartTime = 0;
+
 			BOOL bItWas = g_Opt.m_bUpdateTimeOnPaste;
 			if (updateClipTime != -1)
 			{				
@@ -590,7 +627,38 @@ void CMainFrame::OnTimer(UINT_PTR nIDEvent)
 			{
 				m_thread.FireReadDbFile();
 			}
-		break;
+			break;
+
+		case GROUP_DOUBLE_CLICK:
+			{
+				KillTimer(GROUP_DOUBLE_CLICK);			
+
+				Log(StrF(_T("Processing single click of groupId %d in timer, opening ditto to this group"), m_doubleClickGroupId));
+
+				int maxDiff = (CGetSetOptions::GetGroupDoubleClickTimeMS() * 1.5);
+				DWORD diff = GetTickCount() - m_doubleClickGroupStartTime;					
+
+				if(diff < maxDiff)
+				{					
+					if(m_doubleClickGroupId > -1)
+					{
+						if (theApp.EnterGroupID(m_doubleClickGroupId, FALSE, TRUE))
+						{
+							theApp.m_activeWnd.TrackActiveWnd(true);
+							StartKeyModifyerTimer();
+							m_quickPaste.ShowQPasteWnd(this, false, true, FALSE);
+						}
+					}
+				}
+				else
+				{	
+					Log(StrF(_T("Something happened and we didn't process the group timer in time, Id: %d, Diff ms: %d, maxDiff: %d"), m_doubleClickGroupId, diff, maxDiff));
+				}
+
+				m_doubleClickGroupId = -1;
+				m_doubleClickGroupStartTime = 0;
+			}
+			break;
     }
 
     CFrameWnd::OnTimer(nIDEvent);

+ 3 - 0
MainFrm.h

@@ -17,6 +17,7 @@
 #define ACTIVE_WINDOW_TIMER				9
 #define TEXT_ONLY_PASTE					11
 #define READ_RANDOM_DB_FILE				12
+#define GROUP_DOUBLE_CLICK				13
 
 class CMainFrame: public CFrameWnd
 {
@@ -63,6 +64,8 @@ public:
 	CDialog *m_pGlobalClips;
 	CDialog *m_pDeleteClips;
 	CPropertySheet *m_pOptions;
+	int m_doubleClickGroupId;
+	DWORD m_doubleClickGroupStartTime;
 
     void DoDittoCopyBufferPaste(int nCopyBuffer);
     void DoFirstTenPositionsPaste(int nPos);

+ 20 - 0
Options.cpp

@@ -2217,4 +2217,24 @@ BOOL CGetSetOptions::GetShowGroupsInMainList()
 void CGetSetOptions::SetShowGroupsInMainList(BOOL val)
 {
 	SetProfileLong(_T("ShowGroupsInMainList"), val);
+}
+
+void CGetSetOptions::SetGroupDoubleClickTimeMS(int val)
+{
+	SetProfileLong(_T("GroupDoubleClickTimeMS"), val);
+}
+
+int CGetSetOptions::GetGroupDoubleClickTimeMS()
+{
+	return GetProfileLong(_T("GroupDoubleClickTimeMS"), 500);
+}
+
+void CGetSetOptions::SetSaveToGroupTimeoutMS(int val)
+{
+	SetProfileLong(_T("SaveToGroupTimeoutMS"), val);
+}
+
+int CGetSetOptions::GetSaveToGroupTimeoutMS()
+{
+	return GetProfileLong(_T("SaveToGroupTimeoutMS"), 1000);
 }

+ 6 - 0
Options.h

@@ -480,6 +480,12 @@ public:
 
 	static BOOL GetShowGroupsInMainList();
 	static void SetShowGroupsInMainList(BOOL val);
+
+	static void SetGroupDoubleClickTimeMS(int val);
+	static int GetGroupDoubleClickTimeMS();
+
+	static void SetSaveToGroupTimeoutMS(int val);
+	static int GetSaveToGroupTimeoutMS();
 };
 
 // global for easy access and for initialization of fast access variables