Function MimeAppsListFile.addAssociation

Add desktopId as association for mimeType. Delete it from removed associations if listed.

void addAssociation (
  string mimeType,
  string desktopId
) @trusted;

Note

This only changes the object, but not file itself.

Example

MimeAppsListFile appsList = new MimeAppsListFile();
appsList.addAssociation("text/plain", "geany.desktop");
assert(appsList.addedAssociations() !is null);
assert(appsList.addedAssociations().appsForMimeType("text/plain").equal(["geany.desktop"]));

appsList.addAssociation("image/png", null);
assert(!appsList.addedAssociations().contains("image/png"));

string contents =
`[Added Associations]
text/plain=kde4-kate.desktop;emacs.desktop
[Removed Associations]
text/plain=kde4-okular.desktop;geany.desktop;`;

appsList = new MimeAppsListFile(iniLikeStringReader(contents));
appsList.addAssociation("text/plain", "geany.desktop");
assert(appsList.addedAssociations().appsForMimeType("text/plain").equal(["kde4-kate.desktop", "emacs.desktop", "geany.desktop"]));
assert(appsList.removedAssociations().appsForMimeType("text/plain").equal(["kde4-okular.desktop"]));

contents =
`[Removed Associations]
text/plain=geany.desktop;`;

appsList = new MimeAppsListFile(iniLikeStringReader(contents));
appsList.addAssociation("text/plain", "geany.desktop");
assert(appsList.addedAssociations().appsForMimeType("text/plain").equal(["geany.desktop"]));
assert(!appsList.removedAssociations().contains("text/plain"));