Skip to content

Commit

Permalink
Right-click menus - collections
Browse files Browse the repository at this point in the history
On all relevent right-click menus include a sub-menu to store an image
selection to either a new or existing collection.

On Collection window right-click menu, remove "Append from file list" -
that can be achieved with "Append from file selection"
  • Loading branch information
caclark committed Aug 18, 2017
1 parent 01715c0 commit ae34634
Show file tree
Hide file tree
Showing 15 changed files with 362 additions and 65 deletions.
69 changes: 69 additions & 0 deletions src/collect-io.c
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,75 @@ void collect_manager_notify_cb(FileData *fd, NotifyType type, gpointer data)
case FILEDATA_CHANGE_WRITE_METADATA:
break;
}
}

static gint collection_manager_sort_cb(gconstpointer a, gconstpointer b)
{
const gchar *char_a = a;
const gchar *char_b = b;

return g_strcmp0(char_a, char_b);
}

/* Creates sorted list of collections
* Inputs: none
* Outputs: list of type gchar
* sorted list of collections names excluding extension
* sorted list of collections names including extension
* sorted list of collection paths
* Return: none
* Used lists must be freed with string_list_free()
*/
void collect_manager_list(GList **names_exc, GList **names_inc, GList **paths)
{
FileData *dir_fd;
GList *list = NULL;
gchar *name;
FileData *fd;
gchar *filename;

if (names_exc == NULL && names_inc == NULL && paths == NULL)
{
return;
}

dir_fd = file_data_new_dir((get_collections_dir()));

filelist_read(dir_fd, &list, NULL);

while (list)
{
fd = list->data;
filename = g_strdup(filename_from_path((gchar *)fd->path));

if (file_extension_match(filename, GQ_COLLECTION_EXT))
{
name = remove_extension_from_path(filename);

if (names_exc != NULL)
{
*names_exc = g_list_insert_sorted(*names_exc, g_strdup(name),
collection_manager_sort_cb);
*names_exc = g_list_first(*names_exc);
}
if (names_inc != NULL)
{
*names_inc = g_list_insert_sorted(*names_inc,filename,
collection_manager_sort_cb);
*names_inc = g_list_first(*names_inc);
}
if (paths != NULL)
{
*paths = g_list_insert_sorted(*paths,fd->path,
collection_manager_sort_cb);
*paths = g_list_first(*paths);
}
g_free(name);
}
list = list->next;
g_free(filename);
}

filelist_free(list);
}
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
2 changes: 1 addition & 1 deletion src/collect-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void collect_manager_remove(FileData *fd, const gchar *collection);
void collect_manager_flush(void);

void collect_manager_notify_cb(FileData *fd, NotifyType type, gpointer data);

void collect_manager_list(GList **names_exc, GList **names_inc, GList **paths);

#endif
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
16 changes: 0 additions & 16 deletions src/collect-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -828,20 +828,6 @@ static void collection_table_popup_remove_cb(GtkWidget *widget, gpointer data)
g_list_free(list);
}

static void collection_table_popup_add_filelist_cb(GtkWidget *widget, gpointer data)
{
CollectTable *ct = data;
GList *list;

list = layout_list(NULL);

if (list)
{
collection_table_add_filelist(ct, list);
filelist_free(list);
}
}

