<p>Maybe a use case will make it easier to explain?  I was working with a plugin to save the current fold state when a document is being closed.  This works just fine, except in a specific case - if the document is being closed and there are unsaved changes, i.e. the 'changed' flag in the document reference is TRUE.  In this case I would want to ignore saving the fold state since the next time it is opened all the fold points will likely be wrong.  A simple approach to address this would be to not save the fold state on document close if this flag is TRUE.  This works when a document is closed when I close a tab in the UI - I see the changed flag is set to TRUE and can therefore ignore trying to save the fold state.</p>
<p>There is a specific case where Geany closes a document and the 'changed' state is <em>always</em> FALSE, even if the document has changes that the user discarded.  When Geany calls the 'document_close_all' function, like when Geany is being closed, internally that function calls 'document_account_for_saved' which in turn will always set the 'changed' flag to FALSE before closing a document, so when the document is closed I can never tell if there are unsaved changes or not.  This fix changes Geany to close all documents, but to leave the 'changed' flag untouched so a plugin can see whether any unsaved changes are being discarded when a document is being closed.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/geany/geany/pull/1857#issuecomment-388686531">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABDrJ8jlchbHT5dddWEUgDcyos1H_PXvks5tyPjpgaJpZM4T82nj">mute the thread</a>.<img src="https://github.com/notifications/beacon/ABDrJ0tv50diC4BkkOfdA6KmZgcU9Cguks5tyPjpgaJpZM4T82nj.gif" height="1" width="1" alt="" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/geany/geany/pull/1857#issuecomment-388686531"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>

<script type="application/json" data-scope="inboxmarkup">{"api_version":"1.0","publisher":{"api_key":"05dde50f1d1a384dd78767c55493e4bb","name":"GitHub"},"entity":{"external_key":"github/geany/geany","title":"geany/geany","subtitle":"GitHub repository","main_image_url":"https://cloud.githubusercontent.com/assets/143418/17495839/a5054eac-5d88-11e6-95fc-7290892c7bb5.png","avatar_image_url":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","action":{"name":"Open in GitHub","url":"https://github.com/geany/geany"}},"updates":{"snippets":[{"icon":"PERSON","message":"@chrontec in #1857: Maybe a use case will make it easier to explain?  I was working with a plugin to save the current fold state when a document is being closed.  This works just fine, except in a specific case - if the document is being closed and there are unsaved changes, i.e. the 'changed' flag in the document reference is TRUE.  In this case I would want to ignore saving the fold state since the next time it is opened all the fold points will likely be wrong.  A simple approach to address this would be to not save the fold state on document close if this flag is TRUE.  This works when a document is closed when I close a tab in the UI - I see the changed flag is set to TRUE and can therefore ignore trying to save the fold state.\r\n\r\nThere is a specific case where Geany closes a document and the 'changed' state is *always* FALSE, even if the document has changes that the user discarded.  When Geany calls the 'document_close_all' function, like when Geany is being closed, internally that function calls 'document_account_for_saved' which in turn will always set the 'changed' flag to FALSE before closing a document, so when the document is closed I can never tell if there are unsaved changes or not.  This fix changes Geany to close all documents, but to leave the 'changed' flag untouched so a plugin can see whether any unsaved changes are being discarded when a document is being closed."}],"action":{"name":"View Pull Request","url":"https://github.com/geany/geany/pull/1857#issuecomment-388686531"}}}</script>
<script type="application/ld+json">{"@type":"MessageCard","@context":"http://schema.org/extensions","hideOriginalBody":"false","originator":"37567f93-e2a7-4e2a-ad37-a9160fc62647","title":"Re: [geany/geany] Fix 'changed' flag being altered when all documents are closing. (#1857)","sections":[{"text":"","activityTitle":"**chrontec**","activityImage":"https://cloud.githubusercontent.com/assets/143418/15842166/7c72db34-2c0b-11e6-9aed-b52498112777.png","activitySubtitle":"@chrontec","facts":[]}],"potentialAction":[{"name":"Add a comment","@type":"ActionCard","inputs":[{"isMultiLine":true,"@type":"TextInput","id":"IssueComment","isRequired":false}],"actions":[{"name":"Comment","@type":"HttpPOST","target":"https://api.github.com","body":"{\"commandName\":\"IssueComment\",\"repositoryFullName\":\"geany/geany\",\"issueId\":1857,\"IssueComment\":\"{{IssueComment.value}}\"}"}]},{"name":"Close pull request","@type":"HttpPOST","target":"https://api.github.com","body":"{\"commandName\":\"PullRequestClose\",\"repositoryFullName\":\"geany/geany\",\"pullRequestId\":1857}"},{"targets":[{"os":"default","uri":"https://github.com/geany/geany/pull/1857#issuecomment-388686531"}],"@type":"OpenUri","name":"View on GitHub"},{"name":"Unsubscribe","@type":"HttpPOST","target":"https://api.github.com","body":"{\"commandName\":\"MuteNotification\",\"threadId\":334719459}"}],"themeColor":"26292E"}</script>