void MainWindow::openFileToWorkspace(const QString &xmlFileName, bool clear) { // Open file QFile xmlFile(xmlFileName); if (!xmlFile.open(QIODevice::ReadOnly)) { // Display error message QMessageBox msgBox(this); msgBox.setText(QString(tr("Couldn't open file to read content: %1.") ).arg(xmlFileName)); msgBox.exec(); return; } // Read content QByteArray content = xmlFile.readAll(); QString xml(content); xmlFile.close(); // Set XML to Workspace setXml(xml, clear); // Set XML file name if (clear) { setXmlFileName(xmlFileName); } }
void MainWindow::actionExamples() { // Check whether source was changed if (checkSourceChanged() == QMessageBox::Cancel) { return; } // Open an example from the examples folder actionOpenInclude(tr("Examples"), true, settings->examplesPath()); // Void file name to prevent overwriting the original file by mistake setXmlFileName(""); }
void MainWindow::choiceFilePath(int fileType) { switch(fileType){ case INT_OPEN_FILEPATH_TYPE_INI: setIniFileName(); break; case INT_OPEN_FILEPATH_TYPE_XML: setXmlFileName(); break; default: qDebug()<< "Error : choice file type error!"; return; } }
void MainWindow::actionSaveAndSaveAs(bool askFileName, const QString &directory) { // Save XML file QString xmlFileName; if (this->xmlFileName.isEmpty() || askFileName == true) { // Open file dialog QFileDialog fileDialog(this, tr("Save")); fileDialog.setFileMode(QFileDialog::AnyFile); fileDialog.setNameFilter(QString("Blockly Files %1").arg("(*.bly)")); fileDialog.setDefaultSuffix("bly"); fileDialog.setLabelText(QFileDialog::Accept, tr("Save")); if (!directory.isEmpty()) fileDialog.setDirectory(directory); if (!fileDialog.exec()) return; // Return if cancelled QStringList selectedFiles = fileDialog.selectedFiles(); // Return if no file to open if (selectedFiles.count() < 1) return; xmlFileName = selectedFiles.at(0); } else { xmlFileName = this->xmlFileName; } int result = saveXml(xmlFileName); if (result == 0) { // Display error message QMessageBox msgBox(this); msgBox.setText(QString(tr("Couldn't open file to save content: %1.") ).arg(xmlFileName)); msgBox.exec(); return; } // Set file name setXmlFileName(xmlFileName); // Feedback statusBar()->showMessage(tr("Done saving."), 2000); // Reset status changed status webHelper->resetSourceChanged(); }
void MainWindow::actionNew() { // Check whether source was changed if (checkSourceChanged() == QMessageBox::Cancel) { return; } // Unset file name setXmlFileName(""); // Disable save as ui->actionSave_as->setEnabled(false); // Reset source change status webHelper->resetSourceChanged(); // Clear workspace QWebFrame *frame = ui->webView->page()->mainFrame(); frame->evaluateJavaScript("resetWorkspace();"); // Reset history documentHistoryReset(); }