Example #1
0
File: Gui.cpp Project: macBdog/game
bool Gui::LoadMenus(const char * a_guiPath, const DataPack * a_dataPack)
{
	bool loadSuccess = true;
	if (a_dataPack != NULL && a_dataPack->IsLoaded())
	{
		DataPack::EntryList menuEntries;
		a_dataPack->GetAllEntries(".mnu", menuEntries);
		DataPack::EntryNode * curNode = menuEntries.GetHead();

		// Load each menu in the list
		bool loadSuccess = true;
		while (curNode != NULL)
		{
			GameFile menuFile(curNode->GetData());
			loadSuccess &= LoadMenu(menuFile, a_dataPack);
			curNode = curNode->GetNext();
		}

		// Clean up the list of menu data pack entries
		a_dataPack->CleanupEntryList(menuEntries);
	}
	else
	{
		// Get a list of menu files in the gui directory
		FileManager & fileMan = FileManager::Get();
		FileManager::FileList menuFiles;
		fileMan.FillFileList(a_guiPath, menuFiles, ".mnu");

		// Load each menu in the directory
		FileManager::FileListNode * curNode = menuFiles.GetHead();
		while (curNode != NULL)
		{
			char fullPath[StringUtils::s_maxCharsPerLine];
			sprintf(fullPath, "%s%s", a_guiPath, curNode->GetData()->m_name);
			GameFile menuFile(fullPath);
			loadSuccess &= LoadMenu(menuFile, a_dataPack);
			curNode = curNode->GetNext();
		}

		// Clean up the list of fonts
		fileMan.CleanupFileList(menuFiles);
	}

	return loadSuccess;
}
Example #2
0
wxString CodeLiteApp::DoFindMenuFile(const wxString& installDirectory, const wxString &requiredVersion)
{
    wxString defaultMenuFile = installDirectory + wxFileName::GetPathSeparator() + wxT("rc") + wxFileName::GetPathSeparator() + wxT("menu.xrc");
    wxFileName menuFile(clStandardPaths::Get().GetUserDataDir() + wxFileName::GetPathSeparator() + wxT("rc") + wxFileName::GetPathSeparator() + wxT("menu.xrc"));
    if(menuFile.FileExists()) {
        // if we find the user's file menu, check that it has the required version
        {
            wxLogNull noLog;
            wxXmlDocument doc;
            if(doc.Load(menuFile.GetFullPath())) {
                wxString version = doc.GetRoot()->GetPropVal(wxT("version"), wxT("1.0"));
                if(version != requiredVersion) {
                    return defaultMenuFile;
                }
            }
        }
        return menuFile.GetFullPath();
    }
    return defaultMenuFile;
}
bool FileBasedMenuModel :: loadFromFile(const QString &menuFilePath)
{
	QFile menuFile(menuFilePath);
	if(!menuFile.open(QFile::ReadOnly))	return false; //TODO: implement some error handling here.

	listEntries.clear();
	menuPath = menuFilePath;

	QTextStream stream(&menuFile);
	stream.setCodec("UTF-8");
	QString line;
	do // Each line is a menu item, fields separated by "|"
	{
		line = stream.readLine();
		QStringList fields = line.split("|", QString::SkipEmptyParts);
		QStringListIterator i(fields);

		QString caption, icon, righticon(":/neux/navright.gif"), type, command, helpid;

		if (fields.size() > 0) 
		{
			if (fields.at(0) == "Menu") 
			{
				for (int i = 1; i < fields.size(); i++) 
				{
					QString field = fields.at(i);
					int pos = field.indexOf("=");
					if (pos != -1) 
					{
						QString name = field.left(pos);
						if (name == "Title") menuTitle = field.mid(pos+1);
					}
				}
				continue;
			}
		}

		while(i.hasNext()) // Each field is Name=Value
		{
			QString field = i.next();
			int pos = field.indexOf("=");
			if(pos != -1)
			{
				QString name = field.left(pos);
				// Save the value only for the recognized fields
				if(name == "Name") caption = field.mid(pos+1);
				else if(name == "Icon")	icon = field.mid(pos+1);
				else if(name == "RightIcon")	righticon = field.mid(pos+1);
				else if(name == "Type")	type = field.mid(pos+1);
				else if(name == "Command") command = field.mid(pos+1);
				else if(name == "HelpId") helpid = field.mid(pos+1);
			}
		}

		// Create a menu item if at least the caption was found.
		if(!caption.isEmpty())
		{
			if (type == "MenuOpt")
			{
				QFileInfo f(command);
				if (f.exists()) listEntries << NMenuItem(caption, icon, righticon, true, command, helpid.isEmpty()?0:helpid.toInt());
			}
			else listEntries << NMenuItem(caption, icon, righticon, (type == "Menu"), command, helpid.isEmpty()?0:helpid.toInt());
		}

	} while(!line.isNull());

	return true;
}