static void collection_table_popup_add_file_selection_cb(GtkWidget *widget, gpointer data)
{
CollectTable *ct = data;
Expand Down Expand Up @@ -929,8 +915,6 @@ static GtkWidget *collection_table_popup_menu(CollectTable *ct, gboolean over_ic

menu_item_add_stock(menu, _("Append from file selection"), GTK_STOCK_ADD,
G_CALLBACK(collection_table_popup_add_file_selection_cb), ct);
menu_item_add_stock(menu, _("Append from file list"), GTK_STOCK_ADD,
G_CALLBACK(collection_table_popup_add_filelist_cb), ct);
menu_item_add_stock(menu, _("Append from collection..."), GTK_STOCK_OPEN,
G_CALLBACK(collection_table_popup_add_collection_cb), ct);
menu_item_add_divider(menu);
Expand Down
59 changes: 57 additions & 2 deletions src/collect.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@
#define COLLECT_DEF_WIDTH 440
#define COLLECT_DEF_HEIGHT 450

static GList *collection_list = NULL;
static GList *collection_window_list = NULL;
/* list of paths to collections */

/* List of currently open Collections*/
static GList *collection_list = NULL; /* type CollectionData */
/* List of currently open Collection windows*/
static GList *collection_window_list = NULL; /* type CollectWindow */

static void collection_window_get_geometry(CollectWindow *cw);
static void collection_window_refresh(CollectWindow *cw);
Expand Down Expand Up @@ -307,6 +311,57 @@ CollectWindow *collection_window_find_by_path(const gchar *path)
return NULL;
}

/* Checks string for existence of Collection.
* The parameter is the filename,
* with or without extension of any collection
*
* Returns: full pathname if found or NULL
* Return value must be freed with g_free()
*/
gchar *collection_path(gchar *param)
{
gchar *path = NULL;
gchar *full_name = NULL;

if (file_extension_match(param, GQ_COLLECTION_EXT))
{
path = g_build_filename(get_collections_dir(), param, NULL);
}
else if (file_extension_match(param, NULL))
{
full_name = g_strconcat(param, GQ_COLLECTION_EXT, NULL);
path = g_build_filename(get_collections_dir(), full_name, NULL);
}

if (!isfile(path))
{
g_free(path);
path = NULL;
}

g_free(full_name);
return path;
}

/* Checks input string for existence of Collection.
* The parameter is the filename
* with or without extension of any collection
*
* Returns TRUE if found
*/
gboolean is_collection(gchar *param)
{
gchar *name = NULL;

name = collection_path(param);
if (name)
{
g_free(name);
return TRUE;
}
return FALSE;
}

/*
*-------------------------------------------------------------------
* please use these to actually add/remove stuff
Expand Down
3 changes: 2 additions & 1 deletion src/collect.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ CollectWindow *collection_window_find(CollectionData *cd);
CollectWindow *collection_window_find_by_path(const gchar *path);
gboolean collection_window_modified_exists(void);


gboolean is_collection(gchar *param);
gchar *collection_path(gchar *param);
#endif
/* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */
25 changes: 23 additions & 2 deletions src/dupe.c
Original file line number Diff line number Diff line change
Expand Up @@ -2309,12 +2309,30 @@ static GList *dupe_window_get_fd_list(DupeWindow *dw)
return list;
}

/* Add file selection list to a collection
* Called from a right-click menu
* Inputs:
* data: index to the collection list menu item selected, or -1 for new collection
*/
static void dupe_pop_menu_collections_cb(GtkWidget *widget, gpointer data)
{
DupeWindow *dw;
GList *selection_list;

dw = submenu_item_get_data(widget);
selection_list = dupe_listview_get_selection(dw, dw->listview);
pop_menu_collections(selection_list, data);

filelist_free(selection_list);
}

static GtkWidget *dupe_menu_popup_main(DupeWindow *dw, DupeItem *di)
{
GtkWidget *menu;
GtkWidget *item;
gint on_row;
GList *editmenu_fd_list;
GtkWidget *submenu;

on_row = (di != NULL);

Expand All @@ -2340,8 +2358,11 @@ static GtkWidget *dupe_menu_popup_main(DupeWindow *dw, DupeItem *di)
G_CALLBACK(dupe_menu_popup_destroy_cb), editmenu_fd_list);
submenu_add_edit(menu, &item, G_CALLBACK(dupe_menu_edit_cb), dw, editmenu_fd_list);
if (!on_row) gtk_widget_set_sensitive(item, FALSE);
menu_item_add_stock_sensitive(menu, _("Add to new collection"), GTK_STOCK_INDEX, on_row,
G_CALLBACK(dupe_menu_collection_cb), dw);

submenu = submenu_add_collections(menu, &item,
G_CALLBACK(dupe_pop_menu_collections_cb), dw);
gtk_widget_set_sensitive(item, on_row);

menu_item_add_stock_sensitive(menu, _("Print..."), GTK_STOCK_PRINT, on_row,
G_CALLBACK(dupe_menu_print_cb), dw);
menu_item_add_divider(menu);
Expand Down
27 changes: 27 additions & 0 deletions src/img-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -1254,9 +1254,31 @@ static GList *view_window_get_fd_list(ViewWindow *vw)
return list;
}

/* Add file selection list to a collection
* Called from a right-click submenu
* Inputs:
* data: index to the collection list menu item selected, or -1 for new collection
*/
static void image_pop_menu_collections_cb(GtkWidget *widget, gpointer data)
{
ViewWindow *vw;
ImageWindow *imd;
FileData *fd;
GList *selection_list = NULL;

vw = submenu_item_get_data(widget);
imd = view_window_active_image(vw);
fd = image_get_fd(imd);
selection_list = g_list_append(selection_list, fd);
pop_menu_collections(selection_list, data);

filelist_free(selection_list);
}

static GtkWidget *view_popup_menu(ViewWindow *vw)
{
GtkWidget *menu;
GtkWidget *submenu;
GtkWidget *item;
GList *editmenu_fd_list;

Expand Down Expand Up @@ -1291,6 +1313,11 @@ static GtkWidget *view_popup_menu(ViewWindow *vw)

menu_item_add_divider(menu);

submenu = submenu_add_collections(menu, &item,
G_CALLBACK(image_pop_menu_collections_cb), vw);
gtk_widget_set_sensitive(item, TRUE);
menu_item_add_divider(menu);

if (vw->ss)
{
menu_item_add(menu, _("_Stop slideshow"), G_CALLBACK(view_slideshow_stop_cb), vw);
Expand Down
21 changes: 21 additions & 0 deletions src/layout_image.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,23 @@ static GList *layout_image_get_fd_list(LayoutWindow *lw)
return list;
}

/* Add file selection list to a collection
* Called from a right-click submenu
* Inputs:
* data: index to the collection list menu item selected, or -1 for new collection
*/
static void layout_pop_menu_collections_cb(GtkWidget *widget, gpointer data)
{
LayoutWindow *lw;
GList *selection_list = NULL;

lw = submenu_item_get_data(widget);
selection_list = g_list_append(selection_list, layout_image_get_fd(lw));
pop_menu_collections(selection_list, data);

filelist_free(selection_list);
}

static GtkWidget *layout_image_pop_menu(LayoutWindow *lw)
{
GtkWidget *menu;
Expand Down Expand Up @@ -691,7 +708,11 @@ static GtkWidget *layout_image_pop_menu(LayoutWindow *lw)
if (!path) gtk_widget_set_sensitive(item, FALSE);
item = menu_item_add_stock(menu, _("_Delete..."), GTK_STOCK_DELETE, G_CALLBACK(li_pop_menu_delete_cb), lw);
if (!path) gtk_widget_set_sensitive(item, FALSE);
menu_item_add_divider(menu);

submenu = submenu_add_collections(menu, &item,
G_CALLBACK(layout_pop_menu_collections_cb), lw);
gtk_widget_set_sensitive(item, TRUE);
menu_item_add_divider(menu);

if (layout_image_slideshow_active(lw))
Expand Down
38 changes: 1 addition & 37 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,32 +214,6 @@ static void parse_command_line_process_file(const gchar *file_path, gchar **path
parse_command_line_add_file(file_path, path, file, list, collection_list);
}

static gboolean is_collection(gchar *cmd_param)
{
gchar *path = NULL;
gchar *full_name = NULL;
gboolean result = FALSE;

if (file_extension_match(cmd_param, GQ_COLLECTION_EXT))
{
path = g_build_filename(get_collections_dir(), cmd_param, NULL);
}
else if (file_extension_match(cmd_param, NULL))
{
full_name = g_strconcat(cmd_param, GQ_COLLECTION_EXT, NULL);
path = g_build_filename(get_collections_dir(), full_name, NULL);
}

if (isfile(path))
{
result = TRUE;
}

g_free(path);
g_free(full_name);
return result;
}

static void parse_command_line(gint argc, gchar *argv[])
{
GList *list = NULL;
Expand Down Expand Up @@ -285,21 +259,11 @@ static void parse_command_line(gint argc, gchar *argv[])
else if (is_collection(cmd_line))
{
gchar *path = NULL;
gchar *full_name = NULL;

if (file_extension_match(cmd_line, GQ_COLLECTION_EXT))
{
path = g_build_filename(get_collections_dir(), cmd_line, NULL);
}
else
{
full_name = g_strconcat(cmd_line, GQ_COLLECTION_EXT, NULL);
path = g_build_filename(get_collections_dir(), full_name, NULL);
}
path = collection_path(cmd_line);
parse_command_line_process_file(path, &command_line->path, &command_line->file,
&list, &command_line->collection_list, &first_dir);
g_free(path);
g_free(full_name);
}
else if (strncmp(cmd_line, "--debug", 7) == 0 && (cmd_line[7] == '\0' || cmd_line[7] == '='))
{
Expand Down
Loading

0 comments on commit ae34634

Please sign in to comment.