Explorar o código

Aggregate multiple clips better if some clips don't have all the data needed

sabrogden %!s(int64=7) %!d(string=hai) anos
pai
achega
b87d387efb

+ 1 - 1
CF_HDropAggregator.cpp

@@ -9,7 +9,7 @@ CCF_HDropAggregator::~CCF_HDropAggregator(void)
 {
 }
 
-bool CCF_HDropAggregator::AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount)
+bool CCF_HDropAggregator::AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount, UINT cfType)
 {
 	HDROP drop = (HDROP)GlobalLock((HDROP)lpData);
 	int nNumFiles = DragQueryFile(drop, -1, NULL, 0);

+ 1 - 1
CF_HDropAggregator.h

@@ -8,7 +8,7 @@ public:
 	CCF_HDropAggregator(void);
 	~CCF_HDropAggregator(void);
 
-	virtual bool AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount);
+	virtual bool AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount, UINT cfType);
 	virtual HGLOBAL GetHGlobal();
 	virtual HGLOBAL GetHGlobalAsString();
 

+ 31 - 1
CF_TextAggregator.cpp

@@ -11,8 +11,38 @@ CCF_TextAggregator::~CCF_TextAggregator(void)
 {
 }
 
-bool CCF_TextAggregator::AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount)
+bool CCF_TextAggregator::AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount, UINT cfType)
 {
+	if (cfType == CF_HDROP)
+	{
+		CStringA hDropFiles = _T("");
+		HDROP drop = (HDROP)GlobalLock((HDROP)lpData);
+		int nNumFiles = DragQueryFileA(drop, -1, NULL, 0);
+		CHAR file[MAX_PATH];
+
+		for (int nFile = 0; nFile < nNumFiles; nFile++)
+		{
+			if (DragQueryFileA(drop, nFile, file, sizeof(file)) > 0)
+			{
+				hDropFiles += file;
+				hDropFiles += "\r\n";
+			}
+		}
+
+		if (hDropFiles != _T(""))
+		{
+			m_csNewText += hDropFiles;
+
+			if (nPos != nCount - 1)
+			{
+				m_csNewText += m_csSeparator;
+			}
+
+			return true;
+		}
+		return false;
+	}
+
 	LPCSTR pText = (LPCSTR)lpData;
 	if(pText == NULL)
 	{

+ 1 - 1
CF_TextAggregator.h

@@ -7,7 +7,7 @@ public:
 	CCF_TextAggregator(CStringA csSepator);
 	~CCF_TextAggregator(void);
 
-	virtual bool AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount);
+	virtual bool AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount, UINT cfType);
 	virtual HGLOBAL GetHGlobal();
 
 protected:

+ 31 - 1
CF_UnicodeTextAggregator.cpp

@@ -11,8 +11,38 @@ CCF_UnicodeTextAggregator::~CCF_UnicodeTextAggregator(void)
 {
 }
 
-bool CCF_UnicodeTextAggregator::AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount)
+bool CCF_UnicodeTextAggregator::AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount, UINT cfType)
 {
+	if (cfType == CF_HDROP)
+	{
+		CString hDropFiles = _T("");
+		HDROP drop = (HDROP)GlobalLock((HDROP)lpData);
+		int nNumFiles = DragQueryFile(drop, -1, NULL, 0);
+		TCHAR file[MAX_PATH];
+
+		for (int nFile = 0; nFile < nNumFiles; nFile++)
+		{
+			if (DragQueryFile(drop, nFile, file, sizeof(file)) > 0)
+			{
+				hDropFiles += file;
+				hDropFiles += _T("\r\n");
+			}
+		}
+
+		if (hDropFiles != _T(""))
+		{
+			m_csNewText += hDropFiles;
+
+			if (nPos != nCount - 1)
+			{
+				m_csNewText += m_csSeparator;
+			}
+
+			return true;
+		}
+		return false;
+	}
+
 	LPCWSTR pText = (LPCWSTR)lpData;
 	if(pText == NULL)
 	{

+ 1 - 1
CF_UnicodeTextAggregator.h

@@ -7,7 +7,7 @@ public:
 	CCF_UnicodeTextAggregator(CStringW csSeparator);
 	~CCF_UnicodeTextAggregator(void);
 
-	virtual bool AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount);
+	virtual bool AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount, UINT cfType);
 	virtual HGLOBAL GetHGlobal();
 
 protected:

