Added fields location_mode_box, location_pathbar_radio,
2006-03-24 Federico Mena Quintero <federico@novell.com> * gtk/gtkfilechooserprivate.h (struct _GtkFileChooserDefault): Added fields location_mode_box, location_pathbar_radio, location_filename_radio, location_widget_box, location_label, location_entry. The radio buttons will switch between the pathbar and the location entry; the other boxes are for layout purposes. (enum LocationMode): New enum. (struct _GtkFileChooserDefault): Added a location_mode field. * gtk/gtkfilechooserdefault.c (browse_widgets_create): Create the location radio buttons to switch between the pathbar and the location entry. Pack the browse_path_bar in the new location_widget_box instead of a generic hbox. (location_buttons_create): New function. (gtk_file_chooser_default_init): Initialize impl->location_mode. (location_switch_to_path_bar): New function. (location_switch_to_filename_entry): New function. * gtk/gtkfilechooserbutton.c (model_add_special): The display_name should not be const.
This commit is contained in:
committed by
Federico Mena Quintero
parent
9e4fe9ded3
commit
8d17642575
22
ChangeLog
22
ChangeLog
@@ -1,3 +1,25 @@
|
||||
2006-03-24 Federico Mena Quintero <federico@novell.com>
|
||||
|
||||
* gtk/gtkfilechooserprivate.h (struct _GtkFileChooserDefault):
|
||||
Added fields location_mode_box, location_pathbar_radio,
|
||||
location_filename_radio, location_widget_box, location_label,
|
||||
location_entry. The radio buttons will switch between the pathbar
|
||||
and the location entry; the other boxes are for layout purposes.
|
||||
(enum LocationMode): New enum.
|
||||
(struct _GtkFileChooserDefault): Added a location_mode field.
|
||||
|
||||
* gtk/gtkfilechooserdefault.c (browse_widgets_create): Create the
|
||||
location radio buttons to switch between the pathbar and the
|
||||
location entry. Pack the browse_path_bar in the new
|
||||
location_widget_box instead of a generic hbox.
|
||||
(location_buttons_create): New function.
|
||||
(gtk_file_chooser_default_init): Initialize impl->location_mode.
|
||||
(location_switch_to_path_bar): New function.
|
||||
(location_switch_to_filename_entry): New function.
|
||||
|
||||
* gtk/gtkfilechooserbutton.c (model_add_special): The display_name
|
||||
should not be const.
|
||||
|
||||
2006-03-24 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* gtk/gtktextview.c (gtk_text_view_value_changed): Don't call
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
2006-03-24 Federico Mena Quintero <federico@novell.com>
|
||||
|
||||
* gtk/gtkfilechooserprivate.h (struct _GtkFileChooserDefault):
|
||||
Added fields location_mode_box, location_pathbar_radio,
|
||||
location_filename_radio, location_widget_box, location_label,
|
||||
location_entry. The radio buttons will switch between the pathbar
|
||||
and the location entry; the other boxes are for layout purposes.
|
||||
(enum LocationMode): New enum.
|
||||
(struct _GtkFileChooserDefault): Added a location_mode field.
|
||||
|
||||
* gtk/gtkfilechooserdefault.c (browse_widgets_create): Create the
|
||||
location radio buttons to switch between the pathbar and the
|
||||
location entry. Pack the browse_path_bar in the new
|
||||
location_widget_box instead of a generic hbox.
|
||||
(location_buttons_create): New function.
|
||||
(gtk_file_chooser_default_init): Initialize impl->location_mode.
|
||||
(location_switch_to_path_bar): New function.
|
||||
(location_switch_to_filename_entry): New function.
|
||||
|
||||
* gtk/gtkfilechooserbutton.c (model_add_special): The display_name
|
||||
should not be const.
|
||||
|
||||
2006-03-24 Matthias Clasen <mclasen@redhat.com>
|
||||
|
||||
* gtk/gtktextview.c (gtk_text_view_value_changed): Don't call
|
||||
|
||||
@@ -1,392 +0,0 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include <demos.h>
|
||||
|
||||
static GtkTextBuffer *info_buffer;
|
||||
static GtkTextBuffer *source_buffer;
|
||||
|
||||
static gchar *current_file = NULL;
|
||||
|
||||
enum {
|
||||
TITLE_COLUMN,
|
||||
FILENAME_COLUMN,
|
||||
FUNC_COLUMN,
|
||||
ITALIC_COLUMN,
|
||||
NUM_COLUMNS
|
||||
};
|
||||
|
||||
gboolean
|
||||
read_line (FILE *stream, GString *str)
|
||||
{
|
||||
int n_read = 0;
|
||||
|
||||
flockfile (stream);
|
||||
|
||||
g_string_truncate (str, 0);
|
||||
|
||||
while (1)
|
||||
{
|
||||
int c;
|
||||
|
||||
c = getc_unlocked (stream);
|
||||
|
||||
if (c == EOF)
|
||||
goto done;
|
||||
else
|
||||
n_read++;
|
||||
|
||||
switch (c)
|
||||
{
|
||||
case '\r':
|
||||
case '\n':
|
||||
{
|
||||
int next_c = getc_unlocked (stream);
|
||||
|
||||
if (!(next_c == EOF ||
|
||||
(c == '\r' && next_c == '\n') ||
|
||||
(c == '\n' && next_c == '\r')))
|
||||
ungetc (next_c, stream);
|
||||
|
||||
goto done;
|
||||
}
|
||||
default:
|
||||
g_string_append_c (str, c);
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
|
||||
funlockfile (stream);
|
||||
|
||||
return n_read > 0;
|
||||
}
|
||||
|
||||
void
|
||||
load_file (const gchar *filename)
|
||||
{
|
||||
FILE *file;
|
||||
GtkTextIter start, end;
|
||||
GString *buffer = g_string_new (NULL);
|
||||
int state = 0;
|
||||
gboolean in_para = 0;
|
||||
|
||||
if (current_file && !strcmp (current_file, filename))
|
||||
return;
|
||||
|
||||
g_free (current_file);
|
||||
current_file = g_strdup (filename);
|
||||
|
||||
gtk_text_buffer_get_bounds (info_buffer, &start, &end);
|
||||
gtk_text_buffer_delete (info_buffer, &start, &end);
|
||||
|
||||
gtk_text_buffer_get_bounds (source_buffer, &start, &end);
|
||||
gtk_text_buffer_delete (source_buffer, &start, &end);
|
||||
|
||||
file = fopen (filename, "r");
|
||||
if (!file)
|
||||
{
|
||||
g_warning ("Cannot open %s: %s\n", filename, g_strerror (errno));
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_text_buffer_get_iter_at_offset (info_buffer, &start, 0);
|
||||
while (read_line (file, buffer))
|
||||
{
|
||||
gchar *p = buffer->str;
|
||||
gchar *q;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case 0:
|
||||
/* Reading title */
|
||||
while (*p == '/' || *p == '*' || isspace (*p))
|
||||
p++;
|
||||
q = p + strlen (p);
|
||||
while (q > p && isspace (*(q - 1)))
|
||||
q--;
|
||||
|
||||
if (q > p)
|
||||
{
|
||||
int len_chars = g_utf8_pointer_to_offset (p, q);
|
||||
|
||||
end = start;
|
||||
|
||||
g_assert (strlen (p) >= q - p);
|
||||
gtk_text_buffer_insert (info_buffer, &end, p, q - p);
|
||||
start = end;
|
||||
|
||||
gtk_text_iter_backward_chars (&start, len_chars);
|
||||
gtk_text_buffer_apply_tag_by_name (info_buffer, "title", &start, &end);
|
||||
|
||||
start = end;
|
||||
|
||||
state++;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
/* Reading body of info section */
|
||||
while (isspace (*p))
|
||||
p++;
|
||||
if (*p == '*' && *(p + 1) == '/')
|
||||
{
|
||||
gtk_text_buffer_get_iter_at_offset (source_buffer, &start, 0);
|
||||
state++;
|
||||
}
|
||||
else
|
||||
{
|
||||
int len;
|
||||
|
||||
while (*p == '*' || isspace (*p))
|
||||
p++;
|
||||
|
||||
len = strlen (p);
|
||||
while (isspace (*(p + len - 1)))
|
||||
len--;
|
||||
|
||||
if (len > 0)
|
||||
{
|
||||
if (in_para)
|
||||
gtk_text_buffer_insert (info_buffer, &start, " ", 1);
|
||||
|
||||
g_assert (strlen (p) >= len);
|
||||
gtk_text_buffer_insert (info_buffer, &start, p, len);
|
||||
in_para = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_text_buffer_insert (info_buffer, &start, "\n", 1);
|
||||
in_para = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 2:
|
||||
/* Skipping blank lines */
|
||||
while (isspace (*p))
|
||||
p++;
|
||||
if (*p)
|
||||
{
|
||||
p = buffer->str;
|
||||
state++;
|
||||
/* Fall through */
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
||||
case 3:
|
||||
/* Reading program body */
|
||||
gtk_text_buffer_insert (source_buffer, &start, p, -1);
|
||||
gtk_text_buffer_insert (info_buffer, &start, "\n", 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gtk_text_buffer_get_bounds (source_buffer, &start, &end);
|
||||
gtk_text_buffer_apply_tag_by_name (info_buffer, "source", &start, &end);
|
||||
}
|
||||
|
||||
gboolean
|
||||
button_press_event_cb (GtkTreeView *tree_view,
|
||||
GdkEventButton *event,
|
||||
GtkTreeModel *model)
|
||||
{
|
||||
if (event->type == GDK_2BUTTON_PRESS)
|
||||
{
|
||||
GtkTreePath *path = NULL;
|
||||
|
||||
gtk_tree_view_get_path_at_pos (tree_view,
|
||||
event->window,
|
||||
event->x,
|
||||
event->y,
|
||||
&path,
|
||||
NULL);
|
||||
|
||||
if (path)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
gboolean italic;
|
||||
GVoidFunc func;
|
||||
|
||||
gtk_tree_model_get_iter (model, &iter, path);
|
||||
gtk_tree_store_get (GTK_TREE_STORE (model),
|
||||
&iter,
|
||||
FUNC_COLUMN, &func,
|
||||
ITALIC_COLUMN, &italic,
|
||||
-1);
|
||||
(func) ();
|
||||
gtk_tree_store_set (GTK_TREE_STORE (model),
|
||||
&iter,
|
||||
ITALIC_COLUMN, !italic,
|
||||
-1);
|
||||
gtk_tree_path_free (path);
|
||||
}
|
||||
|
||||
gtk_signal_emit_stop_by_name (GTK_OBJECT (tree_view),
|
||||
"button_press_event");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
selection_cb (GtkTreeSelection *selection,
|
||||
GtkTreeModel *model)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
GValue value = {0, };
|
||||
|
||||
if (! gtk_tree_selection_get_selected (selection, NULL, &iter))
|
||||
return;
|
||||
|
||||
gtk_tree_model_get_value (model, &iter,
|
||||
FILENAME_COLUMN,
|
||||
&value);
|
||||
load_file (g_value_get_string (&value));
|
||||
g_value_unset (&value);
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
create_text (GtkTextBuffer **buffer,
|
||||
gboolean is_source)
|
||||
{
|
||||
GtkWidget *scrolled_window;
|
||||
GtkWidget *text_view;
|
||||
PangoFontDescription *font_desc;
|
||||
|
||||
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
||||
GTK_POLICY_AUTOMATIC,
|
||||
GTK_POLICY_AUTOMATIC);
|
||||
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
|
||||
GTK_SHADOW_IN);
|
||||
|
||||
text_view = gtk_text_view_new ();
|
||||
gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);
|
||||
|
||||
*buffer = gtk_text_buffer_new (NULL);
|
||||
gtk_text_view_set_buffer (GTK_TEXT_VIEW (text_view), *buffer);
|
||||
gtk_text_view_set_editable (GTK_TEXT_VIEW (text_view), FALSE);
|
||||
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (text_view), FALSE);
|
||||
|
||||
if (is_source)
|
||||
{
|
||||
font_desc = pango_font_description_from_string ("Courier 10");
|
||||
gtk_widget_modify_font (text_view, font_desc);
|
||||
pango_font_description_free (font_desc);
|
||||
}
|
||||
|
||||
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (text_view), !is_source);
|
||||
|
||||
return scrolled_window;
|
||||
}
|
||||
|
||||
/* Technically a list, but if we do go to 80 demos, we may want to move to a tree */
|
||||
static GtkWidget *
|
||||
create_tree (void)
|
||||
{
|
||||
GtkTreeSelection *selection;
|
||||
GtkCellRenderer *cell;
|
||||
GtkWidget *tree_view;
|
||||
GtkTreeViewColumn *column;
|
||||
GtkTreeStore *model;
|
||||
GtkTreeIter iter;
|
||||
gint i;
|
||||
|
||||
model = gtk_tree_store_new_with_types (NUM_COLUMNS, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN);
|
||||
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model));
|
||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
|
||||
|
||||
gtk_tree_selection_set_type (GTK_TREE_SELECTION (selection),
|
||||
GTK_TREE_SELECTION_SINGLE);
|
||||
gtk_widget_set_usize (tree_view, 200, -1);
|
||||
|
||||
for (i=0; i < G_N_ELEMENTS (testgtk_demos); i++)
|
||||
{
|
||||
gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
|
||||
|
||||
gtk_tree_store_set (GTK_TREE_STORE (model),
|
||||
&iter,
|
||||
TITLE_COLUMN, testgtk_demos[i].title,
|
||||
FILENAME_COLUMN, testgtk_demos[i].filename,
|
||||
FUNC_COLUMN, testgtk_demos[i].func,
|
||||
ITALIC_COLUMN, FALSE,
|
||||
-1);
|
||||
}
|
||||
|
||||
cell = gtk_cell_renderer_text_new ();
|
||||
column = gtk_tree_view_column_new_with_attributes ("Widget",
|
||||
cell,
|
||||
"text", TITLE_COLUMN,
|
||||
"italic", ITALIC_COLUMN,
|
||||
NULL);
|
||||
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view),
|
||||
GTK_TREE_VIEW_COLUMN (column));
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (selection), "selection_changed", selection_cb, model);
|
||||
gtk_signal_connect (GTK_OBJECT (tree_view), "button_press_event", GTK_SIGNAL_FUNC (button_press_event_cb), model);
|
||||
|
||||
return tree_view;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
GtkWidget *window;
|
||||
GtkWidget *notebook;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *tree;
|
||||
GtkTextTag *tag;
|
||||
|
||||
gtk_init (&argc, &argv);
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
gtk_signal_connect (GTK_OBJECT (window), "destroy",
|
||||
GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
|
||||
|
||||
hbox = gtk_hbox_new (FALSE, 0);
|
||||
gtk_container_add (GTK_CONTAINER (window), hbox);
|
||||
|
||||
tree = create_tree ();
|
||||
gtk_box_pack_start (GTK_BOX (hbox), tree, FALSE, FALSE, 0);
|
||||
|
||||
notebook = gtk_notebook_new ();
|
||||
gtk_box_pack_start (GTK_BOX (hbox), notebook, TRUE, TRUE, 0);
|
||||
|
||||
gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
|
||||
create_text (&info_buffer, FALSE),
|
||||
gtk_label_new ("Info"));
|
||||
|
||||
|
||||
gtk_notebook_append_page (GTK_NOTEBOOK (notebook),
|
||||
create_text (&source_buffer, TRUE),
|
||||
gtk_label_new ("Source"));
|
||||
|
||||
tag = gtk_text_buffer_create_tag (info_buffer, "title");
|
||||
gtk_object_set (GTK_OBJECT (tag),
|
||||
"font", "Sans 18",
|
||||
NULL);
|
||||
|
||||
tag = gtk_text_buffer_create_tag (info_buffer, "source");
|
||||
gtk_object_set (GTK_OBJECT (tag),
|
||||
"font", "Courier 10",
|
||||
"pixels_above_lines", 0,
|
||||
"pixels_below_lines", 0,
|
||||
NULL);
|
||||
|
||||
gtk_window_set_default_size (GTK_WINDOW (window), 600, 400);
|
||||
gtk_widget_show_all (window);
|
||||
|
||||
|
||||
load_file (testgtk_demos[0].filename);
|
||||
|
||||
gtk_main ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1330,7 +1330,7 @@ static inline void
|
||||
model_add_special (GtkFileChooserButton *button)
|
||||
{
|
||||
const gchar *homedir;
|
||||
const gchar *display_name;
|
||||
gchar *display_name;
|
||||
gchar *desktopdir = NULL;
|
||||
GtkListStore *store;
|
||||
GtkTreeIter iter;
|
||||
|
||||
@@ -53,6 +53,7 @@
|
||||
#include "gtkmessagedialog.h"
|
||||
#include "gtkpathbar.h"
|
||||
#include "gtkprivate.h"
|
||||
#include "gtkradiobutton.h"
|
||||
#include "gtkscrolledwindow.h"
|
||||
#include "gtkseparatormenuitem.h"
|
||||
#include "gtksizegroup.h"
|
||||
@@ -683,6 +684,7 @@ gtk_file_chooser_default_init (GtkFileChooserDefault *impl)
|
||||
impl->load_state = LOAD_EMPTY;
|
||||
impl->reload_state = RELOAD_EMPTY;
|
||||
impl->pending_select_paths = NULL;
|
||||
impl->location_mode = LOCATION_MODE_PATH_BAR;
|
||||
|
||||
gtk_box_set_spacing (GTK_BOX (impl), 12);
|
||||
|
||||
@@ -3770,7 +3772,7 @@ create_file_list (GtkFileChooserDefault *impl)
|
||||
gtk_tree_view_column_set_title (column, _("Size"));
|
||||
|
||||
renderer = gtk_cell_renderer_text_new ();
|
||||
gtk_tree_view_column_pack_start (column, renderer, TRUE);
|
||||
gtk_tree_view_column_pack_start (column, renderer, TRUE); /* bug: it doesn't expand */
|
||||
gtk_tree_view_column_set_cell_data_func (column, renderer,
|
||||
list_size_data_func, impl, NULL);
|
||||
gtk_tree_view_column_set_sort_column_id (column, FILE_LIST_COL_SIZE);
|
||||
@@ -4026,6 +4028,238 @@ save_widgets_destroy (GtkFileChooserDefault *impl)
|
||||
impl->save_expander = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
location_switch_to_path_bar (GtkFileChooserDefault *impl)
|
||||
{
|
||||
g_assert (!GTK_WIDGET_VISIBLE (impl->browse_path_bar));
|
||||
g_assert (impl->location_label != NULL);
|
||||
g_assert (impl->location_entry != NULL);
|
||||
|
||||
gtk_widget_destroy (impl->location_label);
|
||||
gtk_widget_destroy (impl->location_entry);
|
||||
gtk_widget_show (impl->browse_path_bar);
|
||||
}
|
||||
|
||||
static void location_button_toggled_cb (GtkToggleButton *toggle,
|
||||
GtkFileChooserDefault *impl);
|
||||
|
||||
static void
|
||||
location_entry_set_initial_text (GtkFileChooserDefault *impl)
|
||||
{
|
||||
char *text;
|
||||
|
||||
if (gtk_file_system_path_is_local (impl->file_system, impl->current_folder))
|
||||
{
|
||||
char *filename;
|
||||
|
||||
filename = gtk_file_system_path_to_filename (impl->file_system, impl->current_folder);
|
||||
if (filename)
|
||||
{
|
||||
text = g_filename_to_utf8 (filename, -1, NULL, NULL, NULL);
|
||||
g_free (filename);
|
||||
}
|
||||
else
|
||||
text = NULL;
|
||||
}
|
||||
else
|
||||
text = gtk_file_system_path_to_uri (impl->file_system, impl->current_folder);
|
||||
|
||||
if (text)
|
||||
{
|
||||
gboolean need_slash;
|
||||
int len;
|
||||
|
||||
len = strlen (text);
|
||||
need_slash = (text[len - 1] != G_DIR_SEPARATOR);
|
||||
|
||||
if (need_slash)
|
||||
{
|
||||
char *slash_text;
|
||||
|
||||
slash_text = g_new (char, len + 2);
|
||||
strcpy (slash_text, text);
|
||||
slash_text[len] = G_DIR_SEPARATOR;
|
||||
slash_text[len + 1] = 0;
|
||||
|
||||
g_free (text);
|
||||
text = slash_text;
|
||||
}
|
||||
|
||||
gtk_entry_set_text (GTK_ENTRY (impl->location_entry), text);
|
||||
g_free (text);
|
||||
}
|
||||
}
|
||||
|
||||
/* Switches from the path bar to the location entry */
|
||||
static void
|
||||
location_switch_to_filename_entry (GtkFileChooserDefault *impl)
|
||||
{
|
||||
g_assert (GTK_WIDGET_VISIBLE (impl->browse_path_bar));
|
||||
|
||||
/* We hide the path bar, rather than destroying it, because we want to
|
||||
* preserve its state. We would get hysteresis otherwise.
|
||||
*/
|
||||
gtk_widget_hide (impl->browse_path_bar);
|
||||
|
||||
/* FMQ: FIXME: don't create this in SAVE mode */
|
||||
|
||||
/* Label */
|
||||
|
||||
impl->location_label = gtk_label_new_with_mnemonic ("<b>_Location:</b>");
|
||||
gtk_label_set_use_markup (GTK_LABEL (impl->location_label), TRUE);
|
||||
gtk_widget_show (impl->location_label);
|
||||
gtk_box_pack_start (GTK_BOX (impl->location_widget_box), impl->location_label, FALSE, FALSE, 0);
|
||||
|
||||
/* Entry */
|
||||
|
||||
impl->location_entry = _gtk_file_chooser_entry_new (TRUE);
|
||||
_gtk_file_chooser_entry_set_file_system (GTK_FILE_CHOOSER_ENTRY (impl->location_entry),
|
||||
impl->file_system);
|
||||
gtk_entry_set_activates_default (GTK_ENTRY (impl->location_entry), TRUE);
|
||||
_gtk_file_chooser_entry_set_action (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->action);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (impl->location_widget_box), impl->location_entry, TRUE, TRUE, 0);
|
||||
gtk_label_set_mnemonic_widget (GTK_LABEL (impl->location_label), impl->location_entry);
|
||||
|
||||
/* Configure the entry */
|
||||
|
||||
_gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->current_folder);
|
||||
location_entry_set_initial_text (impl);
|
||||
|
||||
/* Done */
|
||||
|
||||
gtk_widget_show (impl->location_entry);
|
||||
gtk_widget_grab_focus (impl->location_entry);
|
||||
}
|
||||
|
||||
/* Sets a new location mode. set_buttons determines whether the radio buttons
|
||||
* for the mode will also be changed.
|
||||
*/
|
||||
static void
|
||||
location_mode_set (GtkFileChooserDefault *impl,
|
||||
LocationMode new_mode,
|
||||
gboolean set_buttons)
|
||||
{
|
||||
GtkWidget *button_to_set;
|
||||
|
||||
switch (new_mode)
|
||||
{
|
||||
case LOCATION_MODE_PATH_BAR:
|
||||
button_to_set = impl->location_pathbar_radio;
|
||||
location_switch_to_path_bar (impl);
|
||||
break;
|
||||
|
||||
case LOCATION_MODE_FILENAME_ENTRY:
|
||||
button_to_set = impl->location_filename_radio;
|
||||
location_switch_to_filename_entry (impl);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
return;
|
||||
}
|
||||
|
||||
if (set_buttons)
|
||||
{
|
||||
g_signal_handlers_block_by_func (impl->location_pathbar_radio,
|
||||
G_CALLBACK (location_button_toggled_cb), impl);
|
||||
g_signal_handlers_block_by_func (impl->location_filename_radio,
|
||||
G_CALLBACK (location_button_toggled_cb), impl);
|
||||
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button_to_set), TRUE);
|
||||
|
||||
g_signal_handlers_unblock_by_func (impl->location_pathbar_radio,
|
||||
G_CALLBACK (location_button_toggled_cb), impl);
|
||||
g_signal_handlers_unblock_by_func (impl->location_filename_radio,
|
||||
G_CALLBACK (location_button_toggled_cb), impl);
|
||||
}
|
||||
|
||||
impl->location_mode = new_mode;
|
||||
}
|
||||
|
||||
/* Callback used when one of the location mode buttons is toggled */
|
||||
static void
|
||||
location_button_toggled_cb (GtkToggleButton *toggle,
|
||||
GtkFileChooserDefault *impl)
|
||||
{
|
||||
LocationMode new_mode;
|
||||
gboolean is_active;
|
||||
|
||||
is_active = gtk_toggle_button_get_active (toggle);
|
||||
if (!is_active)
|
||||
return;
|
||||
|
||||
if (GTK_WIDGET (toggle) == impl->location_pathbar_radio)
|
||||
{
|
||||
g_assert (impl->location_mode == LOCATION_MODE_FILENAME_ENTRY);
|
||||
new_mode = LOCATION_MODE_PATH_BAR;
|
||||
}
|
||||
else if (GTK_WIDGET (toggle) == impl->location_filename_radio)
|
||||
{
|
||||
g_assert (impl->location_mode == LOCATION_MODE_PATH_BAR);
|
||||
new_mode = LOCATION_MODE_FILENAME_ENTRY;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_assert_not_reached ();
|
||||
return;
|
||||
}
|
||||
|
||||
location_mode_set (impl, new_mode, FALSE);
|
||||
}
|
||||
|
||||
/* Creates a radio button for the location mode, and packs it on a box */
|
||||
static GtkWidget *
|
||||
location_button_new (GtkFileChooserDefault *impl,
|
||||
GtkWidget *radio_group,
|
||||
const char *stock_id,
|
||||
const char *accessible_name_and_tooltip,
|
||||
GtkWidget *box)
|
||||
{
|
||||
GtkWidget *image;
|
||||
GtkWidget *button;
|
||||
|
||||
image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
|
||||
gtk_widget_show (image);
|
||||
|
||||
button = g_object_new (GTK_TYPE_RADIO_BUTTON,
|
||||
"image", image,
|
||||
"draw-indicator", FALSE,
|
||||
NULL);
|
||||
if (radio_group)
|
||||
gtk_radio_button_set_group (GTK_RADIO_BUTTON (button),
|
||||
gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_group)));
|
||||
|
||||
g_signal_connect (button, "toggled",
|
||||
G_CALLBACK (location_button_toggled_cb), impl);
|
||||
gtk_widget_show (button);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
|
||||
|
||||
gtk_tooltips_set_tip (impl->tooltips, button, accessible_name_and_tooltip, NULL);
|
||||
atk_object_set_name (gtk_widget_get_accessible (button), accessible_name_and_tooltip);
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
/* Creates toggle buttons that switch between the pathbar and the location entry. */
|
||||
static void
|
||||
location_buttons_create (GtkFileChooserDefault *impl)
|
||||
{
|
||||
impl->location_mode_box = gtk_hbox_new (FALSE, 0);
|
||||
|
||||
impl->location_pathbar_radio = location_button_new (impl,
|
||||
NULL,
|
||||
GTK_STOCK_DIRECTORY,
|
||||
_("Show folders"),
|
||||
impl->location_mode_box);
|
||||
impl->location_filename_radio = location_button_new (impl,
|
||||
impl->location_pathbar_radio,
|
||||
GTK_STOCK_EDIT,
|
||||
_("Type a file name"),
|
||||
impl->location_mode_box);
|
||||
}
|
||||
|
||||
/* Creates the main hpaned with the widgets shared by Open and Save mode */
|
||||
static GtkWidget *
|
||||
browse_widgets_create (GtkFileChooserDefault *impl)
|
||||
@@ -4040,15 +4274,25 @@ browse_widgets_create (GtkFileChooserDefault *impl)
|
||||
size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL);
|
||||
vbox = gtk_vbox_new (FALSE, 12);
|
||||
|
||||
/* The path bar and 'Create Folder' button */
|
||||
/* Location widgets */
|
||||
hbox = gtk_hbox_new (FALSE, 12);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
|
||||
gtk_widget_show (hbox);
|
||||
|
||||
location_buttons_create (impl);
|
||||
gtk_widget_show (impl->location_mode_box);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), impl->location_mode_box, FALSE, FALSE, 0);
|
||||
|
||||
impl->location_widget_box = gtk_hbox_new (FALSE, 12);
|
||||
gtk_widget_show (impl->location_widget_box);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), impl->location_widget_box, TRUE, TRUE, 0);
|
||||
|
||||
/* Path bar */
|
||||
|
||||
impl->browse_path_bar = create_path_bar (impl);
|
||||
g_signal_connect (impl->browse_path_bar, "path-clicked", G_CALLBACK (path_bar_clicked), impl);
|
||||
gtk_widget_show_all (impl->browse_path_bar);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), impl->browse_path_bar, TRUE, TRUE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (impl->location_widget_box), impl->browse_path_bar, TRUE, TRUE, 0);
|
||||
|
||||
/* Create Folder */
|
||||
impl->browse_new_folder_button = gtk_button_new_with_mnemonic (_("Create Fo_lder"));
|
||||
@@ -7063,21 +7307,25 @@ list_size_data_func (GtkTreeViewColumn *tree_column,
|
||||
|
||||
if (!info || gtk_file_info_get_is_folder (info))
|
||||
{
|
||||
g_object_set (cell,"sensitive", sensitive, NULL);
|
||||
g_object_set (cell,
|
||||
"text", NULL,
|
||||
"sensitive", sensitive,
|
||||
NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
size = gtk_file_info_get_size (info);
|
||||
|
||||
#if 0
|
||||
if (size < (gint64)1024)
|
||||
str = g_strdup_printf (ngettext ("%d byte", "%d bytes", (gint)size), (gint)size);
|
||||
else if (size < (gint64)1024*1024)
|
||||
str = g_strdup_printf (_("%.1f K"), size / (1024.));
|
||||
str = g_strdup_printf (_("%.1f KB"), size / (1024.));
|
||||
else if (size < (gint64)1024*1024*1024)
|
||||
str = g_strdup_printf (_("%.1f M"), size / (1024.*1024.));
|
||||
str = g_strdup_printf (_("%.1f MB"), size / (1024.*1024.));
|
||||
else
|
||||
str = g_strdup_printf (_("%.1f G"), size / (1024.*1024.*1024.));
|
||||
|
||||
str = g_strdup_printf (_("%.1f GB"), size / (1024.*1024.*1024.));
|
||||
#endif
|
||||
str = g_strdup_printf ("%" G_GINT64_FORMAT, size);
|
||||
if (impl->action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ||
|
||||
impl->action == GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER)
|
||||
sensitive = FALSE;
|
||||
@@ -7085,6 +7333,7 @@ list_size_data_func (GtkTreeViewColumn *tree_column,
|
||||
g_object_set (cell,
|
||||
"text", str,
|
||||
"sensitive", sensitive,
|
||||
"alignment", PANGO_ALIGN_RIGHT,
|
||||
NULL);
|
||||
|
||||
g_free (str);
|
||||
|
||||
@@ -141,6 +141,11 @@ typedef enum {
|
||||
RELOAD_WAS_UNMAPPED /* We had a folder but got unmapped; reload is needed */
|
||||
} ReloadState;
|
||||
|
||||
typedef enum {
|
||||
LOCATION_MODE_PATH_BAR,
|
||||
LOCATION_MODE_FILENAME_ENTRY
|
||||
} LocationMode;
|
||||
|
||||
struct _GtkFileChooserDefault
|
||||
{
|
||||
GtkVBox parent_instance;
|
||||
@@ -182,6 +187,14 @@ struct _GtkFileChooserDefault
|
||||
GtkWidget *extra_align;
|
||||
GtkWidget *extra_widget;
|
||||
|
||||
GtkWidget *location_mode_box;
|
||||
GtkWidget *location_pathbar_radio;
|
||||
GtkWidget *location_filename_radio;
|
||||
GtkWidget *location_widget_box;
|
||||
GtkWidget *location_label;
|
||||
GtkWidget *location_entry;
|
||||
LocationMode location_mode;
|
||||
|
||||
GtkListStore *shortcuts_model;
|
||||
GtkTreeModel *shortcuts_filter_model;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user