for help!!!



Hi, list

I want to add a new menu item to the "Nautilus" menu.
When the menu item
is activated, a dialog window is supposed to pop up.
The dialog has one label
and one entry. The user is required to enter certain
search word into the text entry.
This search word in text entry will retrieved and
append to the web URL
"http://www.google.com//search?hl=en&ie=UTF-8&btnG=Google+Search&q=";.
Then Nautilus window 
will display the html with new created whole URL. 

I have successfully created the menu item and dialog
window. But whenever I enter one word
(I only try one word) into the text entry and click
OK, then the whole Nautilus window disappears.
But if I only have sentence
"nautilus_window_go_web_search (window);" in
"if(result==0)" block, 
it works well and display html page of which URL is
entered in "Preference dialog". I list my code 
and useful functions below. I feel so frustrated on
this problem. I am appreciated if someone can 
help me with it. Thanks.......

__________________________________________________
Do You Yahoo!?
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com

//-------------------------my code-------------------------------------------------
/* following is the callback to the new menu item */
/* it is added into 'nautilus-window-menu.c' */

static void
mycode_customize_callback (BonoboUIComponent *component, 
			       gpointer user_data, 
			       const char *verb)
{
	NautilusWindow *window;
	GtkWidget *dialog;
	GtkWidget *label;
	GtkWidget *entry;
	const gchar str[50]="Enter your search keyword:"; // string displayed on label
	
	int result;  //this is the button number of dialog

	window = NAUTILUS_WINDOW (user_data);
		

	/* create dialog */
	dialog = gnome_dialog_new("Entry dialog",
				  GNOME_STOCK_BUTTON_OK,
				  GNOME_STOCK_BUTTON_CANCEL,
				  NULL);

	/* create and add label into dialog*/
	label = gtk_label_new (str);
	gtk_widget_show (label);
	gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),
			   label,
			   FALSE,FALSE,0);

 	/* create and add entry  into dialog*/
	entry = gtk_entry_new ();
 	gtk_widget_show (entry);
	gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(dialog)->vbox),
			   entry,
			   FALSE,FALSE,0);

	/*set feature to dialog and show it */
	gnome_dialog_set_close(GNOME_DIALOG(dialog),TRUE);  //list below
	gtk_widget_show(dialog);

 	/*  run the dialog in modal mode */
	result = gnome_dialog_run(GNOME_DIALOG(dialog));

	/* when ok button in dialog is clicked, ie result=0 */

	if(result == 0) {
	
		/*if only have this sentence in this block. it works well */
		/* nautilus_window_go_web_search (window);  */
	


		gchar *search_web_uri;

		//set to switchable navigation to location mode
		nautilus_window_set_search_mode (window, FALSE); 

		//get customrized search engine from preference
		search_web_uri = eel_preferences_get (NAUTILUS_PREFERENCES_SEARCH_WEB_URI);

		//attach search word to form whole URL
		strcat(search_web_uri,"/search?hl=en&ie=UTF-8&btnG=Google+Search&q=");
		strcat(search_web_uri,gtk_entry_get_text(GTK_ENTRY(entry)));


		g_assert (search_web_uri != NULL);
	
		nautilus_window_go_to (window, search_web_uri); 


		g_free (search_web_uri); 


	}
}

//-------------------------functions------------------------------------------------------
/* following is the nautilus_window_go_to() function from 
   nautilus-window.c  */

void
nautilus_window_go_to (NautilusWindow *window, const char *uri)
{
	nautilus_window_open_location (window, uri);
}


void
nautilus_window_set_search_mode (NautilusWindow *window,
				 gboolean search_mode)
{
	nautilus_switchable_navigation_bar_set_mode
		(NAUTILUS_SWITCHABLE_NAVIGATION_BAR (window->navigation_bar),
		 search_mode
		 ? NAUTILUS_SWITCHABLE_NAVIGATION_BAR_MODE_SEARCH
		 : NAUTILUS_SWITCHABLE_NAVIGATION_BAR_MODE_LOCATION);

	
}

void
nautilus_window_go_web_search (NautilusWindow *window)
{
	char *search_web_uri;

	nautilus_window_set_search_mode (window, FALSE);

	search_web_uri = eel_preferences_get (NAUTILUS_PREFERENCES_SEARCH_WEB_URI);
	g_assert (search_web_uri != NULL);
	
	nautilus_window_go_to (window, search_web_uri);
	g_free (search_web_uri);
}

//---------------the end----------------------------------------------------------


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]