Commit ea4ed72e authored by Sven Neumann's avatar Sven Neumann Committed by Sven Neumann

app/actions/view-actions.c app/actions/view-commands.[ch]

2007-02-07  Sven Neumann  <sven@gimp.org>

	* app/actions/view-actions.c
	* app/actions/view-commands.[ch]
	* app/display/gimpdisplayshell.[ch]
	* app/display/gimpdisplayshell-scale.[ch]
	* app/widgets/gimphelp-ids.h
	* menus/image-menu.xml.in: applied patch from Robert Helgesson 
that
	adds "Revert Zoom" functionality (bug #338168).


svn path=/trunk/; revision=21855
parent 4bb1692f
2007-02-07 Sven Neumann <sven@gimp.org>
* app/actions/view-actions.c
* app/actions/view-commands.[ch]
* app/display/gimpdisplayshell.[ch]
* app/display/gimpdisplayshell-scale.[ch]
* app/widgets/gimphelp-ids.h
* menus/image-menu.xml.in: applied patch from Robert Helgesson that
adds "Revert Zoom" functionality (bug #338168).
2007-02-06 Sven Neumann <sven@gimp.org> 2007-02-06 Sven Neumann <sven@gimp.org>
* app/core/gimpundo.[ch]: made time a property and added utility * app/core/gimpundo.[ch]: made time a property and added utility
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include "display/gimpdisplayoptions.h" #include "display/gimpdisplayoptions.h"
#include "display/gimpdisplayshell.h" #include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-appearance.h" #include "display/gimpdisplayshell-appearance.h"
#include "display/gimpdisplayshell-scale.h"
#include "display/gimpdisplayshell-selection.h" #include "display/gimpdisplayshell-selection.h"
#include "actions.h" #include "actions.h"
...@@ -93,6 +94,12 @@ static const GimpActionEntry view_actions[] = ...@@ -93,6 +94,12 @@ static const GimpActionEntry view_actions[] =
G_CALLBACK (view_zoom_fit_to_cmd_callback), G_CALLBACK (view_zoom_fit_to_cmd_callback),
GIMP_HELP_VIEW_ZOOM_FIT_TO }, GIMP_HELP_VIEW_ZOOM_FIT_TO },
{ "view-zoom-revert", NULL,
N_("Re_vert Zoom"), "grave",
N_("Restore the previous zoom level"),
G_CALLBACK (view_zoom_revert_cmd_callback),
GIMP_HELP_VIEW_ZOOM_REVERT },
{ "view-navigation-window", GIMP_STOCK_NAVIGATION, { "view-navigation-window", GIMP_STOCK_NAVIGATION,
N_("Na_vigation Window"), NULL, N_("Na_vigation Window"), NULL,
N_("Show an overview window for this image"), N_("Show an overview window for this image"),
...@@ -497,10 +504,12 @@ void ...@@ -497,10 +504,12 @@ void
view_actions_update (GimpActionGroup *group, view_actions_update (GimpActionGroup *group,
gpointer data) gpointer data)
{ {
GimpDisplay *display = action_data_get_display (data); GimpDisplay *display = action_data_get_display (data);
GimpDisplayShell *shell = NULL; GimpDisplayShell *shell = NULL;
GimpDisplayOptions *options = NULL; GimpDisplayOptions *options = NULL;
gboolean fullscreen = FALSE; gchar *label = NULL;
gboolean fullscreen = FALSE;
gboolean revert_enabled = FALSE; /* able to revert zoom? */
if (display) if (display)
{ {
...@@ -509,6 +518,8 @@ view_actions_update (GimpActionGroup *group, ...@@ -509,6 +518,8 @@ view_actions_update (GimpActionGroup *group,
fullscreen = gimp_display_shell_get_fullscreen (shell); fullscreen = gimp_display_shell_get_fullscreen (shell);
options = fullscreen ? shell->fullscreen_options : shell->options; options = fullscreen ? shell->fullscreen_options : shell->options;
revert_enabled = gimp_display_shell_scale_can_revert (shell);
} }
#define SET_ACTIVE(action,condition) \ #define SET_ACTIVE(action,condition) \
...@@ -524,6 +535,20 @@ view_actions_update (GimpActionGroup *group, ...@@ -524,6 +535,20 @@ view_actions_update (GimpActionGroup *group,
SET_SENSITIVE ("view-dot-for-dot", display); SET_SENSITIVE ("view-dot-for-dot", display);
SET_ACTIVE ("view-dot-for-dot", display && shell->dot_for_dot); SET_ACTIVE ("view-dot-for-dot", display && shell->dot_for_dot);
SET_SENSITIVE ("view-zoom-revert", revert_enabled);
if (revert_enabled)
{
label = g_strdup_printf (_("Re_vert Zoom (%d%%)"),
ROUND (shell->last_scale * 100));
gimp_action_group_set_action_label (group, "view-zoom-revert", label);
g_free (label);
}
else
{
gimp_action_group_set_action_label (group, "view-zoom-revert",
N_("Re_vert Zoom"));
}
SET_SENSITIVE ("view-zoom-out", display); SET_SENSITIVE ("view-zoom-out", display);
SET_SENSITIVE ("view-zoom-in", display); SET_SENSITIVE ("view-zoom-in", display);
SET_SENSITIVE ("view-zoom-fit-in", display); SET_SENSITIVE ("view-zoom-fit-in", display);
......
...@@ -108,6 +108,16 @@ view_zoom_fit_to_cmd_callback (GtkAction *action, ...@@ -108,6 +108,16 @@ view_zoom_fit_to_cmd_callback (GtkAction *action,
gimp_display_shell_scale_fit_to (GIMP_DISPLAY_SHELL (display->shell)); gimp_display_shell_scale_fit_to (GIMP_DISPLAY_SHELL (display->shell));
} }
void
view_zoom_revert_cmd_callback (GtkAction *action,
gpointer data)
{
GimpDisplay *display;
return_if_no_display (display, data);
gimp_display_shell_scale_revert (GIMP_DISPLAY_SHELL (display->shell));
}
void void
view_zoom_cmd_callback (GtkAction *action, view_zoom_cmd_callback (GtkAction *action,
gint value, gint value,
......
...@@ -27,6 +27,8 @@ void view_zoom_fit_in_cmd_callback (GtkAction *action, ...@@ -27,6 +27,8 @@ void view_zoom_fit_in_cmd_callback (GtkAction *action,
gpointer data); gpointer data);
void view_zoom_fit_to_cmd_callback (GtkAction *action, void view_zoom_fit_to_cmd_callback (GtkAction *action,
gpointer data); gpointer data);
void view_zoom_revert_cmd_callback (GtkAction *action,
gpointer data);
void view_zoom_cmd_callback (GtkAction *action, void view_zoom_cmd_callback (GtkAction *action,
gint value, gint value,
gpointer data); gpointer data);
......
...@@ -44,6 +44,8 @@ ...@@ -44,6 +44,8 @@
#include "gimp-intl.h" #include "gimp-intl.h"
#define SCALE_EPSILON 0.0001
typedef struct _ScaleDialogData ScaleDialogData; typedef struct _ScaleDialogData ScaleDialogData;
struct _ScaleDialogData struct _ScaleDialogData
...@@ -184,6 +186,47 @@ gimp_display_shell_scale_setup (GimpDisplayShell *shell) ...@@ -184,6 +186,47 @@ gimp_display_shell_scale_setup (GimpDisplayShell *shell)
#endif #endif
} }
/**
* gimp_display_shell_scale_revert:
* @shell: the #GimpDisplayShell
*
* Reverts the display to the previously used scale. If no previous scale
* exist then the call does nothing.
*
* Return value: %TRUE if the scale was reverted, otherwise %FALSE.
**/
gboolean
gimp_display_shell_scale_revert (GimpDisplayShell *shell)
{
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
/* don't bother if no scale has been set */
if (shell->last_scale < SCALE_EPSILON)
return FALSE;
gimp_display_shell_scale_by_values (shell,
shell->last_scale,
shell->last_offset_x,
shell->last_offset_y,
FALSE); /* don't resize the window */
return TRUE;
}
/**
* gimp_display_shell_scale_can_revert:
* @shell: the #GimpDisplayShell
*
* Return value: %TRUE if a previous display scale exists, otherwise %FALSE.
**/
gboolean
gimp_display_shell_scale_can_revert (GimpDisplayShell *shell)
{
g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE);
return (shell->last_scale > SCALE_EPSILON);
}
void void
gimp_display_shell_scale_set_dot_for_dot (GimpDisplayShell *shell, gimp_display_shell_scale_set_dot_for_dot (GimpDisplayShell *shell,
gboolean dot_for_dot) gboolean dot_for_dot)
...@@ -390,6 +433,11 @@ gimp_display_shell_scale_by_values (GimpDisplayShell *shell, ...@@ -390,6 +433,11 @@ gimp_display_shell_scale_by_values (GimpDisplayShell *shell,
shell->offset_y == offset_y) shell->offset_y == offset_y)
return; return;
/* remember the current scale and offsets to allow reverting the scaling */
shell->last_scale = gimp_zoom_model_get_factor (shell->zoom);
shell->last_offset_x = shell->offset_x;
shell->last_offset_y = shell->offset_y;
/* freeze the active tool */ /* freeze the active tool */
gimp_display_shell_pause (shell); gimp_display_shell_pause (shell);
...@@ -459,7 +507,7 @@ gimp_display_shell_scale_dialog (GimpDisplayShell *shell) ...@@ -459,7 +507,7 @@ gimp_display_shell_scale_dialog (GimpDisplayShell *shell)
return; return;
} }
if (fabs (shell->other_scale) <= 0.0001) if (fabs (shell->other_scale) < SCALE_EPSILON)
{ {
/* other_scale not yet initialized */ /* other_scale not yet initialized */
shell->other_scale = gimp_zoom_model_get_factor (shell->zoom); shell->other_scale = gimp_zoom_model_get_factor (shell->zoom);
......
...@@ -22,6 +22,9 @@ ...@@ -22,6 +22,9 @@
void gimp_display_shell_scale_setup (GimpDisplayShell *shell); void gimp_display_shell_scale_setup (GimpDisplayShell *shell);
gboolean gimp_display_shell_scale_revert (GimpDisplayShell *shell);
gboolean gimp_display_shell_scale_can_revert (GimpDisplayShell *shell);
void gimp_display_shell_scale_set_dot_for_dot (GimpDisplayShell *shell, void gimp_display_shell_scale_set_dot_for_dot (GimpDisplayShell *shell,
gboolean dot_for_dot); gboolean dot_for_dot);
......
...@@ -220,6 +220,10 @@ gimp_display_shell_init (GimpDisplayShell *shell) ...@@ -220,6 +220,10 @@ gimp_display_shell_init (GimpDisplayShell *shell)
shell->offset_x = 0; shell->offset_x = 0;
shell->offset_y = 0; shell->offset_y = 0;
shell->last_scale = 0.0;
shell->last_offset_x = 0;
shell->last_offset_y = 0;
shell->disp_width = 0; shell->disp_width = 0;
shell->disp_height = 0; shell->disp_height = 0;
shell->disp_xoffset = 0; shell->disp_xoffset = 0;
......
...@@ -83,6 +83,10 @@ struct _GimpDisplayShell ...@@ -83,6 +83,10 @@ struct _GimpDisplayShell
gint offset_x; /* offset of display image into raw image */ gint offset_x; /* offset of display image into raw image */
gint offset_y; gint offset_y;
gdouble last_scale; /* scale used when reverting zoom */
gint last_offset_x; /* offsets used when reverting zoom */
gint last_offset_y;
gint disp_width; /* width of drawing area */ gint disp_width; /* width of drawing area */
gint disp_height; /* height of drawing area */ gint disp_height; /* height of drawing area */
gint disp_xoffset; gint disp_xoffset;
......
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
#define GIMP_HELP_VIEW_NEW "gimp-view-new" #define GIMP_HELP_VIEW_NEW "gimp-view-new"
#define GIMP_HELP_VIEW_DOT_FOR_DOT "gimp-view-dot-for-dot" #define GIMP_HELP_VIEW_DOT_FOR_DOT "gimp-view-dot-for-dot"
#define GIMP_HELP_VIEW_ZOOM_REVERT "gimp-view-zoom-revert"
#define GIMP_HELP_VIEW_ZOOM_OUT "gimp-view-zoom-out" #define GIMP_HELP_VIEW_ZOOM_OUT "gimp-view-zoom-out"
#define GIMP_HELP_VIEW_ZOOM_IN "gimp-view-zoom-in" #define GIMP_HELP_VIEW_ZOOM_IN "gimp-view-zoom-in"
#define GIMP_HELP_VIEW_ZOOM_100 "gimp-view-zoom-100" #define GIMP_HELP_VIEW_ZOOM_100 "gimp-view-zoom-100"
......
...@@ -219,11 +219,12 @@ ...@@ -219,11 +219,12 @@
<menuitem action="view-new" /> <menuitem action="view-new" />
<menuitem action="view-dot-for-dot" /> <menuitem action="view-dot-for-dot" />
<menu action="view-zoom-menu" name="Zoom"> <menu action="view-zoom-menu" name="Zoom">
<menuitem action="view-zoom-revert" />
<menuitem action="view-zoom-out" /> <menuitem action="view-zoom-out" />
<menuitem action="view-zoom-in" /> <menuitem action="view-zoom-in" />
<menuitem action="view-zoom-fit-in" /> <menuitem action="view-zoom-fit-in" />
<menuitem action="view-zoom-fit-to" /> <menuitem action="view-zoom-fit-to" />
<separator /> <separator />
<menuitem action="view-zoom-16-1" /> <menuitem action="view-zoom-16-1" />
<menuitem action="view-zoom-8-1" /> <menuitem action="view-zoom-8-1" />
<menuitem action="view-zoom-4-1" /> <menuitem action="view-zoom-4-1" />
......
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