Esempio n. 1
0
static void run(int argc, const char* argv[])
{
    PO po;
    PO::Option& inputOpt = po.add("input").requiresValue("<filename>");
    PO::Option& widgetId = po.add("widgetid").requiresValue("<filename>");
    PO::Option& prefH = po.add("pref-h");
    PO::Option& prefCpp = po.add("pref-cpp");
    PO::Option& skin = po.add("skin");
    po.parse(argc, argv);

    // Try to load the XML file
    TiXmlDocument* doc = NULL;

    std::string inputFilename = po.value_of(inputOpt);
    if (!inputFilename.empty()) {
        base::FileHandle inputFile(base::open_file(inputFilename, "rb"));
        doc = new TiXmlDocument();
        doc->SetValue(inputFilename.c_str());
        if (!doc->LoadFile(inputFile.get()))
            throw std::runtime_error("invalid input file");
    }

    if (doc) {
        if (po.enabled(widgetId))
            gen_ui_class(doc, inputFilename, po.value_of(widgetId));
        else if (po.enabled(prefH))
            gen_pref_header(doc, inputFilename);
        else if (po.enabled(prefCpp))
            gen_pref_impl(doc, inputFilename);
        else if (po.enabled(skin))
            gen_skin_class(doc, inputFilename);
    }
}
void XMLUtils::LoadXMLFile( TiXmlDocument& doc, bool condenseWhiteSpace, const wxString& path )
{
	if ( path.empty() )
	{
		THROW_WXFBEX( _("LoadXMLFile needs a path") )
	}

	if ( !::wxFileExists( path ) )
	{
		THROW_WXFBEX( _("The file does not exist.\nFile: ") << path )
	}

	TiXmlBase::SetCondenseWhiteSpace( condenseWhiteSpace );
	doc.SetValue( std::string( path.mb_str( wxConvFile ) ) );
	if ( !doc.LoadFile() )
	{
		// Ask user to all wxFB to convert the file to UTF-8 and add the XML declaration
		wxString msg = _("This xml file could not be loaded. This could be the result of an unsupported encoding.\n");
		msg 		+= _("Would you like wxFormBuilder to backup the file and convert it to UTF-8\?\n");
		msg			+= _("You will be prompted for the original encoding.\n\n");
		msg			+= _("Path: ");
		msg			+= path;
		if ( wxNO == wxMessageBox( msg, _("Unable to load file"), wxICON_QUESTION | wxYES_NO | wxYES_DEFAULT, wxTheApp->GetTopWindow() ) )
		{
			// User declined, give up
			THROW_WXFBEX( _("Unable to load file: ") << path );
		}

		// User accepted, convert the file
		wxFontEncoding chosenEncoding = StringUtils::GetEncodingFromUser( _("Please choose the original encoding.") );
		if ( wxFONTENCODING_MAX == chosenEncoding )
		{
			THROW_WXFBEX( _("Unable to load file: ") << path );
		}

		ConvertAndAddDeclaration( path, chosenEncoding );

		LoadXMLFile( doc, condenseWhiteSpace, path );
	}

	TiXmlDeclaration* declaration = NULL;
	TiXmlNode* firstChild = doc.FirstChild();
	if ( firstChild )
	{
		declaration = firstChild->ToDeclaration();
	}

	LoadXMLFileImp( doc, condenseWhiteSpace, path, declaration );
}
Esempio n. 3
0
static void run(int argc, const char* argv[])
{
  PO po;
  PO::Option& inputFn = po.add("input").requiresValue("<filename>");
  PO::Option& widgetId = po.add("widgetid").requiresValue("<filename>");
  po.parse(argc, argv);

  // Try to load the XML file
  TiXmlDocument* doc = NULL;

  if (inputFn.enabled()) {
    base::FileHandle inputFile(base::open_file(inputFn.value(), "rb"));
    doc = new TiXmlDocument();
    doc->SetValue(inputFn.value().c_str());
    if (!doc->LoadFile(inputFile))
      throw std::runtime_error("invalid input file");
  }

  if (doc && widgetId.enabled())
    gen_ui_class(doc, inputFn.value(), widgetId.value());
}
Esempio n. 4
0
void EdWidget::Save(	const char* xmlFilename,
						KrConsole* console,
						const std::string& surfaceName,
						int nTrans,
						const KrRGBA* trans )
{
	TiXmlDocument doc;
	doc.SetValue( xmlFilename );

	TiXmlElement definition( "Definition" );
	definition.SetAttribute( "filename", surfaceName.c_str() );

	for( int i=0; i<nTrans; i++ )
	{
		char key[256];
		char value[256];
		sprintf( key, "Transparent%d", i );
		sprintf( value, "#%02x%02x%02x", trans[i].c.red, trans[i].c.green, trans[i].c.blue );

		definition.SetAttribute( key, value );
	}

	GlSListIterator< EdWidget* > it( children );
	for( it.Begin(); !it.Done(); it.Next() )
		it.Current()->BuildXML( &definition );

	doc.InsertEndChild( definition );
	doc.SaveFile();
	if ( doc.Error() )
	{
		console->Print( "Error saving XML. '%s'\n", doc.ErrorDesc() );
	}
	else
	{
		console->Print( "XML file '%s' saved.\n", xmlFilename );
	}
}
Esempio n. 5
0
static void run(int argc, const char* argv[])
{
  PO po;
  PO::Option& inputOpt = po.add("input").requiresValue("<filename>");
  PO::Option& widgetId = po.add("widgetid").requiresValue("<id>");
  PO::Option& prefH = po.add("pref-h");
  PO::Option& prefCpp = po.add("pref-cpp");
  PO::Option& theme = po.add("theme");
  PO::Option& strings = po.add("strings");
  PO::Option& commandIds = po.add("command-ids");
  PO::Option& widgetsDir = po.add("widgets-dir").requiresValue("<dir>");
  PO::Option& stringsDir = po.add("strings-dir").requiresValue("<dir>");
  PO::Option& guiFile = po.add("gui-file").requiresValue("<filename>");
  po.parse(argc, argv);

  // Try to load the XML file
  TiXmlDocument* doc = nullptr;

  std::string inputFilename = po.value_of(inputOpt);
  if (!inputFilename.empty() &&
      base::get_file_extension(inputFilename) == "xml") {
    base::FileHandle inputFile(base::open_file(inputFilename, "rb"));
    doc = new TiXmlDocument();
    doc->SetValue(inputFilename.c_str());
    if (!doc->LoadFile(inputFile.get())) {
      std::cerr << doc->Value() << ":"
                << doc->ErrorRow() << ":"
                << doc->ErrorCol() << ": "
                << "error " << doc->ErrorId() << ": "
                << doc->ErrorDesc() << "\n";

      throw std::runtime_error("invalid input file");
    }
  }

  if (doc) {
    // Generate widget class
    if (po.enabled(widgetId))
      gen_ui_class(doc, inputFilename, po.value_of(widgetId));
    // Generate preference header file
    else if (po.enabled(prefH))
      gen_pref_header(doc, inputFilename);
    // Generate preference c++ file
    else if (po.enabled(prefCpp))
      gen_pref_impl(doc, inputFilename);
    // Generate theme class
    else if (po.enabled(theme))
      gen_theme_class(doc, inputFilename);
  }
  // Generate strings.ini.h file
  else if (po.enabled(strings)) {
    gen_strings_class(inputFilename);
  }
  // Generate command_ids.ini.h file
  else if (po.enabled(commandIds)) {
    gen_command_ids(inputFilename);
  }
  // Check all translation files (en.ini, es.ini, etc.)
  else if (po.enabled(widgetsDir) &&
           po.enabled(stringsDir)) {
    check_strings(po.value_of(widgetsDir),
                  po.value_of(stringsDir),
                  po.value_of(guiFile));
  }
}