GNOME Bugzilla – Bug 781095
files-view: disable create-link when the clipboard is empty
Last modified: 2017-06-24 12:20:32 UTC
See patch.
Created attachment 349553 [details] [review] files-view: disable create-link when the clipboard is empty 'Create Link' button does nothing when the clipboard is empty. In order to fix that, disable the button when the clipboard is empty.
I'm not a maintainer of Nautilus (just an enthusiast), but seems that 'selection_data == NULL' checking is redundant. At least we have this call stack: on_clipboard_contents_received -> nautilus_clipboard_is_cut_from_selection_data -> get_item_list_from_selection_data -> gtk_selection_data_get_length (where 'selection_data' are without checking for NULL).
(In reply to Evgeny Shulgin from comment #2) > I'm not a maintainer of Nautilus (just an enthusiast), but seems that > 'selection_data == NULL' checking is redundant. > > At least we have this call stack: on_clipboard_contents_received -> > nautilus_clipboard_is_cut_from_selection_data -> > get_item_list_from_selection_data -> gtk_selection_data_get_length (where > 'selection_data' are without checking for NULL). So it would just crash with a null pointer. For public API it’s just good practice to use g_return{,_val}_if_fail and check if the object is an instance of the type (which is not done here, but should be).
And it does look redundant, yes. The docs, however, don’t mention that it allows null, so it’s also good to not pass null pointers to it (or fix the documentation).
Review of attachment 349553 [details] [review]: LGTM ::: src/nautilus-clipboard.h @@ +37,3 @@ gboolean nautilus_clipboard_is_cut_from_selection_data (GtkSelectionData *selection_data); +gboolean nautilus_clipboard_is_selection_data_empty (GtkSelectionData *selection_data); The parameter should be const-qualified, since we’re not modifying it (nor is gtk_selection_data_get_length ()).
(In reply to Ernestas Kulik from comment #3 and #4) I should just shut up. The null check there is fine. We could require the pointer to be valid (as in gtk_selection_data_get_length () or just passing the pointer through) and get warnings for invalid invocations, but I don’t see a need. There either is something in the selection or not (or there is no selection at all).
Created attachment 354384 [details] [review] clipboard: remove duplicate function declaration
Attachment 349553 [details] pushed as afe1384 - files-view: disable create-link when the clipboard is empty Attachment 354384 [details] pushed as c472551 - clipboard: remove duplicate function declaration