GNOME Bugzilla – Bug 344519
custom print ranges
Last modified: 2015-02-18 00:28:49 UTC
I'd like to have a way to add new print ranges to the print dialogue in addition to the stock ones (All, Current, Range), and a way to hide some. For example, in Epiphany, I'd like to add "Selection" and "Current frame", and remove "Current" which makes no sense there.
Actually, I would use 'selection' range also. Would be nice if GTK_PRINT_PAGES_SELECTION was one of the GtkPrintPages choices.
*** Bug 439157 has been marked as a duplicate of this bug. ***
What about this? Print selection is very useful :-/ Thanks a lot
I am very surprised this feature doesn't exist... we live in 2008..! Everybody who uses printing, has the use for print selection, or am I crazy? Please prioritize!
*** Bug 540590 has been marked as a duplicate of this bug. ***
At least the 'print selection' option should be relatively straightforward to add: - add GTK_PRINT_PAGES_SELECTION to GtkPrintPages - add gtk_print_unix_dialog_set_has_selection and gtk_print_operation_set_has_selection - treat GTK_PRINT_PAGES_SELECTION like GTK_PRINT_PAGES_ALL in the loop-over-pages-to-print logic in GtkPrintOperation Doing things this way would require apps to figure out how many pages the selection will format to, and use gtk_print_operation_set_n_pages in ::begin-print
Created attachment 135172 [details] [review] Add ability to print selected pages Hi, this patch adds ability to print selected pages. There is a new radio button under the "Current Page" radio button. This button is activated by gtk_print_operation_set_has_selection(operation, TRUE) function and the selection itself is filled by gtk_print_operation_set_selection(operation, ranges, num_ranges) in ::begin-print. Marek
some comments: 1) I think the 'selection' choice should only be shown if the application supports it. It should be sensitive depending on whether there is a selection right now. 2) gtk_print_operation_set_selection seems to be a misunderstanding. In most cases, what the user can select will be an arbitrary fragment of a document, not a range of pages. Think about selecting a few lines in gedit, or a few paragraphs in a web page in a browser. I outlined above how I imagine apps to handle this (by calling gtk_print_operation_set_n_pages in ::begin-print).
Created attachment 135379 [details] [review] modified patch Hi, this is modified version of the previous patch. It demands user to call gtk_print_operation_set_support_selection() to show "Selection" radio button and gtk_print_operation_set_has_selection() to control its sensitivity. Number of pages to which the selection will be drawn has to be set by the gtk_print_operation_set_n_pages() function in callback of ::begin-print. Marek
Looks basically ok now. Some pedantic comments: @@ -485,6 +485,7 @@ typedef enum { GTK_PRINT_PAGES_ALL, GTK_PRINT_PAGES_CURRENT, + GTK_PRINT_PAGES_SELECTION, GTK_PRINT_PAGES_RANGES } GtkPrintPages; Please add the new value at the end of the enum, to not change the numeric value of GTK_PRINT_PAGES_RANGES. + case GTK_PRINT_PAGES_SELECTION: + return (page_nr >= 0) && (page_nr < priv->nr_of_pages); Could just as well just add case GTK_PRINT_PAGES_SELECTION: before case GTK_PRINT_PAGES_ALL: since both cases are identical. Same here: + else if (priv->print_pages == GTK_PRINT_PAGES_SELECTION) + { + data->ranges = &data->one_range; + data->num_ranges = 1; + data->ranges[0].start = 0; + data->ranges[0].end = priv->nr_of_pages - 1; + } * @support_selection: TRUE to support selection Please add markup: %TRUE (some more occurrences of this further down) + * will draw by gtk_print_operation_set_n_pages() in a callback of + * ::begin-print. What I am doing for signals in the docs nowadays is: #GtkPrintOperation::begin-print. Then gtk-doc creates a nice link Please add the new functions to docs/reference/gtk/gtk-sections.txt too. One more thing: The new fields in GtkPrintUnixDialog should also be available as properties, including getters: gtk_print_unix_dialog_get_support_selection gtk_print_unix_dialog_get_has_selection and boolean properties GtkPrintUnixDialog::support-selection GtkPrintUnixDialog::has-selection When you add the properties, don't forget to add change notification to the setters. The same goes for capabilities, btw: there should be gtk_print_unix_dialog_get_manual_capabilities, and a GtkPrintUnixDialog::manual-capabilities property (of type GtkPrintCapabilities)
Created attachment 136024 [details] [review] newly modified patch Hi Matthias, thank you for your comments, this patch is modification of the previous patch according to those comments. Marek
Looks good now. Two small remaining comments. The original patch had this: @@ -2476,6 +2480,13 @@ prepare_data (PrintPagesData *data) data->ranges[i].end >= priv->nr_of_pages) data->ranges[i].end = priv->nr_of_pages - 1; } + else if (priv->print_pages == GTK_PRINT_PAGES_SELECTION) + { + data->ranges = &data->one_range; + data->num_ranges = 1; + data->ranges[0].start = 0; + data->ranges[0].end = priv->nr_of_pages - 1; + } else if (priv->print_pages == GTK_PRINT_PAGES_CURRENT && priv->current_page != -1) { Is that not needed anymore, or did it get lost ? Now that we have properties, the setters should do change notification. e.g +void +gtk_print_operation_set_has_selection (GtkPrintOperation *op, + gboolean has_selection) +{ + GtkPrintOperationPrivate *priv; + + g_return_if_fail (GTK_IS_PRINT_OPERATION (op)); + + priv = op->priv; + + priv->has_selection = has_selection; +} Should now do something like: has_selection = has_selection != FALSE; if (priv->selection != has_selection) { priv->selection = has_selection; g_object_notify (G_OBJECT (op), "has-selection"); }
This is not needed any more: + else if (priv->print_pages == GTK_PRINT_PAGES_SELECTION) + { + data->ranges = &data->one_range; + data->num_ranges = 1; + data->ranges[0].start = 0; + data->ranges[0].end = priv->nr_of_pages - 1; + } GTK_PRINT_PAGES_SELECTION is handled in the same way as GTK_PRINT_PAGES_ALL now, which means that it is caught in the last "else" together with GTK_PRINT_PAGES_ALL. The setters in the GtkPrintOperation don't do change notification because there aren't new properties in GtkPrintOperation. I added new properties to GtkPrintUnixDialog only (according to comment #10). I'll add those properties to GtkPrintOperation as well. One question. What exactly do this line: has_selection = has_selection != FALSE; ? (is it some kind of conversion of bad integer values to correct values of gboolean (n (where n > 0) -> TRUE (1), 0 -> FALSE (0)) ?) Marek
>The setters in the GtkPrintOperation don't do change notification because there >aren't new properties in GtkPrintOperation. Ah, I had missed that, sorry. > One question. > What exactly do this line: > has_selection = has_selection != FALSE; ? Yeah, just a safe-guard, since C isn't very good about ensuring that booleans are only TRUE/FALSE. So when comparing them with ==, better be careful.
Created attachment 136137 [details] [review] modified patch This patch adds properties "support-selection" and "has-selection" to the GtkPrintOperation. Marek
thanks, looks good now.
The patch is committed. Should I close this bug or leave it opened? Marek
Leave open, I'd say, for the more radical ideas about custom selections.
time to close it now, though