Kaynağa Gözat

Added an option to paste ascii text only 1- 127 character codes (#651)

sabrogden 1 yıl önce
ebeveyn
işleme
a6b21abfb4
9 değiştirilmiş dosya ile 112 ekleme ve 4 silme
  1. 2 0
      ActionEnums.h
  2. 1 0
      CP_Main.rc
  3. 63 0
      OleClipSource.cpp
  4. 1 0
      OleClipSource.h
  5. 36 2
      QPasteWnd.cpp
  6. 3 0
      QPasteWnd.h
  7. 2 1
      Resource.h
  8. 1 0
      SpecialPasteOptions.cpp
  9. 3 1
      SpecialPasteOptions.h

+ 2 - 0
ActionEnums.h

@@ -132,6 +132,8 @@ public:
 		PASTE_CAMEL_CASE,
 		PASTE_MULTI_IMAGE_HORIZONTAL,
 		PASTE_MULTI_IMAGE_VERTICAL,
+		ASCII_TEXT_ONLY,
+
 		LAST_ACTION
 	};
 

+ 1 - 0
CP_Main.rc

@@ -264,6 +264,7 @@ BEGIN
             MENUITEM "Invert Case",                 ID_SPECIALPASTE_TOGGLECASE
             MENUITEM "Trim White Space",            ID_SPECIALPASTE_TRIM
             MENUITEM "CamelCase",                   ID_SPECIALPASTE_CAMELCASE
+            MENUITEM "Ascii Text Only",             ID_SPECIALPASTE_ASCIITEXTONLY
             MENUITEM SEPARATOR
             MENUITEM "Remove Line Feeds",           ID_SPECIALPASTE_REMOVELINEFEEDS
             MENUITEM "Paste + One Line Feed",       ID_SPECIALPASTE_PASTE

+ 63 - 0
OleClipSource.cpp

@@ -215,6 +215,10 @@ BOOL COleClipSource::DoImmediateRender()
 	{
 		CamelCase(clip);
 	}
+	else if (m_pasteOptions.m_pasteAsciiOnly)
+	{
+		AsciiOnly(clip);
+	}
 	
 	SaveDittoFileDataToFile(clip);
 
@@ -653,6 +657,65 @@ void COleClipSource::SentenceCase(CClip &clip)
 	}
 }
 
+void COleClipSource::AsciiOnly(CClip& clip)
+{
+	IClipFormat* unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
+	if (unicodeTextFormat != NULL)
+	{
+		CString cs(unicodeTextFormat->GetAsCString());
+		CString newString;
+
+		//free the old text we are going to replace it below with an upper case version
+		unicodeTextFormat->Free();
+		
+		long len = cs.GetLength();
+
+		if (len > 0)
+		{
+			for (int i = 0; i < len; i++)
+			{
+				wchar_t item = cs[i];
+				if (item >= 0x00 && item <= 0x7F)
+				{
+					newString += item;
+				}				
+			}
+		}
+
+		HGLOBAL hGlobal = NewGlobalP(newString.GetBuffer(), ((newString.GetLength() + 1) * sizeof(wchar_t)));
+
+		unicodeTextFormat->Data(hGlobal);
+	}
+
+	IClipFormat* asciiTextFormat = clip.m_Formats.FindFormatEx(CF_TEXT);
+	if (asciiTextFormat != NULL)
+	{
+		CStringA cs(asciiTextFormat->GetAsCStringA());
+		CStringA newString;
+
+		//free the old text we are going to replace it below with an upper case version
+		asciiTextFormat->Free();
+				
+		long len = cs.GetLength();
+
+		if (len > 0)
+		{
+			for (int i = 0; i < len; i++)
+			{
+				char item = cs[i];
+				if (item >= 0x00 && item <= 0x7F)
+				{
+					newString += item;
+				}
+			}
+		}
+
+		HGLOBAL hGlobal = NewGlobalP(newString.GetBuffer(), (newString.GetLength() + 1));
+
+		asciiTextFormat->Data(hGlobal);
+	}
+}
+
 void COleClipSource::PlainTextFilter(CClip &clip)
 {
 	bool foundText = false;

+ 1 - 0
OleClipSource.h

@@ -45,4 +45,5 @@ protected:
 	void Slugify(CClip &clip);
 	void InvertCase(CClip &clip);
 	void CamelCase(CClip& clip);
+	void AsciiOnly(CClip& clip);
 };

+ 36 - 2
QPasteWnd.cpp

@@ -366,7 +366,9 @@ BEGIN_MESSAGE_MAP(CQPasteWnd, CWndEx)
 		ON_COMMAND(ID_SPECIALPASTE_MULTIPLEIMAGESVERTICALLY, &CQPasteWnd::OnSpecialpasteMultipleImagesVert)
 		ON_UPDATE_COMMAND_UI(ID_SPECIALPASTE_MULTIPLEIMAGESVERTICALLY, &CQPasteWnd::OnUpdateSpecialpasteMultipleImagesVert)
 
-END_MESSAGE_MAP()
+		ON_COMMAND(ID_SPECIALPASTE_ASCIITEXTONLY, &CQPasteWnd::OnSpecialpasteAsciitextonly)
+		ON_UPDATE_COMMAND_UI(ID_SPECIALPASTE_ASCIITEXTONLY, &CQPasteWnd::OnUpdateSpecialpasteAsciitextonly)
+		END_MESSAGE_MAP()
 
 
 /////////////////////////////////////////////////////////////////////////////
@@ -3362,6 +3364,9 @@ bool CQPasteWnd::DoAction(CAccel a)
 	case ActionEnums::PASTE_MULTI_IMAGE_VERTICAL:
 		ret = DoPasteImagesVert();
 		break;
+	case ActionEnums::ASCII_TEXT_ONLY:
+		ret = DoPasteAsciiOnly();
+		break;
 	}
 
 	return ret;
@@ -4641,6 +4646,19 @@ bool CQPasteWnd::DoPasteImagesVert()
 	return false;
 }
 
+bool CQPasteWnd::DoPasteAsciiOnly()
+{
+	if (::GetFocus() == m_lstHeader.GetSafeHwnd())
+	{
+		CSpecialPasteOptions pasteOptions;
+		pasteOptions.m_pasteAsciiOnly = true;
+		OpenSelection(pasteOptions);
+		return true;
+	}
+
+	return false;
+}
+
 bool CQPasteWnd::DoPasteLowerCase()
 {
 	if (::GetFocus() == m_lstHeader.GetSafeHwnd())
@@ -8032,4 +8050,20 @@ void CQPasteWnd::OnUpdateSpecialpasteMultipleImagesVert(CCmdUI* pCmdUI)
 	}
 
 	UpdateMenuShortCut(pCmdUI, ActionEnums::PASTE_MULTI_IMAGE_VERTICAL);
-}
+}
+
+void CQPasteWnd::OnSpecialpasteAsciitextonly()
+{
+	DoAction(ActionEnums::ASCII_TEXT_ONLY);
+}
+
+
+void CQPasteWnd::OnUpdateSpecialpasteAsciitextonly(CCmdUI* pCmdUI)
+{
+	if (!pCmdUI->m_pMenu)
+	{
+		return;
+	}
+
+	UpdateMenuShortCut(pCmdUI, ActionEnums::ASCII_TEXT_ONLY);
+}

+ 3 - 0
QPasteWnd.h

@@ -278,6 +278,7 @@ public:
 	bool DoPasteUpperCase();
 	bool DoPasteCamelCase();
 	bool DoPasteImagesVert();
+	bool DoPasteAsciiOnly();
 	bool DoPasteImagesHorz();
 	bool DoPasteLowerCase();
 	bool DoPasteCapitalize();
@@ -598,4 +599,6 @@ public:
 	afx_msg void OnUpdateSpecialpasteMultipleImagesHorz(CCmdUI* pCmdUI);
 	afx_msg void OnSpecialpasteMultipleImagesVert();
 	afx_msg void OnUpdateSpecialpasteMultipleImagesVert(CCmdUI* pCmdUI);
+	afx_msg void OnSpecialpasteAsciitextonly();
+	afx_msg void OnUpdateSpecialpasteAsciitextonly(CCmdUI* pCmdUI);
 };

+ 2 - 1
Resource.h

@@ -810,6 +810,7 @@
 #define ID_SPECIALPASTE_MULTIPLEIMAGESHORIZONTALLY 32976
 #define ID_SPECIALPASTE_MULTIPLEIMAGES  32977
 #define ID_SPECIALPASTE_MULTIPLEIMAGESVERTICALLY 32978
+#define ID_SPECIALPASTE_ASCIITEXTONLY   32979
 
 // Next default values for new objects
 // 
@@ -817,7 +818,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_3D_CONTROLS                     1
 #define _APS_NEXT_RESOURCE_VALUE        389
-#define _APS_NEXT_COMMAND_VALUE         32979
+#define _APS_NEXT_COMMAND_VALUE         32980
 #define _APS_NEXT_CONTROL_VALUE         2173
 #define _APS_NEXT_SYMED_VALUE           104
 #endif

+ 1 - 0
SpecialPasteOptions.cpp

@@ -26,6 +26,7 @@ CSpecialPasteOptions::CSpecialPasteOptions()
 	m_pasteCamelCase = false;
 	m_pasteImagesHorizontal = false;
 	m_pasteImagesVertically = false;
+	m_pasteAsciiOnly = false;
 }
 
 CSpecialPasteOptions::~CSpecialPasteOptions()

+ 3 - 1
SpecialPasteOptions.h

@@ -29,6 +29,7 @@ public:
 	bool m_pasteSlugify;
 	bool m_invertCase;
 	bool m_placeCF_HDROP_OnDrag;
+	bool m_pasteAsciiOnly;
 
 	bool LimitFormatsToText() 
 	{ 
@@ -45,7 +46,8 @@ public:
 			m_trimWhiteSpace ||
 			m_pasteSlugify || 
 			m_invertCase ||
-			m_pasteCamelCase;
+			m_pasteCamelCase ||
+			m_pasteAsciiOnly;
 	}
 
 	bool IncludeRTFForTextOnly()