Skip to content

Commit

Permalink
Add Adv. Option fo slugify separator
Browse files Browse the repository at this point in the history
  • Loading branch information
sabrogden committed Nov 25, 2023
1 parent b4e9501 commit 42ae59b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 7 deletions.
9 changes: 9 additions & 0 deletions AdvGeneral.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ END_MESSAGE_MAP()
#define SETTING_DISABLE_FRIENDS 87
#define SETTING_IGNORE_FALSE_COPIES_DEALY 88
#define SETTING_REFRESH_VIEW_AFTER_PASTE 89
#define SETTING_SLUGIFY_SEPARATOR 90


BOOL CAdvGeneral::OnInitDialog()
Expand Down Expand Up @@ -254,6 +255,8 @@ BOOL CAdvGeneral::OnInitDialog()
AddTrueFalse(pGroupTest, _T("Show text for first ten copy hot keys"), CGetSetOptions::GetShowTextForFirstTenHotKeys(), SETTING_TEXT_FIRST_TEN);
AddTrueFalse(pGroupTest, _T("Show thumbnails(for CF_DIB types) (could increase memory usage and display speed)"), CGetSetOptions::GetDrawThumbnail(), SETTING_DRAW_THUMBNAILS);

pGroupTest->AddSubItem(new CMFCPropertyGridProperty(_T("Slugify Separator (default: -)"), CGetSetOptions::GetSlugifySeparator(), _T(""), SETTING_SLUGIFY_SEPARATOR));

pGroupTest->AddSubItem(new CMFCPropertyGridProperty(_T("Text lines per clip"), CGetSetOptions::GetLinesPerRow(), _T(""), SETTING_LINES_PER_ROW));

pGroupTest->AddSubItem(new CMFCPropertyGridProperty(_T("Tooltip display time(ms) max of 32000 (-1 default (5 seconds), 0 to turn off)"), g_Opt.m_tooltipTimeout, _T(""), SETTING_TOOLTIP_TIMEOUT));
Expand Down Expand Up @@ -760,6 +763,12 @@ void CAdvGeneral::OnBnClickedOk()
CGetSetOptions::SetDefaultCutString(pNewValue->bstrVal);
}
break;
case SETTING_SLUGIFY_SEPARATOR:
if (wcscmp(pNewValue->bstrVal, pOrigValue->bstrVal) != 0)
{
CGetSetOptions::SetSlugifySeparator(pNewValue->bstrVal);
}
break;
case SETTING_REVERT_TO_TOP_LEVEL_GROUP:
if (wcscmp(pNewValue->bstrVal, pOrigValue->bstrVal) != 0)
{
Expand Down
2 changes: 1 addition & 1 deletion DittoSetup/BuildDitto.bld
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ DittoSetup*]]></ExclExt>
".\Ditto\Language\French.xml" "Language\French.xml"
".\Ditto\Language\Greek.xml" "Language\Greek.xml"
".\Ditto\Language\Hebrew.xml" "Language\Hebrew.xml"
".\Ditto\Language\italiano.xml" "Language\italiano.xml"
".\Ditto\Language\Italian.xml" "Language\Italian.xml"
".\Ditto\Language\Japanese.xml" "Language\Japanese.xml"
".\Ditto\Language\Korean.xml" "Language\Korean.xml"
".\Ditto\Language\Persian.xml" "Language\Persian.xml"
Expand Down
2 changes: 1 addition & 1 deletion OleClipSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ void COleClipSource::Slugify(CClip &clip)
//free the old text we are going to replace it below with an upper case version
unicodeTextFormat->Free();

CString newString = slugify(cs.GetString()).c_str();
CString newString = slugify(cs.GetString(), CGetSetOptions::GetSlugifySeparator().GetString()).c_str();

long len = newString.GetLength();
HGLOBAL hGlobal = NewGlobalP(newString.GetBuffer(), ((len + 1) * sizeof(wchar_t)));
Expand Down
14 changes: 13 additions & 1 deletion Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2961,4 +2961,16 @@ void CGetSetOptions::SetRefreshViewAfterPasting(BOOL val)
{
m_refreshViewAfterPasting = val;
SetProfileLong("RefreshViewAfterPasting", val);
}
}


CString CGetSetOptions::GetSlugifySeparator()
{
return GetProfileString("SlugifySeparator", _T("-"));
}

void CGetSetOptions::SetSlugifySeparator(CString val)
{
SetProfileString("SlugifySeparator", val);
}

3 changes: 3 additions & 0 deletions Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,9 @@ class CGetSetOptions
static BOOL m_refreshViewAfterPasting;
static BOOL GetRefreshViewAfterPasting();
static void SetRefreshViewAfterPasting(BOOL val);

static CString GetSlugifySeparator();
static void SetSlugifySeparator(CString val);
};

// global for easy access and for initialization of fast access variables
Expand Down
10 changes: 6 additions & 4 deletions Slugify.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ std::wstring trim(const std::wstring &s)
}

// SLUGIFY
std::wstring slugify(std::wstring input)
std::wstring slugify(std::wstring input, std::wstring separator)
{
std::unordered_map<std::wstring, std::wstring> charMap{
// latin
Expand Down Expand Up @@ -117,9 +117,11 @@ std::wstring slugify(std::wstring input)

trim(input);

//replace spaces with hyphens
std::wregex e3(_T("[-\\s]+"));
input = std::regex_replace(input, e3, _T("-"));
auto replaceSpacesAndSep = _T("[") + separator + _T("\\s]+");

//replace spaces with separator
std::wregex e3(replaceSpacesAndSep);
input = std::regex_replace(input, e3, separator);

return input;
};

0 comments on commit 42ae59b

Please sign in to comment.