+ 2 - 2
CP_Main.rc

@@ -307,8 +307,8 @@ BEGIN
             MENUITEM "Export Clip(s)",              32853
             MENUITEM SEPARATOR
             MENUITEM "View as QRCode",              ID_MENU_VIEWASQRCODE
-            MENUITEM "Export Clip(s) to Text File", ID_EXPORT_EXPORTTOTEXTFILE
-            MENUITEM "Export Clip(s) to Image File", ID_IMPORT_EXPORTCLIP_BITMAP
+            MENUITEM "Export Clip(s) to Text File(s)", ID_EXPORT_EXPORTTOTEXTFILE
+            MENUITEM "Export Clip(s) to Image File(s)", ID_IMPORT_EXPORTCLIP_BITMAP
             MENUITEM "Export to Google Translate",  ID_IMPORT_EXPORTTOGOOGLETRANSLATE
             MENUITEM "Import File Contents From CF_HDROP", ID_IMPORT_IMPORTCOPIEDFILE
             MENUITEM SEPARATOR

+ 19 - 11
ClipIds.cpp

@@ -31,7 +31,7 @@ HGLOBAL CClipIDs::Render(UINT cfType)
 	if(cfType == CF_TEXT)
 	{
 		CCF_TextAggregator CFText(SepA);
-		if(AggregateData(CFText, CF_TEXT, g_Opt.m_bMultiPasteReverse))
+		if(AggregateData(CFText, CF_TEXT, g_Opt.m_bMultiPasteReverse, false))
 		{
 			return CFText.GetHGlobal();
 		}
@@ -39,7 +39,7 @@ HGLOBAL CClipIDs::Render(UINT cfType)
 	else if(cfType == CF_UNICODETEXT)
 	{
 		CCF_UnicodeTextAggregator CFUnicodeText(SepW);
-		if(AggregateData(CFUnicodeText, CF_UNICODETEXT, g_Opt.m_bMultiPasteReverse))
+		if(AggregateData(CFUnicodeText, CF_UNICODETEXT, g_Opt.m_bMultiPasteReverse, false))
 		{
 			return CFUnicodeText.GetHGlobal();
 		}
@@ -47,7 +47,7 @@ HGLOBAL CClipIDs::Render(UINT cfType)
 	else if(cfType == CF_HDROP)
 	{
 		CCF_HDropAggregator HDrop;
-		if(AggregateData(HDrop, CF_HDROP, g_Opt.m_bMultiPasteReverse))
+		if(AggregateData(HDrop, CF_HDROP, g_Opt.m_bMultiPasteReverse, false))
 		{
 			return HDrop.GetHGlobal();
 		}
@@ -55,7 +55,7 @@ HGLOBAL CClipIDs::Render(UINT cfType)
 	else if(cfType == theApp.m_HTML_Format)
 	{
 		CHTMLFormatAggregator Html(SepA);
-		if(AggregateData(Html, theApp.m_HTML_Format, g_Opt.m_bMultiPasteReverse))
+		if(AggregateData(Html, theApp.m_HTML_Format, g_Opt.m_bMultiPasteReverse, false))
 		{
 			return Html.GetHGlobal();
 		}
@@ -63,7 +63,7 @@ HGLOBAL CClipIDs::Render(UINT cfType)
 	else if(cfType == theApp.m_RTFFormat)
 	{
 		CRichTextAggregator RichText(SepA);
-		if(AggregateData(RichText, theApp.m_RTFFormat, g_Opt.m_bMultiPasteReverse))
+		if(AggregateData(RichText, theApp.m_RTFFormat, g_Opt.m_bMultiPasteReverse, false))
 		{
 			return RichText.GetHGlobal();
 		}
@@ -124,7 +124,7 @@ void CClipIDs::GetTypes(CClipTypes& types)
 	}
 }
 
-bool CClipIDs::AggregateData(IClipAggregator &Aggregator, UINT cfType, BOOL bReverse)
+bool CClipIDs::AggregateData(IClipAggregator &Aggregator, UINT cfType, BOOL bReverse, bool textOnly)
 {
 	CString csSQL;
 	LPWSTR Text = NULL;
@@ -143,11 +143,20 @@ bool CClipIDs::AggregateData(IClipAggregator &Aggregator, UINT cfType, BOOL bRev
 				nIndex = numIDs - i - 1;
 			}
 
+			CString sqlCF_HDROP = _T("");
+			if (textOnly &&
+				cfType == CF_UNICODETEXT || cfType == CF_TEXT)
+			{
+				sqlCF_HDROP.Format(_T("OR Data.strClipBoardFormat = '%s'"), GetFormatName(CF_HDROP));
+			}
+
 			csSQL.Format(_T("SELECT * FROM Data ")
 				_T("INNER JOIN Main ON Main.lID = Data.lParentID ")
-				_T("WHERE Data.strClipBoardFormat = '%s' ")
+				_T("WHERE (Data.strClipBoardFormat = '%s'")
+				_T(" %s) ")
 				_T("AND Main.lID = %d"),
 				GetFormatName(cfType),
+				sqlCF_HDROP,
 				ElementAt(nIndex));
 
 			CppSQLite3Query q = theApp.m_db.execQuery(csSQL);
@@ -161,15 +170,14 @@ bool CClipIDs::AggregateData(IClipAggregator &Aggregator, UINT cfType, BOOL bRev
 					continue;
 				}
 
-				if(Aggregator.AddClip(pData, nDataLen, (int)i, (int)numIDs))
+				if(Aggregator.AddClip(pData, nDataLen, (int)i, (int)numIDs, GetFormatID(q.getStringField(_T("strClipBoardFormat")))))
 				{
-					bRet = true;
+					bRet |= true;
 				}
 			}
 			else
 			{
-				bRet = false;
-				break;
+				bRet |= false;
 			}
 		}
 	}

+ 1 - 1
ClipIds.h

@@ -12,7 +12,7 @@ public:
 	HGLOBAL	Render(UINT cfType);
 	// Fills "types" with the Format Types corresponding to the Clip IDs in this array.
 	void GetTypes(CClipTypes& types);
-	bool AggregateData(IClipAggregator &Aggregator, UINT cfType, BOOL bReverse);
+	bool AggregateData(IClipAggregator &Aggregator, UINT cfType, BOOL bReverse, bool textOnly);
 
 // MANAGEMENT FUNCTIONS
 

+ 1 - 1
HTMLFormatAggregator.cpp

@@ -20,7 +20,7 @@ CHTMLFormatAggregator::~CHTMLFormatAggregator(void)
 {
 }
 
-bool CHTMLFormatAggregator::AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount)
+bool CHTMLFormatAggregator::AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount, UINT cfType)
 {
 	LPSTR pText = (LPSTR)lpData;
 	if(pText == NULL)

+ 1 - 1
HTMLFormatAggregator.h

@@ -7,7 +7,7 @@ public:
 	CHTMLFormatAggregator(CStringA csSepator);
 	~CHTMLFormatAggregator(void);
 
-	virtual bool AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount);
+	virtual bool AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount, UINT cfType);
 	virtual HGLOBAL GetHGlobal();
 
 protected:

