Changeset View
Changeset View
Standalone View
Standalone View
src/ui/mainwindow.cpp
Show First 20 Lines • Show All 284 Lines • ▼ Show 20 Line(s) | 264 | // m_graphEditor->setupActions(actionCollection()); //FIXME add editor actions to main action collection | |||
---|---|---|---|---|---|
285 | m_recentProjects = new KRecentFilesAction(QIcon ("document-open"), i18nc("@action:inmenu","Recent Projects"), this); | 285 | m_recentProjects = new KRecentFilesAction(QIcon ("document-open"), i18nc("@action:inmenu","Recent Projects"), this); | ||
286 | connect(m_recentProjects, &KRecentFilesAction::urlSelected, | 286 | connect(m_recentProjects, &KRecentFilesAction::urlSelected, | ||
287 | this, &MainWindow::openProject); | 287 | this, &MainWindow::openProject); | ||
288 | actionCollection()->addAction("recent-project", m_recentProjects); | 288 | actionCollection()->addAction("recent-project", m_recentProjects); | ||
289 | m_recentProjects->loadEntries(Settings::self()->config()->group("RecentFiles")); | 289 | m_recentProjects->loadEntries(Settings::self()->config()->group("RecentFiles")); | ||
290 | 290 | | |||
291 | createAction("document-save-as", i18nc("@action:inmenu", "Save Project as"), "save-project-as", SLOT(saveProjectAs()), this); | 291 | createAction("document-save-as", i18nc("@action:inmenu", "Save Project as"), "save-project-as", SLOT(saveProjectAs()), this); | ||
292 | createAction("document-new", i18nc("@action:inmenu", "New Graph Document"), "new-graph", SLOT(createGraphDocument()), this); | 292 | createAction("document-new", i18nc("@action:inmenu", "New Graph Document"), "new-graph", SLOT(createGraphDocument()), this); | ||
293 | createAction("document-new", i18nc("@action:inmenu", "New Script File"), "new-script", SLOT(createCodeDocument()), this); | 293 | createAction("document-new", i18nc("@action:inmenu", "New Script File"), "new-script", SLOT(tryToCreateCodeDocument()), this); | ||
294 | createAction("document-import", i18nc("@action:inmenu", "Import Graph"), "import-graph", SLOT(importGraphDocument()), this); | 294 | createAction("document-import", i18nc("@action:inmenu", "Import Graph"), "import-graph", SLOT(importGraphDocument()), this); | ||
295 | createAction("document-export", i18nc("@action:inmenu", "Export Graph as"), "export-graph-as", SLOT(exportGraphDocument()), this); | 295 | createAction("document-export", i18nc("@action:inmenu", "Export Graph as"), "export-graph-as", SLOT(exportGraphDocument()), this); | ||
296 | createAction("document-import", i18nc("@action:inmenu", "Import Script"), "add-script", SLOT(importCodeDocument()), this); | 296 | createAction("document-import", i18nc("@action:inmenu", "Import Script"), "add-script", SLOT(importCodeDocument()), this); | ||
297 | createAction("document-export", i18nc("@action:inmenu", "Export Script"), "export-script", SLOT(exportCodeDocument()), this); | 297 | createAction("document-export", i18nc("@action:inmenu", "Export Script"), "export-script", SLOT(exportCodeDocument()), this); | ||
298 | } | 298 | } | ||
299 | 299 | | |||
300 | void MainWindow::createAction(const QByteArray& iconName, const QString& actionTitle, const QString& actionName, | 300 | void MainWindow::createAction(const QByteArray& iconName, const QString& actionTitle, const QString& actionName, | ||
301 | const char* slot, QObject *parent) | 301 | const char* slot, QObject *parent) | ||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Line(s) | |||||
362 | 362 | | |||
363 | void MainWindow::createProject() | 363 | void MainWindow::createProject() | ||
364 | { | 364 | { | ||
365 | if (!queryClose()) { | 365 | if (!queryClose()) { | ||
366 | return; | 366 | return; | ||
367 | } | 367 | } | ||
368 | 368 | | |||
369 | Project *project = new Project(m_graphEditor); | 369 | Project *project = new Project(m_graphEditor); | ||
370 | project->addCodeDocument(KTextEditor::Editor::instance()->createDocument(nullptr)); | 370 | project->createCodeDocument(i18n("untitled")); | ||
tcanabrava: QStringLiteral , but perhaps it's better to i18n("untitled") ? | |||||
371 | project->addGraphDocument(m_graphEditor->createDocument()); | 371 | project->addGraphDocument(m_graphEditor->createDocument()); | ||
372 | project->setModified(false); | 372 | project->setModified(false); | ||
373 | 373 | | |||
374 | setProject(project); | 374 | setProject(project); | ||
375 | } | 375 | } | ||
376 | 376 | | |||
377 | void MainWindow::saveProject() | 377 | void MainWindow::saveProject() | ||
378 | { | 378 | { | ||
▲ Show 20 Lines • Show All 96 Lines • ▼ Show 20 Line(s) | 463 | QString MainWindow::uniqueFilename(const QString &basePrefix, const QString &suffix) { | |||
475 | targetFile.setFileName(basePath + fullPrefix + fullSuffix); | 475 | targetFile.setFileName(basePath + fullPrefix + fullSuffix); | ||
476 | for(int i = 1; targetFile.exists(); i++) { | 476 | for(int i = 1; targetFile.exists(); i++) { | ||
477 | targetFile.setFileName(basePath + fullPrefix + QString::number(i) + fullSuffix); | 477 | targetFile.setFileName(basePath + fullPrefix + QString::number(i) + fullSuffix); | ||
478 | } | 478 | } | ||
479 | 479 | | |||
480 | return targetFile.fileName(); | 480 | return targetFile.fileName(); | ||
481 | } | 481 | } | ||
482 | 482 | | |||
483 | void MainWindow::createCodeDocument() | 483 | void MainWindow::tryToCreateCodeDocument() | ||
484 | { | 484 | { | ||
485 | QString basePrefix = QInputDialog::getText(this, | 485 | QString basePrefix = QInputDialog::getText(this, | ||
486 | i18n("ScriptName"), | 486 | i18n("ScriptName"), | ||
487 | i18n("Enter the name of your new script")); | 487 | i18n("Enter the name of your new script")); | ||
488 | if (basePrefix.isNull()) { | 488 | if (basePrefix.isNull()) { | ||
489 | qDebug() << "Filename is empty and no script file was created."; | 489 | qDebug() << "Filename is empty and no script file was created."; | ||
490 | } else { | 490 | return; | ||
491 | QString fileName = uniqueFilename(basePrefix, "js"); //TODO this does nothing | 491 | } | ||
492 | KTextEditor::Document *document = KTextEditor::Editor::instance()->createDocument(nullptr); | 492 | | ||
493 | m_currentProject->addCodeDocument(document); | 493 | QString fullPath = m_currentProject->workingDir() + QLatin1Char('/') + basePrefix + QStringLiteral(".js"); | ||
tcanabrava: QLatin1Char('/'), QStringLiteral(".js") | |||||
494 | QFileInfo file(fullPath); | ||||
tcanabrava: QFileInfo (cheaper than a QFile) | |||||
495 | if (file.exists()) { | ||||
496 | KMessageBox::error(this, i18n("File already exists.")); | ||||
497 | return; | ||||
just use the KMessageBox::error(...) factory to create an error message box with all the typical look and feel in KDE cordlandwehr: just use the KMessageBox::error(...) factory to create an error message box with all the… | |||||
494 | } | 498 | } | ||
499 | | ||||
500 | m_currentProject->createCodeDocument(basePrefix); | ||||
495 | } | 501 | } | ||
496 | 502 | | |||
497 | void MainWindow::createGraphDocument() | 503 | void MainWindow::createGraphDocument() | ||
498 | { | 504 | { | ||
499 | GraphDocumentPtr document = m_graphEditor->createDocument(); | 505 | GraphDocumentPtr document = m_graphEditor->createDocument(); | ||
500 | m_currentProject->addGraphDocument(document); | 506 | m_currentProject->addGraphDocument(document); | ||
501 | } | 507 | } | ||
502 | 508 | | |||
▲ Show 20 Lines • Show All 82 Lines • Show Last 20 Lines |
QStringLiteral , but perhaps it's better to i18n("untitled") ?