Commit b91e3637 authored by Elliot Lee's avatar Elliot Lee

src/explorer-location-bar.[ch]: Copy over from gnome-fm, change signal to



src/explorer-location-bar.[ch]:
	Copy over from gnome-fm, change signal to include new URI.
src/ntl-window.c:
	Make NautilusWindow use it.
parent 92aac378
src/explorer-location-bar.[ch]:
Copy over from gnome-fm, change signal to include new URI.
src/ntl-window.c:
Make NautilusWindow use it.
......@@ -15,4 +15,6 @@ nautilus_SOURCES= \
ntl-view.h \
ntl-view.c \
ntl-window.h \
ntl-window.c
ntl-window.c \
explorer-location-bar.h \
explorer-location-bar.c
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* explorer-location-bar.c - Location bar for the GNOME Explorer.
Copyright (C) 1999 Free Software Foundation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Author: Ettore Perazzoli <ettore@gnu.org>
DnD code added by Michael Meeks <michael@nuclecu.unam.mx>
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gnome.h>
#include "explorer-location-bar.h"
#define EXPLORER_DND_URI_LIST_TYPE "text/uri-list"
#define EXPLORER_DND_TEXT_PLAIN_TYPE "text/plain"
#define EXPLORER_DND_URL_TYPE "_NETSCAPE_URL"
typedef enum {
EXPLORER_DND_MC_DESKTOP_ICON,
EXPLORER_DND_URI_LIST,
EXPLORER_DND_TEXT_PLAIN,
EXPLORER_DND_URL,
EXPLORER_DND_NTARGETS
} ExplorerDndTargetType;
static GtkHBoxClass *parent_class;
enum {
LOCATION_CHANGED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0 };
static GtkTargetEntry drag_types [] = {
{ EXPLORER_DND_URI_LIST_TYPE, 0, EXPLORER_DND_URI_LIST },
{ EXPLORER_DND_TEXT_PLAIN_TYPE, 0, EXPLORER_DND_TEXT_PLAIN },
{ EXPLORER_DND_URL_TYPE, 0, EXPLORER_DND_URL }
};
static const int ndrag_types = sizeof (drag_types) / sizeof (drag_types[0]);
static GtkTargetEntry drop_types [] = {
{ EXPLORER_DND_URI_LIST_TYPE, 0, EXPLORER_DND_URI_LIST },
{ EXPLORER_DND_TEXT_PLAIN_TYPE, 0, EXPLORER_DND_TEXT_PLAIN },
{ EXPLORER_DND_URL_TYPE, 0, EXPLORER_DND_URL }
};
static const int ndrop_types = sizeof (drop_types) / sizeof (drop_types[0]);
static void
drag_data_received_cb (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
GtkSelectionData *data,
guint info,
guint32 time,
ExplorerLocationBar *location_bar)
{
GList *names;
g_return_if_fail (data != NULL);
names = gnome_uri_list_extract_uris (data->data);
if (!names) {
g_warning ("No D&D URI's");
gtk_drag_finish (context, FALSE, FALSE, time);
return;
}
if (g_list_length (names) > 1)
g_warning ("FIXME: should we clone ourselfs ?");
EXPLORER_DEBUG (("Received \"%s\" in location\n",
(gchar *)names->data));
explorer_location_bar_set_uri_string (location_bar,
names->data);
gtk_signal_emit (GTK_OBJECT (location_bar),
signals[LOCATION_CHANGED], names->data);
gnome_uri_list_free_strings (names);
gtk_drag_finish (context, TRUE, FALSE, time);
}
static void
drag_data_get_cb (GtkWidget *widget,
GdkDragContext *context,
GtkSelectionData *selection_data,
guint info,
guint32 time,
ExplorerLocationBar *location_bar)
{
gchar *entry_txt;
g_return_if_fail (location_bar != NULL);
g_return_if_fail (selection_data != NULL);
entry_txt = gtk_entry_get_text (GTK_ENTRY (location_bar->entry));
g_return_if_fail (entry_txt != NULL);
EXPLORER_DEBUG (("Sending location '%s'\n", entry_txt));
switch (info) {
case EXPLORER_DND_URI_LIST:
case EXPLORER_DND_TEXT_PLAIN:
case EXPLORER_DND_URL:
gtk_selection_data_set (selection_data,
selection_data->target,
8, (guchar *)entry_txt,
strlen (entry_txt));
break;
default:
g_assert_not_reached ();
}
g_free (entry_txt);
}
static void
location_changed (ExplorerLocationBar *location_bar)
{
g_return_if_fail (location_bar != NULL);
g_return_if_fail (EXPLORER_IS_LOCATION_BAR
(location_bar));
}
static void
editable_activated_cb (GtkEditable *editable,
ExplorerLocationBar *location_bar)
{
g_return_if_fail (location_bar != NULL);
g_return_if_fail (editable != NULL);
g_return_if_fail (EXPLORER_IS_LOCATION_BAR
(location_bar));
gtk_signal_emit (GTK_OBJECT (location_bar),
signals[LOCATION_CHANGED],
gtk_entry_get_text(GTK_ENTRY(editable)));
}
static void
destroy (GtkObject *object)
{
ExplorerLocationBar *location_bar;
location_bar = EXPLORER_LOCATION_BAR (object);
gtk_widget_destroy (location_bar->label);
gtk_widget_destroy (location_bar->entry);
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
}
static void
class_init (ExplorerLocationBarClass *class)
{
GtkObjectClass *object_class;
parent_class = gtk_type_class (gtk_hbox_get_type ());
object_class = GTK_OBJECT_CLASS (class);
object_class->destroy = destroy;
signals[LOCATION_CHANGED]
= gtk_signal_new ("location_changed",
GTK_RUN_FIRST,
object_class->type,
GTK_SIGNAL_OFFSET (ExplorerLocationBarClass,
location_changed),
gtk_marshal_NONE__STRING,
GTK_TYPE_NONE, 1, GTK_TYPE_STRING);
gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
class->location_changed = location_changed;
}
static void
init (ExplorerLocationBar *location_bar)
{
GtkWidget *label;
GtkWidget *entry;
GtkWidget *eventbox;
eventbox = gtk_event_box_new ();
gtk_container_set_border_width (GTK_CONTAINER (eventbox),
GNOME_PAD_SMALL);
label = gtk_label_new (_("Location:"));
gtk_container_add (GTK_CONTAINER (eventbox), label);
gtk_box_pack_start (GTK_BOX (location_bar), eventbox, FALSE, TRUE,
GNOME_PAD_SMALL);
entry = gtk_entry_new ();
gtk_signal_connect (GTK_OBJECT (entry), "activate",
editable_activated_cb, location_bar);
gtk_box_pack_start (GTK_BOX (location_bar), entry, TRUE, TRUE, 0);
/* Drag source */
gtk_drag_source_set (GTK_WIDGET (eventbox),
GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
drag_types, ndrag_types,
GDK_ACTION_COPY | GDK_ACTION_MOVE);
gtk_signal_connect (GTK_OBJECT (eventbox), "drag_data_get",
GTK_SIGNAL_FUNC (drag_data_get_cb),
location_bar);
/* Drag dest. */
gtk_drag_dest_set (GTK_WIDGET (location_bar),
GTK_DEST_DEFAULT_ALL,
drop_types, ndrop_types,
GDK_ACTION_COPY | GDK_ACTION_MOVE);
gtk_signal_connect (GTK_OBJECT (location_bar), "drag_data_received",
GTK_SIGNAL_FUNC (drag_data_received_cb),
location_bar);
gtk_widget_show (entry);
gtk_widget_show_all (eventbox);
location_bar->label = label;
location_bar->entry = entry;
}
GtkType
explorer_location_bar_get_type (void)
{
static GtkType type = 0;
if (type == 0) {
GtkTypeInfo info = {
"ExplorerLocationBar",
sizeof (ExplorerLocationBar),
sizeof (ExplorerLocationBarClass),
(GtkClassInitFunc) class_init,
(GtkObjectInitFunc) init,
NULL,
NULL,
NULL
};
type = gtk_type_unique (gtk_hbox_get_type (), &info);
}
return type;
}
GtkWidget *
explorer_location_bar_new (void)
{
return gtk_widget_new (explorer_location_bar_get_type (), NULL);
}
void
explorer_location_bar_set_uri_string (ExplorerLocationBar *bar,
const gchar *uri_string)
{
g_return_if_fail (bar != NULL);
g_return_if_fail (EXPLORER_IS_LOCATION_BAR (bar));
if (uri_string == NULL)
uri_string = "";
gtk_entry_set_text (GTK_ENTRY (bar->entry), uri_string);
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* explorer-location-bar.h - Location bar for the GNOME Explorer.
Copyright (C) 1999 Free Software Foundation
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; see the file COPYING. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Author: Ettore Perazzoli <ettore@gnu.org>
*/
#ifndef _EXPLORER_LOCATION_BAR_H
#define _EXPLORER_LOCATION_BAR_H
#include <gnome.h>
#define EXPLORER_LOCATION_BAR(obj) \
GTK_CHECK_CAST (obj, explorer_location_bar_get_type (), ExplorerLocationBar)
#define EXPLORER_LOCATION_BAR_CLASS(klass) \
GTK_CHECK_CLASS_CAST (klass, explorer_location_bar_get_type (), ExplorerLocationBarClass)
#define EXPLORER_IS_LOCATION_BAR(obj) \
GTK_CHECK_TYPE (obj, explorer_location_bar_get_type ())
struct _ExplorerLocationBar {
GtkHBox hbox;
GtkWidget *label;
GtkWidget *entry;
};
typedef struct _ExplorerLocationBar ExplorerLocationBar;
struct _ExplorerLocationBarClass {
GtkHBoxClass parent_class;
void (*location_changed) (ExplorerLocationBar *,
const char *uri_string);
};
typedef struct _ExplorerLocationBarClass ExplorerLocationBarClass;
GtkType explorer_location_bar_get_type (void);
GtkWidget *explorer_location_bar_new (void);
void explorer_location_bar_set_uri_string
(ExplorerLocationBar *bar,
const gchar *uri_string);
#endif /* _EXPLORER_LOCATION_BAR_H */
......@@ -27,6 +27,7 @@
#include "config.h"
#include <gnome.h>
#include "nautilus.h"
#include "explorer-location-bar.h"
static void nautilus_window_class_init (NautilusWindowClass *klass);
static void nautilus_window_init (NautilusWindow *window);
......@@ -41,6 +42,9 @@ static void nautilus_window_get_arg (GtkObject *object,
guint arg_id);
static void nautilus_window_close (GtkWidget *widget,
GtkWidget *window);
static void nautilus_window_goto_url (GtkWidget *widget,
const char *url,
GtkWidget *window);
static void nautilus_window_real_request_location_change (NautilusWindow *window,
Nautilus_NavigationRequestInfo *loc,
GtkWidget *requesting_view);
......@@ -174,6 +178,22 @@ nautilus_window_set_status(NautilusWindow *window, const char *txt)
window->statusbar_clear_id = 0;
}
static void
nautilus_window_goto_url (GtkWidget *widget,
const char *url,
GtkWidget *window)
{
Nautilus_NavigationRequestInfo navinfo;
memset(&navinfo, 0, sizeof(navinfo));
navinfo.requested_uri = url;
navinfo.new_window_default = navinfo.new_window_suggested = Nautilus_V_FALSE;
navinfo.new_window_enforced = V_UNKNOWN;
nautilus_window_request_location_change(NAUTILUS_WINDOW(window), &navinfo,
NULL);
}
static void
gtk_option_menu_do_resize(GtkWidget *widget, GtkWidget *child, GtkWidget *optmenu)
{
......@@ -318,7 +338,9 @@ nautilus_window_constructed(NautilusWindow *window)
gtk_widget_show_all(window->content_hbox);
window->ent_url = gtk_entry_new();
window->ent_url = explorer_location_bar_new();
gtk_signal_connect(GTK_OBJECT(window->ent_url), "location_changed",
nautilus_window_goto_url, window);
gnome_app_add_docked(app, window->ent_url, "url-entry",
GNOME_DOCK_ITEM_BEH_LOCKED|GNOME_DOCK_ITEM_BEH_EXCLUSIVE|GNOME_DOCK_ITEM_BEH_NEVER_VERTICAL,
GNOME_DOCK_TOP, 1, 0, 0);
......@@ -577,6 +599,8 @@ nautilus_window_change_location(NautilusWindow *window,
gtk_widget_set_sensitive(window->btn_back, window->uris_prev?TRUE:FALSE);
gtk_widget_set_sensitive(window->btn_fwd, window->uris_next?TRUE:FALSE);
explorer_location_bar_set_uri_string(EXPLORER_LOCATION_BAR(window->ent_url),
loci->requested_uri);
signum = gtk_signal_lookup("notify_location_change", nautilus_view_get_type());
/* If we need to load a different IID, do that before sending the location change request */
......
......@@ -27,6 +27,7 @@
#include "config.h"
#include <gnome.h>
#include "nautilus.h"
#include "explorer-location-bar.h"
static void nautilus_window_class_init (NautilusWindowClass *klass);
static void nautilus_window_init (NautilusWindow *window);
......@@ -41,6 +42,9 @@ static void nautilus_window_get_arg (GtkObject *object,
guint arg_id);
static void nautilus_window_close (GtkWidget *widget,
GtkWidget *window);
static void nautilus_window_goto_url (GtkWidget *widget,
const char *url,
GtkWidget *window);
static void nautilus_window_real_request_location_change (NautilusWindow *window,
Nautilus_NavigationRequestInfo *loc,
GtkWidget *requesting_view);
......@@ -174,6 +178,22 @@ nautilus_window_set_status(NautilusWindow *window, const char *txt)
window->statusbar_clear_id = 0;
}
static void
nautilus_window_goto_url (GtkWidget *widget,
const char *url,
GtkWidget *window)
{
Nautilus_NavigationRequestInfo navinfo;
memset(&navinfo, 0, sizeof(navinfo));
navinfo.requested_uri = url;
navinfo.new_window_default = navinfo.new_window_suggested = Nautilus_V_FALSE;
navinfo.new_window_enforced = V_UNKNOWN;
nautilus_window_request_location_change(NAUTILUS_WINDOW(window), &navinfo,
NULL);
}
static void
gtk_option_menu_do_resize(GtkWidget *widget, GtkWidget *child, GtkWidget *optmenu)
{
......@@ -318,7 +338,9 @@ nautilus_window_constructed(NautilusWindow *window)
gtk_widget_show_all(window->content_hbox);
window->ent_url = gtk_entry_new();
window->ent_url = explorer_location_bar_new();
gtk_signal_connect(GTK_OBJECT(window->ent_url), "location_changed",
nautilus_window_goto_url, window);
gnome_app_add_docked(app, window->ent_url, "url-entry",
GNOME_DOCK_ITEM_BEH_LOCKED|GNOME_DOCK_ITEM_BEH_EXCLUSIVE|GNOME_DOCK_ITEM_BEH_NEVER_VERTICAL,
GNOME_DOCK_TOP, 1, 0, 0);
......@@ -577,6 +599,8 @@ nautilus_window_change_location(NautilusWindow *window,
gtk_widget_set_sensitive(window->btn_back, window->uris_prev?TRUE:FALSE);
gtk_widget_set_sensitive(window->btn_fwd, window->uris_next?TRUE:FALSE);
explorer_location_bar_set_uri_string(EXPLORER_LOCATION_BAR(window->ent_url),
loci->requested_uri);
signum = gtk_signal_lookup("notify_location_change", nautilus_view_get_type());
/* If we need to load a different IID, do that before sending the location change request */
......
......@@ -27,6 +27,7 @@
#include "config.h"
#include <gnome.h>
#include "nautilus.h"
#include "explorer-location-bar.h"
static void nautilus_window_class_init (NautilusWindowClass *klass);
static void nautilus_window_init (NautilusWindow *window);
......@@ -41,6 +42,9 @@ static void nautilus_window_get_arg (GtkObject *object,
guint arg_id);
static void nautilus_window_close (GtkWidget *widget,
GtkWidget *window);
static void nautilus_window_goto_url (GtkWidget *widget,
const char *url,
GtkWidget *window);
static void nautilus_window_real_request_location_change (NautilusWindow *window,
Nautilus_NavigationRequestInfo *loc,
GtkWidget *requesting_view);
......@@ -174,6 +178,22 @@ nautilus_window_set_status(NautilusWindow *window, const char *txt)
window->statusbar_clear_id = 0;
}
static void
nautilus_window_goto_url (GtkWidget *widget,
const char *url,
GtkWidget *window)
{
Nautilus_NavigationRequestInfo navinfo;
memset(&navinfo, 0, sizeof(navinfo));
navinfo.requested_uri = url;
navinfo.new_window_default = navinfo.new_window_suggested = Nautilus_V_FALSE;
navinfo.new_window_enforced = V_UNKNOWN;
nautilus_window_request_location_change(NAUTILUS_WINDOW(window), &navinfo,
NULL);
}
static void
gtk_option_menu_do_resize(GtkWidget *widget, GtkWidget *child, GtkWidget *optmenu)
{
......@@ -318,7 +338,9 @@ nautilus_window_constructed(NautilusWindow *window)
gtk_widget_show_all(window->content_hbox);
window->ent_url = gtk_entry_new();
window->ent_url = explorer_location_bar_new();
gtk_signal_connect(GTK_OBJECT(window->ent_url), "location_changed",
nautilus_window_goto_url, window);
gnome_app_add_docked(app, window->ent_url, "url-entry",
GNOME_DOCK_ITEM_BEH_LOCKED|GNOME_DOCK_ITEM_BEH_EXCLUSIVE|GNOME_DOCK_ITEM_BEH_NEVER_VERTICAL,
GNOME_DOCK_TOP, 1, 0, 0);
......@@ -577,6 +599,8 @@ nautilus_window_change_location(NautilusWindow *window,
gtk_widget_set_sensitive(window->btn_back, window->uris_prev?TRUE:FALSE);
gtk_widget_set_sensitive(window->btn_fwd, window->uris_next?TRUE:FALSE);
explorer_location_bar_set_uri_string(EXPLORER_LOCATION_BAR(window->ent_url),
loci->requested_uri);
signum = gtk_signal_lookup("notify_location_change", nautilus_view_get_type());
/* If we need to load a different IID, do that before sending the location change request */
......
......@@ -27,6 +27,7 @@
#include "config.h"
#include <gnome.h>
#include "nautilus.h"
#include "explorer-location-bar.h"
static void nautilus_window_class_init (NautilusWindowClass *klass);
static void nautilus_window_init (NautilusWindow *window);
......@@ -41,6 +42,9 @@ static void nautilus_window_get_arg (GtkObject *object,
guint arg_id);
static void nautilus_window_close (GtkWidget *widget,
GtkWidget *window);
static void nautilus_window_goto_url (GtkWidget *widget,
const char *url,
GtkWidget *window);
static void nautilus_window_real_request_location_change (NautilusWindow *window,
Nautilus_NavigationRequestInfo *loc,
GtkWidget *requesting_view);
......@@ -174,6 +178,22 @@ nautilus_window_set_status(NautilusWindow *window, const char *txt)
window->statusbar_clear_id = 0;
}
static void
nautilus_window_goto_url (GtkWidget *widget,
const char *url,
GtkWidget *window)
{
Nautilus_NavigationRequestInfo navinfo;
memset(&navinfo, 0, sizeof(navinfo));
navinfo.requested_uri = url;
navinfo.new_window_default = navinfo.new_window_suggested = Nautilus_V_FALSE;
navinfo.new_window_enforced = V_UNKNOWN;
nautilus_window_request_location_change(NAUTILUS_WINDOW(window), &navinfo,
NULL);
}
static void
gtk_option_menu_do_resize(GtkWidget *widget, GtkWidget *child, GtkWidget *optmenu)
{
......@@ -318,7 +338,9 @@ nautilus_window_constructed(NautilusWindow *window)
gtk_widget_show_all(window->content_hbox);
window->ent_url = gtk_entry_new();
window->ent_url = explorer_location_bar_new();
gtk_signal_connect(GTK_OBJECT(window->ent_url), "location_changed",
nautilus_window_goto_url, window);
gnome_app_add_docked(app, window->ent_url, "url-entry",
GNOME_DOCK_ITEM_BEH_LOCKED|GNOME_DOCK_ITEM_BEH_EXCLUSIVE|GNOME_DOCK_ITEM_BEH_NEVER_VERTICAL,
GNOME_DOCK_TOP, 1, 0, 0);
......@@ -577,6 +599,8 @@ nautilus_window_change_location(NautilusWindow *window,
gtk_widget_set_sensitive(window->btn_back, window->uris_prev?TRUE:FALSE);
gtk_widget_set_sensitive(window->btn_fwd, window->uris_next?TRUE:FALSE);
explorer_location_bar_set_uri_string(EXPLORER_LOCATION_BAR(window->ent_url),
loci->requested_uri);
signum = gtk_signal_lookup("notify_location_change", nautilus_view_get_type());
/* If we need to load a different IID, do that before sending the location change request */
......
......@@ -27,6 +27,7 @@
#include "config.h"
#include <gnome.h>
#include "nautilus.h"
#include "explorer-location-bar.h"
static void nautilus_window_class_init (NautilusWindowClass *klass);
static void nautilus_window_init (NautilusWindow *window);
......@@ -41,6 +42,9 @@ static void nautilus_window_get_arg (GtkObject *object,
guint arg_id);
static void nautilus_window_close (GtkWidget *widget,
GtkWidget *window);
static void nautilus_window_goto_url (GtkWidget *widget,
const char *url,
GtkWidget *window);
static void nautilus_window_real_request_location_change (NautilusWindow *window,
Nautilus_NavigationRequestInfo *loc,
GtkWidget *requesting_view);
......@@ -174,6 +178,22 @@ nautilus_window_set_status(NautilusWindow *window, const char *txt)
window->statusbar_clear_id = 0;
}
static void
nautilus_window_goto_url (GtkWidget *widget,
const char *url,
GtkWidget *window)
{
Nautilus_NavigationRequestInfo navinfo;
memset(&navinfo, 0, sizeof(navinfo));
navinfo.requested_uri = url;