+ 1 - 1
IClipAggregator.h

@@ -3,6 +3,6 @@
 class IClipAggregator
 {
 public:
-	virtual bool AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount) = 0;
+	virtual bool AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount, UINT cfType) = 0;
 	virtual HGLOBAL GetHGlobal() = 0;
 };

+ 7 - 19
OleClipSource.cpp

@@ -92,7 +92,7 @@ BOOL COleClipSource::DoImmediateRender()
 	{
 		CStringA SepA = CTextConvert::ConvertToChar(g_Opt.GetMultiPasteSeparator());
 		CCF_TextAggregator CFText(SepA);
-		if(m_ClipIDs.AggregateData(CFText, CF_TEXT, g_Opt.m_bMultiPasteReverse))
+		if(m_ClipIDs.AggregateData(CFText, CF_TEXT, g_Opt.m_bMultiPasteReverse, m_pasteOptions.LimitFormatsToText()))
 		{
 			CClipFormat cf(CF_TEXT, CFText.GetHGlobal());
 			clip.m_Formats.Add(cf);
@@ -102,7 +102,7 @@ BOOL COleClipSource::DoImmediateRender()
 
 		CStringW SepW = CTextConvert::ConvertToUnicode(g_Opt.GetMultiPasteSeparator());
 		CCF_UnicodeTextAggregator CFUnicodeText(SepW);
-		if(m_ClipIDs.AggregateData(CFUnicodeText, CF_UNICODETEXT, g_Opt.m_bMultiPasteReverse))
+		if(m_ClipIDs.AggregateData(CFUnicodeText, CF_UNICODETEXT, g_Opt.m_bMultiPasteReverse, m_pasteOptions.LimitFormatsToText()))
 		{
 			CClipFormat cf(CF_UNICODETEXT, CFUnicodeText.GetHGlobal());
 			clip.m_Formats.Add(cf);
@@ -110,22 +110,10 @@ BOOL COleClipSource::DoImmediateRender()
 			cf.m_autoDeleteData = false;
 		}
 
-		if ((m_pasteOptions.LimitFormatsToText()) &&
-			clip.m_Formats.GetCount() == 0)
+		if (m_pasteOptions.LimitFormatsToText() == false)
 		{
 			CCF_HDropAggregator HDrop;
-			if (m_ClipIDs.AggregateData(HDrop, CF_HDROP, g_Opt.m_bMultiPasteReverse))
-			{
-				CClipFormat cf(CF_UNICODETEXT, HDrop.GetHGlobalAsString());
-				clip.m_Formats.Add(cf);
-				//clip.m_Formats now owns the global data
-				cf.m_autoDeleteData = false;
-			}
-		}
-		else if (m_pasteOptions.LimitFormatsToText() == false)
-		{
-			CCF_HDropAggregator HDrop;
-			if(m_ClipIDs.AggregateData(HDrop, CF_HDROP, g_Opt.m_bMultiPasteReverse))
+			if(m_ClipIDs.AggregateData(HDrop, CF_HDROP, g_Opt.m_bMultiPasteReverse, m_pasteOptions.LimitFormatsToText()))
 			{
 				CClipFormat cf(CF_HDROP, HDrop.GetHGlobal());
 				clip.m_Formats.Add(cf);
@@ -134,7 +122,7 @@ BOOL COleClipSource::DoImmediateRender()
 			}
 
 			CRichTextAggregator RichText(SepA);
-			if(m_ClipIDs.AggregateData(RichText, theApp.m_RTFFormat, g_Opt.m_bMultiPasteReverse))
+			if(m_ClipIDs.AggregateData(RichText, theApp.m_RTFFormat, g_Opt.m_bMultiPasteReverse, m_pasteOptions.LimitFormatsToText()))
 			{
 				CClipFormat cf(theApp.m_RTFFormat, RichText.GetHGlobal());
 				clip.m_Formats.Add(cf);
@@ -143,7 +131,7 @@ BOOL COleClipSource::DoImmediateRender()
 			}
 
 			CHTMLFormatAggregator Html(SepA);
-			if(m_ClipIDs.AggregateData(Html, theApp.m_HTML_Format, g_Opt.m_bMultiPasteReverse))
+			if(m_ClipIDs.AggregateData(Html, theApp.m_HTML_Format, g_Opt.m_bMultiPasteReverse, m_pasteOptions.LimitFormatsToText()))
 			{
 				CClipFormat cf(theApp.m_HTML_Format, Html.GetHGlobal());
 				clip.m_Formats.Add(cf);
@@ -534,7 +522,7 @@ void COleClipSource::PlainTextFilter(CClip &clip)
 		hDropIndex > -1)
 	{
 		CCF_HDropAggregator HDrop;
-		if (m_ClipIDs.AggregateData(HDrop, CF_HDROP, g_Opt.m_bMultiPasteReverse))
+		if (m_ClipIDs.AggregateData(HDrop, CF_HDROP, g_Opt.m_bMultiPasteReverse, m_pasteOptions.LimitFormatsToText()))
 		{
 			clip.m_Formats.RemoveAt(hDropIndex);
 

+ 5 - 5
QPasteWnd.cpp

@@ -7063,7 +7063,7 @@ bool CQPasteWnd::DoActionEmailTo()
 		CStringW SepW = CTextConvert::ConvertToUnicode(g_Opt.GetMultiPasteSeparator());
 
 		CHTMLFormatAggregator Html(SepA);
-		if (IDs.AggregateData(Html, theApp.m_HTML_Format, g_Opt.m_bMultiPasteReverse))
+		if (IDs.AggregateData(Html, theApp.m_HTML_Format, g_Opt.m_bMultiPasteReverse, false))
 		{
 			CClipFormat cf(theApp.m_HTML_Format, Html.GetHGlobal());
 			clip.m_Formats.Add(cf);
@@ -7072,7 +7072,7 @@ bool CQPasteWnd::DoActionEmailTo()
 		}
 		
 		CCF_UnicodeTextAggregator CFUnicodeText(SepW);
-		if (IDs.AggregateData(CFUnicodeText, CF_UNICODETEXT, g_Opt.m_bMultiPasteReverse))
+		if (IDs.AggregateData(CFUnicodeText, CF_UNICODETEXT, g_Opt.m_bMultiPasteReverse, false))
 		{
 			CClipFormat cf(CF_UNICODETEXT, CFUnicodeText.GetHGlobal());
 			clip.m_Formats.Add(cf);
@@ -7083,7 +7083,7 @@ bool CQPasteWnd::DoActionEmailTo()
 		{
 			
 			CCF_TextAggregator CFText(SepA);
-			if (IDs.AggregateData(CFText, CF_TEXT, g_Opt.m_bMultiPasteReverse))
+			if (IDs.AggregateData(CFText, CF_TEXT, g_Opt.m_bMultiPasteReverse, false))
 			{
 				CClipFormat cf(CF_TEXT, CFText.GetHGlobal());
 				clip.m_Formats.Add(cf);
@@ -7195,7 +7195,7 @@ bool CQPasteWnd::DoActionGmail()
 	{
 		CStringW SepW = CTextConvert::ConvertToUnicode(g_Opt.GetMultiPasteSeparator());
 		CCF_UnicodeTextAggregator CFUnicodeText(SepW);
-		if (IDs.AggregateData(CFUnicodeText, CF_UNICODETEXT, g_Opt.m_bMultiPasteReverse))
+		if (IDs.AggregateData(CFUnicodeText, CF_UNICODETEXT, g_Opt.m_bMultiPasteReverse, false))
 		{
 			CClipFormat cf(CF_UNICODETEXT, CFUnicodeText.GetHGlobal());
 			clip.m_Formats.Add(cf);
@@ -7206,7 +7206,7 @@ bool CQPasteWnd::DoActionGmail()
 		{
 			CStringA SepA = CTextConvert::ConvertToChar(g_Opt.GetMultiPasteSeparator());
 			CCF_TextAggregator CFText(SepA);
-			if (IDs.AggregateData(CFText, CF_TEXT, g_Opt.m_bMultiPasteReverse))
+			if (IDs.AggregateData(CFText, CF_TEXT, g_Opt.m_bMultiPasteReverse, false))
 			{
 				CClipFormat cf(CF_TEXT, CFText.GetHGlobal());
 				clip.m_Formats.Add(cf);

+ 1 - 1
RichTextAggregator.cpp

@@ -19,7 +19,7 @@ CRichTextAggregator::~CRichTextAggregator(void)
 {
 }
 
-bool CRichTextAggregator::AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount)
+bool CRichTextAggregator::AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount, UINT cfType)
 {
 	LPSTR pText = (LPSTR)lpData;
 	if(pText == NULL)

+ 1 - 1
RichTextAggregator.h

@@ -7,7 +7,7 @@ public:
 	CRichTextAggregator(CStringA csSeparator);
 	~CRichTextAggregator(void);
 
-	virtual bool AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount);
+	virtual bool AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount, UINT cfType);
 	virtual HGLOBAL GetHGlobal();
 
 protected: