Fix bug 8000 (Can get two identical "View as" items in "View as"

menu):

	* src/nautilus-window-private.h:
	* src/nautilus-window-manage-views.h:
	* src/nautilus-window-manage-views.c:
	(location_has_really_changed): Make logic clearer by using else
	instead of two if statements.
	(view_frame_info_new), (view_frame_info_free),
	(set_view_frame_info), (view_frame_get_label),
	(view_frame_get_id), (nautilus_window_get_content_view_id),
	(load_content_view), (nautilus_window_set_sidebar_panels): Store a
	NautilusViewIdentifier with each view.

	* src/nautilus-window.h:
	* src/nautilus-window.c: (nautilus_window_destroy): We no longer
	have to store the content view identifier separately.
	(remove_first_child): New function.
	(update_extra_viewer_in_view_as_menus): Shared by the two below,
	this is the old replace_extra_viewer_in_view_as_menus, simplified
	and changed to support both adding and removing the extra viewer.
	(remove_extra_viewer_in_view_as_menus): Cover for removing.
	(replace_extra_viewer_in_view_as_menus): Cover for adding.
	(nautilus_window_synch_view_as_menus): Simplify code a lot by
	removing some special cases and taking advantage of the fact that
	the position of the chosen item is always the same in both menus.
	(chose_component_callback): Removed the FIXME now that the bug is
	fixed.

	* NEWS: Tweak wording.
This commit is contained in:
Darin Adler 2001-04-19 22:33:59 +00:00
parent c41c44e4f1
commit 670fd0d089
13 changed files with 376 additions and 263 deletions

View file

@ -1,3 +1,36 @@
2001-04-19 Darin Adler <darin@eazel.com>
Fix bug 8000 (Can get two identical "View as" items in "View as"
menu):
* src/nautilus-window-private.h:
* src/nautilus-window-manage-views.h:
* src/nautilus-window-manage-views.c:
(location_has_really_changed): Make logic clearer by using else
instead of two if statements.
(view_frame_info_new), (view_frame_info_free),
(set_view_frame_info), (view_frame_get_label),
(view_frame_get_id), (nautilus_window_get_content_view_id),
(load_content_view), (nautilus_window_set_sidebar_panels): Store a
NautilusViewIdentifier with each view.
* src/nautilus-window.h:
* src/nautilus-window.c: (nautilus_window_destroy): We no longer
have to store the content view identifier separately.
(remove_first_child): New function.
(update_extra_viewer_in_view_as_menus): Shared by the two below,
this is the old replace_extra_viewer_in_view_as_menus, simplified
and changed to support both adding and removing the extra viewer.
(remove_extra_viewer_in_view_as_menus): Cover for removing.
(replace_extra_viewer_in_view_as_menus): Cover for adding.
(nautilus_window_synch_view_as_menus): Simplify code a lot by
removing some special cases and taking advantage of the fact that
the position of the chosen item is always the same in both menus.
(chose_component_callback): Removed the FIXME now that the bug is
fixed.
* NEWS: Tweak wording.
2001-04-19 Darin Adler <darin@eazel.com>
Fixed bug 8065 (Cut and Paste file in Trash -> file deleted)

5
NEWS
View file

@ -1,6 +1,7 @@
We're working on the Nautilus 1.0.3 release right now.
We're working on the next Nautilus release right now.
It will most-likely be called Nautilus 1.0.3.
A lot of features have gone in since 1.0.2. These include:
A lot of features have gone in since Nautilus 1.0.2. These include:
- don't allow desktop icons to be under the Panel
- cut, copy, and paste for moving or copying files (a la Windows)

View file

