Browse Source

- added option to move clip order on ctrl-
- added more functions to scripting
- show clip id in properties window
- added option to revert back to top level on close when group is selected

Scott Brogden 7 years ago
parent
commit
3ac2908b79
14 changed files with 176 additions and 12 deletions
  1. 30 3
      AdvGeneral.cpp
  2. 5 0
      ChaiScriptOnCopy.cpp
  3. 19 0
      Clip.cpp
  4. 1 0
      Clip.h
  5. 10 1
      CopyProperties.cpp
  6. 64 0
      DittoChaiScript.cpp
  7. 5 0
      DittoChaiScript.h
  8. 1 3
      MainFrm.cpp
  9. 20 0
      Options.cpp
  10. 6 0
      Options.h
  11. 4 4
      QListCtrl.cpp
  12. 9 1
      QPasteWnd.cpp
  13. 1 0
      Resource.h
  14. 1 0
      Shared/IClip.h

+ 30 - 3
AdvGeneral.cpp

@@ -68,7 +68,7 @@ END_MESSAGE_MAP()
 #define SETTING_SHOW_CLIP_PASTED 23
 #define SETTING_DIFF_APP 24
 #define SETTING_TRANSPARENCY 25
-#define SETTING_UPDATE_ORDER 26
+#define SETTING_UPDATE_ORDER_ON_PASTE 26
 #define SETTING_ALLOW_DUPLICATES 27
 #define SETTING_REGEX_FILTERING_1 28
 #define SETTING_REGEX_FILTERING_2 29
@@ -111,6 +111,8 @@ END_MESSAGE_MAP()
 #define SETTING_DEFAULT_PASTE_STRING 64
 #define SETTING_DEFAULT_COPY_STRING 65
 #define SETTING_DEFAULT_CUT_STRING 66
+#define SETTING_REVERT_TO_TOP_LEVEL_GROUP 67
+#define SETTING_UPDATE_ORDER_ON_CTRL_C 68
 
 BOOL CAdvGeneral::OnInitDialog()
 {
@@ -171,6 +173,8 @@ BOOL CAdvGeneral::OnInitDialog()
 	AddTrueFalse(pGroupTest, _T("Paste Clip in active window after selection"), CGetSetOptions::GetSendPasteAfterSelection(), SETTING_PASTE_IN_ACTIVE_WINDOW);
 	AddTrueFalse(pGroupTest, _T("Prompt when deleting clips"), CGetSetOptions::GetPromptWhenDeletingClips(), SETTING_PROMP_ON_DELETE);
 
+	AddTrueFalse(pGroupTest, _T("Revert to top level group on close"), CGetSetOptions::GetRevertToTopLevelGroup(), SETTING_REVERT_TO_TOP_LEVEL_GROUP);
+
 	pGroupTest->AddSubItem(new CMFCPropertyGridProperty(_T("Save Clipboard Delay (ms, default: 100))"), (long)(CGetSetOptions::GetProcessDrawClipboardDelay()), _T(""), SETTING_CLIPBOARD_SAVE_DELAY));
 
 	AddTrueFalse(pGroupTest, _T("Save Multi-Pastes"), CGetSetOptions::GetSaveMultiPaste(), SETTING_SAVE_MULTI_PASTE);
@@ -195,7 +199,8 @@ BOOL CAdvGeneral::OnInitDialog()
 
 	AddTrueFalse(pGroupTest, _T("Transparency Enabled"), CGetSetOptions::GetEnableTransparency(), SETTING_ENABLE_TRANSPARENCY);
 	pGroupTest->AddSubItem(new CMFCPropertyGridProperty(_T("Transparency Percentage"), CGetSetOptions::GetTransparencyPercent(), _T(""), SETTING_TRANSPARENCY));
-	AddTrueFalse(pGroupTest, _T("Update Clip Order On Paste"), CGetSetOptions::GetUpdateTimeOnPaste(), SETTING_UPDATE_ORDER);
+	AddTrueFalse(pGroupTest, _T("Update Clip Order On Paste"), CGetSetOptions::GetUpdateTimeOnPaste(), SETTING_UPDATE_ORDER_ON_PASTE);
+	AddTrueFalse(pGroupTest, _T("Update Clip Order On Ctrl-C"), CGetSetOptions::GetUpdateClipOrderOnCtrlC(), SETTING_UPDATE_ORDER_ON_CTRL_C);
 
 	CMFCPropertyGridProperty * regexFilterGroup = new CMFCPropertyGridProperty(_T("Exlude clips by Regular Expressions"));
 	m_propertyGrid.AddProperty(regexFilterGroup);	
@@ -542,7 +547,7 @@ void CAdvGeneral::OnBnClickedOk()
 					CGetSetOptions::SetDiffApp(pNewValue->bstrVal);
 				}
 				break;
-			case SETTING_UPDATE_ORDER:
+			case SETTING_UPDATE_ORDER_ON_PASTE:
 				if (wcscmp(pNewValue->bstrVal, pOrigValue->bstrVal) != 0)
 				{
 					BOOL val = false;
@@ -553,6 +558,17 @@ void CAdvGeneral::OnBnClickedOk()
 					CGetSetOptions::SetUpdateTimeOnPaste(val);
 				}
 				break;
+			case SETTING_UPDATE_ORDER_ON_CTRL_C:
+				if (wcscmp(pNewValue->bstrVal, pOrigValue->bstrVal) != 0)
+				{
+					BOOL val = false;
+					if (wcscmp(pNewValue->bstrVal, L"True") == 0)
+					{
+						val = true;
+					}
+					CGetSetOptions::SetUpdateClipOrderOnCtrlC(val);
+				}
+				break;
 			case SETTING_MULTIPASTE_REVERSE_ORDER:
 				if (wcscmp(pNewValue->bstrVal, pOrigValue->bstrVal) != 0)
 				{
@@ -653,6 +669,17 @@ void CAdvGeneral::OnBnClickedOk()
 					CGetSetOptions::SetDefaultCutString(pNewValue->bstrVal);
 				}
 				break;
+			case SETTING_REVERT_TO_TOP_LEVEL_GROUP:
+				if (wcscmp(pNewValue->bstrVal, pOrigValue->bstrVal) != 0)
+				{
+					BOOL val = false;
+					if (wcscmp(pNewValue->bstrVal, L"True") == 0)
+					{
+						val = true;
+					}
+					CGetSetOptions::SetRevertToTopLevelGroup(val);
+				}
+				break;
 			}
 		}
 	}

+ 5 - 0
ChaiScriptOnCopy.cpp

@@ -32,6 +32,11 @@ bool ChaiScriptOnCopy::ProcessScript(CDittoChaiScript &clipData, std::string scr
 		chai.add(chaiscript::fun(&CDittoChaiScript::SetAsciiString), "SetAsciiString");
 		chai.add(chaiscript::fun(&CDittoChaiScript::GetActiveApp), "GetActiveApp");
 
+		chai.add(chaiscript::fun(&CDittoChaiScript::FormatExists), "FormatExists");
+		chai.add(chaiscript::fun(&CDittoChaiScript::RemoveFormat), "RemoveFormat");
+		chai.add(chaiscript::fun(&CDittoChaiScript::SetParentId), "SetParentId");
+		chai.add(chaiscript::fun(&CDittoChaiScript::AsciiTextMatchesRegex), "AsciiTextMatchesRegex");
+
 		chai.add(chaiscript::var(&clipData), "clip");
 
 		//loop over all scripts

+ 19 - 0
Clip.cpp

@@ -205,6 +205,25 @@ CClipFormat* CClipFormats::FindFormat(UINT cfType)
 	return NULL;
 }
 
+bool CClipFormats::RemoveFormat(CLIPFORMAT cfType)
+{
+	bool removed = false;
+	CClipFormat* pCF;
+	INT_PTR count = GetSize();
+
+	for (int i = 0; i < count; i++)
+	{
+		pCF = &ElementAt(i);
+		if (pCF->m_cfType == cfType)
+		{
+			this->RemoveAt(i);
+			removed = true;
+			break;
+		}
+	}
+	return removed;
+}
+
 
 
 

+ 1 - 0
Clip.h

@@ -73,6 +73,7 @@ public:
 	virtual void DeleteAll() { this->RemoveAll(); }
 	virtual INT_PTR AddNew(CLIPFORMAT type, HGLOBAL data) {CClipFormat ft(type, data, -1); ft.m_autoDeleteData = false; return this->Add(ft); }
 	virtual IClipFormat *FindFormatEx(CLIPFORMAT type)	{ return FindFormat((UINT)type); }
+	virtual bool RemoveFormat(CLIPFORMAT type);
 };
 
 

+ 10 - 1
CopyProperties.cpp

@@ -127,6 +127,15 @@ BOOL CCopyProperties::OnInitDialog()
 	
 	theApp.m_Language.UpdateClipProperties(this);
 
+	if (m_clip.ID() > 0)
+	{
+		CString text;
+		this->GetWindowText(text);
+		CString newText;
+		newText.Format(_T("%s - %d"), text, m_clip.ID());
+		this->SetWindowText(newText);
+	}
+
 	return FALSE;
 }
 
@@ -222,7 +231,7 @@ void CCopyProperties::LoadDataFromCClip(CClip &Clip)
 
 	//show the selected data md5
 	OnLbnSelchangeCopyData();
-
+	
 	if(Clip.m_bIsGroup == FALSE)
 	{
 		::ShowWindow(::GetDlgItem(m_hWnd, IDC_STATIC_HOT_KEY_MOVE_TO_GROUP), SW_HIDE);

+ 64 - 0
DittoChaiScript.cpp

@@ -3,6 +3,9 @@
 #include "Shared\TextConvert.h"
 #include "Md5.h"
 #include "Misc.h"
+#include "CP_Main.h"
+
+#include <regex>
 
 CDittoChaiScript::CDittoChaiScript(IClip *pClip, std::string activeApp)
 {
@@ -95,4 +98,65 @@ SIZE_T CDittoChaiScript::GetClipSize(std::string clipboardFormat)
 	}
 
 	return size;
+}
+
+BOOL CDittoChaiScript::FormatExists(std::string clipboardFormat)
+{
+	BOOL exists = FALSE;
+	if (m_pClip)
+	{
+		int formatId = GetFormatID(CTextConvert::MultiByteToUnicodeString(clipboardFormat.c_str()));
+
+		IClipFormat *pFormat = m_pClip->Clips()->FindFormatEx(formatId);
+		if (pFormat)
+		{
+			exists = TRUE;
+		}
+	}
+
+	return exists;
+}
+
+BOOL CDittoChaiScript::RemoveFormat(std::string clipboardFormat)
+{
+	BOOL removed = FALSE;
+	if (m_pClip)
+	{
+		int formatId = GetFormatID(CTextConvert::MultiByteToUnicodeString(clipboardFormat.c_str()));
+
+		if (m_pClip->Clips()->RemoveFormat(formatId))
+		{
+			removed = TRUE;
+		}
+	}
+
+	return removed;
+}
+
+BOOL CDittoChaiScript::SetParentId(int parentId)
+{
+	BOOL set = FALSE;
+	if (m_pClip)
+	{		
+		CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID FROM Main WHERE lID = %d"), parentId);
+		if (q.eof() == false)
+		{
+			m_pClip->Parent(parentId);			
+		}
+	}
+
+	return set;
+}
+
+BOOL CDittoChaiScript::AsciiTextMatchesRegex(std::string regex)
+{
+	BOOL matches = false;
+
+	auto ascii = GetAsciiString();
+	std::regex integer(regex);
+	if (regex_match(ascii, integer))
+	{
+		matches = true;
+	}
+	return matches;
 }

+ 5 - 0
DittoChaiScript.h

@@ -20,5 +20,10 @@ public:
 	SIZE_T GetClipSize(std::string clipboardFormat);
 
 	std::string GetActiveApp() { return m_activeApp; }
+
+	BOOL RemoveFormat(std::string clipboardFormat);
+	BOOL FormatExists(std::string clipboardFormat);
+	BOOL SetParentId(int parentId);
+	BOOL AsciiTextMatchesRegex(std::string regex);
 };
 

+ 1 - 3
MainFrm.cpp

@@ -855,9 +855,7 @@ BOOL CMainFrame::PreTranslateMessage(MSG *pMsg)
 			::GetWindowThreadProcessId(hwndFromPoint, &winProcessId);
 			if (winProcessId == ::GetCurrentProcessId()) //no-fail!
 			{
-				pMsg->hwnd = hwndFromPoint;
-
-				
+				pMsg->hwnd = hwndFromPoint;				
 			}
 		}
 

