Skip to content

Commit

Permalink
Merge pull request #133 from Harry-Hopkinson/fix-remove-all-pets
Browse files Browse the repository at this point in the history
Fix the remove-all-pets command.
  • Loading branch information
tonybaloney authored Sep 30, 2022
2 parents 6261316 + 683e059 commit 056f931
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@
"command": "vscode-pets.delete-pet",
"title": "Remove pet",
"category": "Pet Coding",
"icon" : {
"icon": {
"dark": "media/icon/dark-trash.svg",
"light": "media/icon/light-trash.svg"
}
},
{
"command": "vscode-pets.delete-pets",
"command": "vscode-pets.remove-all-pets",
"title": "Remove all pets",
"category": "Pet Coding",
"icon": {
Expand Down
63 changes: 61 additions & 2 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ function getPetPanel(): IPetPanel | undefined {
} else if (PetPanel.currentPanel) {
return PetPanel.currentPanel;
} else {
vscode.window.showErrorMessage("Please open a Pet's Playground first.");
return undefined;
}
}

Expand Down Expand Up @@ -359,6 +359,34 @@ export function activate(context: vscode.ExtensionContext) {
handleRemovePetMessage,
context,
);
} else {
const spec = PetSpecification.fromConfiguration();
PetPanel.createOrShow(
context.extensionUri,
context.extensionPath,
spec.color,
spec.type,
spec.size,
getConfiguredTheme(),
getConfiguredThemeKind(),
);
if (PetPanel.currentPanel) {
var collection = PetSpecification.collectionFromMemento(
context,
getConfiguredSize(),
);
collection.forEach((item) => {
PetPanel.currentPanel!.spawnPet(item);
});
storeCollectionAsMemento(context, collection);
} else {
var collection = PetSpecification.collectionFromMemento(
context,
getConfiguredSize(),
);
collection.push(spec);
storeCollectionAsMemento(context, collection);
}
}
}),
);
Expand Down Expand Up @@ -478,11 +506,42 @@ export function activate(context: vscode.ExtensionContext) {
);

context.subscriptions.push(
vscode.commands.registerCommand('vscode-pets.reset-pets', () => {
vscode.commands.registerCommand('vscode-pets.remove-all-pets', () => {
const panel = getPetPanel();
if (panel !== undefined) {
panel.resetPets();
storeCollectionAsMemento(context, []);
} else {
const spec = PetSpecification.fromConfiguration();
PetPanel.createOrShow(
context.extensionUri,
context.extensionPath,
spec.color,
spec.type,
spec.size,
getConfiguredTheme(),
getConfiguredThemeKind(),
);
if (PetPanel.currentPanel) {
var collection = PetSpecification.collectionFromMemento(
context,
getConfiguredSize(),
);
collection.forEach((item) => {
PetPanel.currentPanel!.spawnPet(item);
});
storeCollectionAsMemento(context, collection);
} else {
var collection = PetSpecification.collectionFromMemento(
context,
getConfiguredSize(),
);
collection.push(spec);
storeCollectionAsMemento(context, collection);
}
vscode.window.showInformationMessage(
"A Pet Playground has been created. You can now use the 'Remove All Pets' Command to remove all pets.",
);
}
}),
);
Expand Down

0 comments on commit 056f931

Please sign in to comment.