Commit ac5b5739 authored by Andy Hertzfeld's avatar Andy Hertzfeld
Browse files

added nautilus_directory_background_is_set and used it to enable/disable


	added nautilus_directory_background_is_set and used it to
	enable/disable "reset background" menu item in fm-directory-view
parent 1e53144a
2000-06-29 Andy Hertzfeld <andy@eazel.com>
* libnautilus-extensions/nautilus-directory-background.c,h:
(directory_changed_callback),
(nautilus_directory_background_is_set),
(nautilus_connect_background_to_directory_metadata):
added nautilus_directory_background_is_set, and some cleanups
* src/file-manager/fm-directory-view.c: (compute_menu_item_info),
(fm_directory_view_real_update_menus):
used nautilus_directory_background_is_set to enable/disable item
2000-06-29 Pavel Cisler <pavel@eazel.com>
* libnautilus-extensions/nautilus-icon-dnd.h:
......
......@@ -125,24 +125,24 @@ directory_changed_callback (NautilusDirectory *directory,
image = nautilus_directory_get_metadata (directory,
NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_IMAGE,
NULL);
/* if there's none, read the default from the theme */
if (color == NULL && image == NULL) {
color = nautilus_theme_get_theme_data ("directory", NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_COLOR);
image = nautilus_theme_get_theme_data ("directory", NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_IMAGE);
image = local_data_file_to_uri(image);
}
nautilus_background_set_color (background, color);
nautilus_background_set_tile_image_uri (background, image);
g_free (color);
g_free (image);
/* Unblock the handler. */
gtk_signal_handler_unblock_by_func (GTK_OBJECT (background),
background_changed_callback,
directory);
/* Unblock the handler. */
gtk_signal_handler_unblock_by_func (GTK_OBJECT (background),
background_changed_callback,
directory);
}
/* handle the theme changing */
......@@ -225,39 +225,65 @@ dummy_callback (NautilusDirectory *directory,
{
}
/* return true if the background is not in the default state */
gboolean
nautilus_directory_background_is_set (NautilusBackground *background)
{
gboolean is_set;
NautilusDirectory *directory;
char *color, *image;
directory = NAUTILUS_DIRECTORY(gtk_object_get_data (GTK_OBJECT (background),
"nautilus_background_directory"));
color = nautilus_directory_get_metadata (directory,
NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_COLOR,
NULL);
image = nautilus_directory_get_metadata (directory,
NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_IMAGE,
NULL);
is_set = (color != NULL) || (image != NULL);
g_free (color);
g_free (image);
return is_set;
}
/* key routine that hooks up a background and directory */
void
nautilus_connect_background_to_directory_metadata (GtkWidget *widget,
NautilusDirectory *directory)
{
NautilusBackground *background;
gpointer old_directory;
NautilusBackground *background;
gpointer old_directory;
/* Get at the background object we'll be connecting. */
background = nautilus_get_widget_background (widget);
/* Check if it is already connected. */
old_directory = gtk_object_get_data (GTK_OBJECT (background),
/* Check if it is already connected. */
old_directory = gtk_object_get_data (GTK_OBJECT (background),
"nautilus_background_directory");
if (old_directory == directory) {
return;
}
/* Disconnect old signal handlers. */
if (old_directory != NULL) {
g_assert (NAUTILUS_IS_DIRECTORY (old_directory));
gtk_signal_disconnect_by_func (GTK_OBJECT (background),
if (old_directory == directory) {
return;
}
/* Disconnect old signal handlers. */
if (old_directory != NULL) {
g_assert (NAUTILUS_IS_DIRECTORY (old_directory));
gtk_signal_disconnect_by_func (GTK_OBJECT (background),
GTK_SIGNAL_FUNC (background_changed_callback),
old_directory);
gtk_signal_disconnect_by_func (GTK_OBJECT (background),
gtk_signal_disconnect_by_func (GTK_OBJECT (background),
GTK_SIGNAL_FUNC (background_destroyed_callback),
old_directory);
gtk_signal_disconnect_by_func (GTK_OBJECT (background),
gtk_signal_disconnect_by_func (GTK_OBJECT (background),
GTK_SIGNAL_FUNC (background_reset_callback),
old_directory);
gtk_signal_disconnect_by_func (GTK_OBJECT (old_directory),
gtk_signal_disconnect_by_func (GTK_OBJECT (old_directory),
GTK_SIGNAL_FUNC (directory_changed_callback),
background);
nautilus_directory_file_monitor_remove (old_directory, background);
nautilus_directory_file_monitor_remove (old_directory, background);
nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_THEME,
nautilus_directory_background_theme_changed,
background);
......
......@@ -26,8 +26,10 @@
#include <gtk/gtkwidget.h>
#include "nautilus-directory.h"
#include "nautilus-background.h"
void nautilus_connect_background_to_directory_metadata (GtkWidget *widget,
NautilusDirectory *directory);
void nautilus_connect_background_to_directory_metadata_by_uri (GtkWidget *widget,
const char *uri);
gboolean nautilus_directory_background_is_set (NautilusBackground *background);
......@@ -125,24 +125,24 @@ directory_changed_callback (NautilusDirectory *directory,
image = nautilus_directory_get_metadata (directory,
NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_IMAGE,
NULL);
/* if there's none, read the default from the theme */
if (color == NULL && image == NULL) {
color = nautilus_theme_get_theme_data ("directory", NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_COLOR);
image = nautilus_theme_get_theme_data ("directory", NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_IMAGE);
image = local_data_file_to_uri(image);
}
nautilus_background_set_color (background, color);
nautilus_background_set_tile_image_uri (background, image);
g_free (color);
g_free (image);
/* Unblock the handler. */
gtk_signal_handler_unblock_by_func (GTK_OBJECT (background),
background_changed_callback,
directory);
/* Unblock the handler. */
gtk_signal_handler_unblock_by_func (GTK_OBJECT (background),
background_changed_callback,
directory);
}
/* handle the theme changing */
......@@ -225,39 +225,65 @@ dummy_callback (NautilusDirectory *directory,
{
}
/* return true if the background is not in the default state */
gboolean
nautilus_directory_background_is_set (NautilusBackground *background)
{
gboolean is_set;
NautilusDirectory *directory;
char *color, *image;
directory = NAUTILUS_DIRECTORY(gtk_object_get_data (GTK_OBJECT (background),
"nautilus_background_directory"));
color = nautilus_directory_get_metadata (directory,
NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_COLOR,
NULL);
image = nautilus_directory_get_metadata (directory,
NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_IMAGE,
NULL);
is_set = (color != NULL) || (image != NULL);
g_free (color);
g_free (image);
return is_set;
}
/* key routine that hooks up a background and directory */
void
nautilus_connect_background_to_directory_metadata (GtkWidget *widget,
NautilusDirectory *directory)
{
NautilusBackground *background;
gpointer old_directory;
NautilusBackground *background;
gpointer old_directory;
/* Get at the background object we'll be connecting. */
background = nautilus_get_widget_background (widget);
/* Check if it is already connected. */
old_directory = gtk_object_get_data (GTK_OBJECT (background),
/* Check if it is already connected. */
old_directory = gtk_object_get_data (GTK_OBJECT (background),
"nautilus_background_directory");
if (old_directory == directory) {
return;
}
/* Disconnect old signal handlers. */
if (old_directory != NULL) {
g_assert (NAUTILUS_IS_DIRECTORY (old_directory));
gtk_signal_disconnect_by_func (GTK_OBJECT (background),
if (old_directory == directory) {
return;
}
/* Disconnect old signal handlers. */
if (old_directory != NULL) {
g_assert (NAUTILUS_IS_DIRECTORY (old_directory));
gtk_signal_disconnect_by_func (GTK_OBJECT (background),
GTK_SIGNAL_FUNC (background_changed_callback),
old_directory);
gtk_signal_disconnect_by_func (GTK_OBJECT (background),
gtk_signal_disconnect_by_func (GTK_OBJECT (background),
GTK_SIGNAL_FUNC (background_destroyed_callback),
old_directory);
gtk_signal_disconnect_by_func (GTK_OBJECT (background),
gtk_signal_disconnect_by_func (GTK_OBJECT (background),
GTK_SIGNAL_FUNC (background_reset_callback),
old_directory);
gtk_signal_disconnect_by_func (GTK_OBJECT (old_directory),
gtk_signal_disconnect_by_func (GTK_OBJECT (old_directory),
GTK_SIGNAL_FUNC (directory_changed_callback),
background);
nautilus_directory_file_monitor_remove (old_directory, background);
nautilus_directory_file_monitor_remove (old_directory, background);
nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_THEME,
nautilus_directory_background_theme_changed,
background);
......
......@@ -26,8 +26,10 @@
#include <gtk/gtkwidget.h>
#include "nautilus-directory.h"
#include "nautilus-background.h"
void nautilus_connect_background_to_directory_metadata (GtkWidget *widget,
NautilusDirectory *directory);
void nautilus_connect_background_to_directory_metadata_by_uri (GtkWidget *widget,
const char *uri);
gboolean nautilus_directory_background_is_set (NautilusBackground *background);
......@@ -51,6 +51,8 @@
#include <libnautilus-extensions/nautilus-alloc.h>
#include <libnautilus-extensions/nautilus-background.h>
#include <libnautilus-extensions/nautilus-directory.h>
#include <libnautilus-extensions/nautilus-directory-background.h>
#include <libnautilus-extensions/nautilus-drag.h>
#include <libnautilus-extensions/nautilus-file-attributes.h>
#include <libnautilus-extensions/nautilus-glib-extensions.h>
......@@ -2000,7 +2002,7 @@ compute_menu_item_info (FMDirectoryView *directory_view,
*return_sensitivity = files_have_any_custom_images (selection);
} else if (strcmp (path, FM_DIRECTORY_VIEW_MENU_PATH_RESET_BACKGROUND) == 0) {
name = g_strdup (_("Reset _Background"));
*return_sensitivity = nautilus_background_is_set
*return_sensitivity = nautilus_directory_background_is_set
(fm_directory_view_get_background (directory_view));
} else {
g_assert_not_reached ();
......@@ -2726,10 +2728,8 @@ fm_directory_view_real_update_menus (FMDirectoryView *view)
FM_DIRECTORY_VIEW_MENU_PATH_SHOW_PROPERTIES);
update_one_menu_item (view, handler, selection,
FM_DIRECTORY_VIEW_MENU_PATH_EMPTY_TRASH);
update_one_menu_item (view, handler, selection,
update_one_menu_item (view, handler, selection,
FM_DIRECTORY_VIEW_MENU_PATH_REMOVE_CUSTOM_ICONS);
update_one_menu_item (view, handler, selection,
FM_DIRECTORY_VIEW_MENU_PATH_RESET_BACKGROUND);
nautilus_file_list_free (selection);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment