Exemplo n.º 1
0
QMessageBox::StandardButton FritzingWindow::beforeClosingMessage(const QString & filename, bool showCancel) 
{

    QMessageBox messageBox(this);
    setBeforeClosingText(filename, messageBox);
    QMessageBox::StandardButtons buttons = QMessageBox::Save | QMessageBox::Discard;
    if (showCancel) {
        buttons |= QMessageBox::Cancel;
    }
    messageBox.setStandardButtons(buttons);
    messageBox.setDefaultButton(QMessageBox::Save);
    if (m_fwFilename.startsWith(untitledFileName())) {
        messageBox.setButtonText(QMessageBox::Save, tr("Save..."));
    }
	else {
        messageBox.setButtonText(QMessageBox::Save, tr("Save"));
	}
    messageBox.setButtonText(QMessageBox::Discard, tr("Don't Save"));
	if (showCancel) {
		messageBox.setButtonText(QMessageBox::Cancel, tr("Cancel"));
	}
    messageBox.setIcon(QMessageBox::Warning);
    messageBox.setWindowModality(Qt::WindowModal);
    messageBox.button(QMessageBox::Discard)->setShortcut(tr("Ctrl+D"));

	return (QMessageBox::StandardButton) messageBox.exec();
}
Exemplo n.º 2
0
QMessageBox::StandardButton FritzingWindow::beforeClosingMessage(const QString & filename, bool showCancel) 
{
	QString basename = QFileInfo(filename).baseName();

    QMessageBox messageBox(this);
    messageBox.setWindowTitle(tr("Save \"%1\"").arg(basename));
    messageBox.setText(tr("Do you want to save the changes you made in the document \"%1\"?").arg(basename));
    messageBox.setInformativeText(tr("Your changes will be lost if you don't save them."));
    QMessageBox::StandardButtons buttons = QMessageBox::Save | QMessageBox::Discard;
    if (showCancel) {
        buttons |= QMessageBox::Cancel;
    }
    messageBox.setStandardButtons(buttons);
    messageBox.setDefaultButton(QMessageBox::Save);
    if (m_fwFilename.startsWith(untitledFileName())) {
        messageBox.setButtonText(QMessageBox::Save, tr("Save..."));
    }
	else {
        messageBox.setButtonText(QMessageBox::Save, tr("Save"));
	}
    messageBox.setButtonText(QMessageBox::Discard, tr("Don't Save"));
	if (showCancel) {
		messageBox.setButtonText(QMessageBox::Cancel, tr("Cancel"));
	}
    messageBox.setIcon(QMessageBox::Warning);
    messageBox.setWindowModality(Qt::WindowModal);
    messageBox.button(QMessageBox::Discard)->setShortcut(tr("Ctrl+D"));

	return (QMessageBox::StandardButton) messageBox.exec();
}
Exemplo n.º 3
0
bool FritzingWindow::save(const QString & filename, bool readOnly) {
	if (FolderUtils::isEmptyFileName(filename, untitledFileName())) {
		return saveAs(filename, readOnly);
	} else if (m_readOnly) {
		return saveAs(filename, readOnly);
	} else {
		return saveAsAux(filename);
	}
}
Exemplo n.º 4
0
bool FritzingWindow::saveAs(const QString & filename, bool readOnly) {
	DebugDialog::debug(QString("current path: %1").arg(QDir::currentPath()));
	QString fileExt;
    QString path;
    QString untitledBase = untitledFileName();

	if(readOnly) {
		path = defaultSaveFolder() + "/" + QFileInfo(filename).fileName();
    }
	else if(filename.startsWith(untitledBase, Qt::CaseInsensitive)) {
		path = defaultSaveFolder() + "/" + filename;
	}
	else if(filename.isNull() || filename.isEmpty()) {
		path = defaultSaveFolder();
	}
	else {
		path = filename;
	}
	DebugDialog::debug(QString("current file: %1").arg(filename));
    QString newFilename = FolderUtils::getSaveFileName(
						this,
                        tr("Specify a file name"),
                        path,
                        getExtensionString(),
                        &fileExt
                      );

    if (newFilename.isEmpty()) return false; // Cancel pressed

	if (readOnly && (newFilename.compare(filename, Qt::CaseInsensitive) == 0)) {
        QMessageBox::warning(NULL, QObject::tr("Fritzing"),
                     QObject::tr("The file '%1' is read-only; please use a different filename.")
                     .arg(newFilename) );
		return false;

	}

    FileProgressDialog progress("Saving...", 0, this);

	QStringList extensions = getExtensions();
    bool hasExtension = false;
	foreach (QString extension, extensions) {
		if(alreadyHasExtension(newFilename, extension)) {
			hasExtension = true;
			break;
		}
	}

	if (!hasExtension) {
		newFilename += extensions[0];
	}

	return saveAsAux(newFilename);
}
Exemplo n.º 5
0
// returns true if the user wanted to save the file
bool FritzingWindow::save() {
	bool result;
	if (FolderUtils::isEmptyFileName(m_fwFilename, untitledFileName())) {
		result = saveAs();
	} else if (m_readOnly) {
		result = saveAs();
	} else {
		result = saveAsAux(m_fwFilename);
	}

	return result;
}