@ -936,8 +936,6 @@ nautilus_window_destroy (GtkObject *object)
g_list_free (window->sidebar_panels);
nautilus_view_identifier_free (window->content_view_id);
free_stored_viewers (window);
g_free (window->details->location);
@ -1239,22 +1237,39 @@ add_view_as_bonobo_menu_item (NautilusWindow *window,
g_free (tip);
}
static void
remove_first_child (GtkContainer *container)
{
gtk_container_remove (container,
eel_gtk_container_get_first_child (container));
}
/* Make a special first item in the "View as" option menu that represents
* the current content view. This should only be called if the current
* content view isn't already in the "View as" option menu.
*/
static void
replace_extra_viewer_in_view_as_menus (NautilusWindow *window)
update_extra_viewer_in_view_as_menus (NautilusWindow *window,
const NautilusViewIdentifier *id)
{
GtkWidget *menu;
GtkWidget *first_menu_item;
GtkWidget *new_menu_item;
gboolean had_extra_viewer;
had_extra_viewer = window->details->extra_viewer != NULL;
if (id == NULL) {
if (!had_extra_viewer) {
return;
}
} else {
if (had_extra_viewer
&& nautilus_view_identifier_compare (window->details->extra_viewer, id) == 0) {
return;
}
}
nautilus_view_identifier_free (window->details->extra_viewer);
window->details->extra_viewer = nautilus_view_identifier_copy (window->content_view_id);
g_assert (window->details->extra_viewer != NULL);
window->details->extra_viewer = nautilus_view_identifier_copy (id);
/* Update the View As option menu */
menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (window->view_as_option_menu));
@ -1265,28 +1280,54 @@ replace_extra_viewer_in_view_as_menus (NautilusWindow *window)
gtk_widget_ref (menu);
gtk_option_menu_remove_menu (GTK_OPTION_MENU (window->view_as_option_menu));
/* Remove old menu item, and either remove or add separator. */
if (had_extra_viewer) {
first_menu_item = eel_gtk_container_get_first_child (GTK_CONTAINER (menu));
g_assert (first_menu_item != NULL);
g_assert (GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (first_menu_item), "extra viewer")) == TRUE);
gtk_container_remove (GTK_CONTAINER (menu), first_menu_item);
remove_first_child (GTK_CONTAINER (menu));
if (id == NULL) {
remove_first_child (GTK_CONTAINER (menu));
}
} else {
/* Prepend separator. */
gtk_menu_prepend (GTK_MENU (menu), new_gtk_separator ());
if (id != NULL) {
gtk_menu_prepend (GTK_MENU (menu), new_gtk_separator ());
}
}
new_menu_item = create_view_as_menu_item (window, window->details->extra_viewer, 0);
gtk_object_set_data (GTK_OBJECT (new_menu_item), "extra viewer", GINT_TO_POINTER (TRUE));
gtk_menu_prepend (GTK_MENU (menu), new_menu_item);
/* Add new menu item. */
if (id != NULL) {
new_menu_item = create_view_as_menu_item (window, window->details->extra_viewer, 0);
gtk_object_set_data (GTK_OBJECT (new_menu_item), "extra viewer", GINT_TO_POINTER (TRUE));
gtk_menu_prepend (GTK_MENU (menu), new_menu_item);
}
gtk_option_menu_set_menu (GTK_OPTION_MENU (window->view_as_option_menu), menu);
gtk_widget_unref (menu);
/* Also update the Bonobo View menu item */
add_view_as_bonobo_menu_item (window,
NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER,
window->details->extra_viewer,
0);
if (id == NULL) {
nautilus_bonobo_remove_menu_items_and_commands
(window->details->shell_ui, NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER);
} else {
add_view_as_bonobo_menu_item (window,
NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER,
window->details->extra_viewer,
0);
}
}
static void
remove_extra_viewer_in_view_as_menus (NautilusWindow *window)
{
update_extra_viewer_in_view_as_menus (window, NULL);
}
static void
replace_extra_viewer_in_view_as_menus (NautilusWindow *window)
{
NautilusViewIdentifier *id;
id = nautilus_window_get_content_view_id (window);
update_extra_viewer_in_view_as_menus (window, id);
nautilus_view_identifier_free (id);
}
/**
@ -1304,8 +1345,6 @@ nautilus_window_synch_view_as_menus (NautilusWindow *window)
int index;
char *verb_name, *command_path;
GList *node;
int option_menu_index;
int numbered_menu_item_index;
const char *numbered_menu_item_container_path;
g_return_if_fail (NAUTILUS_IS_WINDOW (window));
@ -1314,50 +1353,31 @@ nautilus_window_synch_view_as_menus (NautilusWindow *window)
return;
}
option_menu_index = -1;
numbered_menu_item_index = -1;
numbered_menu_item_container_path = 0;
if (window->details->extra_viewer != NULL &&
nautilus_window_content_view_matches_iid (window, window->details->extra_viewer->iid)) {
option_menu_index = 0;
numbered_menu_item_index = 0;
numbered_menu_item_container_path = NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER;
} else {
for (node = window->details->short_list_viewers, index = 0;
node != NULL;
node = node->next, ++index) {
if (nautilus_window_content_view_matches_iid (window, ((NautilusViewIdentifier *)node->data)->iid)) {
option_menu_index = window->details->extra_viewer == NULL
? index
: index + 2;
numbered_menu_item_index = index;
numbered_menu_item_container_path = NAUTILUS_MENU_PATH_SHORT_LIST_PLACEHOLDER;
break;
}
for (node = window->details->short_list_viewers, index = 0;
node != NULL;
node = node->next, ++index) {
if (nautilus_window_content_view_matches_iid (window, ((NautilusViewIdentifier *)node->data)->iid)) {
break;
}
}
if (option_menu_index == -1) {
if (node == NULL) {
replace_extra_viewer_in_view_as_menus (window);
option_menu_index = 0;
numbered_menu_item_index = 0;
index = 0;
numbered_menu_item_container_path = NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER;
} else {
remove_extra_viewer_in_view_as_menus (window);
numbered_menu_item_container_path = NAUTILUS_MENU_PATH_SHORT_LIST_PLACEHOLDER;
}
g_assert (option_menu_index >= 0);
g_assert (numbered_menu_item_index >= 0);
g_assert (numbered_menu_item_container_path != NULL);
/* Make option menu show the right item */
gtk_option_menu_set_history (GTK_OPTION_MENU (window->view_as_option_menu),
option_menu_index);
gtk_option_menu_set_history (GTK_OPTION_MENU (window->view_as_option_menu), index);
/* Make View menu in menu bar mark the right item */
verb_name = nautilus_bonobo_get_numbered_menu_item_command
(window->details->shell_ui,
numbered_menu_item_container_path,
numbered_menu_item_index);
numbered_menu_item_container_path, index);
command_path = g_strconcat (COMMAND_PREFIX, verb_name, NULL);
nautilus_bonobo_set_toggle_state (window->details->shell_ui, command_path, TRUE);
g_free (command_path);
@ -1380,9 +1400,6 @@ chose_component_callback (NautilusViewIdentifier *identifier, gpointer callback_
* now, hardwire this case, which is the most obvious one by
* far.
*/
/* FIXME bugzilla.eazel.com 8000: It's possible to get the
* same view listed twice in the menu due to this call.
*/
nautilus_window_load_view_as_menus (window);
}

View file

@ -94,7 +94,6 @@ struct NautilusWindow {
/* Current views stuff */
NautilusViewFrame *content_view;
NautilusViewIdentifier *content_view_id;
GList *sidebar_panels;
/* Widgets to keep track of (for state changes, etc) */

View file

@ -936,8 +936,6 @@ nautilus_window_destroy (GtkObject *object)
g_list_free (window->sidebar_panels);
nautilus_view_identifier_free (window->content_view_id);
free_stored_viewers (window);
g_free (window->details->location);
@ -1239,22 +1237,39 @@ add_view_as_bonobo_menu_item (NautilusWindow *window,
g_free (tip);
}
static void
remove_first_child (GtkContainer *container)
{
gtk_container_remove (container,
eel_gtk_container_get_first_child (container));
}
/* Make a special first item in the "View as" option menu that represents
* the current content view. This should only be called if the current
* content view isn't already in the "View as" option menu.
*/
static void
replace_extra_viewer_in_view_as_menus (NautilusWindow *window)
update_extra_viewer_in_view_as_menus (NautilusWindow *window,
const NautilusViewIdentifier *id)
{
GtkWidget *menu;
GtkWidget *first_menu_item;
GtkWidget *new_menu_item;
gboolean had_extra_viewer;
had_extra_viewer = window->details->extra_viewer != NULL;
if (id == NULL) {
if (!had_extra_viewer) {
return;
}
} else {
if (had_extra_viewer
&& nautilus_view_identifier_compare (window->details->extra_viewer, id) == 0) {
return;
}
}
nautilus_view_identifier_free (window->details->extra_viewer);
window->details->extra_viewer = nautilus_view_identifier_copy (window->content_view_id);
g_assert (window->details->extra_viewer != NULL);
window->details->extra_viewer = nautilus_view_identifier_copy (id);
/* Update the View As option menu */
menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (window->view_as_option_menu));
@ -1265,28 +1280,54 @@ replace_extra_viewer_in_view_as_menus (NautilusWindow *window)
gtk_widget_ref (menu);
gtk_option_menu_remove_menu (GTK_OPTION_MENU (window->view_as_option_menu));
/* Remove old menu item, and either remove or add separator. */
if (had_extra_viewer) {
first_menu_item = eel_gtk_container_get_first_child (GTK_CONTAINER (menu));
g_assert (first_menu_item != NULL);
g_assert (GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (first_menu_item), "extra viewer")) == TRUE);
gtk_container_remove (GTK_CONTAINER (menu), first_menu_item);
remove_first_child (GTK_CONTAINER (menu));
if (id == NULL) {
remove_first_child (GTK_CONTAINER (menu));
}
} else {
/* Prepend separator. */
gtk_menu_prepend (GTK_MENU (menu), new_gtk_separator ());
if (id != NULL) {
gtk_menu_prepend (GTK_MENU (menu), new_gtk_separator ());
}
}
new_menu_item = create_view_as_menu_item (window, window->details->extra_viewer, 0);
gtk_object_set_data (GTK_OBJECT (new_menu_item), "extra viewer", GINT_TO_POINTER (TRUE));
gtk_menu_prepend (GTK_MENU (menu), new_menu_item);
/* Add new menu item. */
if (id != NULL) {
new_menu_item = create_view_as_menu_item (window, window->details->extra_viewer, 0);
gtk_object_set_data (GTK_OBJECT (new_menu_item), "extra viewer", GINT_TO_POINTER (TRUE));
gtk_menu_prepend (GTK_MENU (menu), new_menu_item);
}
gtk_option_menu_set_menu (GTK_OPTION_MENU (window->view_as_option_menu), menu);
gtk_widget_unref (menu);
/* Also update the Bonobo View menu item */
add_view_as_bonobo_menu_item (window,
NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER,
window->details->extra_viewer,
0);
if (id == NULL) {
nautilus_bonobo_remove_menu_items_and_commands
(window->details->shell_ui, NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER);
} else {
add_view_as_bonobo_menu_item (window,
NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER,
window->details->extra_viewer,
0);
}
}
static void
remove_extra_viewer_in_view_as_menus (NautilusWindow *window)
{
update_extra_viewer_in_view_as_menus (window, NULL);
}
static void
replace_extra_viewer_in_view_as_menus (NautilusWindow *window)
{
NautilusViewIdentifier *id;
id = nautilus_window_get_content_view_id (window);
update_extra_viewer_in_view_as_menus (window, id);
nautilus_view_identifier_free (id);
}
/**
@ -1304,8 +1345,6 @@ nautilus_window_synch_view_as_menus (NautilusWindow *window)
int index;
char *verb_name, *command_path;
GList *node;
int option_menu_index;
int numbered_menu_item_index;
const char *numbered_menu_item_container_path;
g_return_if_fail (NAUTILUS_IS_WINDOW (window));
@ -1314,50 +1353,31 @@ nautilus_window_synch_view_as_menus (NautilusWindow *window)
return;
}
option_menu_index = -1;
numbered_menu_item_index = -1;
numbered_menu_item_container_path = 0;
if (window->details->extra_viewer != NULL &&
nautilus_window_content_view_matches_iid (window, window->details->extra_viewer->iid)) {
option_menu_index = 0;
numbered_menu_item_index = 0;
numbered_menu_item_container_path = NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER;
} else {
for (node = window->details->short_list_viewers, index = 0;
node != NULL;
node = node->next, ++index) {
if (nautilus_window_content_view_matches_iid (window, ((NautilusViewIdentifier *)node->data)->iid)) {
option_menu_index = window->details->extra_viewer == NULL
? index
: index + 2;
numbered_menu_item_index = index;
numbered_menu_item_container_path = NAUTILUS_MENU_PATH_SHORT_LIST_PLACEHOLDER;
break;
}
for (node = window->details->short_list_viewers, index = 0;
node != NULL;
node = node->next, ++index) {
if (nautilus_window_content_view_matches_iid (window, ((NautilusViewIdentifier *)node->data)->iid)) {
break;
}
}
if (option_menu_index == -1) {
if (node == NULL) {
replace_extra_viewer_in_view_as_menus (window);
option_menu_index = 0;
numbered_menu_item_index = 0;
index = 0;
numbered_menu_item_container_path = NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER;
} else {
remove_extra_viewer_in_view_as_menus (window);
numbered_menu_item_container_path = NAUTILUS_MENU_PATH_SHORT_LIST_PLACEHOLDER;
}
g_assert (option_menu_index >= 0);
g_assert (numbered_menu_item_index >= 0);
g_assert (numbered_menu_item_container_path != NULL);
/* Make option menu show the right item */
gtk_option_menu_set_history (GTK_OPTION_MENU (window->view_as_option_menu),
option_menu_index);
gtk_option_menu_set_history (GTK_OPTION_MENU (window->view_as_option_menu), index);
/* Make View menu in menu bar mark the right item */
verb_name = nautilus_bonobo_get_numbered_menu_item_command
(window->details->shell_ui,
numbered_menu_item_container_path,
numbered_menu_item_index);
numbered_menu_item_container_path, index);
command_path = g_strconcat (COMMAND_PREFIX, verb_name, NULL);
nautilus_bonobo_set_toggle_state (window->details->shell_ui, command_path, TRUE);
g_free (command_path);
@ -1380,9 +1400,6 @@ chose_component_callback (NautilusViewIdentifier *identifier, gpointer callback_
* now, hardwire this case, which is the most obvious one by
* far.
*/
/* FIXME bugzilla.eazel.com 8000: It's possible to get the
* same view listed twice in the menu due to this call.
*/
nautilus_window_load_view_as_menus (window);
}

View file

@ -94,7 +94,6 @@ struct NautilusWindow {
/* Current views stuff */
NautilusViewFrame *content_view;
NautilusViewIdentifier *content_view_id;
GList *sidebar_panels;
/* Widgets to keep track of (for state changes, etc) */

View file

@ -936,8 +936,6 @@ nautilus_window_destroy (GtkObject *object)
g_list_free (window->sidebar_panels);
nautilus_view_identifier_free (window->content_view_id);
free_stored_viewers (window);
g_free (window->details->location);
@ -1239,22 +1237,39 @@ add_view_as_bonobo_menu_item (NautilusWindow *window,
g_free (tip);
}
static void
remove_first_child (GtkContainer *container)
{
gtk_container_remove (container,
eel_gtk_container_get_first_child (container));
}
/* Make a special first item in the "View as" option menu that represents
* the current content view. This should only be called if the current
* content view isn't already in the "View as" option menu.
*/
static void
replace_extra_viewer_in_view_as_menus (NautilusWindow *window)
update_extra_viewer_in_view_as_menus (NautilusWindow *window,
const NautilusViewIdentifier *id)
{
GtkWidget *menu;
GtkWidget *first_menu_item;
GtkWidget *new_menu_item;
gboolean had_extra_viewer;
had_extra_viewer = window->details->extra_viewer != NULL;
if (id == NULL) {
if (!had_extra_viewer) {
return;
}
} else {
if (had_extra_viewer
&& nautilus_view_identifier_compare (window->details->extra_viewer, id) == 0) {
return;
}
}
nautilus_view_identifier_free (window->details->extra_viewer);
window->details->extra_viewer = nautilus_view_identifier_copy (window->content_view_id);
g_assert (window->details->extra_viewer != NULL);
window->details->extra_viewer = nautilus_view_identifier_copy (id);
/* Update the View As option menu */
menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (window->view_as_option_menu));
@ -1265,28 +1280,54 @@ replace_extra_viewer_in_view_as_menus (NautilusWindow *window)
gtk_widget_ref (menu);
gtk_option_menu_remove_menu (GTK_OPTION_MENU (window->view_as_option_menu));
/* Remove old menu item, and either remove or add separator. */
if (had_extra_viewer) {
first_menu_item = eel_gtk_container_get_first_child (GTK_CONTAINER (menu));
g_assert (first_menu_item != NULL);
g_assert (GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (first_menu_item), "extra viewer")) == TRUE);
gtk_container_remove (GTK_CONTAINER (menu), first_menu_item);
remove_first_child (GTK_CONTAINER (menu));
if (id == NULL) {
remove_first_child (GTK_CONTAINER (menu));
}
} else {
/* Prepend separator. */
gtk_menu_prepend (GTK_MENU (menu), new_gtk_separator ());
if (id != NULL) {
gtk_menu_prepend (GTK_MENU (menu), new_gtk_separator ());
}
}
new_menu_item = create_view_as_menu_item (window, window->details->extra_viewer, 0);
gtk_object_set_data (GTK_OBJECT (new_menu_item), "extra viewer", GINT_TO_POINTER (TRUE));
gtk_menu_prepend (GTK_MENU (menu), new_menu_item);
/* Add new menu item. */
if (id != NULL) {
new_menu_item = create_view_as_menu_item (window, window->details->extra_viewer, 0);
gtk_object_set_data (GTK_OBJECT (new_menu_item), "extra viewer", GINT_TO_POINTER (TRUE));
gtk_menu_prepend (GTK_MENU (menu), new_menu_item);
}
gtk_option_menu_set_menu (GTK_OPTION_MENU (window->view_as_option_menu), menu);
gtk_widget_unref (menu);
/* Also update the Bonobo View menu item */
add_view_as_bonobo_menu_item (window,
NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER,
window->details->extra_viewer,
0);
if (id == NULL) {
nautilus_bonobo_remove_menu_items_and_commands
(window->details->shell_ui, NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER);
} else {
add_view_as_bonobo_menu_item (window,
NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER,
window->details->extra_viewer,
0);
}
}
static void
remove_extra_viewer_in_view_as_menus (NautilusWindow *window)
{
update_extra_viewer_in_view_as_menus (window, NULL);
}
static void
replace_extra_viewer_in_view_as_menus (NautilusWindow *window)
{
NautilusViewIdentifier *id;
id = nautilus_window_get_content_view_id (window);
update_extra_viewer_in_view_as_menus (window, id);
nautilus_view_identifier_free (id);
}
/**
@ -1304,8 +1345,6 @@ nautilus_window_synch_view_as_menus (NautilusWindow *window)
int index;
char *verb_name, *command_path;
GList *node;
int option_menu_index;
int numbered_menu_item_index;
const char *numbered_menu_item_container_path;
g_return_if_fail (NAUTILUS_IS_WINDOW (window));
@ -1314,50 +1353,31 @@ nautilus_window_synch_view_as_menus (NautilusWindow *window)
return;
}
option_menu_index = -1;
numbered_menu_item_index = -1;
numbered_menu_item_container_path = 0;
if (window->details->extra_viewer != NULL &&
nautilus_window_content_view_matches_iid (window, window->details->extra_viewer->iid)) {
option_menu_index = 0;
numbered_menu_item_index = 0;
numbered_menu_item_container_path = NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER;
} else {
for (node = window->details->short_list_viewers, index = 0;
node != NULL;
node = node->next, ++index) {
if (nautilus_window_content_view_matches_iid (window, ((NautilusViewIdentifier *)node->data)->iid)) {
option_menu_index = window->details->extra_viewer == NULL
? index
: index + 2;
numbered_menu_item_index = index;
numbered_menu_item_container_path = NAUTILUS_MENU_PATH_SHORT_LIST_PLACEHOLDER;
break;
}
for (node = window->details->short_list_viewers, index = 0;
node != NULL;
node = node->next, ++index) {
if (nautilus_window_content_view_matches_iid (window, ((NautilusViewIdentifier *)node->data)->iid)) {
break;
}
}
if (option_menu_index == -1) {
if (node == NULL) {
replace_extra_viewer_in_view_as_menus (window);
option_menu_index = 0;
numbered_menu_item_index = 0;
index = 0;
numbered_menu_item_container_path = NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER;
} else {
remove_extra_viewer_in_view_as_menus (window);
numbered_menu_item_container_path = NAUTILUS_MENU_PATH_SHORT_LIST_PLACEHOLDER;
}
g_assert (option_menu_index >= 0);
g_assert (numbered_menu_item_index >= 0);
g_assert (numbered_menu_item_container_path != NULL);
/* Make option menu show the right item */
gtk_option_menu_set_history (GTK_OPTION_MENU (window->view_as_option_menu),
option_menu_index);
gtk_option_menu_set_history (GTK_OPTION_MENU (window->view_as_option_menu), index);
/* Make View menu in menu bar mark the right item */
verb_name = nautilus_bonobo_get_numbered_menu_item_command
(window->details->shell_ui,
numbered_menu_item_container_path,
numbered_menu_item_index);
numbered_menu_item_container_path, index);
command_path = g_strconcat (COMMAND_PREFIX, verb_name, NULL);
nautilus_bonobo_set_toggle_state (window->details->shell_ui, command_path, TRUE);
g_free (command_path);
@ -1380,9 +1400,6 @@ chose_component_callback (NautilusViewIdentifier *identifier, gpointer callback_
* now, hardwire this case, which is the most obvious one by
* far.
*/
/* FIXME bugzilla.eazel.com 8000: It's possible to get the
* same view listed twice in the menu due to this call.
*/
nautilus_window_load_view_as_menus (window);
}

