changeset 2440:cb9f25cb54f3

Orientation commands and file selections In the current implementation, the orientation commands (rotate, mirror etc.) affect only the single image that has focus. With this commit, the right-click menu orientation commands affect only the single image the right-click is made upon. The orientation commands from the main menu Edit/Orientation will affect all selected files.
author cclark <cclark@mcb.net>
date Tue, 14 Feb 2017 13:07:07 +0000
parents f48a3335c672
children d99bdd1115fd
files src/collect-table.c src/image.c src/image.h src/img-view.c src/layout_image.c src/typedefs.h src/view_file_icon.c
diffstat 7 files changed, 94 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/src/collect-table.c	Fri Feb 03 09:52:26 2017 +0000
+++ b/src/collect-table.c	Tue Feb 14 13:07:07 2017 +0000
@@ -62,14 +62,6 @@
 	CTABLE_COLUMN_COUNT
 };
 
-typedef enum {
-	SELECTION_NONE		= 0,
-	SELECTION_SELECTED	= 1 << 0,
-	SELECTION_PRELIGHT	= 1 << 1,
-	SELECTION_FOCUS		= 1 << 2
-} SelectionType;
-
-
 #define INFO_SELECTED(x) (x->flag_mask & SELECTION_SELECTED)
 
 
--- a/src/image.c	Fri Feb 03 09:52:26 2017 +0000
+++ b/src/image.c	Tue Feb 14 13:07:07 2017 +0000
@@ -375,7 +375,7 @@
 
 }
 
-void image_alter_orientation(ImageWindow *imd, AlterType type)
+void image_alter_orientation(ImageWindow *imd, FileData *fd_n, AlterType type)
 {
 	static const gint rotate_90[]    = {1,   6, 7, 8, 5, 2, 3, 4, 1};
 	static const gint rotate_90_cc[] = {1,   8, 5, 6, 7, 4, 1, 2, 3};
@@ -383,37 +383,49 @@
 	static const gint mirror[]       = {1,   2, 1, 4, 3, 6, 5, 8, 7};
 	static const gint flip[]         = {1,   4, 3, 2, 1, 8, 7, 6, 5};
 
+	gint orientation;
 
-	if (!imd || !imd->pr || !imd->image_fd) return;
+	if (!imd || !imd->pr || !imd->image_fd || !fd_n) return;
 
-	if (imd->orientation < 1 || imd->orientation > 8) imd->orientation = 1;
+	orientation = EXIF_ORIENTATION_TOP_LEFT;
+	{
+	if (fd_n->user_orientation)
+		{
+		orientation = fd_n->user_orientation;
+		}
+	else
+		if (options->metadata.write_orientation)
+			{
+			orientation = metadata_read_int(fd_n, ORIENTATION_KEY, EXIF_ORIENTATION_TOP_LEFT);
+			}
+	}
 
 	switch (type)
 		{
 		case ALTER_ROTATE_90:
-			imd->orientation = rotate_90[imd->orientation];
+			orientation = rotate_90[orientation];
 			break;
 		case ALTER_ROTATE_90_CC:
-			imd->orientation = rotate_90_cc[imd->orientation];
+			orientation = rotate_90_cc[orientation];
 			break;
 		case ALTER_ROTATE_180:
-			imd->orientation = rotate_180[imd->orientation];
+			orientation = rotate_180[orientation];
 			break;
 		case ALTER_MIRROR:
-			imd->orientation = mirror[imd->orientation];
+			orientation = mirror[orientation];
 			break;
 		case ALTER_FLIP:
-			imd->orientation = flip[imd->orientation];
+			orientation = flip[orientation];
 			break;
 		case ALTER_NONE:
-			imd->orientation = imd->image_fd->exif_orientation ? imd->image_fd->exif_orientation : 1;
+			orientation = fd_n->exif_orientation ? fd_n->exif_orientation : 1;
 			break;
 		default:
 			return;
 			break;
 		}
 
-	if (imd->orientation != (imd->image_fd->exif_orientation ? imd->image_fd->exif_orientation : 1))
+	if (orientation != (fd_n->exif_orientation ? fd_n->exif_orientation : 1))
 		{
 		if (!options->metadata.write_orientation)
 			{
@@ -422,29 +434,33 @@
 			   we must however handle switching metadata.write_orientation on and off, therefore
 			   we just disable referencing new fd's, not unreferencing the old ones
 			*/
-			if (imd->image_fd->user_orientation == 0) file_data_ref(imd->image_fd);
-			imd->image_fd->user_orientation = imd->orientation;
+			if (fd_n->user_orientation == 0) file_data_ref(fd_n);
+			fd_n->user_orientation = orientation;
 			}
 		}
 	else
 		{
-		if (imd->image_fd->user_orientation != 0) file_data_unref(imd->image_fd);
-		imd->image_fd->user_orientation = 0;
+		if (fd_n->user_orientation != 0) file_data_unref(fd_n);
+		fd_n->user_orientation = 0;
 		}
 
 	if (options->metadata.write_orientation)
 		{
 		if (type == ALTER_NONE)
 			{
-			metadata_write_revert(imd->image_fd, ORIENTATION_KEY);
+			metadata_write_revert(fd_n, ORIENTATION_KEY);
 			}
 		else
 			{
-			metadata_write_int(imd->image_fd, ORIENTATION_KEY, imd->orientation);
+			metadata_write_int(fd_n, ORIENTATION_KEY, orientation);
 			}
 		}
 
-	pixbuf_renderer_set_orientation((PixbufRenderer *)imd->pr, imd->orientation);
+	if (imd->image_fd == fd_n && !(options->metadata.write_orientation && !options->image.exif_rotate_enable))
+		{
+		imd->orientation = orientation;
+		pixbuf_renderer_set_orientation((PixbufRenderer *)imd->pr, orientation);
+		}
 }
 
 void image_set_desaturate(ImageWindow *imd, gboolean desaturate)
--- a/src/image.h	Fri Feb 03 09:52:26 2017 +0000
+++ b/src/image.h	Tue Feb 14 13:07:07 2017 +0000
@@ -85,7 +85,7 @@
 			   gdouble x_align, gdouble y_align);
 void image_get_scroll_center(ImageWindow *imd, gdouble *x, gdouble *y);
 void image_set_scroll_center(ImageWindow *imd, gdouble x, gdouble y);
-void image_alter_orientation(ImageWindow *imd, AlterType type);
+void image_alter_orientation(ImageWindow *imd, FileData *fd, AlterType type);
 void image_set_desaturate(ImageWindow *imd, gboolean desaturate);
 gboolean image_get_desaturate(ImageWindow *imd);
 
--- a/src/img-view.c	Fri Feb 03 09:52:26 2017 +0000
+++ b/src/img-view.c	Tue Feb 14 13:07:07 2017 +0000
@@ -421,13 +421,13 @@
 		switch (event->keyval)
 			{
 			case 'R': case 'r':
-				image_alter_orientation(imd, ALTER_ROTATE_180);
+				image_alter_orientation(imd, imd->image_fd, ALTER_ROTATE_180);
 				break;
 			case 'M': case 'm':
-				image_alter_orientation(imd, ALTER_MIRROR);
+				image_alter_orientation(imd, imd->image_fd, ALTER_MIRROR);
 				break;
 			case 'F': case 'f':
-				image_alter_orientation(imd, ALTER_FLIP);
+				image_alter_orientation(imd, imd->image_fd, ALTER_FLIP);
 				break;
 			case 'G': case 'g':
 				image_set_desaturate(imd, !image_get_desaturate(imd));
@@ -531,10 +531,10 @@
 				view_overlay_toggle(vw);
 				break;
 			case ']':
-				image_alter_orientation(imd, ALTER_ROTATE_90);
+				image_alter_orientation(imd, imd->image_fd, ALTER_ROTATE_90);
 				break;
 			case '[':
-				image_alter_orientation(imd, ALTER_ROTATE_90_CC);
+				image_alter_orientation(imd, imd->image_fd, ALTER_ROTATE_90_CC);
 				break;
 			case GDK_KEY_Delete: case GDK_KEY_KP_Delete:
 				if (options->file_ops.enable_delete_key)
@@ -1081,7 +1081,7 @@
 	type = GPOINTER_TO_INT(data);
 
 	if (!vw) return;
-	image_alter_orientation(vw->imd, type);
+	image_alter_orientation(vw->imd, vw->imd->image_fd, type);
 }
 
 static void view_wallpaper_cb(GtkWidget *widget, gpointer data)
--- a/src/layout_image.c	Fri Feb 03 09:52:26 2017 +0000
+++ b/src/layout_image.c	Tue Feb 14 13:07:07 2017 +0000
@@ -48,6 +48,7 @@
 
 #include <gdk/gdkkeysyms.h> /* for keyboard values */
 
+#define FILE_COLUMN_POINTER 0
 
 static GtkWidget *layout_image_pop_menu(LayoutWindow *lw);
 static void layout_image_set_buttons(LayoutWindow *lw);
@@ -484,7 +485,7 @@
 	lw = submenu_item_get_data(widget);
 	type = (AlterType)GPOINTER_TO_INT(data);
 
-	image_alter_orientation(lw->image, type);
+	image_alter_orientation(lw->image, lw->image->image_fd, type);
 }
 
 static void li_pop_menu_new_cb(GtkWidget *widget, gpointer data)
@@ -1062,7 +1063,45 @@
 {
 	if (!layout_valid(&lw)) return;
 
-	image_alter_orientation(lw->image, type);
+	GtkTreeModel *store;
+	GList *work;
+	GtkTreeSelection *selection;
+	GtkTreePath *tpath;
+	FileData *fd_n;
+	GtkTreeIter iter;
+	IconData *id;
+
+	if (!lw || !lw->vf) return;
+
+	if (lw->vf->type == FILEVIEW_ICON)
+		{
+		if (!VFICON(lw->vf)->selection) return;
+		work = VFICON(lw->vf)->selection;
+		}
+	else
+		{
+		selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(lw->vf->listview));
+		work = gtk_tree_selection_get_selected_rows(selection, &store);
+		}
+
+	while (work)
+		{
+		if (lw->vf->type == FILEVIEW_ICON)
+			{
+			id = work->data;
+			fd_n = id->fd;
+			work = work->next;
+			}
+		else
+			{
+			tpath = work->data;
+			gtk_tree_model_get_iter(store, &iter, tpath);
+			gtk_tree_model_get(store, &iter, FILE_COLUMN_POINTER, &fd_n, -1);
+			work = work->next;
+			}
+
+		image_alter_orientation(lw->image, fd_n, type);
+		}
 }
 
 void layout_image_reset_orientation(LayoutWindow *lw)
--- a/src/typedefs.h	Fri Feb 03 09:52:26 2017 +0000
+++ b/src/typedefs.h	Tue Feb 14 13:07:07 2017 +0000
@@ -843,7 +843,19 @@
 	guint select_idle_id; /* event source id */
 };
 
-struct _IconData;
+typedef enum {
+	SELECTION_NONE		= 0,
+	SELECTION_SELECTED	= 1 << 0,
+	SELECTION_PRELIGHT	= 1 << 1,
+	SELECTION_FOCUS		= 1 << 2
+} SelectionType;
+
+typedef struct _IconData IconData;
+struct _IconData
+{
+	SelectionType selected;
+	FileData *fd;
+};
 
 struct _ViewFileInfoIcon
 {
--- a/src/view_file_icon.c	Fri Feb 03 09:52:26 2017 +0000
+++ b/src/view_file_icon.c	Tue Feb 14 13:07:07 2017 +0000
@@ -60,20 +60,6 @@
 	FILE_COLUMN_COUNT
 };
 
-typedef enum {
-	SELECTION_NONE		= 0,
-	SELECTION_SELECTED	= 1 << 0,
-	SELECTION_PRELIGHT	= 1 << 1,
-	SELECTION_FOCUS		= 1 << 2
-} SelectionType;
-
-typedef struct _IconData IconData;
-struct _IconData
-{
-	SelectionType selected;
-	FileData *fd;
-};
-
 static gint vficon_index_by_id(ViewFile *vf, IconData *in_id);
 
 static IconData *vficon_icon_data(ViewFile *vf, FileData *fd)