Commit dfb27bf8 authored by Cosimo Cecchi's avatar Cosimo Cecchi Committed by Carlos Soriano Sánchez

view: cleanup zoom-to-level actions

Instead of putting it in the superclass, have the subclasses implement
it individually.
parent 5951fadb
......@@ -149,8 +149,6 @@ static const SortCriterion sort_criteria[] = {
static void nautilus_canvas_view_set_directory_sort_by (NautilusCanvasView *canvas_view,
NautilusFile *file,
const char *sort_by);
static void nautilus_canvas_view_set_zoom_level (NautilusCanvasView *view,
NautilusCanvasZoomLevel new_level);
static void nautilus_canvas_view_update_click_mode (NautilusCanvasView *canvas_view);
static gboolean nautilus_canvas_view_supports_scaling (NautilusCanvasView *canvas_view);
static void nautilus_canvas_view_reveal_selection (NautilusView *view);
......@@ -685,8 +683,6 @@ get_sort_criterion_by_sort_type (NautilusFileSortType sort_type)
return &sort_criteria[0];
}
#define DEFAULT_ZOOM_LEVEL(canvas_view) default_zoom_level
static NautilusCanvasZoomLevel
get_default_zoom_level (NautilusCanvasView *canvas_view)
{
......@@ -695,7 +691,7 @@ get_default_zoom_level (NautilusCanvasView *canvas_view)
default_zoom_level = g_settings_get_enum (nautilus_icon_view_preferences,
NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_ZOOM_LEVEL);
return CLAMP (DEFAULT_ZOOM_LEVEL(canvas_view), NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL, NAUTILUS_CANVAS_ZOOM_LEVEL_LARGE);
return CLAMP (default_zoom_level, NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL, NAUTILUS_CANVAS_ZOOM_LEVEL_LARGE);
}
static void
......@@ -791,35 +787,24 @@ nautilus_canvas_view_get_zoom_level (NautilusView *view)
}
static void
nautilus_canvas_view_set_zoom_level (NautilusCanvasView *view,
NautilusCanvasZoomLevel new_level)
nautilus_canvas_view_zoom_to_level (NautilusView *view,
gint new_level)
{
NautilusCanvasView *canvas_view;
NautilusCanvasContainer *canvas_container;
g_return_if_fail (NAUTILUS_IS_CANVAS_VIEW (view));
g_return_if_fail (new_level >= NAUTILUS_CANVAS_ZOOM_LEVEL_SMALL &&
new_level <= NAUTILUS_CANVAS_ZOOM_LEVEL_LARGE);
canvas_container = get_canvas_container (view);
canvas_view = NAUTILUS_CANVAS_VIEW (view);
canvas_container = get_canvas_container (canvas_view);
if (nautilus_canvas_container_get_zoom_level (canvas_container) == new_level)
return;
nautilus_canvas_container_set_zoom_level (canvas_container, new_level);
}
static void
nautilus_canvas_view_zoom_to_level (NautilusView *view,
gint zoom_level)
{
NautilusCanvasView *canvas_view;
g_assert (NAUTILUS_IS_CANVAS_VIEW (view));
canvas_view = NAUTILUS_CANVAS_VIEW (view);
nautilus_canvas_view_set_zoom_level (canvas_view, zoom_level);
/* Chain up to the parent to update menus */
NAUTILUS_VIEW_CLASS (nautilus_canvas_view_parent_class)->zoom_to_level (view, zoom_level);
nautilus_view_update_toolbar_menus (view);
}
static void
......@@ -963,6 +948,21 @@ action_sort_order_changed (GSimpleAction *action,
g_simple_action_set_state (action, value);
}
static void
action_zoom_to_level (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
NautilusView *view;
NautilusCanvasZoomLevel zoom_level;
g_assert (NAUTILUS_IS_VIEW (user_data));
view = NAUTILUS_VIEW (user_data);
zoom_level = g_variant_get_int32 (state);
nautilus_canvas_view_zoom_to_level (view, zoom_level);
}
static void
switch_to_manual_layout (NautilusCanvasView *canvas_view)
{
......@@ -1019,6 +1019,7 @@ const GActionEntry canvas_view_entries[] = {
{ "keep-aligned", NULL, NULL, "true", action_keep_aligned },
{ "reversed-order", NULL, NULL, "false", action_reversed_order },
{ "sort", NULL, "s", "'name'", action_sort_order_changed },
{ "zoom-to-level", NULL, NULL, "1", action_zoom_to_level }
};
static void
......@@ -1843,7 +1844,6 @@ nautilus_canvas_view_class_init (NautilusCanvasViewClass *klass)
nautilus_view_class->add_file = nautilus_canvas_view_add_file;
nautilus_view_class->begin_loading = nautilus_canvas_view_begin_loading;
nautilus_view_class->bump_zoom_level = nautilus_canvas_view_bump_zoom_level;
nautilus_view_class->zoom_to_level = nautilus_canvas_view_zoom_to_level;
nautilus_view_class->can_rename_file = nautilus_canvas_view_can_rename_file;
nautilus_view_class->can_zoom_in = nautilus_canvas_view_can_zoom_in;
nautilus_view_class->can_zoom_out = nautilus_canvas_view_can_zoom_out;
......@@ -1862,7 +1862,6 @@ nautilus_canvas_view_class_init (NautilusCanvasViewClass *klass)
nautilus_view_class->set_selection = nautilus_canvas_view_set_selection;
nautilus_view_class->invert_selection = nautilus_canvas_view_invert_selection;
nautilus_view_class->compare_files = compare_files;
nautilus_view_class->zoom_to_level = nautilus_canvas_view_zoom_to_level;
nautilus_view_class->click_policy_changed = nautilus_canvas_view_click_policy_changed;
nautilus_view_class->update_toolbar_menus = nautilus_canvas_view_update_toolbar_menus;
nautilus_view_class->update_actions_state = nautilus_canvas_view_update_actions_state;
......
......@@ -2815,6 +2815,36 @@ nautilus_list_view_select_first (NautilusView *view)
gtk_tree_selection_select_iter (selection, &iter);
}
static void
nautilus_list_view_zoom_to_level (NautilusView *view,
gint zoom_level)
{
NautilusListView *list_view;
g_return_if_fail (NAUTILUS_IS_LIST_VIEW (view));
list_view = NAUTILUS_LIST_VIEW (view);
nautilus_list_view_set_zoom_level (list_view, zoom_level);
nautilus_view_update_toolbar_menus (view);
}
static void
action_zoom_to_level (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
NautilusView *view;
NautilusListZoomLevel zoom_level;
g_assert (NAUTILUS_IS_VIEW (user_data));
view = NAUTILUS_VIEW (user_data);
zoom_level = g_variant_get_int32 (state);
nautilus_list_view_zoom_to_level (view, zoom_level);
}
static void
column_editor_response_callback (GtkWidget *dialog,
int response_id,
......@@ -3018,6 +3048,7 @@ action_visible_columns (GSimpleAction *action,
const GActionEntry list_view_entries[] = {
{ "visible-columns", action_visible_columns },
{ "zoom-to-level", NULL, NULL, "1", action_zoom_to_level }
};
static void
......@@ -3062,21 +3093,6 @@ nautilus_list_view_set_zoom_level (NautilusListView *view,
set_up_pixbuf_size (view);
}
static void
nautilus_list_view_zoom_to_level (NautilusView *view,
gint zoom_level)
{
NautilusListView *list_view;
g_return_if_fail (NAUTILUS_IS_LIST_VIEW (view));
list_view = NAUTILUS_LIST_VIEW (view);
nautilus_list_view_set_zoom_level (list_view, zoom_level);
NAUTILUS_VIEW_CLASS (nautilus_list_view_parent_class)->zoom_to_level (view, zoom_level);
}
static void
nautilus_list_view_bump_zoom_level (NautilusView *view, int zoom_increment)
{
......@@ -3505,7 +3521,6 @@ nautilus_list_view_class_init (NautilusListViewClass *class)
nautilus_view_class->compare_files = nautilus_list_view_compare_files;
nautilus_view_class->sort_directories_first_changed = nautilus_list_view_sort_directories_first_changed;
nautilus_view_class->start_renaming_file = nautilus_list_view_start_renaming_file;
nautilus_view_class->zoom_to_level = nautilus_list_view_zoom_to_level;
nautilus_view_class->end_file_changes = nautilus_list_view_end_file_changes;
nautilus_view_class->using_manual_layout = nautilus_list_view_using_manual_layout;
nautilus_view_class->get_view_id = nautilus_list_view_get_id;
......
......@@ -275,9 +275,6 @@ static void update_templates_directory (NautilusView *vi
static void unschedule_pop_up_pathbar_context_menu (NautilusView *view);
static void real_zoom_to_level (NautilusView *view,
gint zoom_level);
G_DEFINE_TYPE (NautilusView, nautilus_view, GTK_TYPE_SCROLLED_WINDOW);
static char *
......@@ -486,39 +483,6 @@ nautilus_view_bump_zoom_level (NautilusView *view,
NAUTILUS_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->bump_zoom_level (view, zoom_increment);
}
/* We want to keep the logic of which menus and when to update them in
* this class, so children need to chain to the parent when they set the zoom
* level through this function.
* The chain up should be done after the child updated the zoom level, so the
* menus are updated acordingly
*
*/
static void
real_zoom_to_level (NautilusView *view,
gint zoom_level)
{
nautilus_view_update_toolbar_menus (view);
}
/**
* nautilus_view_zoom_to_level:
*
* Set the current zoom level by invoking the relevant subclass through the slot
*
**/
void
nautilus_view_zoom_to_level (NautilusView *view,
gint zoom_level)
{
g_return_if_fail (NAUTILUS_IS_VIEW (view));
if (!nautilus_view_supports_zooming (view)) {
return;
}
NAUTILUS_VIEW_CLASS (G_OBJECT_GET_CLASS (view))->zoom_to_level (view, zoom_level);
}
/**
* nautilus_view_can_zoom_in:
*
......@@ -1902,22 +1866,6 @@ action_zoom_default (GSimpleAction *action,
nautilus_view_restore_default_zoom_level (user_data);
}
static void
action_zoom_to_level (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
NautilusView *view;
gdouble zoom_value;
g_assert (NAUTILUS_IS_VIEW (user_data));
view = NAUTILUS_VIEW (user_data);
zoom_value = g_variant_get_int32 (state);
nautilus_view_zoom_to_level (view, zoom_value);
}
static void
action_open_item_new_window (GSimpleAction *action,
GVariant *state,
......@@ -5725,7 +5673,6 @@ const GActionEntry view_entries[] = {
{ "zoom-in", action_zoom_in },
{ "zoom-out", action_zoom_out },
{ "zoom-default", action_zoom_default },
{ "zoom-to-level", NULL, NULL, "1", action_zoom_to_level },
{ "undo", action_undo },
{ "redo", action_redo },
{ "show-hidden-files", NULL, NULL, "true", action_show_hidden_files },
......@@ -7618,7 +7565,6 @@ nautilus_view_class_init (NautilusViewClass *klass)
klass->update_context_menus = real_update_context_menus;
klass->update_actions_state = real_update_actions_state;
klass->update_toolbar_menus = real_update_toolbar_menus;
klass->zoom_to_level = real_zoom_to_level;
copied_files_atom = gdk_atom_intern ("x-special/gnome-copied-files", FALSE);
......
......@@ -183,11 +183,6 @@ struct NautilusViewClass {
void (* bump_zoom_level) (NautilusView *view,
int zoom_increment);
/* zoom_to_level is a function pointer that subclasses must override
* to set the zoom level of an object to the specified level. */
void (* zoom_to_level) (NautilusView *view,
gint level);
/* restore_default_zoom_level is a function pointer that subclasses must override
* to restore the zoom level of an object to a default setting. */
void (* restore_default_zoom_level) (NautilusView *view);
......
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