Commit ea77e6b6 authored by Victor Ananjevsky's avatar Victor Ananjevsky

rework --file-op option

now it is in common section and works in html and picture dialogs too this option is required now to add open action in popup menu of html dialog
parent 4ee7df95
......@@ -640,6 +640,9 @@ Set path or uri to custom user styles. Path to local file can be an absolute fil
.B \-\-disable-search
Disable search bar.
.TP
.B \-\-file-op
Enable file operations. This option adds open menu item to popup menu,
.TP
.B \-\-wk-prop=\fIPROP\fP
Set additional WebKit setting. This option may be used multiply times. Setting \fIPROP\fP must be in a form "setting-name value". First character of value must be a type identifier \fIb\fP for booleans, \fIi\fP for integers and \fIs\fP for strings. The values itself following by a colon. List of possible settings can be found on this page - https://webkitgtk.org/reference/webkit2gtk/stable/WebKitSettings.html
.PP
......@@ -868,6 +871,9 @@ Set increment value for scaling image.
.B \-\-filename=\fIFILENAME\fP
Set picture filename. If no file name is specified extra data will be used. In this case several filenames can be specified.
.TP
.B \-\-file-op
Enable file operations. This option adds open menu item to popup menu,
.TP
.B \-\-image-changed=\fICMD\fP
Set command which runs after changing image. Argument of a command is a filename of current image. Argument can be specified by '\fI%s\fP' pattern or will be the last part of a command.
.PP
......
......@@ -288,14 +288,17 @@ menu_cb (WebKitWebView *view, WebKitContextMenu *menu, GdkEvent *ev, WebKitHitTe
WebKitContextMenuItem *mi;
GSimpleAction *act;
mi = webkit_context_menu_item_new_separator ();
webkit_context_menu_prepend (menu, mi);
if (options.common_data.file_op)
{
mi = webkit_context_menu_item_new_separator ();
webkit_context_menu_prepend (menu, mi);
act = g_simple_action_new ("open", NULL);
g_signal_connect (G_OBJECT (act), "activate", G_CALLBACK (open_cb), d);
act = g_simple_action_new ("open", NULL);
g_signal_connect (G_OBJECT (act), "activate", G_CALLBACK (open_cb), d);
mi = webkit_context_menu_item_new_from_gaction (G_ACTION (act), _("Open URI"), NULL);
webkit_context_menu_prepend (menu, mi);
mi = webkit_context_menu_item_new_from_gaction (G_ACTION (act), _("Open URI"), NULL);
webkit_context_menu_prepend (menu, mi);
}
mi = webkit_context_menu_item_new_separator ();
webkit_context_menu_append (menu, mi);
......
......@@ -232,6 +232,8 @@ static GOptionEntry common_options[] = {
N_("Make main widget scrollable"), NULL },
{ "disable-search", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &options.common_data.enable_search,
N_("Disable search in text and html dialogs"), NULL },
{ "file-op", 0, 0, G_OPTION_ARG_NONE, &options.common_data.file_op,
N_("Enable file operations"), NULL },
#if GLIB_CHECK_VERSION(2,30,0)
{ "iec-format", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, set_size_format,
N_("Use IEC (base 1024) units with for size values"), NULL },
......@@ -663,8 +665,6 @@ static GOptionEntry text_options[] = {
N_("Use pango markup"), NULL },
{ "in-place", 0, 0, G_OPTION_ARG_NONE, &options.text_data.in_place,
N_("Save file instead of print on exit"), NULL },
{ "file-op", 0, 0, G_OPTION_ARG_NONE, &options.text_data.file_op,
N_("Enable file operations"), NULL },
{ "confirm-save", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, add_confirm_save,
N_("Confirm save the file if text was changed"), N_("[TEXT]") },
{ NULL }
......@@ -1669,6 +1669,7 @@ yad_options_init (void)
options.common_data.icon_size = 0;
options.common_data.scroll = FALSE;
options.common_data.enable_search = TRUE;
options.common_data.file_op = FALSE;
#if GLIB_CHECK_VERSION(2,30,0)
options.common_data.size_fmt = G_FORMAT_SIZE_DEFAULT;
#endif
......@@ -1877,7 +1878,6 @@ yad_options_init (void)
#endif
options.text_data.formatted = FALSE;
options.text_data.in_place = FALSE;
options.text_data.file_op = FALSE;
#ifdef HAVE_SOURCEVIEW
/* Initialize sourceview data */
......
......@@ -54,9 +54,28 @@ static GtkWidget *picture;
static GtkWidget *viewport;
static GtkWidget *popup_menu;
static void create_popup_menu ();
static void
img_free (ImageItem *ii)
{
if (ii)
{
g_free (ii->filename);
if (ii->orig_pb)
g_object_unref (ii->orig_pb);
if (ii->anim_pb)
g_object_unref (ii->anim_pb);
g_free (ii);
}
}
static void
load_picture ()
{
if (!img)
return;
if (!img->loaded)
{
if (img->filename && g_file_test (img->filename, G_FILE_TEST_EXISTS))
......@@ -75,6 +94,8 @@ load_picture ()
gtk_image_set_from_animation (GTK_IMAGE (picture), g_object_ref (img->anim_pb));
else
gtk_image_set_from_pixbuf (GTK_IMAGE (picture), g_object_ref (img->orig_pb));
if (options.picture_data.size == YAD_PICTURE_FIT)
picture_fit_to_window ();
}
else
gtk_image_set_from_icon_name (GTK_IMAGE (picture), "image-missing", GTK_ICON_SIZE_DIALOG);
......@@ -109,8 +130,6 @@ next_img_cb (GtkWidget *w, gpointer d)
img = (ImageItem *) lp->data;
load_picture ();
if (options.picture_data.size == YAD_PICTURE_FIT)
picture_fit_to_window ();
img_changed_hook ();
}
......@@ -124,8 +143,6 @@ prev_img_cb (GtkWidget *w, gpointer d)
img = (ImageItem *) lp->data;
load_picture ();
if (options.picture_data.size == YAD_PICTURE_FIT)
picture_fit_to_window ();
img_changed_hook ();
}
......@@ -137,8 +154,6 @@ first_img_cb (GtkWidget *w, gpointer d)
img = (ImageItem *) lp->data;
load_picture ();
if (options.picture_data.size == YAD_PICTURE_FIT)
picture_fit_to_window ();
img_changed_hook ();
}
......@@ -150,8 +165,6 @@ last_img_cb (GtkWidget *w, gpointer d)
img = (ImageItem *) lp->data;
load_picture ();
if (options.picture_data.size == YAD_PICTURE_FIT)
picture_fit_to_window ();
img_changed_hook ();
}
......@@ -161,7 +174,7 @@ picture_fit_to_window ()
gdouble width, height, ww, wh;
gdouble factor;
if (!gtk_widget_get_realized (viewport))
if (!gtk_widget_get_realized (viewport) || !img)
return;
width = gdk_pixbuf_get_width (img->orig_pb);
......@@ -261,6 +274,75 @@ rotate_cb (GtkWidget *w, gint type)
}
static void
open_file_cb (GtkWidget *w, gpointer d)
{
GtkWidget *dlg;
static GtkFileFilter *imgf = NULL;
static GtkFileFilter *allf = NULL;
static gchar *dir = NULL;
if (!imgf)
{
imgf = gtk_file_filter_new ();
gtk_file_filter_set_name (imgf, _("Images"));
gtk_file_filter_add_pixbuf_formats (imgf);
}
if (!allf)
{
allf = gtk_file_filter_new ();
gtk_file_filter_set_name (allf, _("All files"));
gtk_file_filter_add_pattern (allf, "*");
}
dlg = gtk_file_chooser_dialog_new (_("YAD - Select Image(s)"),
GTK_WINDOW (gtk_widget_get_toplevel (w)),
GTK_FILE_CHOOSER_ACTION_OPEN,
_("Cancel"), GTK_RESPONSE_CANCEL,
_("OK"), GTK_RESPONSE_ACCEPT,
NULL);
gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dlg), TRUE);
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dlg), imgf);
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dlg), allf);
if (dir)
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dlg), dir);
if (gtk_dialog_run (GTK_DIALOG (dlg)) == GTK_RESPONSE_ACCEPT)
{
GSList *fp, *fn = gtk_file_chooser_get_filenames (GTK_FILE_CHOOSER (dlg));
if (img_list)
{
g_list_free_full (img_list, (GDestroyNotify) img_free);
img_list = NULL;
}
for (fp = fn; fp; fp = fp->next)
{
ImageItem *ii = g_new0 (ImageItem, 1);
ii->filename = g_strdup (fp->data);
img_list = g_list_append (img_list, ii);
}
g_slist_free_full (fn, g_free);
lp = g_list_first (img_list);
img = (ImageItem *) lp->data;
load_picture ();
/* recreate menu */
gtk_widget_destroy (popup_menu);
create_popup_menu ();
/* keep current dir */
g_free (dir);
dir = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dlg));
}
gtk_widget_destroy (dlg);
}
static void
copy_cb (GtkWidget *w, gint type)
{
GtkClipboard *clip;
......@@ -286,6 +368,20 @@ create_popup_menu ()
popup_menu = gtk_menu_new ();
gtk_menu_set_reserve_toggle_size (GTK_MENU (popup_menu), FALSE);
if (options.common_data.file_op)
{
mi = gtk_menu_item_new_with_label (_("Open file(s)..."));
al = gtk_bin_get_child (GTK_BIN (mi));
gtk_accel_label_set_accel (GTK_ACCEL_LABEL (al), GDK_KEY_o, GDK_CONTROL_MASK);
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), mi);
g_signal_connect (G_OBJECT (mi), "activate", G_CALLBACK (open_file_cb), NULL);
mi = gtk_separator_menu_item_new ();
gtk_widget_show (mi);
gtk_menu_shell_append (GTK_MENU_SHELL (popup_menu), mi);
}
if (img_list)
{
mi = gtk_menu_item_new_with_label (_("Next image"));
......@@ -399,7 +495,7 @@ create_popup_menu ()
static gboolean
button_handler (GtkWidget *w, GdkEventButton *ev, gpointer data)
{
if (ev->button == 3 && !img->animated)
if (ev->button == 3 && (!img || !img->animated))
{
gtk_menu_popup_at_pointer (GTK_MENU (popup_menu), NULL);
return TRUE;
......@@ -435,7 +531,10 @@ key_handler (GtkWidget *w, GdkEventKey *ev, gpointer data)
return TRUE;
case GDK_KEY_O:
case GDK_KEY_o:
change_size_cb (w, SIZE_ORIG);
if (ev->state & GDK_CONTROL_MASK)
open_file_cb (w, NULL);
else
change_size_cb (w, SIZE_ORIG);
return TRUE;
case GDK_KEY_plus:
case GDK_KEY_KP_Add:
......@@ -489,7 +588,7 @@ static void init_img_data ()
ImageItem *ii;
ii = g_new0 (ImageItem, 1);
ii->filename = args[i];
ii->filename = g_strdup (args[i]);
img_list = g_list_append (img_list, ii);
i++;
}
......@@ -519,18 +618,18 @@ picture_create_widget (GtkWidget * dlg)
gtk_widget_set_can_focus (picture, TRUE); /* need to get key press events */
gtk_container_add (GTK_CONTAINER (ev), picture);
/* load picture */
g_signal_connect (G_OBJECT (ev), "button-press-event", G_CALLBACK (button_handler), NULL);
g_signal_connect (G_OBJECT (ev), "key-press-event", G_CALLBACK (key_handler), NULL);
g_signal_connect (G_OBJECT (ev), "size-allocate", G_CALLBACK (size_allocate_cb), NULL);
init_img_data ();
load_picture ();
/* must be after calling init_img_data() */
create_popup_menu ();
/* load picture */
if (img)
{
create_popup_menu ();
g_signal_connect (G_OBJECT (ev), "button-press-event", G_CALLBACK (button_handler), NULL);
g_signal_connect (G_OBJECT (ev), "key-press-event", G_CALLBACK (key_handler), NULL);
g_signal_connect (G_OBJECT (ev), "size-allocate", G_CALLBACK (size_allocate_cb), NULL);
load_picture (0);
}
load_picture ();
else
gtk_image_set_from_icon_name (GTK_IMAGE (picture), "image-missing", GTK_ICON_SIZE_DIALOG);
......
......@@ -231,7 +231,7 @@ menu_popup_cb (GtkTextView *w, GtkWidget *popup, gpointer d)
if (!GTK_IS_MENU (popup))
return;
if (options.text_data.file_op)
if (options.common_data.file_op)
{
GtkWidget *mitem;
......@@ -285,7 +285,7 @@ key_press_cb (GtkWidget *w, GdkEventKey *key, gpointer d)
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (search_bar->bar), TRUE);
return gtk_search_bar_handle_event (GTK_SEARCH_BAR (search_bar->bar), (GdkEvent *) key);
}
else if (options.text_data.file_op)
else if (options.common_data.file_op)
{
if ((key->state & GDK_CONTROL_MASK) && (key->keyval == GDK_KEY_O || key->keyval == GDK_KEY_o))
{
......@@ -786,7 +786,7 @@ text_create_widget (GtkWidget * dlg)
/* Add keyboard handler */
g_signal_connect (text_view, "key-press-event", G_CALLBACK (key_press_cb), dlg);
if (options.text_data.file_op)
if (options.common_data.file_op)
{
g_signal_connect (G_OBJECT (text_buffer), "changed", G_CALLBACK (text_changed_cb), NULL);
g_signal_connect_after (G_OBJECT (text_view), "populate-popup", G_CALLBACK (menu_popup_cb), dlg);
......
......@@ -479,7 +479,6 @@ typedef struct {
gchar *fore;
gchar *back;
gboolean in_place;
gboolean file_op;
gboolean confirm_save;
gchar *confirm_text;
} YadTextData;
......@@ -527,6 +526,7 @@ typedef struct {
gboolean hide_text;
gint icon_size;
gboolean enable_search;
gboolean file_op;
gboolean scroll;
#if GLIB_CHECK_VERSION(2,30,0)
GFormatSizeFlags size_fmt;
......
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