[Geany-Devel] Devel Digest, Vol 121, Issue 1

Jason Cumbie jscumbie at xxxxx
Sun May 13 16:11:24 UTC 2018


Thanks for the quick reply!

> The best way of providing for changes would be to make a pull request
> on Github.  Then they will at least be CI checked.

I set up an account and made a pull request so you can see the changes.
Let me know if that didn't work.

> Also on Github you can point to parts of the source which support your
> explanation, I can't immediately see where having "changed" false
> stops the signal being emitted.

Apologies for the miscommunication.  I didn't mean that the
'document-close' signal isn't emitted.  I see that just fine.  The issue is
that the document pointer that is sent in doesn't preserve the current
'changed' state of the document when it is closed when exiting Geany.

The reason for that is the 'document_account_for_saved' function that
is called when using 'document_close_all':

gboolean document_account_for_unsaved(void)
{
   guint i, p, page_count;

   page_count = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook));
   /* iterate over documents in tabs order */
   for (p = 0; p < page_count; p++)
   {
      GeanyDocument *doc = document_get_from_page(p);

      if (DOC_VALID(doc) && doc->changed)
      {
         if (! dialogs_show_unsaved_file(doc))
            return FALSE;
      }
   }
   /* all documents should now be accounted for, so ignore any changes */
   foreach_document (i)
   {
      documents[i]->changed = FALSE; // <-----------------   this
alters close state when closing
   }
   return TRUE;
}

Thanks
Jason


