Browse Source

Convert plLocalizationEditor to use plString.

Required to match previous commits to pfLocalizationMgr and retain functionality.
Joseph Davies 12 years ago
parent
commit
fc94e6bee9
  1. 52
      Sources/Tools/plLocalizationEditor/plAddDlgs.cpp
  2. 14
      Sources/Tools/plLocalizationEditor/plAddDlgs.h
  3. 130
      Sources/Tools/plLocalizationEditor/plEditDlg.cpp
  4. 7
      Sources/Tools/plLocalizationEditor/plEditDlg.h
  5. 48
      Sources/Tools/plLocalizationEditor/plLocTreeView.cpp
  6. 8
      Sources/Tools/plLocalizationEditor/plLocTreeView.h
  7. 4
      Sources/Tools/plLocalizationEditor/plLocalizationEditor.cpp

52
Sources/Tools/plLocalizationEditor/plAddDlgs.cpp

@ -151,7 +151,7 @@ BOOL CALLBACK plAddElementDlg::IDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPAR
int index = (int)SendMessage(GetDlgItem(hDlg, IDC_PARENTAGE), CB_GETCURSEL, (WPARAM)0, (LPARAM)0); int index = (int)SendMessage(GetDlgItem(hDlg, IDC_PARENTAGE), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
SendMessage(GetDlgItem(hDlg, IDC_PARENTAGE), CB_GETLBTEXT, (WPARAM)index, (LPARAM)buff); SendMessage(GetDlgItem(hDlg, IDC_PARENTAGE), CB_GETLBTEXT, (WPARAM)index, (LPARAM)buff);
pthis->fAgeName = buff; pthis->fAgeName = plString::FromWchar(buff);
pthis->fAgeChanged = true; pthis->fAgeChanged = true;
pthis->IUpdateDlg(hDlg); pthis->IUpdateDlg(hDlg);
} }
@ -160,7 +160,7 @@ BOOL CALLBACK plAddElementDlg::IDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPAR
wchar_t buff[256]; wchar_t buff[256];
GetDlgItemTextW(hDlg, IDC_PARENTAGE, buff, 256); GetDlgItemTextW(hDlg, IDC_PARENTAGE, buff, 256);
pthis->fAgeName = buff; pthis->fAgeName = plString::FromWchar(buff);
pthis->fAgeChanged = true; pthis->fAgeChanged = true;
pthis->IUpdateDlg(hDlg, false); pthis->IUpdateDlg(hDlg, false);
} }
@ -171,7 +171,7 @@ BOOL CALLBACK plAddElementDlg::IDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPAR
int index = (int)SendMessage(GetDlgItem(hDlg, IDC_PARENTSET), CB_GETCURSEL, (WPARAM)0, (LPARAM)0); int index = (int)SendMessage(GetDlgItem(hDlg, IDC_PARENTSET), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
SendMessage(GetDlgItem(hDlg, IDC_PARENTSET), CB_GETLBTEXT, (WPARAM)index, (LPARAM)buff); SendMessage(GetDlgItem(hDlg, IDC_PARENTSET), CB_GETLBTEXT, (WPARAM)index, (LPARAM)buff);
pthis->fSetName = buff; pthis->fSetName = plString::FromWchar(buff);
pthis->IUpdateDlg(hDlg); pthis->IUpdateDlg(hDlg);
} }
else if (HIWORD(wParam) == CBN_EDITCHANGE && LOWORD(wParam) == IDC_PARENTSET) else if (HIWORD(wParam) == CBN_EDITCHANGE && LOWORD(wParam) == IDC_PARENTSET)
@ -179,14 +179,14 @@ BOOL CALLBACK plAddElementDlg::IDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPAR
wchar_t buff[256]; wchar_t buff[256];
GetDlgItemTextW(hDlg, IDC_PARENTSET, buff, 256); GetDlgItemTextW(hDlg, IDC_PARENTSET, buff, 256);
pthis->fSetName = buff; pthis->fSetName = plString::FromWchar(buff);
pthis->IUpdateDlg(hDlg, false); pthis->IUpdateDlg(hDlg, false);
} }
else if (HIWORD(wParam) == EN_UPDATE && LOWORD(wParam) == IDC_ELEMENTNAME) else if (HIWORD(wParam) == EN_UPDATE && LOWORD(wParam) == IDC_ELEMENTNAME)
{ {
wchar_t buff[256]; wchar_t buff[256];
GetDlgItemTextW(hDlg, IDC_ELEMENTNAME, buff, 256); GetDlgItemTextW(hDlg, IDC_ELEMENTNAME, buff, 256);
pthis->fElementName = buff; pthis->fElementName = plString::FromWchar(buff);
pthis->IUpdateDlg(hDlg); pthis->IUpdateDlg(hDlg);
} }
@ -207,7 +207,7 @@ BOOL CALLBACK plAddElementDlg::IDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPAR
bool plAddElementDlg::IInitDlg(HWND hDlg) bool plAddElementDlg::IInitDlg(HWND hDlg)
{ {
HWND listCtrl = GetDlgItem(hDlg, IDC_PARENTAGE); HWND listCtrl = GetDlgItem(hDlg, IDC_PARENTAGE);
std::vector<std::wstring> ageNames = pfLocalizationDataMgr::Instance().GetAgeList(); std::vector<plString> ageNames = pfLocalizationDataMgr::Instance().GetAgeList();
// add the age names to the list // add the age names to the list
for (int i = 0; i < ageNames.size(); i++) for (int i = 0; i < ageNames.size(); i++)
@ -229,15 +229,15 @@ bool plAddElementDlg::IInitDlg(HWND hDlg)
void plAddElementDlg::IUpdateDlg(HWND hDlg, bool setFocus) void plAddElementDlg::IUpdateDlg(HWND hDlg, bool setFocus)
{ {
std::wstring pathStr = L"Path: " + fAgeName + L"." + fSetName + L"." + fElementName; plString pathStr = plString::Format("Path: %s.%s.%s", fAgeName.c_str(), fSetName.c_str(), fElementName.c_str());
SetDlgItemTextW(hDlg, IDC_PATH, pathStr.c_str()); SetDlgItemTextW(hDlg, IDC_PATH, pathStr.ToWchar());
if (fAgeChanged) // we only update this if the age changed (saves time and prevents weird bugs, like typing backwards) if (fAgeChanged) // we only update this if the age changed (saves time and prevents weird bugs, like typing backwards)
{ {
// now add the sets // now add the sets
HWND listCtrl = GetDlgItem(hDlg, IDC_PARENTSET); HWND listCtrl = GetDlgItem(hDlg, IDC_PARENTSET);
SendMessage(listCtrl, CB_RESETCONTENT, (WPARAM)0, (LPARAM)0); SendMessage(listCtrl, CB_RESETCONTENT, (WPARAM)0, (LPARAM)0);
std::vector<std::wstring> setNames = pfLocalizationDataMgr::Instance().GetSetList(fAgeName); std::vector<plString> setNames = pfLocalizationDataMgr::Instance().GetSetList(fAgeName);
// add the set names to the list // add the set names to the list
for (int i = 0; i < setNames.size(); i++) for (int i = 0; i < setNames.size(); i++)
@ -246,24 +246,24 @@ void plAddElementDlg::IUpdateDlg(HWND hDlg, bool setFocus)
// select the set we currently have // select the set we currently have
int ret = (int)SendMessage(listCtrl, CB_SELECTSTRING, (WPARAM)-1, (LPARAM)fSetName.c_str()); int ret = (int)SendMessage(listCtrl, CB_SELECTSTRING, (WPARAM)-1, (LPARAM)fSetName.c_str());
if (ret == CB_ERR) // couldn't find the string, so just set it as the current string in the edit box if (ret == CB_ERR) // couldn't find the string, so just set it as the current string in the edit box
SetDlgItemTextW(hDlg, IDC_PARENTSET, fSetName.c_str()); SetDlgItemTextW(hDlg, IDC_PARENTSET, fSetName.ToWchar());
fAgeChanged = false; fAgeChanged = false;
} }
if (fSetName != L"" && setFocus) if (!fSetName.IsEmpty() && setFocus)
SetFocus(GetDlgItem(hDlg, IDC_ELEMENTNAME)); SetFocus(GetDlgItem(hDlg, IDC_ELEMENTNAME));
if (fSetName != L"" && fElementName != L"") if (!fSetName.IsEmpty() && fElementName.IsEmpty())
EnableWindow(GetDlgItem(hDlg, IDOK), TRUE); EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
else else
EnableWindow(GetDlgItem(hDlg, IDOK), FALSE); EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
} }
plAddElementDlg::plAddElementDlg(std::wstring parentPath) plAddElementDlg::plAddElementDlg(plString parentPath)
{ {
// throw away vars // throw away vars
std::wstring element, lang; plString element, lang;
SplitLocalizationPath(parentPath, fAgeName, fSetName, element, lang); SplitLocalizationPath(parentPath, fAgeName, fSetName, element, lang);
} }
@ -309,7 +309,7 @@ BOOL CALLBACK plAddLocalizationDlg::IDlgProc(HWND hDlg, UINT msg, WPARAM wParam,
int index = (int)SendMessage(GetDlgItem(hDlg, IDC_LANGUAGE), CB_GETCURSEL, (WPARAM)0, (LPARAM)0); int index = (int)SendMessage(GetDlgItem(hDlg, IDC_LANGUAGE), CB_GETCURSEL, (WPARAM)0, (LPARAM)0);
SendMessage(GetDlgItem(hDlg, IDC_LANGUAGE), CB_GETLBTEXT, (WPARAM)index, (LPARAM)buff); SendMessage(GetDlgItem(hDlg, IDC_LANGUAGE), CB_GETLBTEXT, (WPARAM)index, (LPARAM)buff);
pthis->fLanguageName = buff; pthis->fLanguageName = plString::FromWchar(buff);
pthis->IUpdateDlg(hDlg); pthis->IUpdateDlg(hDlg);
} }
break; break;
@ -326,16 +326,16 @@ BOOL CALLBACK plAddLocalizationDlg::IDlgProc(HWND hDlg, UINT msg, WPARAM wParam,
return FALSE; return FALSE;
} }
std::vector<std::wstring> IGetAllLanguageNames() std::vector<plString> IGetAllLanguageNames()
{ {
int numLocales = plLocalization::GetNumLocales(); int numLocales = plLocalization::GetNumLocales();
std::vector<std::wstring> retVal; std::vector<plString> retVal;
for (int curLocale = 0; curLocale <= numLocales; curLocale++) for (int curLocale = 0; curLocale <= numLocales; curLocale++)
{ {
const char *name = plLocalization::GetLanguageName((plLocalization::Language)curLocale); const char *name = plLocalization::GetLanguageName((plLocalization::Language)curLocale);
wchar_t *wName = hsStringToWString(name); wchar_t *wName = hsStringToWString(name);
retVal.push_back(wName); retVal.push_back(plString::FromWchar(wName));
delete [] wName; delete [] wName;
} }
@ -344,13 +344,13 @@ std::vector<std::wstring> IGetAllLanguageNames()
bool plAddLocalizationDlg::IInitDlg(HWND hDlg) bool plAddLocalizationDlg::IInitDlg(HWND hDlg)
{ {
std::wstring pathStr = L"Path: " + fAgeName + L"." + fSetName + L"." + fElementName; plString pathStr = plString::Format("Path: %s.%s.%s", fAgeName.c_str(), fSetName.c_str(), fElementName.c_str());
SetDlgItemTextW(hDlg, IDC_PATH, pathStr.c_str()); SetDlgItemTextW(hDlg, IDC_PATH, pathStr.ToWchar());
std::vector<std::wstring> existingLanguages; std::vector<plString> existingLanguages;
existingLanguages = pfLocalizationDataMgr::Instance().GetLanguages(fAgeName, fSetName, fElementName); existingLanguages = pfLocalizationDataMgr::Instance().GetLanguages(fAgeName, fSetName, fElementName);
std::vector<std::wstring> missingLanguages = IGetAllLanguageNames(); std::vector<plString> missingLanguages = IGetAllLanguageNames();
for (int i = 0; i < existingLanguages.size(); i++) // remove all languages we already have for (int i = 0; i < existingLanguages.size(); i++) // remove all languages we already have
{ {
for (int j = 0; j < missingLanguages.size(); j++) for (int j = 0; j < missingLanguages.size(); j++)
@ -382,7 +382,7 @@ bool plAddLocalizationDlg::IInitDlg(HWND hDlg)
// and put it's value into the internal variable // and put it's value into the internal variable
wchar_t buff[256]; wchar_t buff[256];
GetDlgItemText(hDlg, IDC_LANGUAGE, buff, 256); GetDlgItemText(hDlg, IDC_LANGUAGE, buff, 256);
fLanguageName = buff; fLanguageName = plString::FromWchar(buff);
IUpdateDlg(hDlg); IUpdateDlg(hDlg);
return true; return true;
@ -390,16 +390,16 @@ bool plAddLocalizationDlg::IInitDlg(HWND hDlg)
void plAddLocalizationDlg::IUpdateDlg(HWND hDlg) void plAddLocalizationDlg::IUpdateDlg(HWND hDlg)
{ {
if (fLanguageName != L"") if (!fLanguageName.IsEmpty())
EnableWindow(GetDlgItem(hDlg, IDOK), TRUE); EnableWindow(GetDlgItem(hDlg, IDOK), TRUE);
else else
EnableWindow(GetDlgItem(hDlg, IDOK), FALSE); EnableWindow(GetDlgItem(hDlg, IDOK), FALSE);
} }
plAddLocalizationDlg::plAddLocalizationDlg(std::wstring parentPath) plAddLocalizationDlg::plAddLocalizationDlg(plString parentPath)
{ {
// throw away vars // throw away vars
std::wstring lang; plString lang;
SplitLocalizationPath(parentPath, fAgeName, fSetName, fElementName, lang); SplitLocalizationPath(parentPath, fAgeName, fSetName, fElementName, lang);
} }

14
Sources/Tools/plLocalizationEditor/plAddDlgs.h

@ -45,7 +45,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h" #include "HeadSpin.h"
#include "hsWindows.h" #include "hsWindows.h"
#include <string> #include "plString.h"
class plAddElementDlg class plAddElementDlg
{ {
@ -55,13 +55,13 @@ protected:
bool IInitDlg(HWND hDlg); bool IInitDlg(HWND hDlg);
void IUpdateDlg(HWND hDlg, bool setFocus = true); void IUpdateDlg(HWND hDlg, bool setFocus = true);
std::wstring fAgeName, fSetName, fElementName; plString fAgeName, fSetName, fElementName;
bool fAgeChanged; bool fAgeChanged;
public: public:
plAddElementDlg(std::wstring parentPath); plAddElementDlg(plString parentPath);
bool DoPick(HWND parent); // returns true if [Ok] clicked, false otherwise. bool DoPick(HWND parent); // returns true if [Ok] clicked, false otherwise.
std::wstring GetValue() {return fAgeName + L"." + fSetName + L"." + fElementName;} plString GetValue() {return plString::Format("%s.%s.%s", fAgeName.c_str(), fSetName.c_str(), fElementName.c_str());}
}; };
class plAddLocalizationDlg class plAddLocalizationDlg
@ -72,12 +72,12 @@ protected:
bool IInitDlg(HWND hDlg); bool IInitDlg(HWND hDlg);
void IUpdateDlg(HWND hDlg); void IUpdateDlg(HWND hDlg);
std::wstring fAgeName, fSetName, fElementName, fLanguageName; plString fAgeName, fSetName, fElementName, fLanguageName;
public: public:
plAddLocalizationDlg(std::wstring parentPath); plAddLocalizationDlg(plString parentPath);
bool DoPick(HWND parent); // returns true if [Ok] clicked, false otherwise. bool DoPick(HWND parent); // returns true if [Ok] clicked, false otherwise.
std::wstring GetValue() {return fLanguageName;} plString GetValue() {return fLanguageName;}
}; };
#endif #endif

130
Sources/Tools/plLocalizationEditor/plEditDlg.cpp

@ -45,7 +45,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "plLocTreeView.h" #include "plLocTreeView.h"
#include "plAddDlgs.h" #include "plAddDlgs.h"
#include "pfLocalizationMgr/pfLocalizationDataMgr.h" #include "pfLocalizationMgr/pfLocalizationDataMgr.h"
#include <map> #include <map>
@ -55,64 +54,40 @@ extern HINSTANCE gInstance;
extern HWND gTreeView; extern HWND gTreeView;
// global data for this dialog // global data for this dialog
std::wstring gCurrentPath = L""; plString gCurrentPath;
// split a subtitle path up into its component parts // split a subtitle path up into its component parts
void SplitLocalizationPath(std::wstring path, std::wstring &ageName, std::wstring &setName, std::wstring &locName, std::wstring &locLanguage) void SplitLocalizationPath(plString path, plString &ageName, plString &setName, plString &locName, plString &locLanguage)
{
ageName = setName = locName = locLanguage = L"";
std::wstring::size_type lastPos = 0, curPos = 0;
// separate the age name out
curPos = path.find(L".");
if (curPos == std::wstring::npos)
{
ageName = path;
return;
}
ageName = path.substr(0, curPos);
path = path.substr(curPos + 1, path.length());
// separate the set name out
curPos = path.find(L".");
if (curPos == std::wstring::npos)
{ {
setName = path; ageName = setName = locName = locLanguage = "";
return;
} std::vector<plString> tokens = path.Tokenize(".");
setName = path.substr(0, curPos); if (tokens.size() >= 1)
path = path.substr(curPos + 1, path.length()); ageName = tokens[0];
if (tokens.size() >= 2)
// separate the element out setName = tokens[1];
curPos = path.find(L"."); if (tokens.size() >= 3)
if (curPos == std::wstring::npos) locName = tokens[2];
{ if (tokens.size() >= 4)
locName = path; locLanguage = tokens[3];
return;
}
locName = path.substr(0, curPos);
path = path.substr(curPos + 1, path.length());
// what's left is the language
locLanguage = path;
} }
// saves the current localization text to the data manager // saves the current localization text to the data manager
void SaveLocalizationText() void SaveLocalizationText()
{ {
if (gCurrentPath == L"") if (gCurrentPath.IsEmpty())
return; // no path to save return; // no path to save
uint32_t textLen = (uint32_t)SendMessage(GetDlgItem(gEditDlg, IDC_LOCALIZATIONTEXT), WM_GETTEXTLENGTH, (WPARAM)0, (LPARAM)0); uint32_t textLen = (uint32_t)SendMessage(GetDlgItem(gEditDlg, IDC_LOCALIZATIONTEXT), WM_GETTEXTLENGTH, (WPARAM)0, (LPARAM)0);
wchar_t *buffer = new wchar_t[textLen + 2]; wchar_t *buffer = new wchar_t[textLen + 2];
GetDlgItemTextW(gEditDlg, IDC_LOCALIZATIONTEXT, buffer, textLen + 1); GetDlgItemTextW(gEditDlg, IDC_LOCALIZATIONTEXT, buffer, textLen + 1);
buffer[textLen + 1] = 0; buffer[textLen + 1] = 0;
std::wstring plainTextData = buffer; plString plainTextData = plString::FromWchar(buffer);
delete [] buffer; delete [] buffer;
std::wstring ageName, setName, elementName, elementLanguage; plString ageName, setName, elementName, elementLanguage;
SplitLocalizationPath(gCurrentPath, ageName, setName, elementName, elementLanguage); SplitLocalizationPath(gCurrentPath, ageName, setName, elementName, elementLanguage);
std::wstring name = ageName + L"." + setName + L"." + elementName; plString name = plString::Format("%s.%s.%s", ageName.c_str(), setName.c_str(), elementName.c_str());
pfLocalizationDataMgr::Instance().SetElementPlainTextData(name, elementLanguage, plainTextData); pfLocalizationDataMgr::Instance().SetElementPlainTextData(name, elementLanguage, plainTextData);
} }
@ -132,38 +107,37 @@ void EnableDlg(BOOL enable)
} }
// updates the edit dialog based on the path specified // updates the edit dialog based on the path specified
void UpdateEditDlg(std::wstring locPath) void UpdateEditDlg(plString locPath)
{ {
if (locPath == gCurrentPath) if (locPath == gCurrentPath)
return; return;
gCurrentPath = locPath; gCurrentPath = locPath;
std::wstring itemText = L"Text ("; plString itemText = plString::Format("Text (%s):", locPath.c_str());
itemText += locPath + L"):"; SetDlgItemTextW(gEditDlg, IDC_LOCPATH, itemText.ToWchar());
SetDlgItemTextW(gEditDlg, IDC_LOCPATH, itemText.c_str());
std::wstring ageName = L"", setName = L"", elementName = L"", elementLanguage = L""; plString ageName, setName, elementName, elementLanguage;
SplitLocalizationPath(locPath, ageName, setName, elementName, elementLanguage); SplitLocalizationPath(locPath, ageName, setName, elementName, elementLanguage);
// now make sure they've drilled down deep enough to enable the dialog // now make sure they've drilled down deep enough to enable the dialog
if (elementLanguage == L"") // not deep enough if (elementLanguage.IsEmpty()) // not deep enough
EnableDlg(FALSE); EnableDlg(FALSE);
else else
{ {
EnableDlg(TRUE); EnableDlg(TRUE);
std::wstring key = ageName + L"." + setName + L"." + elementName; plString key = plString::Format("%s.%s.%s", ageName.c_str(), setName.c_str(), elementName.c_str());
std::wstring elementText = pfLocalizationDataMgr::Instance().GetElementPlainTextData(key, elementLanguage); plString elementText = pfLocalizationDataMgr::Instance().GetElementPlainTextData(key, elementLanguage);
SetDlgItemTextW(gEditDlg, IDC_LOCALIZATIONTEXT, elementText.c_str()); SetDlgItemTextW(gEditDlg, IDC_LOCALIZATIONTEXT, elementText.ToWchar());
} }
// now to setup the add/delete buttons // now to setup the add/delete buttons
if (elementLanguage != L"") // they have selected a language if (!elementLanguage.IsEmpty()) // they have selected a language
{ {
SetDlgItemText(gEditDlg, IDC_ADD, L"Add Localization"); SetDlgItemText(gEditDlg, IDC_ADD, L"Add Localization");
EnableWindow(GetDlgItem(gEditDlg, IDC_ADD), TRUE); EnableWindow(GetDlgItem(gEditDlg, IDC_ADD), TRUE);
SetDlgItemText(gEditDlg, IDC_DELETE, L"Delete Localization"); SetDlgItemText(gEditDlg, IDC_DELETE, L"Delete Localization");
if (elementLanguage != L"English") // don't allow them to delete the default language if (elementLanguage != "English") // don't allow them to delete the default language
EnableWindow(GetDlgItem(gEditDlg, IDC_DELETE), TRUE); EnableWindow(GetDlgItem(gEditDlg, IDC_DELETE), TRUE);
else else
EnableWindow(GetDlgItem(gEditDlg, IDC_DELETE), FALSE); EnableWindow(GetDlgItem(gEditDlg, IDC_DELETE), FALSE);
@ -173,9 +147,9 @@ void UpdateEditDlg(std::wstring locPath)
SetDlgItemText(gEditDlg, IDC_ADD, L"Add Element"); SetDlgItemText(gEditDlg, IDC_ADD, L"Add Element");
EnableWindow(GetDlgItem(gEditDlg, IDC_ADD), TRUE); EnableWindow(GetDlgItem(gEditDlg, IDC_ADD), TRUE);
SetDlgItemText(gEditDlg, IDC_DELETE, L"Delete Element"); SetDlgItemText(gEditDlg, IDC_DELETE, L"Delete Element");
if (elementName != L"") // the have selected an individual element if (!elementName.IsEmpty()) // they have selected an individual element
{ {
std::vector<std::wstring> elementNames = pfLocalizationDataMgr::Instance().GetElementList(ageName, setName); std::vector<plString> elementNames = pfLocalizationDataMgr::Instance().GetElementList(ageName, setName);
if (elementNames.size() > 1) // they can't delete the only subtitle in a set if (elementNames.size() > 1) // they can't delete the only subtitle in a set
EnableWindow(GetDlgItem(gEditDlg, IDC_DELETE), TRUE); EnableWindow(GetDlgItem(gEditDlg, IDC_DELETE), TRUE);
else else
@ -201,43 +175,43 @@ BOOL HandleCommandMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
SaveLocalizationText(); // save any current changes to the database SaveLocalizationText(); // save any current changes to the database
std::wstring buttonText; plString buttonText;
wchar_t buff[256]; wchar_t buff[256];
GetDlgItemText(gEditDlg, IDC_ADD, buff, 256); GetDlgItemText(gEditDlg, IDC_ADD, buff, 256);
buttonText = buff; buttonText = plString::FromWchar(buff);
if (buttonText == L"Add Element") if (buttonText == "Add Element")
{ {
plAddElementDlg dlg(gCurrentPath); plAddElementDlg dlg(gCurrentPath);
if (dlg.DoPick(gEditDlg)) if (dlg.DoPick(gEditDlg))
{ {
std::wstring path = dlg.GetValue(); // path is age.set.name plString path = dlg.GetValue(); // path is age.set.name
if (!pfLocalizationDataMgr::Instance().AddElement(path)) if (!pfLocalizationDataMgr::Instance().AddElement(path))
MessageBox(gEditDlg, L"Couldn't add new element because one already exists with that name!", L"Error", MB_ICONERROR | MB_OK); MessageBox(gEditDlg, L"Couldn't add new element because one already exists with that name!", L"Error", MB_ICONERROR | MB_OK);
else else
{ {
gCurrentPath = L""; gCurrentPath = "";
plLocTreeView::ClearTreeView(gTreeView); plLocTreeView::ClearTreeView(gTreeView);
plLocTreeView::FillTreeViewFromData(gTreeView, path); plLocTreeView::FillTreeViewFromData(gTreeView, path);
UpdateEditDlg(path); UpdateEditDlg(path);
} }
} }
} }
else if (buttonText == L"Add Localization") else if (buttonText == "Add Localization")
{ {
plAddLocalizationDlg dlg(gCurrentPath); plAddLocalizationDlg dlg(gCurrentPath);
if (dlg.DoPick(gEditDlg)) if (dlg.DoPick(gEditDlg))
{ {
std::wstring newLanguage = dlg.GetValue(); plString newLanguage = dlg.GetValue();
std::wstring ageName, setName, elementName, elementLanguage; plString ageName, setName, elementName, elementLanguage;
SplitLocalizationPath(gCurrentPath, ageName, setName, elementName, elementLanguage); SplitLocalizationPath(gCurrentPath, ageName, setName, elementName, elementLanguage);
std::wstring key = ageName + L"." + setName + L"." + elementName; plString key = plString::Format("%s.%s.%s", ageName.c_str(), setName.c_str(), elementName.c_str());
if (!pfLocalizationDataMgr::Instance().AddLocalization(key, newLanguage)) if (!pfLocalizationDataMgr::Instance().AddLocalization(key, newLanguage))
MessageBox(gEditDlg, L"Couldn't add additional localization!", L"Error", MB_ICONERROR | MB_OK); MessageBox(gEditDlg, L"Couldn't add additional localization!", L"Error", MB_ICONERROR | MB_OK);
else else
{ {
std::wstring path = key + L"." + newLanguage; // select the new language plString path = plString::Format("%s.%s", key.c_str(), newLanguage.c_str());
gCurrentPath = L""; gCurrentPath = "";
plLocTreeView::ClearTreeView(gTreeView); plLocTreeView::ClearTreeView(gTreeView);
plLocTreeView::FillTreeViewFromData(gTreeView, path); plLocTreeView::FillTreeViewFromData(gTreeView, path);
UpdateEditDlg(path); UpdateEditDlg(path);
@ -250,39 +224,39 @@ BOOL HandleCommandMessage(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{ {
SaveLocalizationText(); // save any current changes to the database SaveLocalizationText(); // save any current changes to the database
std::wstring messageText = L"Are you sure that you want to delete " + gCurrentPath + L"?"; plString messageText = plString::Format("Are you sure that you want to delete %s?", gCurrentPath.c_str());
int res = MessageBoxW(gEditDlg, messageText.c_str(), L"Delete", MB_ICONQUESTION | MB_YESNO); int res = MessageBoxW(gEditDlg, messageText.ToWchar(), L"Delete", MB_ICONQUESTION | MB_YESNO);
if (res == IDYES) if (res == IDYES)
{ {
std::wstring buttonText; plString buttonText;
wchar_t buff[256]; wchar_t buff[256];
GetDlgItemText(gEditDlg, IDC_DELETE, buff, 256); GetDlgItemText(gEditDlg, IDC_DELETE, buff, 256);
buttonText = buff; buttonText = plString::FromWchar(buff);
if (buttonText == L"Delete Element") if (buttonText == "Delete Element")
{ {
if (!pfLocalizationDataMgr::Instance().DeleteElement(gCurrentPath)) if (!pfLocalizationDataMgr::Instance().DeleteElement(gCurrentPath))
MessageBox(gEditDlg, L"Couldn't delete element!", L"Error", MB_ICONERROR | MB_OK); MessageBox(gEditDlg, L"Couldn't delete element!", L"Error", MB_ICONERROR | MB_OK);
else else
{ {
std::wstring path = gCurrentPath; plString path = gCurrentPath;
gCurrentPath = L""; gCurrentPath = "";
plLocTreeView::ClearTreeView(gTreeView); plLocTreeView::ClearTreeView(gTreeView);
plLocTreeView::FillTreeViewFromData(gTreeView, path); plLocTreeView::FillTreeViewFromData(gTreeView, path);
UpdateEditDlg(path); UpdateEditDlg(path);
} }
} }
else if (buttonText == L"Delete Localization") else if (buttonText == "Delete Localization")
{ {
std::wstring ageName, setName, elementName, elementLanguage; plString ageName, setName, elementName, elementLanguage;
SplitLocalizationPath(gCurrentPath, ageName, setName, elementName, elementLanguage); SplitLocalizationPath(gCurrentPath, ageName, setName, elementName, elementLanguage);
std::wstring key = ageName + L"." + setName + L"." + elementName; plString key = plString::Format("%s.%s.%s", ageName.c_str(), setName.c_str(), elementName.c_str());
if (!pfLocalizationDataMgr::Instance().DeleteLocalization(key, elementLanguage)) if (!pfLocalizationDataMgr::Instance().DeleteLocalization(key, elementLanguage))
MessageBox(gEditDlg, L"Couldn't delete localization!", L"Error", MB_ICONERROR | MB_OK); MessageBox(gEditDlg, L"Couldn't delete localization!", L"Error", MB_ICONERROR | MB_OK);
else else
{ {
std::wstring path = gCurrentPath; plString path = gCurrentPath;
gCurrentPath = L""; gCurrentPath = "";
plLocTreeView::ClearTreeView(gTreeView); plLocTreeView::ClearTreeView(gTreeView);
plLocTreeView::FillTreeViewFromData(gTreeView, path); plLocTreeView::FillTreeViewFromData(gTreeView, path);
UpdateEditDlg(path); UpdateEditDlg(path);

7
Sources/Tools/plLocalizationEditor/plEditDlg.h

@ -45,7 +45,8 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "HeadSpin.h" #include "HeadSpin.h"
#include "hsWindows.h" #include "hsWindows.h"
#include <string>
class plString;
// Little trick to show a wait cursor while something is working // Little trick to show a wait cursor while something is working
class plWaitCursor class plWaitCursor
@ -63,9 +64,9 @@ public:
} }
}; };
void SplitLocalizationPath(std::wstring path, std::wstring &ageName, std::wstring &setName, std::wstring &locName, std::wstring &locLanguage); void SplitLocalizationPath(plString path, plString &ageName, plString &setName, plString &locName, plString &locLanguage);
void SaveLocalizationText(); void SaveLocalizationText();
void UpdateEditDlg(std::wstring subtitlePath); void UpdateEditDlg(plString subtitlePath);
BOOL CALLBACK EditDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); BOOL CALLBACK EditDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
#endif #endif

48
Sources/Tools/plLocalizationEditor/plLocTreeView.cpp

@ -48,21 +48,25 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "res\resource.h" #include "res\resource.h"
#include <vector> #include <vector>
#include <string> #include <list>
#include "pfLocalizationMgr/pfLocalizationDataMgr.h" #include "pfLocalizationMgr/pfLocalizationDataMgr.h"
extern HINSTANCE gInstance; extern HINSTANCE gInstance;
std::wstring plLocTreeView::fPath = L""; plString plLocTreeView::fPath = "";
HTREEITEM AddLeaf(HWND hTree, HTREEITEM hParent, std::wstring text, bool sort = true) HTREEITEM AddLeaf(HWND hTree, HTREEITEM hParent, plString text, bool sort = true)
{ {
// Semi-hack to keep these around as Win32 expects
static std::list<plStringBuffer<wchar_t>> bufs;
plStringBuffer<wchar_t> buf = text.ToWchar();
bufs.push_back(buf);
TVITEM tvi = {0}; TVITEM tvi = {0};
tvi.mask = TVIF_TEXT | TVIF_PARAM; tvi.mask = TVIF_TEXT | TVIF_PARAM;
tvi.pszText = (wchar_t*)text.c_str(); tvi.pszText = const_cast<LPWSTR>(buf.GetData());
tvi.cchTextMax = (int)text.length(); tvi.cchTextMax = static_cast<int>(text.GetSize());
tvi.lParam = NULL; tvi.lParam = NULL;
TVINSERTSTRUCT tvins = {0}; TVINSERTSTRUCT tvins = {0};
@ -76,15 +80,15 @@ HTREEITEM AddLeaf(HWND hTree, HTREEITEM hParent, std::wstring text, bool sort =
return TreeView_InsertItem(hTree, &tvins); return TreeView_InsertItem(hTree, &tvins);
} }
void plLocTreeView::FillTreeViewFromData(HWND treeCtrl, std::wstring selectionPath) void plLocTreeView::FillTreeViewFromData(HWND treeCtrl, plString selectionPath)
{ {
std::wstring targetAge, targetSet, targetElement, targetLang; plString targetAge, targetSet, targetElement, targetLang;
SplitLocalizationPath(selectionPath, targetAge, targetSet, targetElement, targetLang); SplitLocalizationPath(selectionPath, targetAge, targetSet, targetElement, targetLang);
bool ageMatched = false; bool ageMatched = false;
bool setMatched = false; bool setMatched = false;
bool elementMatched = false; bool elementMatched = false;
std::vector<std::wstring> ages = pfLocalizationDataMgr::Instance().GetAgeList(); std::vector<plString> ages = pfLocalizationDataMgr::Instance().GetAgeList();
for (int curAge = 0; curAge < ages.size(); curAge++) for (int curAge = 0; curAge < ages.size(); curAge++)
{ {
// add the age to the tree // add the age to the tree
@ -99,10 +103,10 @@ void plLocTreeView::FillTreeViewFromData(HWND treeCtrl, std::wstring selectionPa
else else
ageMatched = false; ageMatched = false;
std::vector<std::wstring> sets = pfLocalizationDataMgr::Instance().GetSetList(ages[curAge]); std::vector<plString> sets = pfLocalizationDataMgr::Instance().GetSetList(ages[curAge]);
for (int curSet = 0; curSet < sets.size(); curSet++) for (int curSet = 0; curSet < sets.size(); curSet++)
{ {
std::vector<std::wstring> elements = pfLocalizationDataMgr::Instance().GetElementList(ages[curAge], sets[curSet]); std::vector<plString> elements = pfLocalizationDataMgr::Instance().GetElementList(ages[curAge], sets[curSet]);
HTREEITEM setItem = AddLeaf(treeCtrl, ageItem, sets[curSet]); HTREEITEM setItem = AddLeaf(treeCtrl, ageItem, sets[curSet]);
@ -125,13 +129,13 @@ void plLocTreeView::FillTreeViewFromData(HWND treeCtrl, std::wstring selectionPa
TreeView_EnsureVisible(treeCtrl, subItem); TreeView_EnsureVisible(treeCtrl, subItem);
elementMatched = true; elementMatched = true;
if (targetLang.empty()) if (targetLang.IsEmpty())
targetLang = L"English"; targetLang = "English";
} }
else else
elementMatched = false; elementMatched = false;
std::vector<std::wstring> languages = pfLocalizationDataMgr::Instance().GetLanguages(ages[curAge], sets[curSet], elements[curElement]); std::vector<plString> languages = pfLocalizationDataMgr::Instance().GetLanguages(ages[curAge], sets[curSet], elements[curElement]);
for (int curLang = 0; curLang < languages.size(); curLang++) for (int curLang = 0; curLang < languages.size(); curLang++)
{ {
HTREEITEM langItem = AddLeaf(treeCtrl, subItem, languages[curLang]); HTREEITEM langItem = AddLeaf(treeCtrl, subItem, languages[curLang]);
@ -155,8 +159,8 @@ void plLocTreeView::ClearTreeView(HWND treeCtrl)
void plLocTreeView::SelectionChanged(HWND treeCtrl) void plLocTreeView::SelectionChanged(HWND treeCtrl)
{ {
HTREEITEM hItem = TreeView_GetSelection(treeCtrl); HTREEITEM hItem = TreeView_GetSelection(treeCtrl);
std::vector<std::wstring> path; std::vector<plString> path;
fPath = L""; fPath = "";
while (hItem) while (hItem)
{ {
@ -167,7 +171,7 @@ void plLocTreeView::SelectionChanged(HWND treeCtrl)
tvi.pszText = s; tvi.pszText = s;
tvi.cchTextMax = 200; tvi.cchTextMax = 200;
TreeView_GetItem(treeCtrl, &tvi); TreeView_GetItem(treeCtrl, &tvi);
path.push_back(tvi.pszText); path.push_back(plString::FromWchar(tvi.pszText));
hItem = TreeView_GetParent(treeCtrl, hItem); hItem = TreeView_GetParent(treeCtrl, hItem);
} }
@ -177,15 +181,15 @@ void plLocTreeView::SelectionChanged(HWND treeCtrl)
path.pop_back(); path.pop_back();
if (!path.empty()) if (!path.empty())
fPath += L"."; fPath += ".";
} }
} }
void plLocTreeView::SelectionDblClicked(HWND treeCtrl) void plLocTreeView::SelectionDblClicked(HWND treeCtrl)
{ {
HTREEITEM hItem = TreeView_GetSelection(treeCtrl); HTREEITEM hItem = TreeView_GetSelection(treeCtrl);
std::vector<std::wstring> path; std::vector<plString> path;
fPath = L""; fPath = "";
while (hItem) while (hItem)
{ {
@ -196,7 +200,7 @@ void plLocTreeView::SelectionDblClicked(HWND treeCtrl)
tvi.pszText = s; tvi.pszText = s;
tvi.cchTextMax = 200; tvi.cchTextMax = 200;
TreeView_GetItem(treeCtrl, &tvi); TreeView_GetItem(treeCtrl, &tvi);
path.push_back(tvi.pszText); path.push_back(plString::FromWchar(tvi.pszText));
hItem = TreeView_GetParent(treeCtrl, hItem); hItem = TreeView_GetParent(treeCtrl, hItem);
} }
@ -206,6 +210,6 @@ void plLocTreeView::SelectionDblClicked(HWND treeCtrl)
path.pop_back(); path.pop_back();
if (!path.empty()) if (!path.empty())
fPath += L"."; fPath += ".";
} }
} }

8
Sources/Tools/plLocalizationEditor/plLocTreeView.h

@ -43,21 +43,21 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#define _plLocTreeView_h #define _plLocTreeView_h
#include "HeadSpin.h" #include "HeadSpin.h"
#include <string> #include "plString.h"
class plLocTreeView class plLocTreeView
{ {
protected: protected:
static std::wstring fPath; static plString fPath;
public: public:
static void FillTreeViewFromData(HWND treeCtrl, std::wstring selectionPath); static void FillTreeViewFromData(HWND treeCtrl, plString selectionPath);
static void ClearTreeView(HWND treeCtrl); static void ClearTreeView(HWND treeCtrl);
static void SelectionChanged(HWND treeCtrl); static void SelectionChanged(HWND treeCtrl);
static void SelectionDblClicked(HWND treeCtrl); static void SelectionDblClicked(HWND treeCtrl);
static std::wstring GetPath() {return fPath;} static plString GetPath() {return fPath;}
}; };
#endif //_plLocTreeView_h #endif //_plLocTreeView_h

4
Sources/Tools/plLocalizationEditor/plLocalizationEditor.cpp

@ -223,7 +223,7 @@ LRESULT CALLBACK HandleCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
bInfo.pidlRoot = NULL; bInfo.pidlRoot = NULL;
bInfo.pszDisplayName = path; bInfo.pszDisplayName = path;
bInfo.lpszTitle = L"Select a localization data directory:"; bInfo.lpszTitle = L"Select a localization data directory:";
bInfo.ulFlags = BIF_EDITBOX; bInfo.ulFlags = BIF_USENEWUI | BIF_VALIDATE | BIF_RETURNONLYFSDIRS | BIF_NONEWFOLDERBUTTON;
itemList = SHBrowseForFolder(&bInfo); itemList = SHBrowseForFolder(&bInfo);
if (itemList != NULL) if (itemList != NULL)
@ -242,7 +242,7 @@ LRESULT CALLBACK HandleCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
delete [] sPath; delete [] sPath;
plLocTreeView::ClearTreeView(gTreeView); plLocTreeView::ClearTreeView(gTreeView);
plLocTreeView::FillTreeViewFromData(gTreeView, L""); plLocTreeView::FillTreeViewFromData(gTreeView, "");
gCurPath = path; gCurPath = path;
SetWindowTitle(hWnd, path); SetWindowTitle(hWnd, path);

Loading…
Cancel
Save