Changed: #1307 Added Phrase editor files and base functions

This commit is contained in:
cemycc 2011-08-03 23:08:56 +03:00
parent fb5373284d
commit 5a599bc7ff
8 changed files with 158 additions and 66 deletions

View file

@ -0,0 +1,116 @@
// Translation Manager Plugin - OVQT Plugin <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2011 Emanuel Costea <cemycc@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Nel includes
#include "nel/misc/path.h"
#include "nel/misc/diff_tool.h"
// Qt includes
#include <QtGui/QErrorMessage>
#include <QtCore/qfileinfo.h>
#include <QtGui/QMessageBox>
#include <QtGui/QCloseEvent>
// Project includes
#include "editor_phrase.h"
#include "translation_manager_constants.h"
using namespace std;
namespace Plugin {
void CEditorPhrase::open(QString filename)
{
vector<STRING_MANAGER::TPhrase> phrases;
if(readPhraseFile(filename.toStdString(), phrases, false))
{
text_edit = new QTextEdit();
// read the file content
QFile file(filename);
QTextStream in(&file);
// set the file content to the text edit
QString content = in.readAll();
text_edit->setText(content);
// window settings
setCurrentFile(filename);
setAttribute(Qt::WA_DeleteOnClose);
setWidget(text_edit);
editor_type = Constants::ED_PHRASE;
current_file = filename;
} else {
QErrorMessage error;
error.showMessage("This file is not a phrase file.");
error.exec();
}
}
void CEditorPhrase::activateWindow()
{
showMaximized();
}
void CEditorPhrase::save()
{
QFile file(current_file);
QTextStream out(&file);
out<<text_edit->toPlainText();
setCurrentFile(current_file);
}
void CEditorPhrase::saveAs(QString filename)
{
QFile file(filename);
QTextStream out(&file);
out<<text_edit->toPlainText();
current_file = filename;
setCurrentFile(current_file);
}
void CEditorPhrase::closeEvent(QCloseEvent *event)
{
if(isWindowModified())
{
QMessageBox msgBox;
msgBox.setText("The document has been modified.");
msgBox.setInformativeText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox.exec();
switch (ret)
{
case QMessageBox::Save:
save();
event->accept();
close();
break;
case QMessageBox::Discard:
event->accept();
close();
break;
case QMessageBox::Cancel:
event->ignore();
break;
default:
break;
}
} else {
event->accept();
close();
}
}
}

View file

@ -1,53 +0,0 @@
// Translation Manager Plugin - OVQT Plugin <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2011 Emanuel Costea <cemycc@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
// Qt includes
#include <QtGui/QErrorMessage>
#include <QtCore/qfileinfo.h>
#include <QtGui/QMessageBox>
#include <QtGui/QCloseEvent>
// Project includes
#include "editor_phrase.h"
#include "translation_manager_constants.h"
using namespace std;
namespace Plugin {
void CEditorPhrase::open(QString filename)
{
}
void CEditorPhrase::activateWindow()
{
}
void CEditorPhrase::save()
{
}
void CEditorPhrase::saveAs(QString filename)
{
}
}

View file

@ -20,11 +20,14 @@
// Qt includes
#include <QtCore/QObject>
#include <QtCore/QFile>
#include <QtCore/QTextStream>
#include <QtGui/QWidget>
#include <QtGui/QMdiArea>
#include <QtGui/QMdiSubWindow>
#include <QtGui/QUndoCommand>
#include <QtGui/QUndoStack>
#include <QtGui/QTextEdit>
// Project includes
#include "translation_manager_editor.h"
@ -34,6 +37,8 @@ namespace Plugin {
class CEditorPhrase : public CEditor
{
Q_OBJECT
private:
QTextEdit *text_edit;
public:
CEditorPhrase(QMdiArea* parent) : CEditor(parent) {}
CEditorPhrase() : CEditor() {}
@ -41,6 +46,7 @@ public:
void save();
void saveAs(QString filename);
void activateWindow();
void closeEvent(QCloseEvent *event);
};
}

View file

@ -202,6 +202,7 @@ void CEditorWorksheet::saveAs(QString filename)
}
ucstring s = prepareExcelSheet(new_file);
NLMISC::CI18N::writeTextFile(filename.toStdString(), s, false);
current_file = filename;
setCurrentFile(filename);
}
@ -484,15 +485,6 @@ void CEditorWorksheet::mergeWorksheetFile(QString filename)
}
}
void CEditorWorksheet::setCurrentFile(QString filename)
{
QFileInfo *file = new QFileInfo(filename);
current_file = file->canonicalFilePath();
setWindowModified(false);
setWindowTitle(file->fileName() + "[*]");
setWindowFilePath(current_file);
}
void CEditorWorksheet::closeEvent(QCloseEvent *event)
{
if(isWindowModified())

View file

@ -65,8 +65,6 @@ private Q_SLOTS:
void worksheetEditorChanged(QTableWidgetItem * item);
void insertRow();
void deleteRow();
private:
void setCurrentFile(QString filename);
};

View file

@ -23,6 +23,7 @@
#include <QtGui/QMdiArea>
#include <QtGui/QMdiSubWindow>
#include <QtGui/QUndoStack>
#include <QtCore/QFileInfo>
namespace Plugin {
@ -52,6 +53,15 @@ public:
{
current_stack = stack;
}
void setCurrentFile(QString filename)
{
QFileInfo *file = new QFileInfo(filename);
current_file = file->canonicalFilePath();
setWindowModified(false);
setWindowTitle(file->fileName() + "[*]");
setWindowFilePath(current_file);
}
};
}

View file

@ -216,6 +216,14 @@ void CMainWindow::open()
new_window->setUndoStack(m_undoStack);
new_window->open(file_name);
new_window->activateWindow();
}
// phrase editor
if(isPhraseEditor(file_name))
{
CEditorPhrase *new_window = new CEditorPhrase(_ui.mdiArea);
new_window->setUndoStack(m_undoStack);
new_window->open(file_name);
new_window->activateWindow();
}
#ifndef QT_NO_CURSOR
QApplication::restoreOverrideCursor();
@ -558,6 +566,20 @@ bool CMainWindow::isWorksheetEditor(QString filename)
{
STRING_MANAGER::TWorksheet wk_file;
if(loadExcelSheet(filename.toStdString(), wk_file, true) == true)
{
if(wk_file.ColCount > 1)
return true;
else
return false;
} else {
return false;
}
}
bool CMainWindow::isPhraseEditor(QString filename)
{
vector<STRING_MANAGER::TPhrase> phrases;
if(readPhraseFile(filename.toStdString(), phrases, false))
{
return true;
} else {

View file

@ -45,6 +45,7 @@
#include "ui_translation_manager_main_window.h"
#include <set>
#include "editor_worksheet.h"
#include "editor_phrase.h"
class QWidget;
@ -101,7 +102,7 @@ private:
// Worksheet specific functions
CEditorWorksheet* getEditorByWorksheetType(const QString &type);
bool isWorksheetEditor(QString filename);
bool isPhraseEditor(QString filename);
};