On Sun, May 13, 2018 at 2:00 AM,  <devel-request at lists.geany.org> wrote:
> Send Devel mailing list submissions to
>         devel at lists.geany.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://lists.geany.org/cgi-bin/mailman/listinfo/devel
> or, via email, send a message with subject or body 'help' to
>         devel-request at lists.geany.org
>
> You can reach the person managing the list at
>         devel-owner at lists.geany.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Devel digest..."
>
>
> Today's Topics:
>
>    1. Geany Plugins and Document Close Behavior (Jason Cumbie)
>    2. Re: Geany Plugins and Document Close Behavior (Lex Trotman)
>    3. Re: Geany Plugins and Document Close Behavior (Lex Trotman)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sat, 12 May 2018 23:55:20 -0700
> From: Jason Cumbie <jscumbie at gmail.com>
> To: devel at lists.geany.org
> Subject: [Geany-Devel] Geany Plugins and Document Close Behavior
> Message-ID:
>         <CAJWb6j2yKe4JY+EWqveZcz8nLO164PBp3L_qfk2Me5VZB12hYQ at mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Hello Geany Developers,
>
> I’m a software developer who has had fun using Geany for my own
> projects, so thank you for all the hard work you guys have been doing
> - I love it! Hopefully this is the right place to post this - if there
> is somewhere else I should post this additionally and/or instead let
> me know.
>
> When playing around with modifying plugins I found a potential issue
> with document closing. The ‘document-close’ signal only supplies
> plugins with a document that has the ‘changed’ flag set if one
> document is closed, e.g. a user hit the 'x' on the UI document tab,
> but not when all documents are being closed, e.g. when quitting Geany,
> regardless of whether the ‘document’ has changes. The cause for this
> behavior appears to be the 'document_account_for_saved' function in
> document.c which sets the 'changed' flag to FALSE when closing all
> documents. I've attached a patch to this email that could address
> this. At the bottom of this email I've described the approach I took
> with this patch.  If the patch doesn’t look good let me know what I
> can do to fix it, or if this behavior is expected, would love
> suggestions on how a plugin should be able to get this information
> when a document is being closed.
>
> I'm running Geany by installing it from source from the most recent
> version: 1.34., but the behavior I see is caused by functions and code
> which appear to have been around for awhile so I don't think this
> would be much different for previous versions.
>
> Thank you for any feedback you guys can give. Again really love the
> Geany project, and I’m glad you’ve made it possible to have fun coding
> without requiring shelling out massive amounts of money to use a
> really nice light-weight editor.
>
> Jason
>
>
> The approach in the patch is simple – remove the code that modifies
> the ‘changed’ flag in 'document_account_for_saved', and add a check in
> the ‘remove_page’ function for the ‘main_status.closing_all’ to avoid
> prompting the user when closing all documents. This flag gets set
> during ‘force_close_all’ which is only called in ‘document_close_all’,
> so I couldn’t find anything wrong with this approach – let me know if
> that is not the case.
>
> The only other change that was needed is in how ‘main_quit’ handles
> closing all documents to ensure the current behavior behavior isn’t
> changed when closing Geany, especially since it also calls
> ‘document_account_for_unsaved’. The approach I took to this was to
> remove the ‘document_account_for_unsaved’ out of the ‘main_quit’
> function since this will be called with ‘project_close’ or
> ‘document_close_all’ in 'do_main_quit', and change the ‘do_main_quit’
> function to use the return value from ‘project_close’ and/or
> ‘document_close_all’ to allow aborting the procedure if the user
> canceled and pass this back up to the ‘main_quit’ , or return TRUE at
> the end of the function call otherwise.
> -------------- next part --------------
> A non-text attachment was scrubbed...
> Name: document-close.patch
> Type: text/x-patch
> Size: 2232 bytes
> Desc: not available
> URL: <https://lists.geany.org/pipermail/devel/attachments/20180512/f1023363/attachment-0001.bin>
>
> ------------------------------
>
> Message: 2
> Date: Sun, 13 May 2018 17:35:47 +1000
> From: Lex Trotman <elextr at gmail.com>
> To: Geany development list <devel at lists.geany.org>
> Subject: Re: [Geany-Devel] Geany Plugins and Document Close Behavior
> Message-ID:
>         <CAKhWKDPwyACxSu3MK9qPR7vHBrhysLKtb0Vv5gt-Lg+VsJM0mQ at mail.gmail.com>
> Content-Type: text/plain; charset="UTF-8"
>
> Hi,
>
> The best way of providing for changes would be to make a pull request
> on Github.  Then they will at least be CI checked.
>
> Cheers
> Lex
>
>
> On 13 May 2018 at 16:55, Jason Cumbie <jscumbie at gmail.com> wrote:
>> Hello Geany Developers,
>>
>> I’m a software developer who has had fun using Geany for my own
>> projects, so thank you for all the hard work you guys have been doing
>> - I love it! Hopefully this is the right place to post this - if there
>> is somewhere else I should post this additionally and/or instead let
>> me know.
>>
>> When playing around with modifying plugins I found a potential issue
>> with document closing. The ‘document-close’ signal only supplies
>> plugins with a document that has the ‘changed’ flag set if one
>> document is closed, e.g. a user hit the 'x' on the UI document tab,
>> but not when all documents are being closed, e.g. when quitting Geany,
>> regardless of whether the ‘document’ has changes. The cause for this
>> behavior appears to be the 'document_account_for_saved' function in
>> document.c which sets the 'changed' flag to FALSE when closing all
>> documents. I've attached a patch to this email that could address
>> this. At the bottom of this email I've described the approach I took
>> with this patch.  If the patch doesn’t look good let me know what I
>> can do to fix it, or if this behavior is expected, would love
>> suggestions on how a plugin should be able to get this information
>> when a document is being closed.
>>
>> I'm running Geany by installing it from source from the most recent
>> version: 1.34., but the behavior I see is caused by functions and code
>> which appear to have been around for awhile so I don't think this
>> would be much different for previous versions.
>>
>> Thank you for any feedback you guys can give. Again really love the
>> Geany project, and I’m glad you’ve made it possible to have fun coding
>> without requiring shelling out massive amounts of money to use a
>> really nice light-weight editor.
>>
>> Jason
>>
>>
>> The approach in the patch is simple – remove the code that modifies
>> the ‘changed’ flag in 'document_account_for_saved', and add a check in
>> the ‘remove_page’ function for the ‘main_status.closing_all’ to avoid
>> prompting the user when closing all documents. This flag gets set
>> during ‘force_close_all’ which is only called in ‘document_close_all’,
>> so I couldn’t find anything wrong with this approach – let me know if
>> that is not the case.
>>
>> The only other change that was needed is in how ‘main_quit’ handles
>> closing all documents to ensure the current behavior behavior isn’t
>> changed when closing Geany, especially since it also calls
>> ‘document_account_for_unsaved’. The approach I took to this was to
>> remove the ‘document_account_for_unsaved’ out of the ‘main_quit’
>> function since this will be called with ‘project_close’ or
>> ‘document_close_all’ in 'do_main_quit', and change the ‘do_main_quit’
>> function to use the return value from ‘project_close’ and/or
>> ‘document_close_all’ to allow aborting the procedure if the user
>> canceled and pass this back up to the ‘main_quit’ , or return TRUE at
>> the end of the function call otherwise.
>>
>> _______________________________________________
>> Devel mailing list
>> Devel at lists.geany.org
>> https://lists.geany.org/cgi-bin/mailman/listinfo/devel
>>
>
>
> ------------------------------
>
> Message: 3
> Date: Sun, 13 May 2018 17:50:55 +1000
> From: Lex Trotman <elextr at gmail.com>
> To: Geany development list <devel at lists.geany.org>
> Subject: Re: [Geany-Devel] Geany Plugins and Document Close Behavior
> Message-ID:
>         <CAKhWKDN6n5sF0RsN=cyxGKv84Xi1bJ23wZx8A9Jj3XD9wgWymA at mail.gmail.com>
> Content-Type: text/plain; charset="UTF-8"
>
> On 13 May 2018 at 17:35, Lex Trotman <elextr at gmail.com> wrote:
>> Hi,
>>
>> The best way of providing for changes would be to make a pull request
>> on Github.  Then they will at least be CI checked.
>
> Also on Github you can point to parts of the source which support your
> explanation, I can't immediately see where having "changed" false
> stops the signal being emitted.
>
> Cheers
> Lex
>
>>
>> Cheers
>> Lex
>>
>>
>> On 13 May 2018 at 16:55, Jason Cumbie <jscumbie at gmail.com> wrote:
>>> Hello Geany Developers,
>>>
>>> I’m a software developer who has had fun using Geany for my own
>>> projects, so thank you for all the hard work you guys have been doing
>>> - I love it! Hopefully this is the right place to post this - if there
>>> is somewhere else I should post this additionally and/or instead let
>>> me know.
>>>
>>> When playing around with modifying plugins I found a potential issue
>>> with document closing. The ‘document-close’ signal only supplies
>>> plugins with a document that has the ‘changed’ flag set if one
>>> document is closed, e.g. a user hit the 'x' on the UI document tab,
>>> but not when all documents are being closed, e.g. when quitting Geany,
>>> regardless of whether the ‘document’ has changes. The cause for this
>>> behavior appears to be the 'document_account_for_saved' function in
>>> document.c which sets the 'changed' flag to FALSE when closing all
>>> documents. I've attached a patch to this email that could address
>>> this. At the bottom of this email I've described the approach I took
>>> with this patch.  If the patch doesn’t look good let me know what I
>>> can do to fix it, or if this behavior is expected, would love
>>> suggestions on how a plugin should be able to get this information
>>> when a document is being closed.
>>>
>>> I'm running Geany by installing it from source from the most recent
>>> version: 1.34., but the behavior I see is caused by functions and code
>>> which appear to have been around for awhile so I don't think this
>>> would be much different for previous versions.
>>>
>>> Thank you for any feedback you guys can give. Again really love the
>>> Geany project, and I’m glad you’ve made it possible to have fun coding
>>> without requiring shelling out massive amounts of money to use a
>>> really nice light-weight editor.
>>>
>>> Jason
>>>
>>>
>>> The approach in the patch is simple – remove the code that modifies
>>> the ‘changed’ flag in 'document_account_for_saved', and add a check in
>>> the ‘remove_page’ function for the ‘main_status.closing_all’ to avoid
>>> prompting the user when closing all documents. This flag gets set
>>> during ‘force_close_all’ which is only called in ‘document_close_all’,
>>> so I couldn’t find anything wrong with this approach – let me know if
>>> that is not the case.
>>>
>>> The only other change that was needed is in how ‘main_quit’ handles
>>> closing all documents to ensure the current behavior behavior isn’t
>>> changed when closing Geany, especially since it also calls
>>> ‘document_account_for_unsaved’. The approach I took to this was to
>>> remove the ‘document_account_for_unsaved’ out of the ‘main_quit’
>>> function since this will be called with ‘project_close’ or
>>> ‘document_close_all’ in 'do_main_quit', and change the ‘do_main_quit’
>>> function to use the return value from ‘project_close’ and/or
>>> ‘document_close_all’ to allow aborting the procedure if the user
>>> canceled and pass this back up to the ‘main_quit’ , or return TRUE at
>>> the end of the function call otherwise.
>>>
>>> _______________________________________________
>>> Devel mailing list
>>> Devel at lists.geany.org
>>> https://lists.geany.org/cgi-bin/mailman/listinfo/devel
>>>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Devel mailing list
> Devel at lists.geany.org
> https://lists.geany.org/cgi-bin/mailman/listinfo/devel
>
>
> ------------------------------
>
> End of Devel Digest, Vol 121, Issue 1
> *************************************


More information about the Devel mailing list