## Description: Add 'Save search as' button on search toolbar
## Origin/Author: Vadim Rutkovsky <roignac@gmail.com>
## Bug: https://bugs.launchpad.net/ubuntu/+source/nautilus/+bug/32542, https://bugzilla.gnome.org/show_bug.cgi?id=332299
Index: trunk/src/nautilus-query-editor.c
===================================================================
--- trunk.orig/src/nautilus-query-editor.c	2012-03-07 09:45:57.319085722 +0300
+++ trunk/src/nautilus-query-editor.c	2012-03-07 11:59:08.746123993 +0300
@@ -24,6 +24,8 @@
 #include <config.h>
 #include "nautilus-query-editor.h"
 #include "nautilus-window-slot.h"
+#include "nautilus-actions.h"
+#include "nautilus-view.h"
 
 #include <string.h>
 #include <glib/gi18n.h>
@@ -1017,9 +1019,19 @@
 }
 
 static void
+save_search_cb (GtkButton *clicked_button, NautilusQueryEditor *editor)
+{
+	
+	NautilusView *view;
+
+	view = nautilus_window_slot_get_current_view (editor->details->slot);
+	nautilus_activate_search_save_as (view);
+}
+
+static void
 finish_first_line (NautilusQueryEditor *editor, GtkWidget *hbox, gboolean use_go)
 {
-	GtkWidget *button, *image;
+	GtkWidget *button, *save_search_as, *image;
 
 	button = gtk_button_new ();
 	image = gtk_image_new_from_stock (GTK_STOCK_ADD,
@@ -1051,6 +1063,14 @@
 			  G_CALLBACK (go_search_cb), editor);
 		
 	gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
+
+	if (!use_go) {
+		save_search_as = gtk_button_new_with_label (_("Save Search as"));
+		g_signal_connect (save_search_as, "clicked",
+		                  G_CALLBACK (save_search_cb), editor);
+		gtk_widget_show (save_search_as);
+		gtk_box_pack_end (GTK_BOX (hbox), save_search_as, FALSE, FALSE, 0);
+	}
 }
 
 static void
Index: trunk/src/nautilus-view.c
===================================================================
--- trunk.orig/src/nautilus-view.c	2012-03-07 08:08:01.221113000 +0300
+++ trunk/src/nautilus-view.c	2012-03-07 12:00:50.982630965 +0300
@@ -1774,6 +1774,18 @@
 	}
 }
 
+void
+nautilus_activate_search_save_as (NautilusView *view)
+{
+	GtkAction *action;
+
+	g_assert (NAUTILUS_IS_VIEW (view));
+
+	action = gtk_action_group_get_action (view->details->dir_action_group,
+					      NAUTILUS_ACTION_SAVE_SEARCH_AS);
+	gtk_action_activate (action);
+}
+
 
 static void
 action_empty_trash_callback (GtkAction *action,
Index: trunk/src/nautilus-view.h
===================================================================
--- trunk.orig/src/nautilus-view.h	2012-03-07 08:08:01.221113000 +0300
+++ trunk/src/nautilus-view.h	2012-03-07 11:58:58.938075362 +0300
@@ -365,6 +365,7 @@
 
 /* NautilusView methods */
 const char *      nautilus_view_get_view_id                (NautilusView      *view);
+void		  nautilus_activate_search_save_as         (NautilusView      *view);
 
 /* file operations */
 char *            nautilus_view_get_backing_uri            (NautilusView      *view);
