omit unchanged default binds from saved.cfg

omitunchangeddefaultbinds n

  0 print
  1 print, but commented out
  2 omit

The new var _defaultbinds is used to mark default binds in resetbinds.cfg.

DOCREF omitunchangeddefaultbinds
This commit is contained in:
ac-stef
2016-08-26 14:31:33 +02:00
parent daae49273d
commit dbfdb5927b
3 changed files with 19 additions and 7 deletions
+13 -5
View File
@@ -211,12 +211,17 @@ COMMAND(findkeycode, "s");
keym *keypressed = NULL;
char *keyaction = NULL;
VAR(_defaultbinds, 0, 0, 1);
bool bindkey(keym *km, const char *action, int type)
{
if(!km) return false;
if(type < keym::ACTION_DEFAULT || type >= keym::NUMACTIONS) { conoutf("invalid bind type \"%i\"", type); return false; }
if(!keypressed || keyaction!=km->actions[type]) delete[] km->actions[type];
km->actions[type] = newstring(action);
if(!km || type < keym::ACTION_DEFAULT || type >= keym::NUMACTIONS) return false;
if(strcmp(action, km->actions[type]))
{
if(!keypressed || keyaction!=km->actions[type]) delete[] km->actions[type];
km->actions[type] = newstring(action);
km->unchangeddefault[type] = _defaultbinds != 0;
}
return true;
}
@@ -601,12 +606,15 @@ char *getcurcommand()
return saycommandon ? cmdline.buf : NULL;
}
VARP(omitunchangeddefaultbinds, 0, 1, 2);
void writebinds(stream *f)
{
loopv(keyms)
{
keym *km = &keyms[i];
loopj(3) if(*km->actions[j]) f->printf("%s \"%s\" %s\n", keycmd(j), km->name, escapestring(km->actions[j]));
loopj(3) if(*km->actions[j] && (!km->unchangeddefault[j] || omitunchangeddefaultbinds < 2))
f->printf("%s%s \"%s\" %s\n", km->unchangeddefault[j] && omitunchangeddefaultbinds ? "//" : "", keycmd(j), km->name, escapestring(km->actions[j]));
}
}