Commit c70aeb59 authored by Paolo Bacchilega's avatar Paolo Bacchilega
Browse files

started work on scripts support

parent c95579c6
......@@ -236,6 +236,8 @@ extensions/image_viewer/Makefile
extensions/image_viewer/data/Makefile
extensions/image_viewer/data/ui/Makefile
extensions/list_tools/Makefile
extensions/list_tools/data/Makefile
extensions/list_tools/data/ui/Makefile
extensions/search/Makefile
extensions/search/data/Makefile
extensions/search/data/ui/Makefile
......
SUBDIRS = data
extensiondir = $(libdir)/gthumb-2.0/extensions
extension_LTLIBRARIES = liblist_tools.la
......@@ -6,6 +8,14 @@ liblist_tools_la_SOURCES = \
actions.h \
callbacks.c \
callbacks.h \
dlg-personalize-scripts.c \
dlg-personalize-scripts.h \
gth-script.c \
gth-script.h \
gth-script-editor-dialog.c \
gth-script-editor-dialog.h \
gth-script-file.c \
gth-script-file.h \
main.c
liblist_tools_la_CFLAGS = $(GTHUMB_CFLAGS) $(DISABLE_DEPRECATED) $(WARNINGS) -I$(top_srcdir) -I$(top_builddir)/gthumb
......
......@@ -24,11 +24,12 @@
#include <config.h>
#include <glib/gi18n.h>
#include <gthumb.h>
#include "dlg-personalize-scripts.h"
void
gth_browser_action_list_tools_edit_scripts (GtkAction *action,
GthBrowser *browser)
GthBrowser *browser)
{
/* FIXME */
dlg_personalize_scripts (browser);
}
......@@ -26,6 +26,7 @@
#include <glib-object.h>
#include <gthumb.h>
#include "actions.h"
#include "gth-script-file.h"
#define BROWSER_DATA_KEY "list-tools-browser-data"
......@@ -35,10 +36,9 @@ static const char *fixed_ui_info =
"<ui>"
" <popup name='ListToolsPopup'>"
" <placeholder name='Tools'/>"
" <separator/>"
" <placeholder name='Scripts'/>"
" <separator/>"
" <menuitem action='ListTools_EditScripts'/>"
" <separator name='ScriptsListSeparator'/>"
" <menuitem name='EditScripts' action='ListTools_EditScripts'/>"
" </popup>"
"</ui>";
......@@ -52,18 +52,106 @@ static GtkActionEntry action_entries[] = {
typedef struct {
GthBrowser *browser;
GtkToolItem *tool_item;
GtkActionGroup *action_group;
gulong scripts_changed_id;
} BrowserData;
static void
browser_data_free (BrowserData *data)
{
g_signal_handler_disconnect (gth_script_file_get (), data->scripts_changed_id);
g_free (data);
}
static void
activate_script_menu_item (GtkMenuItem *menuitem,
gpointer user_data)
{
BrowserData *data = user_data;
GthScript *script;
script = gth_script_file_get_script (gth_script_file_get (), g_object_get_data (G_OBJECT (menuitem), "script_id"));
if (script != NULL) {
GList *items;
GList *file_list;
GthTask *task;
items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (data->browser)));
file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (data->browser)), items);
task = gth_script_get_task (script, file_list);
gth_browser_exec_task (data->browser, task);
g_object_unref (task);
_g_object_list_unref (file_list);
_gtk_tree_path_list_free (items);
}
}
static void
update_scripts_menu (BrowserData *data)
{
GtkWidget *separator1;
GtkWidget *separator2;
GtkWidget *menu;
GList *script_list;
GList *scan;
int pos;
gboolean script_present = FALSE;
separator1 = gtk_ui_manager_get_widget (gth_browser_get_ui_manager (data->browser), "/ListToolsPopup/Tools");
separator2 = gtk_ui_manager_get_widget (gth_browser_get_ui_manager (data->browser), "/ListToolsPopup/Scripts");
menu = gtk_widget_get_parent (separator1);
_gtk_container_remove_children (GTK_CONTAINER (menu), separator1, separator2);
script_list = gth_script_file_get_scripts (gth_script_file_get ());
pos = _gtk_container_get_pos (GTK_CONTAINER (menu), separator2);
for (scan = script_list; scan; scan = scan->next) {
GthScript *script = scan->data;
GtkWidget *menu_item;
if (! gth_script_is_visible (script))
continue;
menu_item = gtk_image_menu_item_new_with_label (gth_script_get_display_name (script));
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menu_item), gtk_image_new_from_stock (GTK_STOCK_EXECUTE, GTK_ICON_SIZE_MENU));
gtk_widget_show (menu_item);
gtk_menu_shell_insert (GTK_MENU_SHELL (menu), menu_item, pos++);
g_object_set_data_full (G_OBJECT (menu_item),
"script_id",
g_strdup (gth_script_get_id (script)),
(GDestroyNotify) g_free);
g_signal_connect (menu_item,
"activate",
G_CALLBACK (activate_script_menu_item),
data);
script_present = TRUE;
}
separator1 = gtk_ui_manager_get_widget (gth_browser_get_ui_manager (data->browser), "/ListToolsPopup/ScriptsListSeparator");
if (script_present)
gtk_widget_show (separator1);
else
gtk_widget_hide (separator1);
_g_object_list_unref (script_list);
}
static void
scripts_changed_cb (GthScriptFile *script_file,
BrowserData *data)
{
update_scripts_menu (data);
}
void
list_tools__gth_browser_construct_cb (GthBrowser *browser)
{
......@@ -73,7 +161,7 @@ list_tools__gth_browser_construct_cb (GthBrowser *browser)
g_return_if_fail (GTH_IS_BROWSER (browser));
data = g_new0 (BrowserData, 1);
data->browser = browser;
data->action_group = gtk_action_group_new ("List Tools Manager Actions");
gtk_action_group_set_translation_domain (data->action_group, NULL);
gtk_action_group_add_actions (data->action_group,
......@@ -97,6 +185,12 @@ list_tools__gth_browser_construct_cb (GthBrowser *browser)
gtk_toolbar_insert (GTK_TOOLBAR (gth_browser_get_browser_toolbar (browser)), data->tool_item, -1);
g_object_set_data_full (G_OBJECT (browser), BROWSER_DATA_KEY, data, (GDestroyNotify) browser_data_free);
update_scripts_menu (data);
data->scripts_changed_id = g_signal_connect (gth_script_file_get (),
"changed",
G_CALLBACK (scripts_changed_cb),
data);
}
......
SUBDIRS = ui
-include $(top_srcdir)/git.mk
uidir = $(datadir)/gthumb/ui
ui_DATA = personalize-scripts.ui script-editor.ui
EXTRA_DIST = $(ui_DATA)
-include $(top_srcdir)/git.mk
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.14"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkDialog" id="personalize_scripts_dialog">
<property name="border_width">5</property>
<property name="title" translatable="yes">Scripts</property>
<property name="type_hint">normal</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<object class="GtkVBox" id="dialog-vbox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child>
<object class="GtkVBox" id="vbox4">
<property name="visible">True</property>
<property name="border_width">6</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkVBox" id="vbox6">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkLabel" id="scripts_label">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">_Scripts:</property>
</object>
<packing>
<property name="expand">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="hbox3">
<property name="visible">True</property>
<property name="spacing">12</property>
<child>
<object class="GtkScrolledWindow" id="scripts_scrolledwindow">
<property name="width_request">250</property>
<property name="height_request">300</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hscrollbar_policy">automatic</property>
<property name="vscrollbar_policy">automatic</property>
<property name="shadow_type">etched-in</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkVButtonBox" id="vbuttonbox3">
<property name="visible">True</property>
<property name="spacing">6</property>
<property name="layout_style">start</property>
<child>
<object class="GtkButton" id="new_button">
<property name="label">gtk-new</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="edit_button">
<property name="label">gtk-edit</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="delete_button">
<property name="label">gtk-remove</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child internal-child="action_area">
<object class="GtkHButtonBox" id="dialog-action_area">
<property name="visible">True</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="close_button">
<property name="label">gtk-close</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="help_button">
<property name="label">gtk-help</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="use_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">1</property>
<property name="secondary">True</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="pack_type">end</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
<action-widgets>
<action-widget response="0">close_button</action-widget>
<action-widget response="0">help_button</action-widget>
</action-widgets>
</object>
</interface>
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkVBox" id="script_editor">
<property name="visible">True</property>
<property name="border_width">6</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child>
<object class="GtkTable" id="table1">
<property name="visible">True</property>
<property name="n_rows">5</property>
<property name="n_columns">2</property>
<property name="column_spacing">12</property>
<property name="row_spacing">6</property>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">_Name:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">name_entry</property>
</object>
<packing>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label4">
<property name="visible">True</property>
<property name="xalign">1</property>
<property name="label" translatable="yes">_Command:</property>
<property name="use_underline">True</property>
<property name="mnemonic_widget">name_entry</property>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">GTK_FILL</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="name_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x25CF;</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="command_entry">
<property name="width_request">400</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">&#x25CF;</property>
<property name="secondary_icon_stock">gtk-help</property>
<property name="secondary_icon_activatable">True</property>
<property name="secondary_icon_sensitive">True</property>
<property name="secondary_icon_tooltip_text">Help</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="wait_command_checkbutton">
<property name="label" translatable="yes">_Wait for the command to finish</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="right_attach">2</property>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
</packing>
</child>
<child>
<object class="GtkCheckButton" id="for_each_file_checkbutton">
<property name="label" translatable="yes">E_xecute the command a file at a time</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
<packing>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<object class="GtkHBox" id="command_help_box">
<child>
<object class="GtkTable" id="table2">
<property name="visible">True</property>
<property name="n_rows">7</property>
<property name="n_columns">2</property>
<property name="column_spacing">12</property>
<property name="row_spacing">6</property>
<child>
<object class="GtkLabel" id="label3">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">%U</property>
<attributes>
<attribute name="size" value="8000"/>
</attributes>
</object>
<packing>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">%F</property>
<attributes>
<attribute name="size" value="8000"/>
</attributes>
</object>
<packing>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label6">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">%B</property>
<attributes>
<attribute name="size" value="8000"/>
</attributes>
</object>
<packing>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label7">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">%P</property>
<attributes>
<attribute name="size" value="8000"/>
</attributes>
</object>
<packing>
<property name="top_attach">4</property>
<property name="bottom_attach">5</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label9">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">The file uri</property>
<attributes>
<attribute name="size" value="8000"/>
</attributes>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label10">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">The file path</property>
<attributes>
<attribute name="size" value="8000"/>
</attributes>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label11">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">The file basename</property>
<attributes>
<attribute name="size" value="8000"/>
</attributes>
</object>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">3</property>
<property name="bottom_attach">4</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label12">
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="label" translatable="yes">The parent folder path</property>
<attributes>
<attribute name="size" value="8000"/>
</attributes>
</object>