示例#1
0
JucerDocument* loadDocumentFromFile (const File& f, const bool showErrorMessage)
{
    File file (f);

    if (file == File::nonexistent && showErrorMessage)
    {
        FileChooser fc ("Open a Jucer C++ file...",
                        StoredSettings::getInstance()->recentFiles.getFile (0),
                        "*.cpp");

        if (! fc.browseForFileToOpen())
            return 0;

        file = fc.getResult();
    }

    XmlElement* xml = JucerDocument::pullMetaDataFromCppFile (file.loadFileAsString());

    if (xml == 0 || ! xml->hasTagName (JucerDocument::jucerCompXmlTag))
    {
        if (file != File::nonexistent && showErrorMessage)
            AlertWindow::showMessageBox (AlertWindow::WarningIcon,
                                         TRANS("Failed to open file..."),
                                         TRANS("This wasn't a valid Jucer .cpp file..."));

        delete xml;
        return 0;
    }

    const String docType (xml->getStringAttribute ("documentType"));
    delete xml;

    // (reverse order so ComponentDocument is default last-case)
    for (int i = numDocumentTypes; --i >= 0;)
    {
        if (docType.equalsIgnoreCase (documentTypeNames[i]) || i == 0)
        {
            JucerDocument* doc = createNewDocument (i);

            if (doc->loadFrom (file, showErrorMessage))
                return doc;

            delete doc;
            break;
        }
    }

    return 0;
}
示例#2
0
/**
 * Setups the UI: textarea transparency, preferences restore, signals&slots.
 */
void MEdiText::init()
{
	// ui
	setupUi(this);
	showFullScreen();
	this->textEdit->viewport()->setAutoFillBackground(false);

	// signal listening
	connect( newBtn, SIGNAL( clicked() ), this, SLOT( createNewDocument() ) );
	connect( openBtn, SIGNAL( clicked() ), this, SLOT( openExistingDocument() ) );
	connect( saveBtn, SIGNAL( clicked() ), this, SLOT( saveDocument() ) );
	connect( quitBtn, SIGNAL( clicked() ), this, SLOT( closeIfSaved() ) );
	connect( prefsBtn, SIGNAL( clicked() ), this, SLOT( openPreferences() ) );

	// preference restore
	this->settings = new QSettings("MEdiText", "MEdiText");
	QString path = this->settings->value("background_path", "mckenzie.jpg").toString();
	int alpha = this->settings->value("background_alpha", 128).toInt();
	this->setBackground(path, alpha);

	QString family = this->settings->value("font_family", "DejaVu Sans").toString();
	int size = this->settings->value("font_size", 11).toInt();
	this->setFont(family, size);
}