Commit 52957edb authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Fix journal file data loss for new projects.

This change ensures that journal files for new created projects are
saved. The problem was located in the missing associated project
for the journal file.

BUG: 311174
parent 0ec062a8
......@@ -39,18 +39,19 @@ JournalEditorWidget::JournalEditorWidget(QWidget* parent)
connect(ui->editor, SIGNAL(textChanged()), this, SLOT(setModified()));
}
void JournalEditorWidget::openJournal(Project* project)
void JournalEditorWidget::openJournal(Project *project)
{
_modified = false;
_currentProject = project;
if (!project) {
kError() << "No project specified! Cannot set journal widget.";
return;
}
if (project->journalFile().isEmpty()) {
kDebug() << "Skipping loading of journal file, project does not contain any, yet.";
ui->editor->setHtml(QString());
return;
}
_currentProject = project;
QFile fileHandle(project->journalFile().toLocalFile());
if (!fileHandle.open(QIODevice::ReadOnly | QIODevice::Text)) {
kError() << "Could not open file"
......@@ -66,9 +67,13 @@ void JournalEditorWidget::openJournal(Project* project)
void JournalEditorWidget::saveJournal()
{
Q_ASSERT(_currentProject);
if (!_currentProject) {
kError() << "Associated project is not set: cannot save journal file and hence aborting saving.";
kDebug() << "Journal must be created with JournalEditorWidget::openJournal(...).";
return;
}
KSaveFile saveFile(_currentProject->journalFile().toLocalFile());
saveFile.open();
......
......@@ -221,7 +221,8 @@ void MainWindow::setupToolbars()
Project* MainWindow::createNewProject()
{
Project* newProject = new Project();
//TODO duplicated functionality with newProject(): merge them for 4.11
Project *newProject = new Project();
// create new document and add this to project new
newProject->addGraphFileNew(DocumentManager::self()->newDocument());
newProject->addCodeFileNew(_codeEditor->newScript());
......@@ -593,8 +594,9 @@ void MainWindow::loadDocument(const QString& name)
void MainWindow::newProject()
{
if (saveIfChanged() == KMessageBox::Cancel)
if (saveIfChanged() == KMessageBox::Cancel) {
return;
}
_codeEditor->closeAllScripts();
DocumentManager::self()->closeAllDocuments();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment