Browse Source

When opening a group through a global key save the current group so when we close the group we revert back to the last opened group

git-svn-id: svn://svn.code.sf.net/p/ditto-cp/code/trunk@685 595ec19a-5cb4-439b-94a8-42fb3063c22c
sabrogden 12 years ago
parent
commit
3ea0db2fb5
4 changed files with 61 additions and 4 deletions
  1. 49 1
      CP_Main.cpp
  2. 8 1
      CP_Main.h
  3. 2 2
      MainFrm.cpp
  4. 2 0
      QPasteWnd.cpp

+ 49 - 1
CP_Main.cpp

@@ -100,6 +100,8 @@ CCP_MainApp::CCP_MainApp()
 	m_GroupText = "History";
 	m_FocusID = -1;
 
+	ClearOldGroupState();
+
 	m_bAsynchronousRefreshView = true;
 
 	m_lClipsSent = 0;
@@ -625,7 +627,43 @@ void CCP_MainApp::IC_Paste()
 
 // Groups
 
-BOOL CCP_MainApp::EnterGroupID(long lID)
+void CCP_MainApp::SaveCurrentGroupState()
+{
+	m_oldGroupID = m_GroupID;
+	m_oldGroupParentID = m_GroupParentID;
+	m_oldGroupText = m_GroupText;
+}
+
+void CCP_MainApp::ClearOldGroupState()
+{
+	m_oldGroupID = -2;
+	m_oldGroupParentID = -2;
+	m_oldGroupText = _T("");
+}
+
+BOOL CCP_MainApp::TryEnterOldGroupState()
+{
+	BOOL enteredGroup = FALSE;
+
+	if(m_oldGroupID > -2)
+	{
+		m_GroupID = m_oldGroupID;
+		m_GroupParentID = m_oldGroupParentID;
+		m_GroupText = m_oldGroupText;
+
+		ClearOldGroupState();
+
+		theApp.RefreshView();
+		if(QPasteWnd())
+			QPasteWnd()->UpdateStatus(true);
+
+		enteredGroup = TRUE;
+	}
+
+	return enteredGroup;
+}
+
+BOOL CCP_MainApp::EnterGroupID(long lID, BOOL clearOldGroupState/* = TRUE*/, BOOL saveCurrentGroupState/* = FALSE*/)
 {
 	BOOL bResult = FALSE;
 
@@ -634,6 +672,16 @@ BOOL CCP_MainApp::EnterGroupID(long lID)
 
 	DWORD startTick = GetTickCount();
 
+	if(clearOldGroupState)
+	{
+		ClearOldGroupState();
+	}
+
+	if(saveCurrentGroupState)
+	{
+		SaveCurrentGroupState();
+	}
+
 	// if we are switching to the parent, focus on the previous group
 	if(m_GroupParentID == lID && m_GroupID > 0)
 		m_FocusID = m_GroupID;

+ 8 - 1
CP_Main.h

@@ -115,7 +115,14 @@ public:
 	long		m_GroupParentID;  // current group's parent
 	CString		m_GroupText;      // current group's description
 
-	BOOL EnterGroupID(long lID);
+	long		m_oldGroupID;
+	long		m_oldGroupParentID;
+	CString		m_oldGroupText;
+
+	void SaveCurrentGroupState();
+	void ClearOldGroupState();
+	BOOL TryEnterOldGroupState();
+	BOOL EnterGroupID(long lID, BOOL clearOldGroupState = TRUE, BOOL saveCurrentGroupState = FALSE);
 	long GetValidGroupID(); // returns a valid id (not negative)
 	void SetGroupDefaultID(long lID); // sets a valid id
 

+ 2 - 2
MainFrm.cpp

@@ -415,8 +415,8 @@ void CMainFrame::PasteOrShowGroup(int dbId, BOOL updateClipTime, BOOL activeTarg
 {
 	try
 	{
-		if (theApp.EnterGroupID(dbId))
-		{
+		if (theApp.EnterGroupID(dbId, FALSE, TRUE))
+		{			
 			theApp.m_activeWnd.TrackActiveWnd(true);
 			m_quickPaste.ShowQPasteWnd(this, false, true, FALSE);
 		}

+ 2 - 0
QPasteWnd.cpp

@@ -553,6 +553,8 @@ BOOL CQPasteWnd::HideQPasteWindow(bool releaseFocus)
         }
     }
 
+	theApp.TryEnterOldGroupState();
+
 	DWORD endTick = GetTickCount();
 	if((endTick-startTick) > 150)
 		Log(StrF(_T("Paste Timing HideQPasteWindow: %d"), endTick-startTick));