1 // Translation Manager Plugin - OVQT Plugin <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2011 Emanuel COSTEA <cemycc@gmail.com>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "editor_phrase.h"
19 #include "translation_manager_constants.h"
22 #include "nel/misc/path.h"
23 #include "nel/misc/diff_tool.h"
26 #include <QtCore/QFileInfo>
27 #include <QtCore/QByteArray>
28 #include <QtCore/QTextCodec>
29 #include <QtCore/QTextStream>
30 #include <QtGui/QTextCursor>
31 #include <QtGui/QErrorMessage>
32 #include <QtGui/QMessageBox>
33 #include <QtGui/QCloseEvent>
37 namespace TranslationManager
40 void CEditorPhrase::open(QString filename
)
42 std::vector
<STRING_MANAGER::TPhrase
> phrases
;
43 if(readPhraseFile(filename
.toUtf8().constData(), phrases
, false))
45 text_edit
= new CTextEdit(this);
46 text_edit
->setUndoStack(current_stack
);
47 SyntaxHighlighter
*highlighter
= new SyntaxHighlighter(text_edit
);
48 text_edit
->setUndoRedoEnabled(true);
49 text_edit
->document()->setUndoRedoEnabled(true);
51 // read the file content
53 file
.open(QIODevice::ReadOnly
| QIODevice::Text
);
54 QTextStream
in(&file
);
55 // set the file content to the text edit
56 QString data
= in
.readAll();
57 text_edit
->append(data
);
59 setCurrentFile(filename
);
60 setAttribute(Qt::WA_DeleteOnClose
);
61 editor_type
= Constants::ED_PHRASE
;
62 current_file
= filename
;
63 connect(text_edit
->document(), SIGNAL(contentsChanged()), this, SLOT(docContentsChanged()));
64 connect(text_edit
->document(), SIGNAL(undoCommandAdded()), this, SLOT(newUndoCommandAdded()));
69 error
.showMessage("This file is not a phrase file.");
74 void CEditorPhrase::newUndoCommandAdded()
76 current_stack
->push(new CUndoPhraseNewCommand(text_edit
));
79 void CEditorPhrase::docContentsChanged()
81 setWindowModified(true);
84 void CEditorPhrase::activateWindow()
89 void CEditorPhrase::save()
94 void CEditorPhrase::saveAs(QString filename
)
97 file
.open(QIODevice::WriteOnly
| QIODevice::Text
);
98 QTextStream
out(&file
);
99 out
.setCodec("UTF-8");
100 out
.setGenerateByteOrderMark(true);
101 out
<< text_edit
->toPlainText();
102 current_file
= filename
;
103 setCurrentFile(current_file
);
106 void CEditorPhrase::closeEvent(QCloseEvent
*event
)
108 if(isWindowModified())
111 msgBox
.setIcon(QMessageBox::Question
);
112 msgBox
.setText(tr("The document has been modified."));
113 msgBox
.setInformativeText(tr("Do you want to save your changes?"));
114 msgBox
.setStandardButtons(QMessageBox::Save
| QMessageBox::Discard
| QMessageBox::Cancel
);
115 msgBox
.setDefaultButton(QMessageBox::Save
);
117 int ret
= msgBox
.exec();
120 case QMessageBox::Save
:
123 case QMessageBox::Discard
:
125 case QMessageBox::Cancel
: