|
|
@ -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); |
|
|
|