mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-09-21 14:24:19 +00:00
filechooser: Add gtk_file_chooser_get_shortcuts
Replace gtk_file_chooser_list_shortcuts with a new api that returns a list model. Update all callers.
This commit is contained in:
parent
ea07a92366
commit
57a225681c
@ -767,21 +767,23 @@ gtk_file_chooser_get_filter (GtkFileChooser *chooser)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gtk_file_chooser_list_shortcut_folders:
|
* gtk_file_chooser_get_shortcut_folders:
|
||||||
* @chooser: a #GtkFileChooser
|
* @chooser: a #GtkFileChooser
|
||||||
*
|
*
|
||||||
* Queries the list of shortcut folders in the file chooser, as set by
|
* Queries the list of shortcut folders in the file chooser, as set by
|
||||||
* gtk_file_chooser_add_shortcut_folder().
|
* gtk_file_chooser_add_shortcut_folder().
|
||||||
*
|
*
|
||||||
* Returns: (nullable) (element-type Gio.File) (transfer full): A list
|
* You should not modify the returned list model. Future changes to
|
||||||
* of folder filenames, or %NULL if there are no shortcut folders.
|
* @chooser may or may not affect the returned model.
|
||||||
|
*
|
||||||
|
* Returns: (transfer full): A list model of #GFiles
|
||||||
*/
|
*/
|
||||||
GSList *
|
GListModel *
|
||||||
gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser)
|
gtk_file_chooser_get_shortcut_folders (GtkFileChooser *chooser)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
|
g_return_val_if_fail (GTK_IS_FILE_CHOOSER (chooser), NULL);
|
||||||
|
|
||||||
return GTK_FILE_CHOOSER_GET_IFACE (chooser)->list_shortcut_folders (chooser);
|
return GTK_FILE_CHOOSER_GET_IFACE (chooser)->get_shortcut_folders (chooser);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -164,14 +164,14 @@ GtkFileFilter *gtk_file_chooser_get_filter (GtkFileChooser *chooser);
|
|||||||
|
|
||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
gboolean gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
|
gboolean gtk_file_chooser_add_shortcut_folder (GtkFileChooser *chooser,
|
||||||
GFile *folder,
|
GFile *folder,
|
||||||
GError **error);
|
GError **error);
|
||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
gboolean gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
|
gboolean gtk_file_chooser_remove_shortcut_folder (GtkFileChooser *chooser,
|
||||||
GFile *folder,
|
GFile *folder,
|
||||||
GError **error);
|
GError **error);
|
||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
GSList *gtk_file_chooser_list_shortcut_folders (GtkFileChooser *chooser);
|
GListModel *gtk_file_chooser_get_shortcut_folders (GtkFileChooser *chooser);
|
||||||
|
|
||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
void gtk_file_chooser_add_choice (GtkFileChooser *chooser,
|
void gtk_file_chooser_add_choice (GtkFileChooser *chooser,
|
||||||
|
@ -66,7 +66,7 @@ typedef struct {
|
|||||||
char *cancel_label;
|
char *cancel_label;
|
||||||
char *title;
|
char *title;
|
||||||
|
|
||||||
GSList *shortcut_files;
|
GListModel *shortcut_files;
|
||||||
GArray *choices_selections;
|
GArray *choices_selections;
|
||||||
|
|
||||||
GFile *current_folder;
|
GFile *current_folder;
|
||||||
@ -330,7 +330,7 @@ filechooser_win32_thread_data_free (FilechooserWin32ThreadData *data)
|
|||||||
g_array_free (data->choices_selections, TRUE);
|
g_array_free (data->choices_selections, TRUE);
|
||||||
data->choices_selections = NULL;
|
data->choices_selections = NULL;
|
||||||
}
|
}
|
||||||
g_slist_free_full (data->shortcut_files, g_object_unref);
|
g_object_unref (data->shortcut_files);
|
||||||
g_slist_free_full (data->files, g_object_unref);
|
g_slist_free_full (data->files, g_object_unref);
|
||||||
if (data->self)
|
if (data->self)
|
||||||
g_object_unref (data->self);
|
g_object_unref (data->self);
|
||||||
@ -465,7 +465,7 @@ filechooser_win32_thread (gpointer _data)
|
|||||||
IFileDialog2 *pfd2 = NULL;
|
IFileDialog2 *pfd2 = NULL;
|
||||||
DWORD flags;
|
DWORD flags;
|
||||||
DWORD cookie;
|
DWORD cookie;
|
||||||
GSList *l;
|
guint j, n_items;
|
||||||
|
|
||||||
CoInitializeEx (NULL, COINIT_APARTMENTTHREADED);
|
CoInitializeEx (NULL, COINIT_APARTMENTTHREADED);
|
||||||
|
|
||||||
@ -531,9 +531,11 @@ filechooser_win32_thread (gpointer _data)
|
|||||||
g_free (label);
|
g_free (label);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (l = data->shortcut_files; l != NULL; l = l->next)
|
n_items = g_list_model_get_n_items (data->shortcut_files);
|
||||||
|
for (j = 0; j < n_items; j++)
|
||||||
{
|
{
|
||||||
IShellItem *item = get_shell_item_for_file (l->data);
|
GFile *file = g_list_model_get_item (data->shortcut_files, j);
|
||||||
|
IShellItem *item = get_shell_item_for_file (file);
|
||||||
if (item)
|
if (item)
|
||||||
{
|
{
|
||||||
hr = IFileDialog_AddPlace (pfd, item, FDAP_BOTTOM);
|
hr = IFileDialog_AddPlace (pfd, item, FDAP_BOTTOM);
|
||||||
@ -541,6 +543,7 @@ filechooser_win32_thread (gpointer _data)
|
|||||||
g_warning_hr ("Can't add dialog shortcut", hr);
|
g_warning_hr ("Can't add dialog shortcut", hr);
|
||||||
IShellItem_Release (item);
|
IShellItem_Release (item);
|
||||||
}
|
}
|
||||||
|
g_object_unref (file);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data->current_file)
|
if (data->current_file)
|
||||||
@ -594,17 +597,16 @@ filechooser_win32_thread (gpointer _data)
|
|||||||
if (data->self->current_filter)
|
if (data->self->current_filter)
|
||||||
{
|
{
|
||||||
GListModel *filters;
|
GListModel *filters;
|
||||||
guint n_items, i;
|
|
||||||
guint current_filter_index = GTK_INVALID_LIST_POSITION;
|
guint current_filter_index = GTK_INVALID_LIST_POSITION;
|
||||||
|
|
||||||
filters = gtk_file_chooser_get_filters (GTK_FILE_CHOOSER (data->self));
|
filters = gtk_file_chooser_get_filters (GTK_FILE_CHOOSER (data->self));
|
||||||
n_items = g_list_model_get_n_items (filters);
|
n_items = g_list_model_get_n_items (filters);
|
||||||
for (i = 0; i < n_items; i++)
|
for (j = 0; j < n_items; j++)
|
||||||
{
|
{
|
||||||
gpointer item = g_list_model_get_item (filters, i);
|
gpointer item = g_list_model_get_item (filters, j);
|
||||||
if (item == data->self->current_filter)
|
if (item == data->self->current_filter)
|
||||||
{
|
{
|
||||||
current_filter_index = i;
|
current_filter_index = j;
|
||||||
g_object_unref (item);
|
g_object_unref (item);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -634,6 +636,8 @@ filechooser_win32_thread (gpointer _data)
|
|||||||
hr = IFileDialog_QueryInterface (pfd, &IID_IFileDialogCustomize, (LPVOID *) &pfdc);
|
hr = IFileDialog_QueryInterface (pfd, &IID_IFileDialogCustomize, (LPVOID *) &pfdc);
|
||||||
if (SUCCEEDED (hr))
|
if (SUCCEEDED (hr))
|
||||||
{
|
{
|
||||||
|
GSList *l;
|
||||||
|
|
||||||
for (l = data->self->choices; l; l = l->next, dialog_control_id++)
|
for (l = data->self->choices; l; l = l->next, dialog_control_id++)
|
||||||
{
|
{
|
||||||
GtkFileChooserNativeChoice *choice = (GtkFileChooserNativeChoice*) l->data;
|
GtkFileChooserNativeChoice *choice = (GtkFileChooserNativeChoice*) l->data;
|
||||||
@ -759,6 +763,8 @@ filechooser_win32_thread (gpointer _data)
|
|||||||
hr = IFileDialog_QueryInterface (pfd, &IID_IFileDialogCustomize, (LPVOID *) &pfdc);
|
hr = IFileDialog_QueryInterface (pfd, &IID_IFileDialogCustomize, (LPVOID *) &pfdc);
|
||||||
if (SUCCEEDED (hr))
|
if (SUCCEEDED (hr))
|
||||||
{
|
{
|
||||||
|
GSList *l;
|
||||||
|
|
||||||
for (l = data->self->choices; l; l = l->next)
|
for (l = data->self->choices; l; l = l->next)
|
||||||
{
|
{
|
||||||
GtkFileChooserNativeChoice *choice = (GtkFileChooserNativeChoice*) l->data;
|
GtkFileChooserNativeChoice *choice = (GtkFileChooserNativeChoice*) l->data;
|
||||||
@ -915,7 +921,7 @@ gtk_file_chooser_native_win32_show (GtkFileChooserNative *self)
|
|||||||
data->self = g_object_ref (self);
|
data->self = g_object_ref (self);
|
||||||
|
|
||||||
data->shortcut_files =
|
data->shortcut_files =
|
||||||
gtk_file_chooser_list_shortcut_folders (GTK_FILE_CHOOSER (self->dialog));
|
gtk_file_chooser_get_shortcut_folders (GTK_FILE_CHOOSER (self->dialog));
|
||||||
|
|
||||||
data->accept_label = translate_mnemonics (self->accept_label);
|
data->accept_label = translate_mnemonics (self->accept_label);
|
||||||
data->cancel_label = translate_mnemonics (self->cancel_label);
|
data->cancel_label = translate_mnemonics (self->cancel_label);
|
||||||
|
@ -85,7 +85,7 @@ struct _GtkFileChooserIface
|
|||||||
gboolean (*remove_shortcut_folder) (GtkFileChooser *chooser,
|
gboolean (*remove_shortcut_folder) (GtkFileChooser *chooser,
|
||||||
GFile *file,
|
GFile *file,
|
||||||
GError **error);
|
GError **error);
|
||||||
GSList * (*list_shortcut_folders) (GtkFileChooser *chooser);
|
GListModel * (*get_shortcut_folders) (GtkFileChooser *chooser);
|
||||||
|
|
||||||
/* Signals
|
/* Signals
|
||||||
*/
|
*/
|
||||||
|
@ -52,7 +52,7 @@ static gboolean delegate_add_shortcut_folder (GtkFileChooser *choose
|
|||||||
static gboolean delegate_remove_shortcut_folder (GtkFileChooser *chooser,
|
static gboolean delegate_remove_shortcut_folder (GtkFileChooser *chooser,
|
||||||
GFile *file,
|
GFile *file,
|
||||||
GError **error);
|
GError **error);
|
||||||
static GSList * delegate_list_shortcut_folders (GtkFileChooser *chooser);
|
static GListModel * delegate_get_shortcut_folders (GtkFileChooser *chooser);
|
||||||
static void delegate_notify (GObject *object,
|
static void delegate_notify (GObject *object,
|
||||||
GParamSpec *pspec,
|
GParamSpec *pspec,
|
||||||
gpointer data);
|
gpointer data);
|
||||||
@ -137,7 +137,7 @@ _gtk_file_chooser_delegate_iface_init (GtkFileChooserIface *iface)
|
|||||||
iface->get_filters = delegate_get_filters;
|
iface->get_filters = delegate_get_filters;
|
||||||
iface->add_shortcut_folder = delegate_add_shortcut_folder;
|
iface->add_shortcut_folder = delegate_add_shortcut_folder;
|
||||||
iface->remove_shortcut_folder = delegate_remove_shortcut_folder;
|
iface->remove_shortcut_folder = delegate_remove_shortcut_folder;
|
||||||
iface->list_shortcut_folders = delegate_list_shortcut_folders;
|
iface->get_shortcut_folders = delegate_get_shortcut_folders;
|
||||||
iface->add_choice = delegate_add_choice;
|
iface->add_choice = delegate_add_choice;
|
||||||
iface->remove_choice = delegate_remove_choice;
|
iface->remove_choice = delegate_remove_choice;
|
||||||
iface->set_choice = delegate_set_choice;
|
iface->set_choice = delegate_set_choice;
|
||||||
@ -266,10 +266,10 @@ delegate_remove_shortcut_folder (GtkFileChooser *chooser,
|
|||||||
return gtk_file_chooser_remove_shortcut_folder (get_delegate (chooser), file, error);
|
return gtk_file_chooser_remove_shortcut_folder (get_delegate (chooser), file, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
static GSList *
|
static GListModel *
|
||||||
delegate_list_shortcut_folders (GtkFileChooser *chooser)
|
delegate_get_shortcut_folders (GtkFileChooser *chooser)
|
||||||
{
|
{
|
||||||
return gtk_file_chooser_list_shortcut_folders (get_delegate (chooser));
|
return gtk_file_chooser_get_shortcut_folders (get_delegate (chooser));
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@ -492,7 +492,7 @@ static gboolean gtk_file_chooser_widget_add_shortcut_folder (GtkFileCho
|
|||||||
static gboolean gtk_file_chooser_widget_remove_shortcut_folder (GtkFileChooser *chooser,
|
static gboolean gtk_file_chooser_widget_remove_shortcut_folder (GtkFileChooser *chooser,
|
||||||
GFile *file,
|
GFile *file,
|
||||||
GError **error);
|
GError **error);
|
||||||
static GSList * gtk_file_chooser_widget_list_shortcut_folders (GtkFileChooser *chooser);
|
static GListModel * gtk_file_chooser_widget_get_shortcut_folders (GtkFileChooser *chooser);
|
||||||
|
|
||||||
static gboolean gtk_file_chooser_widget_should_respond (GtkFileChooserEmbed *chooser_embed);
|
static gboolean gtk_file_chooser_widget_should_respond (GtkFileChooserEmbed *chooser_embed);
|
||||||
static void gtk_file_chooser_widget_initial_focus (GtkFileChooserEmbed *chooser_embed);
|
static void gtk_file_chooser_widget_initial_focus (GtkFileChooserEmbed *chooser_embed);
|
||||||
@ -622,7 +622,7 @@ gtk_file_chooser_widget_iface_init (GtkFileChooserIface *iface)
|
|||||||
iface->get_filters = gtk_file_chooser_widget_get_filters;
|
iface->get_filters = gtk_file_chooser_widget_get_filters;
|
||||||
iface->add_shortcut_folder = gtk_file_chooser_widget_add_shortcut_folder;
|
iface->add_shortcut_folder = gtk_file_chooser_widget_add_shortcut_folder;
|
||||||
iface->remove_shortcut_folder = gtk_file_chooser_widget_remove_shortcut_folder;
|
iface->remove_shortcut_folder = gtk_file_chooser_widget_remove_shortcut_folder;
|
||||||
iface->list_shortcut_folders = gtk_file_chooser_widget_list_shortcut_folders;
|
iface->get_shortcut_folders = gtk_file_chooser_widget_get_shortcut_folders;
|
||||||
iface->add_choice = gtk_file_chooser_widget_add_choice;
|
iface->add_choice = gtk_file_chooser_widget_add_choice;
|
||||||
iface->remove_choice = gtk_file_chooser_widget_remove_choice;
|
iface->remove_choice = gtk_file_chooser_widget_remove_choice;
|
||||||
iface->set_choice = gtk_file_chooser_widget_set_choice;
|
iface->set_choice = gtk_file_chooser_widget_set_choice;
|
||||||
@ -3433,25 +3433,27 @@ set_startup_mode (GtkFileChooserWidget *impl)
|
|||||||
static gboolean
|
static gboolean
|
||||||
shortcut_exists (GtkFileChooserWidget *impl, GFile *needle)
|
shortcut_exists (GtkFileChooserWidget *impl, GFile *needle)
|
||||||
{
|
{
|
||||||
GSList *haystack;
|
GListModel *haystack;
|
||||||
GSList *l;
|
guint n, i;
|
||||||
gboolean exists;
|
gboolean exists;
|
||||||
|
|
||||||
exists = FALSE;
|
exists = FALSE;
|
||||||
|
|
||||||
haystack = gtk_places_sidebar_list_shortcuts (GTK_PLACES_SIDEBAR (impl->places_sidebar));
|
haystack = gtk_places_sidebar_get_shortcuts (GTK_PLACES_SIDEBAR (impl->places_sidebar));
|
||||||
for (l = haystack; l; l = l->next)
|
n = g_list_model_get_n_items (haystack);
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
GFile *hay;
|
GFile *hay = g_list_model_get_item (haystack, i);
|
||||||
|
|
||||||
hay = G_FILE (l->data);
|
|
||||||
if (g_file_equal (hay, needle))
|
if (g_file_equal (hay, needle))
|
||||||
{
|
{
|
||||||
|
g_object_unref (hay);
|
||||||
exists = TRUE;
|
exists = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
g_object_unref (hay);
|
||||||
}
|
}
|
||||||
g_slist_free_full (haystack, g_object_unref);
|
g_object_unref (haystack);
|
||||||
|
|
||||||
return exists;
|
return exists;
|
||||||
}
|
}
|
||||||
@ -5637,12 +5639,12 @@ gtk_file_chooser_widget_remove_shortcut_folder (GtkFileChooser *chooser,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GSList *
|
static GListModel *
|
||||||
gtk_file_chooser_widget_list_shortcut_folders (GtkFileChooser *chooser)
|
gtk_file_chooser_widget_get_shortcut_folders (GtkFileChooser *chooser)
|
||||||
{
|
{
|
||||||
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (chooser);
|
||||||
|
|
||||||
return gtk_places_sidebar_list_shortcuts (GTK_PLACES_SIDEBAR (impl->places_sidebar));
|
return gtk_places_sidebar_get_shortcuts (GTK_PLACES_SIDEBAR (impl->places_sidebar));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct switch_folder_closure {
|
struct switch_folder_closure {
|
||||||
|
@ -162,7 +162,7 @@ struct _GtkPlacesSidebar {
|
|||||||
|
|
||||||
GtkWidget *popover;
|
GtkWidget *popover;
|
||||||
GtkSidebarRow *context_row;
|
GtkSidebarRow *context_row;
|
||||||
GSList *shortcuts;
|
GListStore *shortcuts;
|
||||||
|
|
||||||
GDBusProxy *hostnamed_proxy;
|
GDBusProxy *hostnamed_proxy;
|
||||||
GCancellable *hostnamed_cancellable;
|
GCancellable *hostnamed_cancellable;
|
||||||
@ -709,15 +709,25 @@ file_is_shown (GtkPlacesSidebar *sidebar,
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
GtkPlacesSidebar *sidebar;
|
||||||
|
guint position;
|
||||||
|
} ShortcutData;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_app_shortcuts_query_complete (GObject *source,
|
on_app_shortcuts_query_complete (GObject *source,
|
||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
GtkPlacesSidebar *sidebar = data;
|
ShortcutData *sdata = data;
|
||||||
|
GtkPlacesSidebar *sidebar = sdata->sidebar;
|
||||||
|
guint pos = sdata->position;
|
||||||
GFile *file = G_FILE (source);
|
GFile *file = G_FILE (source);
|
||||||
GFileInfo *info;
|
GFileInfo *info;
|
||||||
|
|
||||||
|
g_free (sdata);
|
||||||
|
|
||||||
info = g_file_query_info_finish (file, result, NULL);
|
info = g_file_query_info_finish (file, result, NULL);
|
||||||
|
|
||||||
if (info)
|
if (info)
|
||||||
@ -726,20 +736,12 @@ on_app_shortcuts_query_complete (GObject *source,
|
|||||||
gchar *tooltip;
|
gchar *tooltip;
|
||||||
const gchar *name;
|
const gchar *name;
|
||||||
GIcon *start_icon;
|
GIcon *start_icon;
|
||||||
int pos = 0;
|
|
||||||
|
|
||||||
name = g_file_info_get_display_name (info);
|
name = g_file_info_get_display_name (info);
|
||||||
start_icon = g_file_info_get_symbolic_icon (info);
|
start_icon = g_file_info_get_symbolic_icon (info);
|
||||||
uri = g_file_get_uri (file);
|
uri = g_file_get_uri (file);
|
||||||
tooltip = g_file_get_parse_name (file);
|
tooltip = g_file_get_parse_name (file);
|
||||||
|
|
||||||
/* XXX: we could avoid this by using an ancillary closure
|
|
||||||
* with the index coming from add_application_shortcuts(),
|
|
||||||
* but in terms of algorithmic overhead, the application
|
|
||||||
* shortcuts is not going to be really big
|
|
||||||
*/
|
|
||||||
pos = g_slist_index (sidebar->shortcuts, file);
|
|
||||||
|
|
||||||
add_place (sidebar, PLACES_BUILT_IN,
|
add_place (sidebar, PLACES_BUILT_IN,
|
||||||
SECTION_COMPUTER,
|
SECTION_COMPUTER,
|
||||||
name, start_icon, NULL, uri,
|
name, start_icon, NULL, uri,
|
||||||
@ -757,11 +759,13 @@ on_app_shortcuts_query_complete (GObject *source,
|
|||||||
static void
|
static void
|
||||||
add_application_shortcuts (GtkPlacesSidebar *sidebar)
|
add_application_shortcuts (GtkPlacesSidebar *sidebar)
|
||||||
{
|
{
|
||||||
GSList *l;
|
guint i, n;
|
||||||
|
|
||||||
for (l = sidebar->shortcuts; l; l = l->next)
|
n = g_list_model_get_n_items (G_LIST_MODEL (sidebar->shortcuts));
|
||||||
|
for (i = 0; i < n; i++)
|
||||||
{
|
{
|
||||||
GFile *file = l->data;
|
GFile *file = g_list_model_get_item (G_LIST_MODEL (sidebar->shortcuts), i);
|
||||||
|
ShortcutData *data;
|
||||||
|
|
||||||
if (!should_show_file (sidebar, file))
|
if (!should_show_file (sidebar, file))
|
||||||
continue;
|
continue;
|
||||||
@ -769,13 +773,16 @@ add_application_shortcuts (GtkPlacesSidebar *sidebar)
|
|||||||
if (file_is_shown (sidebar, file))
|
if (file_is_shown (sidebar, file))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
data = g_new (ShortcutData, 1);
|
||||||
|
data->sidebar = sidebar;
|
||||||
|
data->position = i;
|
||||||
g_file_query_info_async (file,
|
g_file_query_info_async (file,
|
||||||
"standard::display-name,standard::symbolic-icon",
|
"standard::display-name,standard::symbolic-icon",
|
||||||
G_FILE_QUERY_INFO_NONE,
|
G_FILE_QUERY_INFO_NONE,
|
||||||
G_PRIORITY_DEFAULT,
|
G_PRIORITY_DEFAULT,
|
||||||
sidebar->cancellable,
|
sidebar->cancellable,
|
||||||
on_app_shortcuts_query_complete,
|
on_app_shortcuts_query_complete,
|
||||||
sidebar);
|
data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3748,6 +3755,8 @@ gtk_places_sidebar_init (GtkPlacesSidebar *sidebar)
|
|||||||
sidebar->show_recent = TRUE;
|
sidebar->show_recent = TRUE;
|
||||||
sidebar->show_desktop = TRUE;
|
sidebar->show_desktop = TRUE;
|
||||||
|
|
||||||
|
sidebar->shortcuts = g_list_store_new (G_TYPE_FILE);
|
||||||
|
|
||||||
create_volume_monitor (sidebar);
|
create_volume_monitor (sidebar);
|
||||||
|
|
||||||
sidebar->open_flags = GTK_PLACES_OPEN_NORMAL;
|
sidebar->open_flags = GTK_PLACES_OPEN_NORMAL;
|
||||||
@ -4018,9 +4027,7 @@ gtk_places_sidebar_dispose (GObject *object)
|
|||||||
|
|
||||||
g_clear_object (&sidebar->current_location);
|
g_clear_object (&sidebar->current_location);
|
||||||
g_clear_pointer (&sidebar->rename_uri, g_free);
|
g_clear_pointer (&sidebar->rename_uri, g_free);
|
||||||
|
g_clear_object (&sidebar->shortcuts);
|
||||||
g_slist_free_full (sidebar->shortcuts, g_object_unref);
|
|
||||||
sidebar->shortcuts = NULL;
|
|
||||||
|
|
||||||
#ifdef HAVE_CLOUDPROVIDERS
|
#ifdef HAVE_CLOUDPROVIDERS
|
||||||
for (l = cloud_providers_collector_get_providers (sidebar->cloud_manager);
|
for (l = cloud_providers_collector_get_providers (sidebar->cloud_manager);
|
||||||
@ -4782,24 +4789,6 @@ gtk_places_sidebar_get_show_trash (GtkPlacesSidebar *sidebar)
|
|||||||
return sidebar->show_trash;
|
return sidebar->show_trash;
|
||||||
}
|
}
|
||||||
|
|
||||||
static GSList *
|
|
||||||
find_shortcut_link (GtkPlacesSidebar *sidebar,
|
|
||||||
GFile *location)
|
|
||||||
{
|
|
||||||
GSList *l;
|
|
||||||
|
|
||||||
for (l = sidebar->shortcuts; l; l = l->next)
|
|
||||||
{
|
|
||||||
GFile *shortcut;
|
|
||||||
|
|
||||||
shortcut = G_FILE (l->data);
|
|
||||||
if (g_file_equal (shortcut, location))
|
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* gtk_places_sidebar_add_shortcut:
|
* gtk_places_sidebar_add_shortcut:
|
||||||
* @sidebar: a places sidebar
|
* @sidebar: a places sidebar
|
||||||
@ -4823,8 +4812,7 @@ gtk_places_sidebar_add_shortcut (GtkPlacesSidebar *sidebar,
|
|||||||
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
||||||
g_return_if_fail (G_IS_FILE (location));
|
g_return_if_fail (G_IS_FILE (location));
|
||||||
|
|
||||||
g_object_ref (location);
|
g_list_store_append (sidebar->shortcuts, location);
|
||||||
sidebar->shortcuts = g_slist_append (sidebar->shortcuts, location);
|
|
||||||
|
|
||||||
update_places (sidebar);
|
update_places (sidebar);
|
||||||
}
|
}
|
||||||
@ -4842,43 +4830,46 @@ void
|
|||||||
gtk_places_sidebar_remove_shortcut (GtkPlacesSidebar *sidebar,
|
gtk_places_sidebar_remove_shortcut (GtkPlacesSidebar *sidebar,
|
||||||
GFile *location)
|
GFile *location)
|
||||||
{
|
{
|
||||||
GSList *link;
|
guint i, n;
|
||||||
GFile *shortcut;
|
|
||||||
|
|
||||||
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
g_return_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar));
|
||||||
g_return_if_fail (G_IS_FILE (location));
|
g_return_if_fail (G_IS_FILE (location));
|
||||||
|
|
||||||
link = find_shortcut_link (sidebar, location);
|
n = g_list_model_get_n_items (G_LIST_MODEL (sidebar->shortcuts));
|
||||||
if (!link)
|
for (i = 0; i < n; i++)
|
||||||
return;
|
{
|
||||||
|
GFile *shortcut = g_list_model_get_item (G_LIST_MODEL (sidebar->shortcuts), i);
|
||||||
|
|
||||||
shortcut = G_FILE (link->data);
|
if (shortcut == location)
|
||||||
g_object_unref (shortcut);
|
{
|
||||||
|
g_list_store_remove (sidebar->shortcuts, i);
|
||||||
|
g_object_unref (shortcut);
|
||||||
|
update_places (sidebar);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
sidebar->shortcuts = g_slist_delete_link (sidebar->shortcuts, link);
|
g_object_unref (shortcut);
|
||||||
update_places (sidebar);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* gtk_places_sidebar_list_shortcuts:
|
* gtk_places_sidebar_list_shortcuts:
|
||||||
* @sidebar: a places sidebar
|
* @sidebar: a places sidebar
|
||||||
*
|
*
|
||||||
* Gets the list of shortcuts.
|
* Gets the list of shortcuts, as a list model containing #GFile objects.
|
||||||
*
|
*
|
||||||
* Returns: (element-type GFile) (transfer full):
|
* You should not modify the returned list model. Future changes to
|
||||||
* A #GSList of #GFile of the locations that have been added as
|
* @sidebar may or may not affect the returned model.
|
||||||
|
*
|
||||||
|
* Returns: (transfer full): a list model of #GFiles that have been added as
|
||||||
* application-specific shortcuts with gtk_places_sidebar_add_shortcut().
|
* application-specific shortcuts with gtk_places_sidebar_add_shortcut().
|
||||||
* To free this list, you can use
|
|
||||||
* |[<!-- language="C" -->
|
|
||||||
* g_slist_free_full (list, (GDestroyNotify) g_object_unref);
|
|
||||||
* ]|
|
|
||||||
*/
|
*/
|
||||||
GSList *
|
GListModel *
|
||||||
gtk_places_sidebar_list_shortcuts (GtkPlacesSidebar *sidebar)
|
gtk_places_sidebar_get_shortcuts (GtkPlacesSidebar *sidebar)
|
||||||
{
|
{
|
||||||
g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), NULL);
|
g_return_val_if_fail (GTK_IS_PLACES_SIDEBAR (sidebar), NULL);
|
||||||
|
|
||||||
return g_slist_copy_deep (sidebar->shortcuts, (GCopyFunc) g_object_ref, NULL);
|
return G_LIST_MODEL (g_object_ref (sidebar->shortcuts));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -92,7 +92,7 @@ void gtk_places_sidebar_add_shortcut (GtkPlacesSideb
|
|||||||
GFile *location);
|
GFile *location);
|
||||||
void gtk_places_sidebar_remove_shortcut (GtkPlacesSidebar *sidebar,
|
void gtk_places_sidebar_remove_shortcut (GtkPlacesSidebar *sidebar,
|
||||||
GFile *location);
|
GFile *location);
|
||||||
GSList * gtk_places_sidebar_list_shortcuts (GtkPlacesSidebar *sidebar);
|
GListModel * gtk_places_sidebar_get_shortcuts (GtkPlacesSidebar *sidebar);
|
||||||
|
|
||||||
GFile * gtk_places_sidebar_get_nth_bookmark (GtkPlacesSidebar *sidebar,
|
GFile * gtk_places_sidebar_get_nth_bookmark (GtkPlacesSidebar *sidebar,
|
||||||
gint n);
|
gint n);
|
||||||
|
Loading…
Reference in New Issue
Block a user