+ 20 - 0
Options.cpp

@@ -2710,4 +2710,24 @@ BOOL CGetSetOptions::GetDisableExpireClipsConfig()
 void CGetSetOptions::SetDisableExpireClipsConfig(BOOL val)
 {
 	SetProfileLong("DisableExpireClipsConfig", val);
+}
+
+BOOL CGetSetOptions::GetRevertToTopLevelGroup()
+{
+	return GetProfileLong("RevertToTopLevelGroup", FALSE);
+}
+
+void CGetSetOptions::SetRevertToTopLevelGroup(BOOL val)
+{
+	SetProfileLong("RevertToTopLevelGroup", val);
+}
+
+BOOL CGetSetOptions::GetUpdateClipOrderOnCtrlC()
+{
+	return GetProfileLong("UpdateClipOrderOnCtrlC", FALSE);
+}
+
+void CGetSetOptions::SetUpdateClipOrderOnCtrlC(BOOL val)
+{
+	SetProfileLong("UpdateClipOrderOnCtrlC", val);
 }

+ 6 - 0
Options.h

@@ -605,6 +605,12 @@ public:
 
 	static BOOL GetDisableExpireClipsConfig();
 	static void SetDisableExpireClipsConfig(BOOL val);
+
+	static BOOL GetRevertToTopLevelGroup();
+	static void SetRevertToTopLevelGroup(BOOL val);
+
+	static BOOL GetUpdateClipOrderOnCtrlC();
+	static void SetUpdateClipOrderOnCtrlC(BOOL val);
 };
 
 // global for easy access and for initialization of fast access variables

+ 4 - 4
QListCtrl.cpp

@@ -899,12 +899,12 @@ void CQListCtrl::LoadCopyOrCutToClipboard()
 		paste.GetClipIDs().Add(arr[0]);
 	
 	//Don't move these to the top
-	BOOL bItWas = g_Opt.m_bUpdateTimeOnPaste;
-	g_Opt.m_bUpdateTimeOnPaste = FALSE;
-
+	BOOL itWas = g_Opt.m_bUpdateTimeOnPaste;
+	g_Opt.m_bUpdateTimeOnPaste = CGetSetOptions::GetUpdateClipOrderOnCtrlC();
+	
 	paste.DoPaste();
 
-	g_Opt.m_bUpdateTimeOnPaste = bItWas;
+	g_Opt.m_bUpdateTimeOnPaste = itWas;	
 }
 
 bool CQListCtrl::PostEventLoadedCheckDescription(int updatedRow)

+ 9 - 1
QPasteWnd.cpp

@@ -808,7 +808,15 @@ BOOL CQPasteWnd::HideQPasteWindow (bool releaseFocus, bool clearSearchData)
 		}
 	}
 
-	theApp.TryEnterOldGroupState();
+	if (theApp.m_GroupID > 0 &&
+		CGetSetOptions::GetRevertToTopLevelGroup())
+	{
+		theApp.EnterGroupID(-1);
+	}
+	else
+	{
+		theApp.TryEnterOldGroupState();
+	}
 
 	DWORD endTick = GetTickCount();
 	if((endTick-startTick) > 150)

+ 1 - 0
Resource.h

@@ -412,6 +412,7 @@
 #define IDC_STATIC_HOT_KEY_MOVE_TO_GROUP 2044
 #define IDC_CHECK_WIN4                  2045
 #define IDC_STATIC_SOUND                2045
+#define IDC_STATIC_DATE3                2045
 #define IDC_CHECK_WIN5                  2046
 #define IDC_STATIC_MAX_SIZE             2046
 #define IDC_STATIC_NO_LIMIT             2047

+ 1 - 0
Shared/IClip.h

@@ -26,6 +26,7 @@ public:
 	virtual void DeleteAll() = 0;
 	virtual INT_PTR AddNew(CLIPFORMAT type, HGLOBAL data) = 0;
 	virtual IClipFormat *FindFormatEx(CLIPFORMAT type) = 0;
+	virtual bool RemoveFormat(CLIPFORMAT type) = 0;
 };
 
 class IClip