Ejemplo n.º 1
0
void SaveCommandMap( const char* path ){
	StringOutputStream strINI( 256 );
	strINI << path << "shortcuts.ini";

	TextFileOutputStream file( strINI.c_str() );
	if ( !file.failed() ) {
		file << "[Version]\n";
		file << "number=" << COMMANDS_VERSION << "\n";
		file << "\n";
		file << "[Commands]\n";
		class WriteCommandMap : public CommandVisitor
		{
		TextFileOutputStream& m_file;
public:
		WriteCommandMap( TextFileOutputStream& file ) : m_file( file ){
		}
		void visit( const char* name, Accelerator& accelerator ){
			m_file << name << "=";

			const char* key = gtk_accelerator_name( accelerator.key, accelerator.modifiers );
			m_file << key;
			m_file << "\n";
		}
		} visitor( file );
		GlobalShortcuts_foreach( visitor );
	}
}
Ejemplo n.º 2
0
void LoadCommandMap( const char* path ){
	StringOutputStream strINI( 256 );
	strINI << path << "shortcuts.ini";

	FILE* f = fopen( strINI.c_str(), "r" );
	if ( f != 0 ) {
		fclose( f );
		globalOutputStream() << "loading custom shortcuts list from " << makeQuoted( strINI.c_str() ) << "\n";

		Version version = version_parse( COMMANDS_VERSION );
		Version dataVersion = { 0, 0 };

		{
			char value[1024];
			if ( read_var( strINI.c_str(), "Version", "number", value ) ) {
				dataVersion = version_parse( value );
			}
		}

		if ( version_compatible( version, dataVersion ) ) {
			globalOutputStream() << "commands import: data version " << dataVersion << " is compatible with code version " << version << "\n";
			ReadCommandMap visitor( strINI.c_str() );
			GlobalShortcuts_foreach( visitor );
			globalOutputStream() << "parsed " << Unsigned( visitor.count() ) << " custom shortcuts\n";
		}
		else
		{
			globalOutputStream() << "commands import: data version " << dataVersion << " is not compatible with code version " << version << "\n";
		}
	}
	else
	{
		globalOutputStream() << "failed to load custom shortcuts from " << makeQuoted( strINI.c_str() ) << "\n";
	}
}
Ejemplo n.º 3
0
void SaveCommandMap(const char* path)
{
  StringOutputStream strINI(256);
  strINI << path << "shortcuts.ini";

  TextFileOutputStream file(strINI.c_str());
  if(!file.failed())
  {
    file << "[Version]\n";
    file << "number=" << COMMANDS_VERSION << "\n";
    file << "\n";
    file << "[Commands]\n";
    class WriteCommandMap : public CommandVisitor
    {
      TextFileOutputStream& m_file;
    public:
      WriteCommandMap(TextFileOutputStream& file) : m_file(file)
      {
      }
      void visit(const char* name, Accelerator& accelerator)
      {
        m_file << name << "=";

        const char* key = global_keys_find(accelerator.key);
        if(!string_empty(key))
        {
          m_file << key;
        }
        else if(accelerator.key != 0)
        {
          m_file << gdk_keyval_name(accelerator.key);
        }

        if(accelerator.modifiers & GDK_MOD1_MASK)
        {
          m_file << "+Alt";
        }
        if(accelerator.modifiers & GDK_CONTROL_MASK)
        {
          m_file << "+Ctrl";
        }
        if(accelerator.modifiers & GDK_SHIFT_MASK)
        {
          m_file << "+Shift";
        }

        m_file << "\n";
      }
    } visitor(file);
    GlobalShortcuts_foreach(visitor);
  }
}