Skip to content

Commit

Permalink
:) 22 file path
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercury13 committed May 7, 2022
1 parent 89296ce commit 1614c8e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Libs/SelfMade/Strings/u_Qstrings.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ namespace str {
inline QString toQ(std::string_view x)
{ return QString::fromUtf8(x.data(), x.size()); }

inline QString toQ(std::wstring_view x)
{ return QString::fromWCharArray(x.data(), x.size()); }

inline QString toQ(std::u8string_view x)
{ return QString::fromUtf8(x.data(), x.size()); }

Expand Down
5 changes: 4 additions & 1 deletion UTranslator/FmMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ FmMain::FmMain(QWidget *parent)

// Signals/slots: editing
connect(ui->edId, &QLineEdit::textEdited, this, &This::tempModify);
connect(ui->edFilePath, &QLineEdit::textEdited, this, &This::tempModify);
connect(ui->memoOriginal, &QPlainTextEdit::textChanged, this, &This::tempModify);
connect(ui->chkIdless, &QCheckBox::clicked, this, &This::tempModify);
connect(ui->memoTranslation, &QPlainTextEdit::textChanged, this, &This::tempModify);
Expand Down Expand Up @@ -617,6 +618,7 @@ void FmMain::loadObject(tr::UiObject& obj)
if (auto fi = obj.ownFileInfo()) {
ui->stackOriginal->setCurrentWidget(ui->pageFile);
ui->chkIdless->setChecked(fi->isIdless);
ui->edFilePath->setText(str::toQ(fi->origPath.wstring()));
bool canAddFiles = project->info.canAddFiles();
ui->pageFile->setEnabled(canAddFiles);
ui->wiId->setEnabled(canAddFiles);
Expand Down Expand Up @@ -704,8 +706,9 @@ void FmMain::acceptObject(tr::UiObject& obj)
auto idx9 = treeModel.toIndex(obj, treeModel.columnCount() - 1);
treeModel.dataChanged(idx0, idx9);
std::string cache;
if (project->info.canEditOriginal()) {
if (project->info.canAddFiles()) {
obj.setId(toU8sv(ui->edId, cache), tr::Modify::YES);
obj.setOrigPath(ui->edFilePath->text().toStdWString(), tr::Modify::YES);
obj.setIdless(ui->chkIdless->isChecked(), tr::Modify::YES);
obj.setOriginal(toTextSv(ui->memoOriginal, cache), tr::Modify::YES);
// Bilingual (currently unimplemented):
Expand Down
4 changes: 2 additions & 2 deletions UTranslator/FmMain.ui
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ QLabel {
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit"/>
<widget class="QLineEdit" name="edFilePath"/>
</item>
</layout>
</item>
Expand Down Expand Up @@ -955,7 +955,7 @@ QLabel {
<tabstop>btStartOpen</tabstop>
<tabstop>treeStrings</tabstop>
<tabstop>edId</tabstop>
<tabstop>lineEdit</tabstop>
<tabstop>edFilePath</tabstop>
<tabstop>memoOriginal</tabstop>
<tabstop>chkIdless</tabstop>
<tabstop>btFileFormat</tabstop>
Expand Down
20 changes: 20 additions & 0 deletions UTranslator/TrProject/TrProject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ bool tr::UiObject::setIdless(bool x, tr::Modify wantModify)
}


bool tr::UiObject::setOrigPath(const std::filesystem::path& x, tr::Modify wantModify)
{
if (auto fi = ownFileInfo()) {
if (fi->origPath != x) {
fi->origPath = x;
if (wantModify != Modify::NO) {
doModify(Mch::ORIG);
}
}
}
return false;
}


bool tr::UiObject::setTranslation(
std::optional<std::u8string_view> x, tr::Modify wantModify)
{
Expand Down Expand Up @@ -993,6 +1007,10 @@ void tr::File::writeToXml(pugi::xml_node& root, WrCache& c) const
auto node = root.append_child("file");
node.append_attribute("name") = str::toC(id);
node.append_attribute("idless") = info.isIdless;
if (!info.origPath.empty())
node.append_attribute("orig-path") = str::toC(info.origPath.u8string());
if (!info.translPath.empty())
node.append_attribute("transl-path") = str::toC(info.translPath.u8string());
if (info.format) {
auto nodeFormat = node.append_child("format");
nodeFormat.append_attribute("name") = info.format->proto().techName().data(); // Tech names are const, so OK
Expand All @@ -1006,6 +1024,8 @@ void tr::File::readFromXml(const pugi::xml_node& node, const PrjInfo& pinfo)
{
id = str::toU8sv(node.attribute("name").as_string());
info.isIdless = node.attribute("idless").as_bool(false);
info.origPath = str::toU8sv(node.attribute("orig-path").as_string());
info.translPath = str::toU8sv(node.attribute("transl-path").as_string());
if (auto nodeFormat = node.child("format")) {
std::string_view sName = nodeFormat.attribute("name").as_string();
if (!sName.empty()) {
Expand Down
2 changes: 2 additions & 0 deletions UTranslator/TrProject/TrProject.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ namespace tr {
bool setTranslatorsComment(std::u8string_view x, tr::Modify wantModify);
/// @return [+] was actually changed
bool setIdless(bool x, tr::Modify wantModify);
/// @return [+] was actually changed
bool setOrigPath(const std::filesystem::path& x, tr::Modify wantModify);
/// @return some ID
std::u8string makeId(
std::u8string_view prefix,
Expand Down

0 comments on commit 1614c8e

Please sign in to comment.