New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added prevent option to ::onWillDestroyPaneItem() #13812

wants to merge 14 commits into
base: master


None yet
3 participants
Copy link

ericcornelissen commented Feb 14, 2017

Description of the Change

This PR implements the feature requested in issue #12376. It adds a method to the parameter of the ::onWillDestroyPaneItem callback named prevent which allows packages to prevent a tab from closing by adding an event listener via ::onWillDestroyPaneItem

Alternate Designs

An alternative for the requested feature overall isn't really present, as the previous implementation would close the tab no matter what or request the user to safe in case of unsaved changes. Both of these are unwanted behaviour as described in #12376.

As for alternative ways to implement the functionality, I considered prevent to be a (boolean) value instead of a function. However, this seemed not such a good choice mainly because I find it more intuitive to use as a function, but also because JavaScript can't enforce the value to be a boolean.

Why Should This Be In Core?

As explained in #12376, the problem is that it isn't part of the core. As of now it is nearly impossible to implement this as a package, and non of the solutions I could think of are even remotely elegant (e.g. recording what tab(s) closed and reopening them after they've been closed).


It will help developers of packages prevent the unwanted closing of "special" tabs e.g. when "Close all tabs" is called by the user. This has, for example, been requested in this issue on one of my own packages.

Possible Drawbacks

When used incorrectly this functionality could make closing tabs impossible for users. However, simply disabling the package that uses this functionality incorrectly will solve the problem.

Applicable Issues


ericcornelissen added some commits Feb 13, 2017

Prevent method in onWillDestroyPaneItem callback
Added a new key to the object provided to the onWillDestroyPaneItem
callback with the name 'prevent'. The value for this key is a method
that can be used to prevent closing the given pane item.

This is done via a flag in the function calling the callback notifying
that it shouldn't actually destroy the pane item.
Update pane.destroyItem documentation
Updated the documentation for the destroyItem method in src/
to include a short note on the new prevent functionality.
Added test case for::onWillDestroyPaneItem prevent
Added a test case to the testsuite testing the
functionality of the prevent method on the ::onWillDestroyPaneItem
callback parameter.

ericcornelissen added a commit to ericcornelissen/pinned-tabs-for-atom that referenced this pull request Feb 14, 2017

Prevent closing pinned tabs upon "Close all tabs"
Added functionality to prevent closing a pinned tabs when "Close all
tabs" has been initialized.

This functionality depends on the following PR in the Atom core
repository: atom/atom#13812

ericcornelissen added some commits Feb 14, 2017

Fixed linting issues
Fixed a CoffeeScript linting issue with an empty parameter list in
pane.coffees destroyItem method.
Removed unnecessary fat arrow
Removed the unnecessary use of a fat arrow in the new test case in the
pane spec.

@50Wliu 50Wliu added the needs-review label Feb 14, 2017

ericcornelissen added some commits Feb 27, 2017

Fix broken test regarding callback invocation onWillDestroy
Fixed a broken test in pane-container-spec which was introduced by the
addition of the 'prevent' key.

This comment has been minimized.

Copy link

ericcornelissen commented Mar 1, 2017

@50Wliu (or anyone else), I was wonder if you could help me here?

After I pushed some commits to this PR yesterday all CI systems have failed for some mysterious reason, I can build Atom locally. Also, the logs do not point to something related to my changes, but instead to a build issue related to node-gyp (see AppVeyor)... Maybe it possible to restart the CI systems?


This comment has been minimized.

Copy link

50Wliu commented Mar 1, 2017

AWS was down yesterday. I've restarted all three.

ericcornelissen added some commits Jul 5, 2017

Add missing prevent argument
Readded the prevent function argument to the willDestroyPaneItem which was
lost in the previous merge with atom/atom's master branch.

This comment has been minimized.

Copy link

pmlodawski commented Jul 28, 2017

+1 for this pull request, I was looking for this functionality.


This comment has been minimized.

Copy link

ericcornelissen commented Aug 18, 2017

Build execution time has reached the maximum allowed time for your plan (90 minutes).

Build timeout on AppVeyor (see link) @50Wliu 😞

ericcornelissen added some commits Sep 20, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment