Commit 3e6324f1 authored by John Sullivan's avatar John Sullivan
Browse files

The content view type menu now works (can switch between Icons and List views)

parent 737b2381
2000-01-11 John Sullivan <sullivan@eazel.com>
Content view menu now works (can switch between List and Icon views).
* src/ntl-window-msgs.c:
(nautilus_window_load_content_view): Made it return the new
content view, so callers don't need a load_info structure to
determine the new view. Also made it accept NULL for
requesting_view.
(view_menu_switch_views_cb): New function, callback for when
a view is chosen from the list of available content views.
Elliot told me that this requires further work, so I checked
it in with comments for later fixing by Elliot or someone
else who understands the loading process better.
(nautilus_view_load_content_view_menu): Added explicit
parameter for NautilusNavigationInfo for clarity (had been
getting this from deep in window temporary state guts).
Connected view_menu_switch_views_cb to menu items.
* src/ntl-window.c:
(nautilus_window_set_arg): Fixed bug in ARG_CONTENT_VIEW case where
new view was sometimes being added to view hierarchy twice. Then
moved this code into...
(real_nautilus_window_set_content_view): New function, implements
guts of content-view changing so set_arg doesn't have a big block
of code in a switch statement.
(nautilus_window_set_content_view): Moved the gtk_widget_show call
from here to real_nautilus_window_set_content_view so it happens
even if set_arg is called from elsewhere.
(gtk_option_menu_do_resize): Removed this
obsolete function (I removed the callers yesterday but forgot this).
2000-01-11 Darin Adler <darin@eazel.com>
* libnautilus/ntl-view-frame.c: Fixed typos and oversights in
......
......@@ -37,6 +37,7 @@
#include <libnautilus/nautilus-gtk-extensions.h>
static void nautilus_window_realize (GtkWidget *widget);
static void real_nautilus_window_set_content_view (NautilusWindow *window, NautilusView *new_view);
static GnomeAppClass *parent_class = NULL;
......@@ -400,15 +401,6 @@ nautilus_window_goto_uri_cb (GtkWidget *widget,
nautilus_window_goto_uri(NAUTILUS_WINDOW(window), uri);
}
static void
gtk_option_menu_do_resize(GtkWidget *widget, GtkWidget *child, GtkWidget *optmenu)
{
GtkRequisition req;
gtk_widget_size_request(widget, &req);
gtk_widget_set_usize(optmenu, req.width, -1);
}
static void
nautilus_window_constructed(NautilusWindow *window)
{
......@@ -538,34 +530,7 @@ nautilus_window_set_arg (GtkObject *object,
nautilus_window_constructed(NAUTILUS_WINDOW(object));
break;
case ARG_CONTENT_VIEW:
new_cv = (GtkWidget *)GTK_VALUE_OBJECT(*arg);
if(window->content_view)
{
gtk_widget_ref(GTK_WIDGET(window->content_view));
gtk_container_remove(GTK_CONTAINER(window->content_hbox), GTK_WIDGET(window->content_view));
if(new_cv)
{
#ifdef CONTENTS_AS_HBOX
gtk_box_pack_end(GTK_BOX(window->content_hbox), new_cv, TRUE, TRUE, 0);
#else
gtk_paned_pack2(GTK_PANED(window->content_hbox), new_cv, TRUE, FALSE);
#endif
}
gtk_widget_unref(GTK_WIDGET(window->content_view));
}
if (new_cv)
{
#ifdef CONTENTS_AS_HBOX
gtk_box_pack_end(GTK_BOX(window->content_hbox), new_cv, TRUE, TRUE, 0);
#else
gtk_paned_pack2(GTK_PANED(window->content_hbox), new_cv, TRUE, FALSE);
#endif
}
gtk_widget_queue_resize(window->content_hbox);
window->content_view = (NautilusView *)new_cv;
real_nautilus_window_set_content_view (window, (NautilusView *)GTK_VALUE_OBJECT(*arg));
break;
}
}
......@@ -728,10 +693,7 @@ nautilus_window_send_show_properties(GtkWidget *dockitem, GdkEventButton *event,
void
nautilus_window_set_content_view(NautilusWindow *window, NautilusView *content_view)
{
gtk_object_set(GTK_OBJECT(window), "content_view", content_view, NULL);
if(content_view)
gtk_widget_show(GTK_WIDGET(content_view));
real_nautilus_window_set_content_view (window, content_view);
}
void
......@@ -982,3 +944,34 @@ nautilus_window_display_error(NautilusWindow *window, const char *error_msg)
gtk_widget_show(dialog);
}
static void
real_nautilus_window_set_content_view (NautilusWindow *window, NautilusView *new_view)
{
g_return_if_fail (NAUTILUS_IS_WINDOW (window));
g_return_if_fail (new_view == NULL || NAUTILUS_IS_VIEW (new_view));
if (new_view == window->content_view)
{
return;
}
if (window->content_view != NULL)
{
gtk_container_remove(GTK_CONTAINER(window->content_hbox), GTK_WIDGET(window->content_view));
}
if (new_view != NULL)
{
gtk_widget_show (GTK_WIDGET (new_view));
#ifdef CONTENTS_AS_HBOX
gtk_box_pack_end(GTK_BOX(window->content_hbox), GTK_WIDGET (new_view), TRUE, TRUE, 0);
#else
gtk_paned_pack2(GTK_PANED(window->content_hbox), GTK_WIDGET (new_view), TRUE, FALSE);
#endif
}
gtk_widget_queue_resize(window->content_hbox);
window->content_view = new_view;
}
......@@ -37,6 +37,7 @@
#include <libnautilus/nautilus-gtk-extensions.h>
static void nautilus_window_realize (GtkWidget *widget);
static void real_nautilus_window_set_content_view (NautilusWindow *window, NautilusView *new_view);
static GnomeAppClass *parent_class = NULL;
......@@ -400,15 +401,6 @@ nautilus_window_goto_uri_cb (GtkWidget *widget,
nautilus_window_goto_uri(NAUTILUS_WINDOW(window), uri);
}
static void
gtk_option_menu_do_resize(GtkWidget *widget, GtkWidget *child, GtkWidget *optmenu)
{
GtkRequisition req;
gtk_widget_size_request(widget, &req);
gtk_widget_set_usize(optmenu, req.width, -1);
}
static void
nautilus_window_constructed(NautilusWindow *window)
{
......@@ -538,34 +530,7 @@ nautilus_window_set_arg (GtkObject *object,
nautilus_window_constructed(NAUTILUS_WINDOW(object));
break;
case ARG_CONTENT_VIEW:
new_cv = (GtkWidget *)GTK_VALUE_OBJECT(*arg);
if(window->content_view)
{
gtk_widget_ref(GTK_WIDGET(window->content_view));
gtk_container_remove(GTK_CONTAINER(window->content_hbox), GTK_WIDGET(window->content_view));
if(new_cv)
{
#ifdef CONTENTS_AS_HBOX
gtk_box_pack_end(GTK_BOX(window->content_hbox), new_cv, TRUE, TRUE, 0);
#else
gtk_paned_pack2(GTK_PANED(window->content_hbox), new_cv, TRUE, FALSE);
#endif
}
gtk_widget_unref(GTK_WIDGET(window->content_view));
}
if (new_cv)
{
#ifdef CONTENTS_AS_HBOX
gtk_box_pack_end(GTK_BOX(window->content_hbox), new_cv, TRUE, TRUE, 0);
#else
gtk_paned_pack2(GTK_PANED(window->content_hbox), new_cv, TRUE, FALSE);
#endif
}
gtk_widget_queue_resize(window->content_hbox);
window->content_view = (NautilusView *)new_cv;
real_nautilus_window_set_content_view (window, (NautilusView *)GTK_VALUE_OBJECT(*arg));
break;
}
}
......@@ -728,10 +693,7 @@ nautilus_window_send_show_properties(GtkWidget *dockitem, GdkEventButton *event,
void
nautilus_window_set_content_view(NautilusWindow *window, NautilusView *content_view)
{
gtk_object_set(GTK_OBJECT(window), "content_view", content_view, NULL);
if(content_view)
gtk_widget_show(GTK_WIDGET(content_view));
real_nautilus_window_set_content_view (window, content_view);
}
void
......@@ -982,3 +944,34 @@ nautilus_window_display_error(NautilusWindow *window, const char *error_msg)
gtk_widget_show(dialog);
}
static void
real_nautilus_window_set_content_view (NautilusWindow *window, NautilusView *new_view)
{
g_return_if_fail (NAUTILUS_IS_WINDOW (window));
g_return_if_fail (new_view == NULL || NAUTILUS_IS_VIEW (new_view));
if (new_view == window->content_view)
{
return;
}
if (window->content_view != NULL)
{
gtk_container_remove(GTK_CONTAINER(window->content_hbox), GTK_WIDGET(window->content_view));
}
if (new_view != NULL)
{
gtk_widget_show (GTK_WIDGET (new_view));
#ifdef CONTENTS_AS_HBOX
gtk_box_pack_end(GTK_BOX(window->content_hbox), GTK_WIDGET (new_view), TRUE, TRUE, 0);
#else
gtk_paned_pack2(GTK_PANED(window->content_hbox), GTK_WIDGET (new_view), TRUE, FALSE);
#endif
}
gtk_widget_queue_resize(window->content_hbox);
window->content_view = new_view;
}
......@@ -37,6 +37,7 @@
#include <libnautilus/nautilus-gtk-extensions.h>
static void nautilus_window_realize (GtkWidget *widget);
static void real_nautilus_window_set_content_view (NautilusWindow *window, NautilusView *new_view);
static GnomeAppClass *parent_class = NULL;
......@@ -400,15 +401,6 @@ nautilus_window_goto_uri_cb (GtkWidget *widget,
nautilus_window_goto_uri(NAUTILUS_WINDOW(window), uri);
}
static void
gtk_option_menu_do_resize(GtkWidget *widget, GtkWidget *child, GtkWidget *optmenu)
{
GtkRequisition req;
gtk_widget_size_request(widget, &req);
gtk_widget_set_usize(optmenu, req.width, -1);
}
static void
nautilus_window_constructed(NautilusWindow *window)
{
......@@ -538,34 +530,7 @@ nautilus_window_set_arg (GtkObject *object,
nautilus_window_constructed(NAUTILUS_WINDOW(object));
break;
case ARG_CONTENT_VIEW:
new_cv = (GtkWidget *)GTK_VALUE_OBJECT(*arg);
if(window->content_view)
{
gtk_widget_ref(GTK_WIDGET(window->content_view));
gtk_container_remove(GTK_CONTAINER(window->content_hbox), GTK_WIDGET(window->content_view));
if(new_cv)
{
#ifdef CONTENTS_AS_HBOX
gtk_box_pack_end(GTK_BOX(window->content_hbox), new_cv, TRUE, TRUE, 0);
#else
gtk_paned_pack2(GTK_PANED(window->content_hbox), new_cv, TRUE, FALSE);
#endif
}
gtk_widget_unref(GTK_WIDGET(window->content_view));
}
if (new_cv)
{
#ifdef CONTENTS_AS_HBOX
gtk_box_pack_end(GTK_BOX(window->content_hbox), new_cv, TRUE, TRUE, 0);
#else
gtk_paned_pack2(GTK_PANED(window->content_hbox), new_cv, TRUE, FALSE);
#endif
}
gtk_widget_queue_resize(window->content_hbox);
window->content_view = (NautilusView *)new_cv;
real_nautilus_window_set_content_view (window, (NautilusView *)GTK_VALUE_OBJECT(*arg));
break;
}
}
......@@ -728,10 +693,7 @@ nautilus_window_send_show_properties(GtkWidget *dockitem, GdkEventButton *event,
void
nautilus_window_set_content_view(NautilusWindow *window, NautilusView *content_view)
{
gtk_object_set(GTK_OBJECT(window), "content_view", content_view, NULL);
if(content_view)
gtk_widget_show(GTK_WIDGET(content_view));
real_nautilus_window_set_content_view (window, content_view);
}
void
......@@ -982,3 +944,34 @@ nautilus_window_display_error(NautilusWindow *window, const char *error_msg)
gtk_widget_show(dialog);
}
static void
real_nautilus_window_set_content_view (NautilusWindow *window, NautilusView *new_view)
{
g_return_if_fail (NAUTILUS_IS_WINDOW (window));
g_return_if_fail (new_view == NULL || NAUTILUS_IS_VIEW (new_view));
if (new_view == window->content_view)
{
return;
}
if (window->content_view != NULL)
{
gtk_container_remove(GTK_CONTAINER(window->content_hbox), GTK_WIDGET(window->content_view));
}
if (new_view != NULL)
{
gtk_widget_show (GTK_WIDGET (new_view));
#ifdef CONTENTS_AS_HBOX
gtk_box_pack_end(GTK_BOX(window->content_hbox), GTK_WIDGET (new_view), TRUE, TRUE, 0);
#else
gtk_paned_pack2(GTK_PANED(window->content_hbox), GTK_WIDGET (new_view), TRUE, FALSE);
#endif
}
gtk_widget_queue_resize(window->content_hbox);
window->content_view = new_view;
}
......@@ -69,6 +69,10 @@ static void nautilus_window_notify_selection_change(NautilusWindow *window,
NautilusView *requesting_view);
static void nautilus_window_advance_state(NautilusWindow *window);
static NautilusView *nautilus_window_load_content_view(NautilusWindow *window,
const char *iid,
Nautilus_NavigationInfo *navinfo,
NautilusView **requesting_view);
static void nautilus_window_switch_to_new_views(NautilusWindow *window);
static void nautilus_window_revert_to_old_views(NautilusWindow *window);
static void nautilus_window_free_load_info(NautilusWindow *window);
......@@ -206,7 +210,42 @@ Nautilus_NavigationInfo__copy(Nautilus_NavigationInfo *dest_ni, Nautilus_Navigat
}
static void
nautilus_window_load_content_view_menu (NautilusWindow *window)
view_menu_switch_views_cb (GtkWidget *widget, gpointer data)
{
NautilusWindow *window;
NautilusView *view;
char *iid;
g_return_if_fail (GTK_IS_MENU_ITEM (widget));
g_return_if_fail (NAUTILUS_IS_WINDOW (gtk_object_get_user_data(GTK_OBJECT(widget))));
g_return_if_fail (data != NULL);
window = NAUTILUS_WINDOW (gtk_object_get_user_data (GTK_OBJECT(widget)));
g_assert (window->content_view != NULL);
g_assert (window->ni != NULL);
iid = (char *)data;
view = nautilus_window_load_content_view (window, iid, window->ni, NULL);
/* FIXME: This is probably too simplistic; might need to clean up after failure analogously
* to nautilus_window_end_location_change. Also Elliot says this view-switching
* needs to be interruptable by the location-switching code, so the loading state
* machine probably needs to get involved somehow.
*/
if (view != NULL)
{
nautilus_window_set_content_view(window, view);
}
/* FIXME: After switching from one view to another (e.g. Icons to List), then immediately
* quitting, get a segmentation fault deep in Bonobo code somewhere.
*/
}
/* FIXME: Probably this should be moved to ntl-window.c with the rest of the UI.
* I was waiting until we had the framework settled before doing that.
*/
static void
nautilus_window_load_content_view_menu (NautilusWindow *window, NautilusNavigationInfo *ni)
{
GList *children;
GList *iter_old;
......@@ -216,13 +255,12 @@ nautilus_window_load_content_view_menu (NautilusWindow *window)
g_return_if_fail (NAUTILUS_IS_WINDOW (window));
g_return_if_fail (GTK_IS_OPTION_MENU (window->option_cvtype));
g_return_if_fail (window->load_info != NULL);
g_return_if_fail (window->load_info->ni != NULL);
g_return_if_fail (ni != NULL);
new_menu = gtk_menu_new ();
/* Add a menu item for each available content view type */
iter_new = window->load_info->ni->content_identifiers;
iter_new = ni->content_identifiers;
index = 0;
default_view_index = -1;
while (iter_new != NULL)
......@@ -232,11 +270,16 @@ nautilus_window_load_content_view_menu (NautilusWindow *window)
identifier = (NautilusViewIdentifier *)iter_new->data;
menu_item = gtk_menu_item_new_with_label (identifier->name);
if (strcmp (identifier->iid, window->load_info->ni->default_content_iid) == 0)
if (strcmp (identifier->iid, ni->default_content_iid) == 0)
{
default_view_index = index;
}
/* FIXME: Need to connect menu item to signal here */
/* FIXME: copy of identifier->iid doesn't get freed */
gtk_signal_connect (GTK_OBJECT (menu_item),
"activate",
GTK_SIGNAL_FUNC (view_menu_switch_views_cb),
g_strdup (identifier->iid));
gtk_object_set_user_data (GTK_OBJECT (menu_item), window);
gtk_menu_append (GTK_MENU (new_menu), menu_item);
gtk_widget_show (menu_item);
iter_new = g_slist_next (iter_new);
......@@ -315,7 +358,7 @@ nautilus_window_change_location_internal(NautilusWindow *window, Nautilus_Naviga
window->si = NULL;
}
nautilus_window_load_content_view_menu (window);
nautilus_window_load_content_view_menu (window, window->load_info->ni);
explorer_location_bar_set_uri_string(EXPLORER_LOCATION_BAR(window->ent_uri),
loci->requested_uri);
......@@ -369,25 +412,27 @@ nautilus_window_view_destroyed(NautilusView *view, NautilusWindow *window)
}
}
static void
static NautilusView *
nautilus_window_load_content_view(NautilusWindow *window,
const char *iid,
NautilusNavigationInfo *loci,
Nautilus_NavigationInfo *navinfo,
NautilusView **requesting_view)
{
NautilusView *content_view = window->content_view;
NautilusView *new_view;
g_return_if_fail(iid);
g_return_if_fail(loci);
g_return_if_fail(requesting_view);
g_return_val_if_fail(iid, NULL);
g_return_val_if_fail(navinfo, NULL);
if((!content_view || !NAUTILUS_IS_VIEW(content_view)) || strcmp(nautilus_view_get_iid(content_view), iid))
{
if(*requesting_view == window->content_view) /* If we are going to be zapping the old view,
we definitely don't want any of the new views
thinking they made the request */
*requesting_view = NULL;
if(requesting_view != NULL && *requesting_view == window->content_view)
{
/* If we are going to be zapping the old view,
we definitely don't want any of the new views
thinking they made the request */
*requesting_view = NULL;
}
new_view = NAUTILUS_VIEW(gtk_widget_new(nautilus_content_view_get_type(), "main_window", window, NULL));
......@@ -406,13 +451,20 @@ nautilus_window_load_content_view(NautilusWindow *window,
{
gtk_object_ref(GTK_OBJECT(new_view));
loci->navinfo.content_view = nautilus_view_get_client_objref(new_view);
window->load_info->new_content_view = new_view;
navinfo->content_view = nautilus_view_get_client_objref(new_view);
if (window->load_info != NULL)
window->load_info->new_content_view = new_view;
nautilus_view_set_active_errors(new_view, TRUE);
nautilus_window_update_view(window, new_view, &(loci->navinfo), *requesting_view, window->load_info->new_content_view);
nautilus_window_update_view(window,
new_view,
navinfo,
requesting_view == NULL ? NULL : *requesting_view,
new_view);
}
return new_view;
}
static void
......@@ -589,7 +641,8 @@ nautilus_window_change_location_2(NautilusNavigationInfo *ni, gpointer data)
return;
}
nautilus_window_load_content_view(window, ni->default_content_iid, ni, (NautilusView **)&ni->requesting_view);
nautilus_window_load_content_view(window, ni->default_content_iid, &ni->navinfo, (NautilusView **)&ni->requesting_view);
if(!window->load_info->new_content_view)
{
nautilus_window_display_error
......
......@@ -37,6 +37,7 @@
#include <libnautilus/nautilus-gtk-extensions.h>
static void nautilus_window_realize (GtkWidget *widget);
static void real_nautilus_window_set_content_view (NautilusWindow *window, NautilusView *new_view);
static GnomeAppClass *parent_class = NULL;
......@@ -400,15 +401,6 @@ nautilus_window_goto_uri_cb (GtkWidget *widget,
nautilus_window_goto_uri(NAUTILUS_WINDOW(window), uri);
}
static void
gtk_option_menu_do_resize(GtkWidget *widget, GtkWidget *child, GtkWidget *optmenu)
{
GtkRequisition req;
gtk_widget_size_request(widget, &req);
gtk_widget_set_usize(optmenu, req.width, -1);
}
static void
nautilus_window_constructed(NautilusWindow *window)
{
......@@ -538,34 +530,7 @@ nautilus_window_set_arg (GtkObject *object,
nautilus_window_constructed(NAUTILUS_WINDOW(object));
break;
case ARG_CONTENT_VIEW:
new_cv = (GtkWidget *)GTK_VALUE_OBJECT(*arg);
if(window->content_view)
{
gtk_widget_ref(GTK_WIDGET(window->content_view));
gtk_container_remove(GTK_CONTAINER(window->content_hbox), GTK_WIDGET(window->content_view));
if(new_cv)
{
#ifdef CONTENTS_AS_HBOX
gtk_box_pack_end(GTK_BOX(window->content_hbox), new_cv, TRUE, TRUE, 0);
#else
gtk_paned_pack2(GTK_PANED(window->content_hbox), new_cv, TRUE, FALSE);
#endif
}
gtk_widget_unref(GTK_WIDGET(window->content_view));
}
if (new_cv)
{
#ifdef CONTENTS_AS_HBOX
gtk_box_pack_end(GTK_BOX(window->content_hbox), new_cv, TRUE, TRUE, 0);
#else
gtk_paned_pack2(GTK_PANED(window->content_hbox), new_cv, TRUE, FALSE);
#endif
}
gtk_widget_queue_resize(window->content_hbox);
window->content_view = (NautilusView *)new_cv;
real_nautilus_window_set_content_view (window, (NautilusView *)GTK_VALUE_OBJECT(*arg));
break;
}
}
......@@ -728,10 +693,7 @@ nautilus_window_send_show_properties(GtkWidget *dockitem, GdkEventButton *event,
void
nautilus_window_set_content_view(NautilusWindow *window, NautilusView *content_view)
{
gtk_object_set(GTK_OBJECT(window), "content_view", content_view, NULL);
if(content_view)
gtk_widget_show(GTK_WIDGET(content_view));
real_nautilus_window_set_content_view (window, content_view);
}
void
......@@ -982,3 +944,34 @@ nautilus_window_display_error(NautilusWindow *window, const char *error_msg)
gtk_widget_show(dialog);
}
static void
real_nautilus_window_set_content_view (NautilusWindow *window, NautilusView *new_view)
{
g_return_if_fail (NAUTILUS_IS_WINDOW (window));
g_return_if_fail (new_view == NULL || NAUTILUS_IS_VIEW (new_view));
if (new_view == window->content_view)
{
return;
}
if (window->content_view != NULL)
{
gtk_container_remove(GTK_CONTAINER(window->content_hbox), GTK_WIDGET(window->content_view));
}
if (new_view != NULL)
{
gtk_widget_show (GTK_WIDGET (new_view));
#ifdef CONTENTS_AS_HBOX
gtk_box_pack_end(GTK_BOX(window->content_hbox), GTK_WIDGET (new_view), TRUE, TRUE, 0);
#else
gtk_paned_pack2(GTK_PANED(window->content_hbox), GTK_WIDGET (new_view), TRUE, FALSE);
#endif
}