Ejemplo n.º 1
0
CommandMap ParseCommands(int argc, char* argv[]){

	CommandMap parameters;

	int command_index = -1;	//Last command's index
	string key;				//Last command's name
	vector<string> values;	//Last command's values

	//Parameters beginning with a "-" are keys, the rest are values...
	for (int arg_index = 0; arg_index < argc; ++arg_index){

		if (argv[arg_index][0] == kCommandToken){

			// Add a command_index entry inside the parameter map
			key = command_index > -1 ?
				argv[command_index] :
				kGlobalCommand;

			parameters.insert(make_pair(key, values));

			values.clear();

			command_index = arg_index;

		}
		else
		{

			// Add a new value to the previous command
			values.push_back(argv[arg_index]);

		}

	}

	//Add the last values...
	key = command_index > -1 ?
		argv[command_index] :
		kGlobalCommand;

	parameters.insert(make_pair(key, values));

	return parameters;

}
Ejemplo n.º 2
0
CommandMap CreateCursorDependantFunctions()
{
	CommandMap fns;
	REGISTER_FUNCTION(Qt::Key_Backspace, [](QShell& shell, QKeyEvent* e){
		if (CursorCanWrite(shell) && (shell.textCursor().hasSelection() || CursorBlockDifference(shell) > 0))
		{
			shell.processKeyEvent(e);
		}
		return true;
	});
	REGISTER_FUNCTION(Qt::Key_Enter, [](QShell& shell, QKeyEvent* e){
		if (e->modifiers().testFlag(Qt::ShiftModifier))
		{
			shell.processKeyEvent(e);
			return true;
		}
		return false;
	});
	fns.insert(make_pair(Qt::Key_Return, fns[Qt::Key_Enter]));

	return fns;
}