Activate the bonobo property pages asynchronously Hide the bonobo property

2002-10-25  James Willcox  <jwillcox@gnome.org>

        * components/notes/Nautilus_View_notes.server.in.in:
        * libnautilus-private/nautilus-mime-actions.c:
        (nautilus_mime_has_any_components_for_file_extended),
        (nautilus_mime_has_any_components_for_file):
        * libnautilus-private/nautilus-mime-actions.h:
        * libnautilus-private/nautilus-program-chooser.c:
        (repopulate_program_list):
        * libnautilus-private/nautilus-program-choosing.c:
        (choose_component_callback):
        * src/file-manager/fm-properties-window.c: (clear_bonobo_pages),
        (refresh_bonobo_pages), (properties_window_file_changed_callback),
        (bonobo_page_error_message), (bonobo_page_activate_callback),
        (append_bonobo_pages):

        * Activate the bonobo property pages asynchronously
        * Hide the bonobo property pages from the component chooser
        * Slightly modify the notes sidebar to also work as a property page
        * Handle changes in the file type (add/remove pages)
This commit is contained in:
James Willcox 2002-10-25 17:38:35 +00:00 committed by James Willcox
parent f2a40b0f23
commit abd72b6825
7 changed files with 169 additions and 53 deletions

View file

@ -1,3 +1,24 @@
2002-10-25 James Willcox <jwillcox@gnome.org>
* components/notes/Nautilus_View_notes.server.in.in:
* libnautilus-private/nautilus-mime-actions.c:
(nautilus_mime_has_any_components_for_file_extended),
(nautilus_mime_has_any_components_for_file):
* libnautilus-private/nautilus-mime-actions.h:
* libnautilus-private/nautilus-program-chooser.c:
(repopulate_program_list):
* libnautilus-private/nautilus-program-choosing.c:
(choose_component_callback):
* src/file-manager/fm-properties-window.c: (clear_bonobo_pages),
(refresh_bonobo_pages), (properties_window_file_changed_callback),
(bonobo_page_error_message), (bonobo_page_activate_callback),
(append_bonobo_pages):
* Activate the bonobo property pages asynchronously
* Hide the bonobo property pages from the component chooser
* Slightly modify the notes sidebar to also work as a property page
* Handle changes in the file type (add/remove pages)
2002-10-24 Dennis M. Cranston <dennis_cranston@yahoo.com>
* src/file-manager/fm-properties-window.[ch]:

View file

@ -13,6 +13,11 @@
<oaf_attribute name="nautilus:recommended_uri_schemes" type="stringv">
<item value="*"/>
</oaf_attribute>
<oaf_attribute name="bonobo:supported_mime_types" type="stringv">
<item value="*/*"/>
</oaf_attribute>
<oaf_attribute name="nautilus:view_as_name" type="string" _value="Notes"/>
<oaf_attribute name="nautilus:property_page_name" type="string" _value="Notes"/>
</oaf_server>
</oaf_info>

View file

@ -811,18 +811,25 @@ nautilus_mime_get_all_components_for_file (NautilusFile *file)
}
gboolean
nautilus_mime_has_any_components_for_file (NautilusFile *file)
nautilus_mime_has_any_components_for_file_extended (NautilusFile *file,
char *extra_reqs)
{
GList *list;
gboolean result;
list = nautilus_mime_get_all_components_for_file (file);
list = nautilus_mime_get_all_components_for_file_extended (file,
extra_reqs);
result = list != NULL;
gnome_vfs_mime_component_list_free (list);
return result;
}
gboolean
nautilus_mime_has_any_components_for_file (NautilusFile *file)
{
return nautilus_mime_has_any_components_for_file_extended (file, NULL);
}
static GList *
mime_get_all_components_for_uri_scheme (const char *uri_scheme)

View file

@ -45,6 +45,7 @@ GList * nautilus_mime_get_all_applications_for_file
GList * nautilus_mime_get_all_components_for_file (NautilusFile *file);
GList * nautilus_mime_get_all_components_for_file_extended (NautilusFile *file, char *extra_requirements);
gboolean nautilus_mime_has_any_components_for_file (NautilusFile *file);
gboolean nautilus_mime_has_any_components_for_file_extended (NautilusFile *file, char *extra_requirements);
gboolean nautilus_mime_has_any_applications_for_file (NautilusFile *file);
gboolean nautilus_mime_has_any_applications_for_file_type (NautilusFile *file);
GnomeVFSResult nautilus_mime_set_default_action_type_for_file (NautilusFile *file,

View file

@ -433,7 +433,7 @@ repopulate_program_list (NautilusProgramChooser *program_chooser)
gchar *program_name, *status_text;
GtkTreeIter iter;
GtkTreePath *path;
type = program_chooser->details->action_type;
g_assert (type == GNOME_VFS_MIME_ACTION_TYPE_COMPONENT
@ -441,7 +441,7 @@ repopulate_program_list (NautilusProgramChooser *program_chooser)
programs = type == GNOME_VFS_MIME_ACTION_TYPE_COMPONENT
? nautilus_mime_get_all_components_for_file (program_chooser->details->file)
? nautilus_mime_get_all_components_for_file_extended (program_chooser->details->file, "(NOT nautilus:property_page_name.defined)")
: nautilus_mime_get_all_applications_for_file (program_chooser->details->file);
list_store = program_chooser->details->list_store;

View file

@ -193,7 +193,8 @@ choose_component_callback (NautilusFile *file,
identifier = NULL;
dialog = NULL;
if (nautilus_mime_has_any_components_for_file (file)) {
if (nautilus_mime_has_any_components_for_file_extended (file,
"(NOT nautilus:property_page_name.defined()")) {
dialog = set_up_program_chooser (file, GNOME_VFS_MIME_ACTION_TYPE_COMPONENT,
choose_data->parent_window);
if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {

View file

@ -134,6 +134,12 @@ typedef struct {
FMDirectoryView *directory_view;
} StartupData;
typedef struct {
FMPropertiesWindow *window;
GtkWidget *vbox;
char *view_name;
} ActivationData;
/* drag and drop definitions */
@ -170,6 +176,8 @@ static void remove_pending_file (StartupData *data
gboolean cancel_timed_wait,
gboolean cancel_destroy_handler);
static void append_bonobo_pages (FMPropertiesWindow *window);
GNOME_CLASS_BOILERPLATE (FMPropertiesWindow, fm_properties_window,
GtkDialog, GTK_TYPE_DIALOG)
@ -619,7 +627,35 @@ update_properties_window_title (GtkWindow *window, NautilusFile *file)
}
static void
properties_window_file_changed_callback (GtkWindow *window, NautilusFile *file)
clear_bonobo_pages (FMPropertiesWindow *window)
{
int i;
int num_pages;
GtkWidget *page;
num_pages = gtk_notebook_get_n_pages
(GTK_NOTEBOOK (window->details->notebook));
for (i=0; i < num_pages; i++) {
page = gtk_notebook_get_nth_page
(GTK_NOTEBOOK (window->details->notebook), i);
if (g_object_get_data (G_OBJECT (page), "is-bonobo-page")) {
gtk_notebook_remove_page
(GTK_NOTEBOOK (window->details->notebook), i);
}
}
}
static void
refresh_bonobo_pages (FMPropertiesWindow *window)
{
clear_bonobo_pages (window);
append_bonobo_pages (window);
}
static void
properties_window_file_changed_callback (FMPropertiesWindow *window, NautilusFile *file)
{
g_assert (GTK_IS_WINDOW (window));
g_assert (NAUTILUS_IS_FILE (file));
@ -627,7 +663,26 @@ properties_window_file_changed_callback (GtkWindow *window, NautilusFile *file)
if (nautilus_file_is_gone (file)) {
gtk_widget_destroy (GTK_WIDGET (window));
} else {
update_properties_window_title (window, file);
char *orig_mime_type;
char *new_mime_type;
orig_mime_type = nautilus_file_get_mime_type
(window->details->target_file);
nautilus_file_unref (window->details->target_file);
window->details->target_file = nautilus_file_ref (file);
update_properties_window_title (GTK_WINDOW (window), file);
new_mime_type = nautilus_file_get_mime_type
(window->details->target_file);
if (strcmp (orig_mime_type, new_mime_type) == 0) {
refresh_bonobo_pages (window);
}
g_free (orig_mime_type);
g_free (new_mime_type);
}
}
@ -2108,30 +2163,82 @@ create_permissions_page (FMPropertiesWindow *window)
}
static GtkWidget *
bonobo_page_error_message (NautilusViewIdentifier *view_id,
CORBA_Environment *ev)
bonobo_page_error_message (const char *view_name,
const char *msg)
{
GtkWidget *hbox;
GtkWidget *label;
GtkWidget *image;
char *msg;
hbox = gtk_hbox_new (FALSE, GNOME_PAD);
image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR,
GTK_ICON_SIZE_DIALOG);
msg = g_strdup_printf ("There was an error while trying to create the view named `%s': %s", view_id->name, CORBA_exception_id (ev));
msg = g_strdup_printf ("There was an error while trying to create the view named `%s': %s", view_name, msg);
label = gtk_label_new (msg);
g_free (msg);
gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
gtk_widget_show_all (hbox);
return hbox;
}
static void
bonobo_page_activate_callback (CORBA_Object obj,
const char *error_reason,
gpointer user_data)
{
ActivationData *data;
FMPropertiesWindow *window;
GtkWidget *widget;
CORBA_Environment ev;
data = (ActivationData *)user_data;
window = data->window;
g_return_if_fail (FM_IS_PROPERTIES_WINDOW (window));
CORBA_exception_init (&ev);
widget = NULL;
if (obj != CORBA_OBJECT_NIL) {
Bonobo_Control control;
Nautilus_View view;
char *uri;
control = Bonobo_Unknown_queryInterface
(obj, "IDL:Bonobo/Control:1.0", &ev);
view = Bonobo_Unknown_queryInterface
(control, "IDL:Nautilus/View:1.0", &ev);
uri = nautilus_file_get_uri (window->details->target_file);
Nautilus_View_load_location (view, uri, &ev);
if (!BONOBO_EX (&ev)) {
widget = bonobo_widget_new_control_from_objref
(control, CORBA_OBJECT_NIL);
}
g_free (uri);
}
if (widget == NULL) {
widget = bonobo_page_error_message (data->view_name,
error_reason);
}
gtk_container_add (GTK_CONTAINER (data->vbox), widget);
gtk_widget_show (widget);
g_free (data->view_name);
g_free (data);
}
static void
append_bonobo_pages (FMPropertiesWindow *window)
{
@ -2149,54 +2256,28 @@ append_bonobo_pages (FMPropertiesWindow *window)
while (l != NULL) {
NautilusViewIdentifier *view_id;
Bonobo_ServerInfo *server;
GtkWidget *vbox, *widget;
Bonobo_Unknown obj;
widget = NULL;
ActivationData *data;
GtkWidget *vbox;
server = l->data;
l = l->next;
view_id = nautilus_view_identifier_new_from_property_page (server);
obj = bonobo_activation_activate_from_id (view_id->iid,
0, NULL, &ev);
if (!BONOBO_EX (&ev)) {
Bonobo_Control control;
Nautilus_View view;
char *uri;
control = Bonobo_Unknown_queryInterface
(obj, "IDL:Bonobo/Control:1.0", &ev);
view = Bonobo_Unknown_queryInterface
(control, "IDL:Nautilus/View:1.0", &ev);
uri = nautilus_file_get_uri
(window->details->target_file);
Nautilus_View_load_location (view, uri, &ev);
if (!BONOBO_EX (&ev)) {
widget = bonobo_widget_new_control_from_objref
(control, CORBA_OBJECT_NIL);
}
g_free (uri);
}
if (widget == NULL) {
widget = bonobo_page_error_message (view_id, &ev);
}
vbox = create_page_with_vbox (window->details->notebook,
view_id->name);
gtk_container_add (GTK_CONTAINER (vbox), widget);
gtk_widget_show_all (vbox);
nautilus_view_identifier_free (view_id);
/* just a tag...the value doesn't matter */
g_object_set_data (G_OBJECT (vbox), "is-bonobo-page",
vbox);
data = g_new (ActivationData, 1);
data->window = window;
data->vbox = vbox;
data->view_name = g_strdup (view_id->name);
bonobo_activation_activate_from_id_async (view_id->iid,
0, bonobo_page_activate_callback,
data, &ev);
}
}