Skip to content

Commit

Permalink
rewritten utilops.h:
Browse files Browse the repository at this point in the history
- better integration of external commands
- filter commands
  • Loading branch information
nadvornik committed May 24, 2008
1 parent d2e0888 commit 56b0d6e
Show file tree
Hide file tree
Showing 19 changed files with 1,064 additions and 2,436 deletions.
72 changes: 39 additions & 33 deletions src/bar_sort.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "layout.h"
#include "layout_image.h"
#include "utilops.h"
#include "editors.h"
#include "ui_bookmark.h"
#include "ui_fileops.h"
#include "ui_menu.h"
Expand All @@ -41,8 +42,8 @@ typedef enum {
typedef enum {
BAR_SORT_COPY = 0,
BAR_SORT_MOVE,
BAR_SORT_LINK,
BAR_SORT_ACTION_COUNT
BAR_SORT_FILTER,
BAR_SORT_ACTION_COUNT = BAR_SORT_FILTER + GQ_EDITOR_GENERIC_SLOTS
} SortActionType;

typedef enum {
Expand Down Expand Up @@ -203,24 +204,16 @@ static void bar_sort_undo_folder(SortData *sd, GtkWidget *button)

list = g_list_append(NULL, file_data_new_simple(sd->undo_dest));
src_dir = remove_level_from_path(sd->undo_src);
file_util_move_simple(list, src_dir);
file_util_move_simple(list, src_dir, sd->lw->window);
g_free(src_dir);
}
break;
case BAR_SORT_COPY:
file_util_delete(file_data_new_simple(sd->undo_dest), NULL, button);
break;
case BAR_SORT_LINK:
if (!unlink_file(sd->undo_dest))
{
gchar *buf;

buf = g_strdup_printf(_("Unable to remove symbolic link:\n%s"), sd->undo_dest);
file_util_warning_dialog(_("Unlink failed"), buf, GTK_STOCK_DIALOG_ERROR, button);
g_free(buf);
}
break;
default:
/* undo external command */
file_util_delete(file_data_new_simple(sd->undo_dest), NULL, button);
break;
}

Expand Down Expand Up @@ -280,30 +273,21 @@ static void bar_sort_bookmark_select_folder(SortData *sd, FileData *source, cons
switch (sd->action)
{
case BAR_SORT_COPY:
file_util_copy_simple(list, path);
file_util_copy_simple(list, path, sd->lw->window);
list = NULL;
layout_image_next(sd->lw);
break;
case BAR_SORT_MOVE:
file_util_move_simple(list, path);
file_util_move_simple(list, path, sd->lw->window);
list = NULL;
break;
case BAR_SORT_LINK:
if (symlink_utf8(source->path, dest_path))
default:
if (sd->action >= BAR_SORT_FILTER && sd->action < BAR_SORT_ACTION_COUNT)
{
file_util_start_filter_from_filelist(sd->action - BAR_SORT_FILTER, list, path, sd->lw->window);
list = NULL;
layout_image_next(sd->lw);
}
else
{
gchar *buf;

buf = g_strdup_printf(_("Unable to create symbolic link:\n%s"), dest_path);
file_util_warning_dialog(_("Link failed"), buf, GTK_STOCK_DIALOG_ERROR, sd->bookmarks);

g_free(buf);
}
break;
default:
break;
}

Expand Down Expand Up @@ -382,11 +366,15 @@ static void bar_sort_set_move_cb(GtkWidget *button, gpointer data)
bar_sort_set_action(sd, BAR_SORT_MOVE);
}

static void bar_sort_set_link_cb(GtkWidget *button, gpointer data)
static void bar_sort_set_filter_cb(GtkWidget *button, gpointer data)
{
SortData *sd = data;
gint n;
if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button))) return;
bar_sort_set_action(sd, BAR_SORT_LINK);
n = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(button), "filter_idx"));
if (n == 0) return;
n--;
bar_sort_set_action(sd, BAR_SORT_FILTER + n);
}

static void bar_sort_set_selection(SortData *sd, SortSelectionType selection)
Expand Down Expand Up @@ -561,6 +549,7 @@ GtkWidget *bar_sort_new(LayoutWindow *lw)
GtkWidget *tbar;
GtkWidget *combo;
SortModeType mode;
guint i;

if (!lw) return NULL;

Expand All @@ -570,6 +559,9 @@ GtkWidget *bar_sort_new(LayoutWindow *lw)

mode = CLAMP(options->panels.sort.mode_state, 0, BAR_SORT_MODE_COUNT - 1);
sd->action = CLAMP(options->panels.sort.action_state, 0, BAR_SORT_ACTION_COUNT - 1);

while (sd->action >= BAR_SORT_FILTER && !editor_is_filter(sd->action - BAR_SORT_FILTER)) sd->action--;

sd->selection = CLAMP(options->panels.sort.selection_state, 0, BAR_SORT_SELECTION_COUNT - 1);
sd->undo_src = NULL;
sd->undo_dest = NULL;
Expand Down Expand Up @@ -602,9 +594,23 @@ GtkWidget *bar_sort_new(LayoutWindow *lw)
pref_radiobutton_new(sd->folder_group, buttongrp,
_("Move"), (sd->action == BAR_SORT_MOVE),
G_CALLBACK(bar_sort_set_move_cb), sd);
pref_radiobutton_new(sd->folder_group, buttongrp,
_("Link"), (sd->action == BAR_SORT_LINK),
G_CALLBACK(bar_sort_set_link_cb), sd);


for (i = 0; i < GQ_EDITOR_GENERIC_SLOTS; i++)
{
GtkWidget *button;

const gchar *name = editor_get_name(i);
if (!name || !editor_is_filter(i)) continue;

button = pref_radiobutton_new(sd->folder_group, buttongrp,
name, (sd->action == BAR_SORT_FILTER + i),
G_CALLBACK(bar_sort_set_filter_cb), sd);


g_object_set_data(G_OBJECT(button), "filter_idx", GUINT_TO_POINTER(i + 1));
}


sd->collection_group = pref_box_new(sd->vbox, FALSE, GTK_ORIENTATION_VERTICAL, 0);

Expand Down
2 changes: 1 addition & 1 deletion src/collect-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ static void collection_table_popup_edit_cb(GtkWidget *widget, gpointer data)
list = collection_table_popup_file_list(ct);
if (list)
{
start_editor_from_filelist(n, list);
file_util_start_editor_from_filelist(n, list, ct->listview);
filelist_free(list);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/collect.c
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ static gint collection_window_keypress(GtkWidget *widget, GdkEventKey *event, gp
if (edit_val != -1)
{
list = collection_table_selection_get_list(cw->table);
start_editor_from_filelist(edit_val, list);
file_util_start_editor_from_filelist(edit_val, list, cw->window);
filelist_free(list);
}

Expand Down
2 changes: 1 addition & 1 deletion src/dupe.c
Original file line number Diff line number Diff line change
Expand Up @@ -2053,7 +2053,7 @@ static void dupe_window_edit_selected(DupeWindow *dw, gint n)

list = dupe_listview_get_selection(dw, dw->listview);

start_editor_from_filelist(n, list);
file_util_start_editor_from_filelist(n, list, dw->window);

filelist_free(list);
}
Expand Down
7 changes: 7 additions & 0 deletions src/editors.c
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,13 @@ gint editor_window_flag_set(gint n)
return (editor_command_parse(options->editor[n].command, NULL, NULL) & EDITOR_KEEP_FS);
}

gint editor_is_filter(gint n)
{
if (!is_valid_editor_command(n)) return FALSE;

return (editor_command_parse(options->editor[n].command, NULL, NULL) & EDITOR_DEST);
}

const gchar *editor_get_error_str(gint flags)
{
if (flags & EDITOR_ERROR_EMPTY) return _("Editor template is empty.");
Expand Down
1 change: 1 addition & 0 deletions src/editors.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ gint start_editor_from_filelist(gint n, GList *list);
gint start_editor_from_file_full(gint n, FileData *fd, EditorCallback cb, gpointer data);
gint start_editor_from_filelist_full(gint n, GList *list, EditorCallback cb, gpointer data);
gint editor_window_flag_set(gint n);
gint editor_is_filter(gint n);
const gchar *editor_get_error_str(gint flags);

const gchar *editor_get_name(gint n);
Expand Down
43 changes: 40 additions & 3 deletions src/filedata.c
Original file line number Diff line number Diff line change
Expand Up @@ -1022,9 +1022,11 @@ gboolean file_data_sc_add_ci_delete(FileData *fd)
return file_data_sc_add_ci(fd, FILEDATA_CHANGE_DELETE);
}

gboolean file_data_sc_add_ci_update(FileData *fd)
gboolean file_data_sc_add_ci_unspecified(FileData *fd, const gchar *dest_path)
{
return file_data_sc_add_ci(fd, FILEDATA_CHANGE_UPDATE);
if (!file_data_sc_add_ci(fd, FILEDATA_CHANGE_UNSPECIFIED)) return FALSE;
file_data_sc_update_ci_unspecified(fd, dest_path);
return TRUE;
}

void file_data_sc_free_ci(FileData *fd)
Expand Down Expand Up @@ -1099,6 +1101,20 @@ gboolean file_data_sc_add_ci_rename_list(GList *fd_list, const gchar *dest)
return ret;
}

gboolean file_data_sc_add_ci_unspecified_list(GList *fd_list, const gchar *dest)
{
GList *work;
gboolean ret = TRUE;
work = fd_list;
while (work)
{
FileData *fd = work->data;
if (!file_data_sc_add_ci_unspecified(fd, dest)) ret = FALSE;
work = work->next;
}
return ret;
}

void file_data_sc_free_ci_list(GList *fd_list)
{
GList *work;
Expand Down Expand Up @@ -1186,6 +1202,13 @@ gint file_data_sc_update_ci_rename(FileData *fd, const gchar *dest_path)
return TRUE;
}

gint file_data_sc_update_ci_unspecified(FileData *fd, const gchar *dest_path)
{
if (!file_data_sc_check_ci(fd, FILEDATA_CHANGE_UNSPECIFIED)) return FALSE;
file_data_sc_update_ci(fd, dest_path);
return TRUE;
}


gboolean file_data_sc_update_ci_move_list(GList *fd_list, const gchar *dest)
{
Expand Down Expand Up @@ -1215,6 +1238,20 @@ gboolean file_data_sc_update_ci_copy_list(GList *fd_list, const gchar *dest)
return ret;
}

gboolean file_data_sc_update_ci_unspecified_list(GList *fd_list, const gchar *dest)
{
GList *work;
gboolean ret = TRUE;
work = fd_list;
while (work)
{
FileData *fd = work->data;
if (!file_data_sc_update_ci_unspecified(fd, dest)) ret = FALSE;
work = work->next;
}
return ret;
}


/*
* check dest paths - dest image exists, etc.
Expand Down Expand Up @@ -1266,7 +1303,7 @@ static gboolean file_data_perform_ci(FileData *fd)
return file_data_perform_move(fd); /* the same as move */
case FILEDATA_CHANGE_DELETE:
return file_data_perform_delete(fd);
case FILEDATA_CHANGE_UPDATE:
case FILEDATA_CHANGE_UNSPECIFIED:
/* nothing to do here */
break;
}
Expand Down
5 changes: 4 additions & 1 deletion src/filedata.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,23 @@ gboolean file_data_sc_add_ci_copy(FileData *fd, const gchar *dest_path);
gboolean file_data_sc_add_ci_move(FileData *fd, const gchar *dest_path);
gboolean file_data_sc_add_ci_rename(FileData *fd, const gchar *dest_path);
gboolean file_data_sc_add_ci_delete(FileData *fd);
gboolean file_data_sc_add_ci_update(FileData *fd);
gboolean file_data_sc_add_ci_unspecified(FileData *fd, const gchar *dest_path);

gboolean file_data_sc_add_ci_delete_list(GList *fd_list);
gboolean file_data_sc_add_ci_copy_list(GList *fd_list, const gchar *dest);
gboolean file_data_sc_add_ci_move_list(GList *fd_list, const gchar *dest);
gboolean file_data_sc_add_ci_rename_list(GList *fd_list, const gchar *dest);
gboolean file_data_sc_add_ci_unspecified_list(GList *fd_list, const gchar *dest);

gboolean file_data_sc_update_ci_copy_list(GList *fd_list, const gchar *dest);
gboolean file_data_sc_update_ci_move_list(GList *fd_list, const gchar *dest);
gboolean file_data_sc_update_ci_unspecified_list(GList *fd_list, const gchar *dest);


gint file_data_sc_update_ci_copy(FileData *fd, const gchar *dest_path);
gint file_data_sc_update_ci_move(FileData *fd, const gchar *dest_path);
gint file_data_sc_update_ci_rename(FileData *fd, const gchar *dest_path);
gint file_data_sc_update_ci_unspecified(FileData *fd, const gchar *dest_path);
gint file_data_sc_check_ci_dest(FileData *fd);
gboolean file_data_sc_perform_ci(FileData *fd);
gint file_data_sc_apply_ci(FileData *fd);
Expand Down
4 changes: 2 additions & 2 deletions src/img-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ static gint view_window_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpoi
view_fullscreen_toggle(vw, TRUE);
}
imd = view_window_active_image(vw);
start_editor_from_file(n, image_get_fd(imd));
file_util_start_editor_from_file(n, image_get_fd(imd), imd->widget);
}
}
else if (event->state & GDK_SHIFT_MASK)
Expand Down Expand Up @@ -1085,7 +1085,7 @@ static void view_edit_cb(GtkWidget *widget, gpointer data)
}

imd = view_window_active_image(vw);
start_editor_from_file(n, image_get_fd(imd));
file_util_start_editor_from_file(n, image_get_fd(imd), imd->widget);
}

static void view_alter_cb(GtkWidget *widget, gpointer data)
Expand Down
4 changes: 2 additions & 2 deletions src/layout_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ static gint layout_image_full_screen_key_press_cb(GtkWidget *widget, GdkEventKey
{
layout_image_full_screen_stop(lw);
}
start_editor_from_file(n, layout_image_get_fd(lw));
file_util_start_editor_from_file(n, layout_image_get_fd(lw), lw->widget);
}
}
else if (event->state & GDK_SHIFT_MASK)
Expand Down Expand Up @@ -575,7 +575,7 @@ static void li_pop_menu_edit_cb(GtkWidget *widget, gpointer data)
{
layout_image_full_screen_stop(lw);
}
start_editor_from_file(n, layout_image_get_fd(lw));
file_util_start_editor_from_file(n, layout_image_get_fd(lw), lw->window);
}

static void li_pop_menu_wallpaper_cb(GtkWidget *widget, gpointer data)
Expand Down
2 changes: 1 addition & 1 deletion src/layout_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ static void layout_menu_edit_cb(GtkAction *action, gpointer data)
layout_image_full_screen_stop(lw);
}
list = layout_selection_list(lw);
start_editor_from_filelist(n, list);
file_util_start_editor_from_filelist(n, list, lw->window);
filelist_free(list);
}

Expand Down
4 changes: 2 additions & 2 deletions src/pan-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,7 @@ static gint pan_window_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpoin
{
pan_fullscreen_toggle(pw, TRUE);
}
start_editor_from_file(n, fd);
file_util_start_editor_from_file(n, fd, GTK_WIDGET(pr));
}
}
else
Expand Down Expand Up @@ -2668,7 +2668,7 @@ static void pan_edit_cb(GtkWidget *widget, gpointer data)
{
pan_fullscreen_toggle(pw, TRUE);
}
start_editor_from_file(n, fd);
file_util_start_editor_from_file(n, fd, pw->imd->widget);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ static void search_result_edit_selected(SearchData *sd, gint n)
GList *list;

list = search_result_selection_list(sd);
start_editor_from_filelist(n, list);
file_util_start_editor_from_filelist(n, list, sd->window);
filelist_free(list);
}

Expand Down
2 changes: 1 addition & 1 deletion src/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ typedef enum {
FILEDATA_CHANGE_MOVE,
FILEDATA_CHANGE_RENAME,
FILEDATA_CHANGE_COPY,
FILEDATA_CHANGE_UPDATE
FILEDATA_CHANGE_UNSPECIFIED
} FileDataChangeType;

typedef enum {
Expand Down
Loading

0 comments on commit 56b0d6e

Please sign in to comment.