View file

@ -94,7 +94,6 @@ struct NautilusWindow {
/* Current views stuff */
NautilusViewFrame *content_view;
NautilusViewIdentifier *content_view_id;
GList *sidebar_panels;
/* Widgets to keep track of (for state changes, etc) */

View file

@ -91,7 +91,7 @@ typedef enum {
typedef struct {
gboolean is_sidebar_panel;
char *label;
NautilusViewIdentifier *id;
} ViewFrameInfo;
static void connect_view (NautilusWindow *window,
@ -662,10 +662,8 @@ location_has_really_changed (NautilusWindow *window)
*/
if (window->details->pending_location == NULL) {
nautilus_window_synch_view_as_menus (window);
}
/* Tell the window we are finished. */
if (window->details->pending_location != NULL) {
} else {
/* Tell the window we are finished. */
update_for_new_location (window);
}
@ -756,15 +754,16 @@ nautilus_window_open_location_with_selection (NautilusWindow *window,
static ViewFrameInfo *
view_frame_info_new (gboolean is_sidebar_panel, const char *label)
view_frame_info_new (gboolean is_sidebar_panel,
const NautilusViewIdentifier *id)
{
ViewFrameInfo *new_info;
g_return_val_if_fail (label != NULL, NULL);
g_return_val_if_fail (id != NULL, NULL);
new_info = g_new0 (ViewFrameInfo, 1);
new_info = g_new (ViewFrameInfo, 1);
new_info->is_sidebar_panel = is_sidebar_panel;
new_info->label = g_strdup (label);
new_info->id = nautilus_view_identifier_copy (id);
return new_info;
}
@ -773,7 +772,7 @@ static void
view_frame_info_free (ViewFrameInfo *info)
{
if (info != NULL) {
g_free (info->label);
nautilus_view_identifier_free (info->id);
g_free (info);
}
}
@ -781,11 +780,11 @@ view_frame_info_free (ViewFrameInfo *info)
static void
set_view_frame_info (NautilusViewFrame *view_frame,
gboolean is_sidebar_panel,
const char *label)
const NautilusViewIdentifier *id)
{
gtk_object_set_data_full (GTK_OBJECT (view_frame),
"info",
view_frame_info_new (is_sidebar_panel, label),
view_frame_info_new (is_sidebar_panel, id),
(GtkDestroyNotify) view_frame_info_free);
}
@ -806,7 +805,17 @@ view_frame_get_label (NautilusViewFrame *view_frame)
info = (ViewFrameInfo *)gtk_object_get_data
(GTK_OBJECT (view_frame), "info");
return g_strdup (info->label);
return g_strdup (info->id->name);
}
static NautilusViewIdentifier *
view_frame_get_id (NautilusViewFrame *view_frame)
{
ViewFrameInfo *info;
info = (ViewFrameInfo *)gtk_object_get_data
(GTK_OBJECT (view_frame), "info");
return nautilus_view_identifier_copy (info->id);
}
static void
@ -913,6 +922,15 @@ set_to_pending_location_and_selection (NautilusWindow *window)
window->details->pending_selection = NULL;
}
NautilusViewIdentifier *
nautilus_window_get_content_view_id (NautilusWindow *window)
{
if (window->content_view == NULL) {
return NULL;
}
return view_frame_get_id (window->content_view);
}
gboolean
nautilus_window_content_view_matches_iid (NautilusWindow *window,
const char *iid)
@ -961,9 +979,6 @@ load_content_view (NautilusWindow *window,
bonobo_ui_component_thaw (window->details->shell_ui, NULL);
nautilus_view_identifier_free (window->content_view_id);
window->content_view_id = nautilus_view_identifier_copy (id);
if (nautilus_window_content_view_matches_iid (window, iid)) {
/* reuse existing content view */
view = window->content_view;
@ -977,7 +992,7 @@ load_content_view (NautilusWindow *window,
window->new_content_view = view;
gtk_object_ref (GTK_OBJECT (view));
gtk_object_sink (GTK_OBJECT (view));
set_view_frame_info (view, FALSE, id->name);
set_view_frame_info (view, FALSE, id);
connect_view (window, view);
nautilus_view_frame_load_view (view, iid);
}
@ -1538,7 +1553,7 @@ nautilus_window_set_sidebar_panels (NautilusWindow *window,
sidebar_panel = nautilus_view_frame_new (window->details->ui_container,
window->application->undo_manager);
nautilus_view_frame_set_label (sidebar_panel, identifier->name);
set_view_frame_info (sidebar_panel, TRUE, identifier->name);
set_view_frame_info (sidebar_panel, TRUE, identifier);
connect_view (window, sidebar_panel);
nautilus_window_add_sidebar_panel (window, sidebar_panel);
nautilus_view_frame_load_view (sidebar_panel, identifier->iid);

View file

@ -4,7 +4,7 @@
* Nautilus
*
* Copyright (C) 1999, 2000 Red Hat, Inc.
* Copyright (C) 1999, 2000 Eazel, Inc.
* Copyright (C) 1999, 2000, 2001 Eazel, Inc.
*
* Nautilus is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
@ -20,7 +20,7 @@
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Author: Elliot Lee <sopwith@redhat.com>
* Author: Darin Adler <darin@eazel.com>
*
*/
@ -29,20 +29,22 @@
#include "nautilus-window.h"
void nautilus_window_manage_views_destroy (NautilusWindow *window);
void nautilus_window_open_location (NautilusWindow *window,
const char *location);
void nautilus_window_open_location_with_selection
(NautilusWindow *window,
const char *location,
GList *selection);
void nautilus_window_stop_loading (NautilusWindow *window);
void nautilus_window_set_content_view (NautilusWindow *window,
NautilusViewIdentifier *id);
void nautilus_window_set_sidebar_panels (NautilusWindow *window,
GList *view_identifier_list);
void nautilus_window_back_or_forward (NautilusWindow *window,
gboolean back,
guint distance);
void nautilus_window_manage_views_destroy (NautilusWindow *window);
void nautilus_window_open_location (NautilusWindow *window,
const char *location);
void nautilus_window_open_location_with_selection (NautilusWindow *window,
const char *location,
GList *selection);
void nautilus_window_stop_loading (NautilusWindow *window);
void nautilus_window_set_content_view (NautilusWindow *window,
NautilusViewIdentifier *id);
void nautilus_window_set_sidebar_panels (NautilusWindow *window,
GList *view_identifier_list);
void nautilus_window_back_or_forward (NautilusWindow *window,
gboolean back,
guint distance);
gboolean nautilus_window_content_view_matches_iid (NautilusWindow *window,
const char *iid);
NautilusViewIdentifier *nautilus_window_get_content_view_id (NautilusWindow *window);
#endif /* NAUTILUS_WINDOW_MANAGE_VIEWS_H */

View file

@ -123,8 +123,6 @@ struct NautilusWindowDetails
#define NAUTILUS_WINDOW_DEFAULT_WIDTH 800
#define NAUTILUS_WINDOW_DEFAULT_HEIGHT 550
gboolean nautilus_window_content_view_matches_iid (NautilusWindow *window,
const char *iid);
void nautilus_window_set_status (NautilusWindow *window,
const char *status);
void nautilus_window_load_view_as_menus (NautilusWindow *window);

View file

@ -936,8 +936,6 @@ nautilus_window_destroy (GtkObject *object)
g_list_free (window->sidebar_panels);
nautilus_view_identifier_free (window->content_view_id);
free_stored_viewers (window);
g_free (window->details->location);
@ -1239,22 +1237,39 @@ add_view_as_bonobo_menu_item (NautilusWindow *window,
g_free (tip);
}
static void
remove_first_child (GtkContainer *container)
{
gtk_container_remove (container,
eel_gtk_container_get_first_child (container));
}
/* Make a special first item in the "View as" option menu that represents
* the current content view. This should only be called if the current
* content view isn't already in the "View as" option menu.
*/
static void
replace_extra_viewer_in_view_as_menus (NautilusWindow *window)
update_extra_viewer_in_view_as_menus (NautilusWindow *window,
const NautilusViewIdentifier *id)
{
GtkWidget *menu;
GtkWidget *first_menu_item;
GtkWidget *new_menu_item;
gboolean had_extra_viewer;
had_extra_viewer = window->details->extra_viewer != NULL;
if (id == NULL) {
if (!had_extra_viewer) {
return;
}
} else {
if (had_extra_viewer
&& nautilus_view_identifier_compare (window->details->extra_viewer, id) == 0) {
return;
}
}
nautilus_view_identifier_free (window->details->extra_viewer);
window->details->extra_viewer = nautilus_view_identifier_copy (window->content_view_id);
g_assert (window->details->extra_viewer != NULL);
window->details->extra_viewer = nautilus_view_identifier_copy (id);
/* Update the View As option menu */
menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (window->view_as_option_menu));
@ -1265,28 +1280,54 @@ replace_extra_viewer_in_view_as_menus (NautilusWindow *window)
gtk_widget_ref (menu);
gtk_option_menu_remove_menu (GTK_OPTION_MENU (window->view_as_option_menu));
/* Remove old menu item, and either remove or add separator. */
if (had_extra_viewer) {
first_menu_item = eel_gtk_container_get_first_child (GTK_CONTAINER (menu));
g_assert (first_menu_item != NULL);
g_assert (GPOINTER_TO_INT (gtk_object_get_data (GTK_OBJECT (first_menu_item), "extra viewer")) == TRUE);
gtk_container_remove (GTK_CONTAINER (menu), first_menu_item);
remove_first_child (GTK_CONTAINER (menu));
if (id == NULL) {
remove_first_child (GTK_CONTAINER (menu));
}
} else {
/* Prepend separator. */
gtk_menu_prepend (GTK_MENU (menu), new_gtk_separator ());
if (id != NULL) {
gtk_menu_prepend (GTK_MENU (menu), new_gtk_separator ());
}
}
new_menu_item = create_view_as_menu_item (window, window->details->extra_viewer, 0);
gtk_object_set_data (GTK_OBJECT (new_menu_item), "extra viewer", GINT_TO_POINTER (TRUE));
gtk_menu_prepend (GTK_MENU (menu), new_menu_item);
/* Add new menu item. */
if (id != NULL) {
new_menu_item = create_view_as_menu_item (window, window->details->extra_viewer, 0);
gtk_object_set_data (GTK_OBJECT (new_menu_item), "extra viewer", GINT_TO_POINTER (TRUE));
gtk_menu_prepend (GTK_MENU (menu), new_menu_item);
}
gtk_option_menu_set_menu (GTK_OPTION_MENU (window->view_as_option_menu), menu);
gtk_widget_unref (menu);
/* Also update the Bonobo View menu item */
add_view_as_bonobo_menu_item (window,
NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER,
window->details->extra_viewer,
0);
if (id == NULL) {
nautilus_bonobo_remove_menu_items_and_commands
(window->details->shell_ui, NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER);
} else {
add_view_as_bonobo_menu_item (window,
NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER,
window->details->extra_viewer,
0);
}
}
static void
remove_extra_viewer_in_view_as_menus (NautilusWindow *window)
{
update_extra_viewer_in_view_as_menus (window, NULL);
}
static void
replace_extra_viewer_in_view_as_menus (NautilusWindow *window)
{
NautilusViewIdentifier *id;
id = nautilus_window_get_content_view_id (window);
update_extra_viewer_in_view_as_menus (window, id);
nautilus_view_identifier_free (id);
}
/**
@ -1304,8 +1345,6 @@ nautilus_window_synch_view_as_menus (NautilusWindow *window)
int index;
char *verb_name, *command_path;
GList *node;
int option_menu_index;
int numbered_menu_item_index;
const char *numbered_menu_item_container_path;
g_return_if_fail (NAUTILUS_IS_WINDOW (window));
@ -1314,50 +1353,31 @@ nautilus_window_synch_view_as_menus (NautilusWindow *window)
return;
}
option_menu_index = -1;
numbered_menu_item_index = -1;
numbered_menu_item_container_path = 0;
if (window->details->extra_viewer != NULL &&
nautilus_window_content_view_matches_iid (window, window->details->extra_viewer->iid)) {
option_menu_index = 0;
numbered_menu_item_index = 0;
numbered_menu_item_container_path = NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER;
} else {
for (node = window->details->short_list_viewers, index = 0;
node != NULL;
node = node->next, ++index) {
if (nautilus_window_content_view_matches_iid (window, ((NautilusViewIdentifier *)node->data)->iid)) {
option_menu_index = window->details->extra_viewer == NULL
? index
: index + 2;
numbered_menu_item_index = index;
numbered_menu_item_container_path = NAUTILUS_MENU_PATH_SHORT_LIST_PLACEHOLDER;
break;
}
for (node = window->details->short_list_viewers, index = 0;
node != NULL;
node = node->next, ++index) {
if (nautilus_window_content_view_matches_iid (window, ((NautilusViewIdentifier *)node->data)->iid)) {
break;
}
}
if (option_menu_index == -1) {
if (node == NULL) {
replace_extra_viewer_in_view_as_menus (window);
option_menu_index = 0;
numbered_menu_item_index = 0;
index = 0;
numbered_menu_item_container_path = NAUTILUS_MENU_PATH_EXTRA_VIEWER_PLACEHOLDER;
} else {
remove_extra_viewer_in_view_as_menus (window);
numbered_menu_item_container_path = NAUTILUS_MENU_PATH_SHORT_LIST_PLACEHOLDER;
}
g_assert (option_menu_index >= 0);
g_assert (numbered_menu_item_index >= 0);
g_assert (numbered_menu_item_container_path != NULL);
/* Make option menu show the right item */
gtk_option_menu_set_history (GTK_OPTION_MENU (window->view_as_option_menu),
option_menu_index);
gtk_option_menu_set_history (GTK_OPTION_MENU (window->view_as_option_menu), index);
/* Make View menu in menu bar mark the right item */
verb_name = nautilus_bonobo_get_numbered_menu_item_command
(window->details->shell_ui,
numbered_menu_item_container_path,
numbered_menu_item_index);
numbered_menu_item_container_path, index);
command_path = g_strconcat (COMMAND_PREFIX, verb_name, NULL);
nautilus_bonobo_set_toggle_state (window->details->shell_ui, command_path, TRUE);
g_free (command_path);
@ -1380,9 +1400,6 @@ chose_component_callback (NautilusViewIdentifier *identifier, gpointer callback_
* now, hardwire this case, which is the most obvious one by
* far.
*/
/* FIXME bugzilla.eazel.com 8000: It's possible to get the
* same view listed twice in the menu due to this call.
*/
nautilus_window_load_view_as_menus (window);
}

View file

@ -94,7 +94,6 @@ struct NautilusWindow {
/* Current views stuff */
NautilusViewFrame *content_view;
NautilusViewIdentifier *content_view_id;
GList *sidebar_panels;
/* Widgets to keep track of (for state changes, etc) */