diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp index 696bd41b1..c1633c3be 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_phrase.cpp @@ -75,29 +75,6 @@ void CEditorPhrase::newUndoCommandAdded() current_stack->push(new CUndoPhraseNewCommand(text_edit)); } -/* void CTextEdit::keyPressEvent(QKeyEvent *event) -{ - QString chars = event->text(); - int index = textCursor().position(); - - switch(event->key()) - { - case Qt::Key_Backspace: - if (index > 0) - m_undoStack->push(new CUndoPhraseRemoveCommand(index--, 1, this)); - break; - case Qt::Key_Delete: - if (index < toPlainText().length()) - m_undoStack->push(new CUndoPhraseRemoveCommand(index, 1, this)); - break; - default: - if (!chars.isEmpty()) - m_undoStack->push(new CUndoPhraseInsertCommand(index, chars, this)); - break; - } - -} */ - void CEditorPhrase::docContentsChanged() { setWindowModified(true); @@ -110,13 +87,7 @@ void CEditorPhrase::activateWindow() void CEditorPhrase::save() { - QFile file(current_file); - file.open(QIODevice::WriteOnly | QIODevice::Text); - QTextStream out(&file); - out.setCodec("UTF-8"); - out.setGenerateByteOrderMark(true); - out<toPlainText(); - setCurrentFile(current_file); + saveAs(current_file); } void CEditorPhrase::saveAs(QString filename) diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp index 6e71a9290..c957e6506 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.cpp @@ -34,8 +34,6 @@ using namespace std; namespace TranslationManager { - - void CEditorWorksheet::open(QString filename) { STRING_MANAGER::TWorksheet wk_file; @@ -134,54 +132,7 @@ void CEditorWorksheet::activateWindow() void CEditorWorksheet::save() { - STRING_MANAGER::TWorksheet wk_file; - loadExcelSheet(current_file.toStdString(), wk_file, true); - uint rowIdx; - uint colIdx = 0; - bool hasHashValue = false; - if(wk_file.getData(0, 0) == ucstring("*HASH_VALUE")) - { - hasHashValue = true; - colIdx = 1; - } - for(int i = 0; i < table_editor->rowCount(); i++) - { - // maybe extra rows ? - if((unsigned)table_editor->rowCount() > (wk_file.size() - 1)) - { - rowIdx = wk_file.size(); - wk_file.resize(rowIdx + table_editor->rowCount() - wk_file.size() + 1); - } - for(int j = 0; j < table_editor->columnCount(); j++) - { - ucstring tvalue; - ucstring colname; - uint rowIdf; - QString tvalueQt = table_editor->item(i, j)->text(); - tvalue.fromUtf8(std::string(tvalueQt.toUtf8())); - colname = wk_file.getData(0, j + colIdx); - - rowIdf = uint(i + 1); - if(wk_file.findRow(j + colIdx, colname, rowIdf)) // search for the row - { - if(wk_file.getData(i + 1, j + colIdx) != tvalue) // verify the current value - { - wk_file.setData(i + 1, j + colIdx, tvalue); // change the value - } - } else { - wk_file.setData(i + 1, j + colIdx, tvalue); // insert the value - } - } - } - if(hasHashValue) - { - // rewrite the hash codes - makeHashCode(wk_file, true); - } - // write to file - ucstring s = prepareExcelSheet(wk_file); - NLMISC::CI18N::writeTextFile(current_file.toStdString(), s, false); - setCurrentFile(current_file); + saveAs(current_file); } void CEditorWorksheet::saveAs(QString filename) @@ -238,8 +189,8 @@ void CEditorWorksheet::deleteRow() { int selected_row = table_editor->currentRow(); QMessageBox msgBox; - msgBox.setText("The row will be deleted."); - msgBox.setInformativeText("Do you want to delete the selected row ?"); + msgBox.setText(tr("The row will be deleted.")); + msgBox.setInformativeText(tr("Do you want to delete the selected row ?")); msgBox.setStandardButtons(QMessageBox::No | QMessageBox::Yes); msgBox.setDefaultButton(QMessageBox::No); int ret = msgBox.exec(); @@ -286,30 +237,15 @@ void CEditorWorksheet::extractBotNames(list filters, string level_design for (; it != last; ++it) { - QList search_results = table_editor->findItems(tr(it->first.c_str()), Qt::MatchExactly); + QList search_results = table_editor->findItems(QString(it->first.c_str()), Qt::MatchExactly); if(search_results.size() == 0) { - const int currentRow = table_editor->rowCount(); - table_editor->setRowCount(currentRow + 1); - QTableWidgetItem *bot_name_row = new QTableWidgetItem(); - bot_name_row->setText(tr(it->first.c_str())); - bot_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 0, bot_name_row); - QTableWidgetItem *translation_name_row = new QTableWidgetItem(); - translation_name_row->setBackgroundColor(QColor("#F75D59")); - translation_name_row->setText(tr(it->first.c_str())); - table_editor ->setItem(currentRow , 1, translation_name_row); - QTableWidgetItem *sheet_name_row = new QTableWidgetItem(); - sheet_name_row->setText(tr(it->second.SheetName.c_str())); - sheet_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 2, sheet_name_row); - if(!modified) modified = true; - CTableWidgetItemStore bot_name_row_s(bot_name_row, currentRow, 0); - new_items.push_back(bot_name_row_s); - CTableWidgetItemStore translation_name_row_s(translation_name_row, currentRow, 1); - new_items.push_back(translation_name_row_s); - CTableWidgetItemStore sheet_name_row_s(sheet_name_row, currentRow, 2); - new_items.push_back(sheet_name_row_s); + QList records; + records.push_back(tr(it->first.c_str())); + records.push_back(tr(it->first.c_str())); + records.push_back(tr(it->second.SheetName.c_str())); + insertTableRecords(records, new_items); + if(!modified) modified = true; } } ebn.cleanSimpleNames(); @@ -321,30 +257,15 @@ void CEditorWorksheet::extractBotNames(list filters, string level_design for (; it != last; ++it) { string gnName = "gn_" + ebn.cleanupName(*it); - QList search_results = table_editor->findItems(tr((*it).c_str()), Qt::MatchExactly); + QList search_results = table_editor->findItems(QString((*it).c_str()), Qt::MatchExactly); if(search_results.size() == 0) { - const int currentRow = table_editor->rowCount(); - table_editor->setRowCount(currentRow + 1); - QTableWidgetItem *bot_name_row = new QTableWidgetItem(); - bot_name_row->setText(tr((*it).c_str())); - bot_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 0, bot_name_row); - QTableWidgetItem *translation_name_row = new QTableWidgetItem(); - translation_name_row->setBackgroundColor(QColor("#F75D59")); - translation_name_row->setText(tr(gnName.c_str())); - table_editor ->setItem(currentRow , 1, translation_name_row); - QTableWidgetItem *sheet_name_row = new QTableWidgetItem(); - sheet_name_row->setText(" "); - sheet_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, 2, sheet_name_row); + QList records; + records.push_back(tr((*it).c_str())); + records.push_back(tr(gnName.c_str())); + records.push_back(" "); + insertTableRecords(records, new_items); if(!modified) modified = true; - CTableWidgetItemStore bot_name_row_s(bot_name_row, currentRow, 0); - new_items.push_back(bot_name_row_s); - CTableWidgetItemStore translation_name_row_s(translation_name_row, currentRow, 1); - new_items.push_back(translation_name_row_s); - CTableWidgetItemStore sheet_name_row_s(sheet_name_row, currentRow, 2); - new_items.push_back(sheet_name_row_s); } } ebn.cleanGenericNames(); @@ -399,8 +320,7 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis string keyName = allWords[i]; QList search_results = table_editor->findItems(tr(keyName.c_str()), Qt::MatchExactly); if(search_results.size() == 0) - { - + { int knPos = 0, nPos = 0; if(workSheet.getData(0, 0) == ucstring("*HASH_VALUE")) { @@ -409,25 +329,13 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis } else { knPos = keyColIndex; nPos = nameColIndex; - } - const int currentRow = table_editor->rowCount(); - table_editor->setRowCount(currentRow + 1); - // keyName row - QTableWidgetItem *key_name_row = new QTableWidgetItem(); - key_name_row->setText(tr(keyName.c_str())); - key_name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, knPos, key_name_row); - // nameColumn key - QTableWidgetItem *name_row = new QTableWidgetItem(); - name_row->setText(QString("") + tr(keyName.c_str())); - name_row->setBackgroundColor(QColor("#F75D59")); - table_editor ->setItem(currentRow, nPos, name_row); - if(!modified) modified = true; - CTableWidgetItemStore key_name_row_s(key_name_row, currentRow, knPos); - new_items.push_back(key_name_row_s); - CTableWidgetItemStore name_row_s(name_row, currentRow, nPos); - new_items.push_back(name_row_s); + } + QList records; + records.push_back(tr(keyName.c_str())); + records.push_back(QString("") + tr(keyName.c_str())); + insertTableRecords(records, new_items); + if(!modified) modified = true; } } current_stack->push(new CUndoWorksheetExtraction(new_items, table_editor)); @@ -438,6 +346,23 @@ void CEditorWorksheet::extractWords(QString filename, QString columnId, IWordLis } } +void CEditorWorksheet::insertTableRecords(QList records, QList new_items) +{ + const int currentRow = table_editor->rowCount(); + table_editor->setRowCount(currentRow + 1); + int n = 0; + Q_FOREACH(QString record, records) + { + QTableWidgetItem *rec = new QTableWidgetItem(); + rec->setBackgroundColor(QColor("#F75D59")); + table_editor ->setItem(currentRow, n, rec); + CTableWidgetItemStore rec_s(rec, currentRow, n); + new_items.push_back(rec_s); + n++; + } + +} + bool CEditorWorksheet::compareWorksheetFile(QString filename) { STRING_MANAGER::TWorksheet wk_file; @@ -503,7 +428,7 @@ void CEditorWorksheet::mergeWorksheetFile(QString filename) } } else { QErrorMessage error; - error.showMessage("This file is not a worksheet file."); + error.showMessage(tr("This file is not a worksheet file.")); error.exec(); } } @@ -513,8 +438,8 @@ void CEditorWorksheet::closeEvent(QCloseEvent *event) if(isWindowModified()) { QMessageBox msgBox; - msgBox.setText("The document has been modified."); - msgBox.setInformativeText("Do you want to save your changes?"); + msgBox.setText(tr("The document has been modified.")); + msgBox.setInformativeText(tr("Do you want to save your changes?")); msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); msgBox.setDefaultButton(QMessageBox::Save); int ret = msgBox.exec(); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h index 839601047..487a9eea8 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/editor_worksheet.h @@ -40,6 +40,18 @@ namespace TranslationManager { +struct CTableWidgetItemStore +{ +public: + CTableWidgetItemStore(QTableWidgetItem *item, int row, int column) : + m_item(item), + m_row(row), + m_column(column) { } + QTableWidgetItem *m_item; + int m_row; + int m_column; +}; + class CEditorWorksheet : public CEditor { Q_OBJECT @@ -57,6 +69,7 @@ public: bool compareWorksheetFile(QString filename); void extractBotNames(list filters, string level_design_path, NLLIGO::CLigoConfig ligoConfig); void extractWords(QString filename, QString columnId, IWordListBuilder &wordListBuilder); + void insertTableRecords(QList records, QList new_items); bool isBotNamesTable(); bool isSheetTable(QString type); void closeEvent(QCloseEvent *event); @@ -69,18 +82,6 @@ private Q_SLOTS: }; -struct CTableWidgetItemStore -{ -public: - CTableWidgetItemStore(QTableWidgetItem *item, int row, int column) : - m_item(item), - m_row(row), - m_column(column) { } - QTableWidgetItem *m_item; - int m_row; - int m_column; -}; - class CUndoWorksheetCommand : public QUndoCommand { public: diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.ui index b8b0bf447..444a7d97e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/ftp_selection.ui @@ -6,7 +6,7 @@ 0 0 - 388 + 446 560 @@ -18,7 +18,7 @@ 10 10 - 371 + 421 541 @@ -29,9 +29,9 @@ 10 - 130 - 351 - 361 + 110 + 401 + 381 @@ -55,7 +55,7 @@ 10 40 - 331 + 381 311 @@ -69,49 +69,9 @@ - 11 - 29 - 351 - 101 - - - - - - - Ftp server - - - - - - - - - - Connect - - - - - - - - - - - :/translationManager/images/cdtoparent.png:/translationManager/images/cdtoparent.png - - - - - - - - - 0 + 10 500 - 371 + 401 33 @@ -132,6 +92,46 @@ + + + + 10 + 20 + 411 + 81 + + + + + + + Ftp server + + + + + + + + + + + + + + :/translationManager/images/cdtoparent.png:/translationManager/images/cdtoparent.png + + + + + + + Connect + + + + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp index 365304c5b..ee509c8ad 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/translation_manager/translation_manager_main_window.cpp @@ -37,7 +37,6 @@ #include #include #include -#include // Plugin includes #include "translation_manager_main_window.h" #include "translation_manager_constants.h" @@ -70,7 +69,7 @@ CMainWindow::CMainWindow(QWidget *parent) void CMainWindow::createToolbar() { // File menu - openAct = new QAction(QIcon(Core::Constants::ICON_OPEN), "&Open...", this); + openAct = new QAction(QIcon(Core::Constants::ICON_OPEN), "&Open file(s)...", this); _ui.toolBar->addAction(openAct); connect(openAct, SIGNAL(triggered()), this, SLOT(open())); saveAct = new QAction(QIcon(Core::Constants::ICON_SAVE), "&Save...", this); @@ -147,11 +146,11 @@ void CMainWindow::updateToolbar(QMdiSubWindow *window) if(QString(window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor { //setContextMenuPolicy(Qt::ActionsContextMenu); - QAction *insertRowAct = new QAction("Insert new row", this); + QAction *insertRowAct = new QAction(tr("Insert new row"), this); connect(insertRowAct, SIGNAL(triggered()), window, SLOT(insertRow())); //addAction(insertRowAct); windowMenu->addAction(insertRowAct); - QAction *deleteRowAct = new QAction("Delete row", this); + QAction *deleteRowAct = new QAction(tr("Delete row"), this); connect(deleteRowAct, SIGNAL(triggered()), window, SLOT(deleteRow())); //addAction(deleteRowAct); windowMenu->addAction(deleteRowAct); @@ -202,7 +201,14 @@ void CMainWindow::updateWindowsList() void CMainWindow::open() { - QString file_name = QFileDialog::getOpenFileName(this); + QSettings *settings = Core::ICore::instance()->settings(); + settings->beginGroup("translationmanager"); + QString lastOpenLocation = settings->value("lastOpenLocation").toString(); + QString file_name = QFileDialog::getOpenFileName(this, tr("Open translation file"), lastOpenLocation, tr("Translation files (*txt)")); + QFileInfo* file_info = new QFileInfo(file_name); + settings->setValue("lastOpenLocation", file_info->absolutePath()); + settings->endGroup(); + if(!file_name.isEmpty()) { CEditor *editor = getEditorByWindowFilePath(file_name); @@ -303,14 +309,22 @@ void CMainWindow::initializeSettings(bool georges = false) if(initialize_settings["ligo"] == false) { - //------------------------------------------------------------------- - // init ligo config - string ligoPath = CPath::lookup("world_editor_classes.xml", true, true); - ligoConfig.readPrimitiveClass(ligoPath.c_str(), false); - NLLIGO::Register(); - NLLIGO::CPrimitiveContext::instance().CurrentLigoConfig = &ligoConfig; - initialize_settings["ligo"] = true; + try + { + // Search path of file world_editor_classes.xml + std::string ligoPath = NLMISC::CPath::lookup("world_editor_classes.xml"); + // Init LIGO + ligoConfig.readPrimitiveClass(ligoPath.c_str(), true); + NLLIGO::Register(); + NLLIGO::CPrimitiveContext::instance().CurrentLigoConfig = &ligoConfig; + initialize_settings["ligo"] = true; + } + catch (NLMISC::Exception &e) + { + nlerror("Can't found path to world_editor_classes.xml"); + } } + } void CMainWindow::extractWords(QString typeq) @@ -510,7 +524,7 @@ bool CMainWindow::verifySettings() if(level_design_path.isNull() || primitives_path.isNull() || work_path.isNull()) { QErrorMessage error_settings; - error_settings.showMessage("Please write all the paths on the settings dialog."); + error_settings.showMessage(tr("Please write all the paths on the settings dialog.")); error_settings.exec(); count_errors = true; } @@ -574,11 +588,9 @@ bool CMainWindow::isWorksheetEditor(QString filename) { if(wk_file.ColCount > 1) return true; - else - return false; - } else { - return false; } + + return false; } bool CMainWindow::isPhraseEditor(QString filename)