Commit e52cc990 authored by John Sullivan's avatar John Sullivan Committed by John Sullivan
Browse files

Added a missing space.

2000-05-25  John Sullivan  <sullivan@eazel.com>

	* src/ntl-app.c: (display_caveat): Added a missing space.


	More work on the "Open with Other" dialogs. Most of
	the UI features are present now, but they don't do
	anything since there's no API to call yet.

	* libnautilus-extensions/nautilus-gtk-extensions.h,
	* libnautilus-extensions/nautilus-gtk-extensions.c:
	(nautilus_gtk_clist_get_first_selected_row),
	(nautilus_gtk_clist_get_last_selected_row):
	Moved these functions to here from NautilusList, since
	they only require a GtkCList and I needed to use one
	of them outside of NautilusList.

	* libnautilus-extensions/nautilus-list.c:
	(nautilus_list_get_first_selected_row),
	(nautilus_list_get_last_selected_row),
	(nautilus_list_keyboard_navigation_key_press),
	(nautilus_list_new_with_titles):
	Removed get_first and get_last_selected_row, and updated
	callers to call new nautilus_gtk_clist versions.

	* libnautilus-extensions/nautilus-program-chooser.c:
	(populate_program_list), (nautilus_program_chooser_get_file),
	(nautilus_program_chooser_get_clist),
	(nautilus_program_chooser_get_frame),
	(nautilus_program_chooser_get_status_label),
	(nautilus_program_chooser_set_file),
	(nautilus_program_chooser_set_clist),
	(nautilus_program_chooser_set_frame),
	(nautilus_program_chooser_set_status_label), (is_in_short_list),
	(is_in_metadata_list), (update_selected_item_details),
	(program_list_selection_changed_callback), (pack_radio_button),
	(run_program_configurator_callback),
	(nautilus_program_chooser_new):
	Whole bunch of changes to push the "Open with Other" dialogs
	closer to reality.

	* src/ntl-window.c:
	(view_menu_choose_view_callback): Comment changes only.
	(nautilus_window_load_content_view_menu): Changed menu item
	text from "View as ..." to "View as Other..."
parent 082b0a23
2000-05-25 John Sullivan <sullivan@eazel.com>
* src/ntl-app.c: (display_caveat): Added a missing space.
More work on the "Open with Other" dialogs. Most of
the UI features are present now, but they don't do
anything since there's no API to call yet.
* libnautilus-extensions/nautilus-gtk-extensions.h,
* libnautilus-extensions/nautilus-gtk-extensions.c:
(nautilus_gtk_clist_get_first_selected_row),
(nautilus_gtk_clist_get_last_selected_row):
Moved these functions to here from NautilusList, since
they only require a GtkCList and I needed to use one
of them outside of NautilusList.
* libnautilus-extensions/nautilus-list.c:
(nautilus_list_get_first_selected_row),
(nautilus_list_get_last_selected_row),
(nautilus_list_keyboard_navigation_key_press),
(nautilus_list_new_with_titles):
Removed get_first and get_last_selected_row, and updated
callers to call new nautilus_gtk_clist versions.
* libnautilus-extensions/nautilus-program-chooser.c:
(populate_program_list), (nautilus_program_chooser_get_file),
(nautilus_program_chooser_get_clist),
(nautilus_program_chooser_get_frame),
(nautilus_program_chooser_get_status_label),
(nautilus_program_chooser_set_file),
(nautilus_program_chooser_set_clist),
(nautilus_program_chooser_set_frame),
(nautilus_program_chooser_set_status_label), (is_in_short_list),
(is_in_metadata_list), (update_selected_item_details),
(program_list_selection_changed_callback), (pack_radio_button),
(run_program_configurator_callback),
(nautilus_program_chooser_new):
Whole bunch of changes to push the "Open with Other" dialogs
closer to reality.
* src/ntl-window.c:
(view_menu_choose_view_callback): Comment changes only.
(nautilus_window_load_content_view_menu): Changed menu item
text from "View as ..." to "View as Other..."
2000-05-25 Darin Adler <darin@eazel.com>
* libnautilus-extensions/nautilus-file.c:
I am getting a little careless. This must end.
* libnautilus-extensions/nautilus-file.c:
......
......@@ -32,6 +32,62 @@
#include <libgnomeui/gnome-geometry.h>
#include "nautilus-glib-extensions.h"
/**
* nautilus_gtk_clist_get_first_selected_row:
*
* Get the index of the first selected row, or -1 if no rows are selected.
* @list: Any GtkCList
**/
int
nautilus_gtk_clist_get_first_selected_row (GtkCList *list)
{
GtkCListRow *row;
GList *p;
int row_number;
g_return_val_if_fail (GTK_IS_CLIST (list), -1);
row_number = 0;
for (p = GTK_CLIST (list)->row_list; p != NULL; p = p->next) {
row = p->data;
if (row->state == GTK_STATE_SELECTED) {
return row_number;
}
++row_number;
}
return -1;
}
/**
* nautilus_gtk_clist_get_last_selected_row:
*
* Get the index of the last selected row, or -1 if no rows are selected.
* @list: Any GtkCList
**/
int
nautilus_gtk_clist_get_last_selected_row (GtkCList *list)
{
GtkCListRow *row;
GList *p;
int row_number;
g_return_val_if_fail (GTK_IS_CLIST (list), -1);
row_number = GTK_CLIST (list)->rows - 1;
for (p = GTK_CLIST (list)->row_list_end; p != NULL; p = p->prev) {
row = p->data;
if (row->state == GTK_STATE_SELECTED) {
return row_number;
}
--row_number;
}
return -1;
}
/**
* nautilus_gtk_signal_connect_free_data:
*
......
......@@ -27,11 +27,16 @@
#ifndef NAUTILUS_GTK_EXTENSIONS_H
#define NAUTILUS_GTK_EXTENSIONS_H
#include <gtk/gtkclist.h>
#include <gtk/gtkmenu.h>
#include <gtk/gtkwindow.h>
#define NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT 2
/* GtkCList */
int nautilus_gtk_clist_get_first_selected_row (GtkCList *list);
int nautilus_gtk_clist_get_last_selected_row (GtkCList *list);
/* signals */
guint nautilus_gtk_signal_connect_free_data (GtkObject *object,
const gchar *name,
......
......@@ -42,6 +42,7 @@
#include "nautilus-gdk-pixbuf-extensions.h"
#include "nautilus-glib-extensions.h"
#include "nautilus-global-preferences.h"
#include "nautilus-gtk-extensions.h"
#include "nautilus-gtk-macros.h"
#include "nautilus-list-column-title.h"
......@@ -206,8 +207,6 @@ static void nautilus_list_drag_data_received (GtkWidget *w
guint time);
static void nautilus_list_clear_keyboard_focus (NautilusList *list);
static void nautilus_list_draw_focus (GtkWidget *widget);
static int nautilus_list_get_first_selected_row (NautilusList *list);
static int nautilus_list_get_last_selected_row (NautilusList *list);
static gint nautilus_list_key_press (GtkWidget *widget,
GdkEventKey *event);
static void nautilus_list_unselect_all (GtkCList *clist);
......@@ -1030,8 +1029,8 @@ nautilus_list_keyboard_navigation_key_press (NautilusList *list, GdkEventKey *ev
start_row = clist->focus_row;
} else {
start_row = (scroll_type == GTK_SCROLL_STEP_FORWARD || scroll_type == GTK_SCROLL_PAGE_FORWARD ?
nautilus_list_get_last_selected_row (list) :
nautilus_list_get_first_selected_row (list));
nautilus_gtk_clist_get_last_selected_row (clist) :
nautilus_gtk_clist_get_first_selected_row (clist));
}
/* If there's no row to start with, select the row farthest toward the end.
......@@ -2438,50 +2437,6 @@ nautilus_list_new_with_titles (int columns, const char * const *titles)
return GTK_WIDGET (list);
}
static int
nautilus_list_get_first_selected_row (NautilusList *list)
{
GtkCListRow *row;
GList *p;
int row_number;
g_return_val_if_fail (NAUTILUS_IS_LIST (list), -1);
row_number = 0;
for (p = GTK_CLIST (list)->row_list; p != NULL; p = p->next) {
row = p->data;
if (row->state == GTK_STATE_SELECTED) {
return row_number;
}
++row_number;
}
return -1;
}
static int
nautilus_list_get_last_selected_row (NautilusList *list)
{
GtkCListRow *row;
GList *p;
int row_number;
g_return_val_if_fail (NAUTILUS_IS_LIST (list), -1);
row_number = GTK_CLIST (list)->rows - 1;
for (p = GTK_CLIST (list)->row_list_end; p != NULL; p = p->prev) {
row = p->data;
if (row->state == GTK_STATE_SELECTED) {
return row_number;
}
--row_number;
}
return -1;
}
GList *
nautilus_list_get_selection (NautilusList *list)
{
......
......@@ -26,8 +26,12 @@
#include <config.h>
#include "nautilus-program-chooser.h"
#include <gtk/gtkcheckbutton.h>
#include "nautilus-gtk-extensions.h"
#include <gtk/gtkradiobutton.h>
#include <gtk/gtkclist.h>
#include <gtk/gtkframe.h>
#include <gtk/gtkhbox.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkscrolledwindow.h>
#include <gtk/gtkvbox.h>
......@@ -50,7 +54,7 @@
* Hardwire an initial window size here, but let user resize
* bigger or smaller.
*/
#define PROGRAM_CHOOSER_DEFAULT_HEIGHT 272
#define PROGRAM_CHOOSER_DEFAULT_HEIGHT 303
static void
populate_program_list (NautilusProgramChooserType type,
......@@ -65,7 +69,7 @@ populate_program_list (NautilusProgramChooserType type,
for (i = 0; i < 10; ++i) {
/* One extra slot so it's NULL-terminated */
text = g_new0 (char *, PROGRAM_LIST_COLUMN_COUNT+1);
text[PROGRAM_LIST_NAME_COLUMN] = g_strdup_printf ("Viewer %d", i+1);
text[PROGRAM_LIST_NAME_COLUMN] = g_strdup_printf ("View as Viewer %d", i+1);
gtk_clist_append (clist, text);
g_strfreev (text);
......@@ -82,16 +86,284 @@ populate_program_list (NautilusProgramChooserType type,
}
}
}
static NautilusFile *
nautilus_program_chooser_get_file (GnomeDialog *chooser)
{
return NAUTILUS_FILE (gtk_object_get_data (GTK_OBJECT (chooser), "file"));
}
static GtkCList *
nautilus_program_chooser_get_clist (GnomeDialog *chooser)
{
return GTK_CLIST (gtk_object_get_data (GTK_OBJECT (chooser), "clist"));
}
static GtkFrame *
nautilus_program_chooser_get_frame (GnomeDialog *chooser)
{
return GTK_FRAME (gtk_object_get_data (GTK_OBJECT (chooser), "frame"));
}
static GtkLabel *
nautilus_program_chooser_get_status_label (GnomeDialog *chooser)
{
return GTK_LABEL (gtk_object_get_data (GTK_OBJECT (chooser), "status_label"));
}
static void
nautilus_program_chooser_set_file (GnomeDialog *chooser, NautilusFile *file)
{
nautilus_file_ref (file);
gtk_object_set_data_full (GTK_OBJECT (chooser),
"file",
file,
(GtkDestroyNotify)nautilus_file_unref);
}
static void
nautilus_program_chooser_set_clist (GnomeDialog *chooser, GtkCList *clist)
{
gtk_object_set_data (GTK_OBJECT (chooser), "clist", clist);
}
static void
nautilus_program_chooser_set_frame (GnomeDialog *chooser, GtkFrame *frame)
{
gtk_object_set_data (GTK_OBJECT (chooser), "frame", frame);
}
static void
nautilus_program_chooser_set_status_label (GnomeDialog *chooser, GtkLabel *status_label)
{
gtk_object_set_data (GTK_OBJECT (chooser), "status_label", status_label);
}
static gboolean
is_in_short_list (NautilusFile *file, const char *program_name) {
/* FIXME: This needs to use the real API when there is a
* real API. Passing the program name won't be good enough.
* For now, just return hardwired values.
*/
g_assert (NAUTILUS_IS_FILE (file));
g_assert (program_name != NULL);
return FALSE;
}
static gboolean
is_in_metadata_list (NautilusFile *file, const char *program_name) {
/* FIXME: This needs to use the real API when there is a
* real API. Passing the program name won't be good enough.
* For now, just return hardwired values.
*/
g_assert (NAUTILUS_IS_FILE (file));
g_assert (program_name != NULL);
return TRUE;
}
static void
update_selected_item_details (GnomeDialog *dialog)
{
NautilusFile *file;
GtkCList *clist;
GtkFrame *frame;
GtkLabel *status_label;
int selected_row;
char *row_text;
char *frame_label_text, *status_label_text;
char *file_type, *file_name;
file = nautilus_program_chooser_get_file (dialog);
clist = nautilus_program_chooser_get_clist (dialog);
frame = nautilus_program_chooser_get_frame (dialog);
status_label = nautilus_program_chooser_get_status_label (dialog);
selected_row = nautilus_gtk_clist_get_first_selected_row (clist);
if (selected_row >= 0 && gtk_clist_get_text (clist,
selected_row,
PROGRAM_LIST_NAME_COLUMN,
&row_text)) {
/* row_text is now a pointer to the text in the list. */
frame_label_text = g_strdup (row_text);
if (is_in_short_list (file, frame_label_text)) {
file_type = nautilus_file_get_string_attribute (file, "type");
status_label_text = g_strdup_printf (_("Is in the menu for all \"%s\" items."),
file_type);
g_free (file_type);
} else if (is_in_metadata_list (file, frame_label_text)) {
file_name = nautilus_file_get_name (file);
status_label_text = g_strdup_printf (_("Is in the menu for \"%s\"."),
file_name);
g_free (file_name);
} else {
file_name = nautilus_file_get_name (file);
status_label_text = g_strdup_printf (_("Is not in the menu for \"%s\"."),
file_name);
g_free (file_name);
}
} else {
frame_label_text = NULL;
status_label_text = NULL;
}
gtk_frame_set_label (frame, frame_label_text);
gtk_label_set_text (status_label, status_label_text);
g_free (frame_label_text);
g_free (status_label_text);
}
static void
program_list_selection_changed_callback (GtkCList *clist,
gint row,
gint column,
GdkEventButton *event,
gpointer user_data)
{
g_assert (GTK_IS_CLIST (clist));
g_assert (GNOME_IS_DIALOG (user_data));
update_selected_item_details (GNOME_DIALOG (user_data));
}
static GtkRadioButton *
pack_radio_button (GtkBox *box, const char *label_text, GtkRadioButton *group)
{
GtkWidget *radio_button;
radio_button = gtk_radio_button_new_with_label_from_widget (group, label_text);
gtk_widget_show (radio_button);
gtk_box_pack_start_defaults (box, radio_button);
return GTK_RADIO_BUTTON (radio_button);
}
static void
run_program_configurator_callback (GtkWidget *button, gpointer callback_data)
{
GnomeDialog *program_chooser;
NautilusFile *file;
GtkCList *clist;
GtkWidget *dialog;
GtkRadioButton *type_radio_button, *item_radio_button, *none_radio_button;
GtkRadioButton *old_active_button;
char *radio_button_text;
char *file_type, *file_name;
char *row_text;
char *title;
int selected_row;
g_assert (GNOME_IS_DIALOG (callback_data));
program_chooser = GNOME_DIALOG (callback_data);
file = nautilus_program_chooser_get_file (program_chooser);
clist = nautilus_program_chooser_get_clist (program_chooser);
selected_row = nautilus_gtk_clist_get_first_selected_row (clist);
if (selected_row < 0 || !gtk_clist_get_text (clist,
selected_row,
PROGRAM_LIST_NAME_COLUMN,
&row_text)) {
/* No valid selected item, don't do anything. Probably the UI
* should prevent this.
*/
return;
}
title = g_strdup_printf (_("Change %s"), row_text);
dialog = gnome_dialog_new (title,
GNOME_STOCK_BUTTON_OK,
GNOME_STOCK_BUTTON_CANCEL,
NULL);
g_free (title);
/* Radio button for adding to short list for file type. */
file_type = nautilus_file_get_string_attribute (file, "type");
radio_button_text = g_strdup_printf ("Include %s in the menu for all \"%s\" items",
row_text, file_type);
type_radio_button = pack_radio_button (GTK_BOX (GNOME_DIALOG (dialog)->vbox),
radio_button_text,
NULL);
g_free (file_type);
g_free (radio_button_text);
/* Radio button for adding to short list for specific file. */
file_name = nautilus_file_get_name (file);
radio_button_text = g_strdup_printf ("Include %s in the menu just for \"%s\"",
row_text, file_name);
item_radio_button = pack_radio_button (GTK_BOX (GNOME_DIALOG (dialog)->vbox),
radio_button_text,
type_radio_button);
g_free (radio_button_text);
/* Radio button for not including program in short list for type or file. */
radio_button_text = g_strdup_printf ("Don't include %s in the menu for \"%s\"",
row_text, file_name);
none_radio_button = pack_radio_button (GTK_BOX (GNOME_DIALOG (dialog)->vbox),
radio_button_text,
item_radio_button);
g_free (file_name);
g_free (radio_button_text);
/* Activate the correct radio button. */
if (is_in_short_list (file, row_text)) {
old_active_button = type_radio_button;
} else if (is_in_metadata_list (file, row_text)) {
old_active_button = item_radio_button;
} else {
old_active_button = none_radio_button;
}
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (old_active_button), TRUE);
/* Buttons close this dialog. */
gnome_dialog_set_close (GNOME_DIALOG (dialog), TRUE);
/* Make OK button the default. */
gnome_dialog_set_default (GNOME_DIALOG (dialog), GNOME_OK);
gnome_dialog_set_parent (GNOME_DIALOG (dialog), GTK_WINDOW (program_chooser));
/* Don't destroy on close because callers will need
* to extract some information from the dialog after
* it closes.
*/
gnome_dialog_close_hides (GNOME_DIALOG (dialog), TRUE);
if (gnome_dialog_run (GNOME_DIALOG (dialog)) == GNOME_OK) {
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (old_active_button))) {
g_message ("no change");
} else {
g_message ("user chose different radio button, will update when API is available");
update_selected_item_details (program_chooser);
}
}
gtk_widget_destroy (dialog);
}
GnomeDialog *
nautilus_program_chooser_new (NautilusProgramChooserType type,
NautilusFile *file)
{
GtkWidget *window;
GtkWidget *dialog_vbox;
GtkWidget *prompt_label;
GtkWidget *list_scroller, *clist;
GtkWidget *remember_for_type, *remember_for_file;
GtkWidget *frame;
GtkWidget *framed_hbox;
GtkWidget *status_label;
GtkWidget *change_button_holder;
GtkWidget *change_button;
char *file_name, *prompt;
const char *title;
......@@ -101,19 +373,20 @@ nautilus_program_chooser_new (NautilusProgramChooserType type,
switch (type) {
case NAUTILUS_PROGRAM_CHOOSER_APPLICATIONS:
title = _("Nautilus: Choose an application");
title = _("Nautilus: Open with Other");
prompt = g_strdup_printf (_("Choose an application with which to open \"%s\"."), file_name);
break;
case NAUTILUS_PROGRAM_CHOOSER_COMPONENTS:
default:
title = _("Nautilus: Choose a viewer");
prompt = g_strdup_printf (_("Choose a viewer with which to display \"%s\"."), file_name);
title = _("Nautilus: View as Other");
prompt = g_strdup_printf (_("Choose a view for \"%s\"."), file_name);
break;
}
g_free (file_name);
window = gnome_dialog_new (title,
GNOME_STOCK_BUTTON_OK,
_("Choose"),
GNOME_STOCK_BUTTON_CANCEL,
NULL);
gtk_container_set_border_width (GTK_CONTAINER (window), GNOME_PAD);
......@@ -122,14 +395,14 @@ nautilus_program_chooser_new (NautilusProgramChooserType type,
NO_DEFAULT_MAGIC_NUMBER,
PROGRAM_CHOOSER_DEFAULT_HEIGHT);
dialog_vbox = GNOME_DIALOG (window)->vbox;
/* Prompt at top of dialog. */
prompt_label = gtk_label_new (prompt);
gtk_widget_show (prompt_label);
g_free (prompt);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (window)->vbox),
prompt_label,
FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (dialog_vbox), prompt_label, FALSE, FALSE, 0);
/* Scrolling list to hold choices. */
list_scroller = gtk_scrolled_window_new (NULL, NULL);
......@@ -146,24 +419,55 @@ nautilus_program_chooser_new (NautilusProgramChooserType type,
gtk_container_add (GTK_CONTAINER (list_scroller), clist);
gtk_clist_column_titles_hide (GTK_CLIST (clist));
/* Checkboxes to remember these for later. */
remember_for_type = gtk_check_button_new_with_label (_("Always offer this program with this document type."));
gtk_widget_show (remember_for_type);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (window)->vbox),
remember_for_type,
FALSE, FALSE, 0);
/* Framed area with selection-specific details */
frame = gtk_frame_new (NULL);
gtk_widget_show (frame);
gtk_box_pack_start (GTK_BOX (dialog_vbox), frame, FALSE, FALSE, 0);
framed_hbox = gtk_hbox_new (FALSE, GNOME_PAD);
gtk_widget_show (framed_hbox);
gtk_container_add (GTK_CONTAINER (frame), framed_hbox);
gtk_container_set_border_width (GTK_CONTAINER (framed_hbox), GNOME_PAD);
status_label = gtk_label_new (NULL);
gtk_label_set_justify (GTK_LABEL (status_label), GTK_JUSTIFY_LEFT);
gtk_widget_show (status_label);
gtk_box_pack_start (GTK_BOX (framed_hbox), status_label, FALSE, FALSE, 0);
change_button_holder = gtk_vbox_new (FALSE, 0);
gtk_widget_show (change_button_holder);
gtk_box_pack_end (GTK_BOX (framed_hbox), change_button_holder, FALSE, FALSE, 0);
remember_for_file = gtk_check_button_new_with_label (_("Always offer this program with this document."));
gtk_widget_show (remember_for_file);
gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (window)->vbox),
remember_for_file,
FALSE, FALSE, 0);
change_button = gtk_button_new_with_label(_("Change..."));
gtk_widget_show (change_button);