2006-12-09 21:33:38 +00:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2003-02-21 19:03:19 +00:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpcontainertreeview.c
|
2010-05-19 20:07:31 +02:00
|
|
|
* Copyright (C) 2003-2010 Michael Natterer <mitch@gimp.org>
|
2003-02-21 19:03:19 +00:00
|
|
|
*
|
2009-01-17 22:28:01 +00:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2003-02-21 19:03:19 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-17 22:28:01 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2003-02-21 19:03:19 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2018-07-11 23:27:07 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2003-02-21 19:03:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2003-03-26 14:56:10 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2012-03-29 19:19:01 +02:00
|
|
|
#include <gegl.h>
|
2011-02-14 20:01:08 +01:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
2003-02-21 19:03:19 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2004-07-26 21:09:16 +00:00
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
2003-02-21 19:03:19 +00:00
|
|
|
#include "widgets-types.h"
|
|
|
|
|
|
|
|
#include "core/gimpcontainer.h"
|
|
|
|
#include "core/gimpcontext.h"
|
2011-02-14 20:01:08 +01:00
|
|
|
#include "core/gimpmarshal.h"
|
2003-02-21 19:03:19 +00:00
|
|
|
#include "core/gimpviewable.h"
|
|
|
|
|
2016-10-01 20:55:13 +02:00
|
|
|
#include "gimpcellrendererbutton.h"
|
2003-02-26 16:17:10 +00:00
|
|
|
#include "gimpcellrendererviewable.h"
|
2010-05-17 21:06:28 +02:00
|
|
|
#include "gimpcontainertreestore.h"
|
2003-02-21 19:03:19 +00:00
|
|
|
#include "gimpcontainertreeview.h"
|
2003-03-19 15:17:13 +00:00
|
|
|
#include "gimpcontainertreeview-dnd.h"
|
2008-11-15 18:08:50 +00:00
|
|
|
#include "gimpcontainertreeview.h"
|
|
|
|
#include "gimpcontainertreeview-private.h"
|
2004-05-10 23:22:39 +00:00
|
|
|
#include "gimpcontainerview.h"
|
2003-02-21 19:03:19 +00:00
|
|
|
#include "gimpdnd.h"
|
2004-08-25 22:31:44 +00:00
|
|
|
#include "gimpviewrenderer.h"
|
2003-03-16 11:14:29 +00:00
|
|
|
#include "gimpwidgets-utils.h"
|
2003-02-21 19:03:19 +00:00
|
|
|
|
|
|
|
|
2011-02-14 20:01:08 +01:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
EDIT_NAME,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-01-03 22:27:30 +00:00
|
|
|
static void gimp_container_tree_view_view_iface_init (GimpContainerViewInterface *iface);
|
|
|
|
|
2011-01-14 09:38:11 +01:00
|
|
|
static void gimp_container_tree_view_constructed (GObject *object);
|
2009-01-03 22:27:30 +00:00
|
|
|
static void gimp_container_tree_view_finalize (GObject *object);
|
2011-01-14 09:38:11 +01:00
|
|
|
|
2015-12-13 17:54:13 +01:00
|
|
|
static void gimp_container_tree_view_style_updated (GtkWidget *widget);
|
2009-01-03 22:27:30 +00:00
|
|
|
static void gimp_container_tree_view_unmap (GtkWidget *widget);
|
|
|
|
static gboolean gimp_container_tree_view_popup_menu (GtkWidget *widget);
|
|
|
|
|
|
|
|
static void gimp_container_tree_view_set_container (GimpContainerView *view,
|
|
|
|
GimpContainer *container);
|
|
|
|
static void gimp_container_tree_view_set_context (GimpContainerView *view,
|
|
|
|
GimpContext *context);
|
2010-05-19 20:07:31 +02:00
|
|
|
static void gimp_container_tree_view_set_selection_mode(GimpContainerView *view,
|
|
|
|
GtkSelectionMode mode);
|
2010-03-11 17:40:00 +02:00
|
|
|
|
2009-01-03 22:27:30 +00:00
|
|
|
static gpointer gimp_container_tree_view_insert_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
2009-08-01 19:13:35 +02:00
|
|
|
gpointer parent_insert_data,
|
2009-01-03 22:27:30 +00:00
|
|
|
gint index);
|
|
|
|
static void gimp_container_tree_view_remove_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data);
|
|
|
|
static void gimp_container_tree_view_reorder_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gint new_index,
|
|
|
|
gpointer insert_data);
|
|
|
|
static void gimp_container_tree_view_rename_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data);
|
2017-10-22 11:50:37 -04:00
|
|
|
static void gimp_container_tree_view_expand_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data);
|
2009-01-03 22:27:30 +00:00
|
|
|
static gboolean gimp_container_tree_view_select_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data);
|
2020-03-21 19:03:07 +01:00
|
|
|
static gboolean gimp_container_tree_view_select_items (GimpContainerView *view,
|
|
|
|
GList *viewables,
|
|
|
|
GList *paths);
|
2009-01-03 22:27:30 +00:00
|
|
|
static void gimp_container_tree_view_clear_items (GimpContainerView *view);
|
|
|
|
static void gimp_container_tree_view_set_view_size (GimpContainerView *view);
|
|
|
|
|
2011-02-14 20:01:08 +01:00
|
|
|
static void gimp_container_tree_view_real_edit_name (GimpContainerTreeView *tree_view);
|
|
|
|
|
2015-06-11 19:33:58 +02:00
|
|
|
static gboolean gimp_container_tree_view_edit_focus_out (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
gpointer user_data);
|
2012-02-06 19:28:37 +01:00
|
|
|
static void gimp_container_tree_view_name_started (GtkCellRendererText *cell,
|
|
|
|
GtkCellEditable *editable,
|
|
|
|
const gchar *path_str,
|
|
|
|
GimpContainerTreeView *tree_view);
|
2009-01-03 22:27:30 +00:00
|
|
|
static void gimp_container_tree_view_name_canceled (GtkCellRendererText *cell,
|
|
|
|
GimpContainerTreeView *tree_view);
|
|
|
|
|
|
|
|
static void gimp_container_tree_view_selection_changed (GtkTreeSelection *sel,
|
|
|
|
GimpContainerTreeView *tree_view);
|
2020-03-22 00:15:18 +01:00
|
|
|
static gboolean gimp_container_tree_view_button (GtkWidget *widget,
|
2009-01-03 22:27:30 +00:00
|
|
|
GdkEventButton *bevent,
|
|
|
|
GimpContainerTreeView *tree_view);
|
|
|
|
static gboolean gimp_container_tree_view_tooltip (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gboolean keyboard_tip,
|
|
|
|
GtkTooltip *tooltip,
|
|
|
|
GimpContainerTreeView *tree_view);
|
|
|
|
static GimpViewable *gimp_container_tree_view_drag_viewable (GtkWidget *widget,
|
|
|
|
GimpContext **context,
|
|
|
|
gpointer data);
|
2020-03-24 22:06:28 +01:00
|
|
|
static GList * gimp_container_tree_view_drag_viewable_list (GtkWidget *widget,
|
|
|
|
GimpContext **context,
|
|
|
|
gpointer data);
|
2009-01-03 22:27:30 +00:00
|
|
|
static GdkPixbuf *gimp_container_tree_view_drag_pixbuf (GtkWidget *widget,
|
|
|
|
gpointer data);
|
2003-02-24 20:31:14 +00:00
|
|
|
|
2010-03-07 18:54:20 +02:00
|
|
|
static gboolean gimp_container_tree_view_get_selected_single (GimpContainerTreeView *tree_view,
|
|
|
|
GtkTreeIter *iter);
|
|
|
|
static gint gimp_container_tree_view_get_selected (GimpContainerView *view,
|
2020-03-21 19:03:07 +01:00
|
|
|
GList **items,
|
|
|
|
GList **paths);
|
2011-09-25 21:57:20 +02:00
|
|
|
static void gimp_container_tree_view_row_expanded (GtkTreeView *tree_view,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GimpContainerTreeView *view);
|
|
|
|
static void gimp_container_tree_view_expand_rows (GtkTreeModel *model,
|
|
|
|
GtkTreeView *view,
|
|
|
|
GtkTreeIter *parent);
|
2010-03-07 18:54:20 +02:00
|
|
|
|
2016-06-01 22:38:58 +02:00
|
|
|
static void gimp_container_tree_view_monitor_changed (GimpContainerTreeView *view);
|
|
|
|
|
2020-03-26 00:33:11 +01:00
|
|
|
static gboolean gimp_container_tree_view_search_path_foreach (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data);
|
|
|
|
static GtkTreePath * gimp_container_tree_view_get_path (GimpContainerTreeView *tree_view,
|
|
|
|
GimpViewable *viewable);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2005-12-19 22:37:49 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpContainerTreeView, gimp_container_tree_view,
|
|
|
|
GIMP_TYPE_CONTAINER_BOX,
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-18 12:09:39 -04:00
|
|
|
G_ADD_PRIVATE (GimpContainerTreeView)
|
2005-12-19 22:37:49 +00:00
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONTAINER_VIEW,
|
2006-08-31 21:40:16 +00:00
|
|
|
gimp_container_tree_view_view_iface_init))
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2005-12-19 22:37:49 +00:00
|
|
|
#define parent_class gimp_container_tree_view_parent_class
|
|
|
|
|
2006-08-31 21:40:16 +00:00
|
|
|
static GimpContainerViewInterface *parent_view_iface = NULL;
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2011-02-14 20:01:08 +01:00
|
|
|
static guint tree_view_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2003-02-21 19:03:19 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_tree_view_class_init (GimpContainerTreeViewClass *klass)
|
|
|
|
{
|
2004-05-10 23:22:39 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2011-02-14 20:01:08 +01:00
|
|
|
GtkBindingSet *binding_set;
|
2003-07-24 17:23:56 +00:00
|
|
|
|
2015-12-13 17:54:13 +01:00
|
|
|
object_class->constructed = gimp_container_tree_view_constructed;
|
|
|
|
object_class->finalize = gimp_container_tree_view_finalize;
|
2003-03-16 11:14:29 +00:00
|
|
|
|
2015-12-13 17:54:13 +01:00
|
|
|
widget_class->style_updated = gimp_container_tree_view_style_updated;
|
|
|
|
widget_class->unmap = gimp_container_tree_view_unmap;
|
|
|
|
widget_class->popup_menu = gimp_container_tree_view_popup_menu;
|
2003-09-30 15:55:23 +00:00
|
|
|
|
2015-12-13 17:54:13 +01:00
|
|
|
klass->edit_name = gimp_container_tree_view_real_edit_name;
|
|
|
|
klass->drop_possible = gimp_container_tree_view_real_drop_possible;
|
2020-03-24 22:06:28 +01:00
|
|
|
klass->drop_viewables = gimp_container_tree_view_real_drop_viewables;
|
2015-12-13 17:54:13 +01:00
|
|
|
klass->drop_color = NULL;
|
|
|
|
klass->drop_uri_list = NULL;
|
|
|
|
klass->drop_svg = NULL;
|
|
|
|
klass->drop_component = NULL;
|
|
|
|
klass->drop_pixbuf = NULL;
|
2008-11-15 18:08:50 +00:00
|
|
|
|
2011-02-14 20:01:08 +01:00
|
|
|
tree_view_signals[EDIT_NAME] =
|
|
|
|
g_signal_new ("edit-name",
|
|
|
|
G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
|
|
|
|
G_STRUCT_OFFSET (GimpContainerTreeViewClass, edit_name),
|
2020-01-12 11:06:05 +01:00
|
|
|
NULL, NULL, NULL,
|
2011-02-14 20:01:08 +01:00
|
|
|
G_TYPE_NONE, 0);
|
|
|
|
|
|
|
|
binding_set = gtk_binding_set_by_class (klass);
|
|
|
|
|
2011-03-29 15:27:25 +02:00
|
|
|
gtk_binding_entry_add_signal (binding_set, GDK_KEY_F2, 0,
|
2011-02-14 20:01:08 +01:00
|
|
|
"edit-name", 0);
|
2003-02-21 19:03:19 +00:00
|
|
|
}
|
|
|
|
|
2006-08-29 21:44:51 +00:00
|
|
|
static void
|
|
|
|
gimp_container_tree_view_view_iface_init (GimpContainerViewInterface *iface)
|
|
|
|
{
|
|
|
|
parent_view_iface = g_type_interface_peek_parent (iface);
|
|
|
|
|
2010-03-11 17:40:00 +02:00
|
|
|
if (! parent_view_iface)
|
|
|
|
parent_view_iface = g_type_default_interface_peek (GIMP_TYPE_CONTAINER_VIEW);
|
|
|
|
|
2010-05-19 20:07:31 +02:00
|
|
|
iface->set_container = gimp_container_tree_view_set_container;
|
|
|
|
iface->set_context = gimp_container_tree_view_set_context;
|
|
|
|
iface->set_selection_mode = gimp_container_tree_view_set_selection_mode;
|
|
|
|
iface->insert_item = gimp_container_tree_view_insert_item;
|
|
|
|
iface->remove_item = gimp_container_tree_view_remove_item;
|
|
|
|
iface->reorder_item = gimp_container_tree_view_reorder_item;
|
|
|
|
iface->rename_item = gimp_container_tree_view_rename_item;
|
2017-10-22 11:50:37 -04:00
|
|
|
iface->expand_item = gimp_container_tree_view_expand_item;
|
2010-05-19 20:07:31 +02:00
|
|
|
iface->select_item = gimp_container_tree_view_select_item;
|
2020-03-21 19:03:07 +01:00
|
|
|
iface->select_items = gimp_container_tree_view_select_items;
|
2010-05-19 20:07:31 +02:00
|
|
|
iface->clear_items = gimp_container_tree_view_clear_items;
|
|
|
|
iface->set_view_size = gimp_container_tree_view_set_view_size;
|
|
|
|
iface->get_selected = gimp_container_tree_view_get_selected;
|
2006-08-29 21:44:51 +00:00
|
|
|
|
2007-05-20 11:47:27 +00:00
|
|
|
iface->insert_data_free = (GDestroyNotify) gtk_tree_iter_free;
|
2006-08-29 21:44:51 +00:00
|
|
|
}
|
|
|
|
|
2003-02-21 19:03:19 +00:00
|
|
|
static void
|
|
|
|
gimp_container_tree_view_init (GimpContainerTreeView *tree_view)
|
|
|
|
{
|
2004-05-10 11:08:51 +00:00
|
|
|
GimpContainerBox *box = GIMP_CONTAINER_BOX (tree_view);
|
2003-03-26 14:56:10 +00:00
|
|
|
|
app, libgimp*, modules: don't use g_type_class_add_private() ...
... and G_TYPE_INSTANCE_GET_PRIVATE()
g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() were
deprecated in GLib 2.58. Instead, use
G_DEFINE_[ABSTRACT_]TYPE_WITH_PRIVATE(), and
G_ADD_PRIVATE[_DYNAMIC](), and the implictly-defined
foo_get_instance_private() functions, all of which are available in
the GLib versions we depend on.
This commit only covers types registered using one of the
G_DEFINE_FOO() macros (i.e., most types), but not types with a
custom registration function, of which we still have a few -- GLib
currently only provides a (non-deprecated) public API for adding a
private struct using the G_DEFINE_FOO() macros.
Note that this commit was 99% auto-generated (because I'm not
*that* crazy :), so if there are any style mismatches... we'll have
to live with them for now.
2018-09-18 12:09:39 -04:00
|
|
|
tree_view->priv = gimp_container_tree_view_get_instance_private (tree_view);
|
2008-11-15 18:08:50 +00:00
|
|
|
|
2010-05-17 21:34:11 +02:00
|
|
|
gimp_container_tree_store_columns_init (tree_view->model_columns,
|
|
|
|
&tree_view->n_model_columns);
|
2003-03-16 11:14:29 +00:00
|
|
|
|
2004-05-10 11:08:51 +00:00
|
|
|
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (box->scrolled_win),
|
2003-02-21 19:03:19 +00:00
|
|
|
GTK_SHADOW_IN);
|
2004-05-10 11:08:51 +00:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (box->scrolled_win),
|
2003-03-26 14:56:10 +00:00
|
|
|
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
2016-06-01 22:38:58 +02:00
|
|
|
|
|
|
|
gimp_widget_track_monitor (GTK_WIDGET (tree_view),
|
|
|
|
G_CALLBACK (gimp_container_tree_view_monitor_changed),
|
2019-08-07 23:44:18 +02:00
|
|
|
NULL, NULL);
|
2003-03-16 11:14:29 +00:00
|
|
|
}
|
|
|
|
|
2011-01-14 09:38:11 +01:00
|
|
|
static void
|
|
|
|
gimp_container_tree_view_constructed (GObject *object)
|
2003-03-16 11:14:29 +00:00
|
|
|
{
|
2011-01-14 09:38:11 +01:00
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (object);
|
|
|
|
GimpContainerView *view = GIMP_CONTAINER_VIEW (object);
|
|
|
|
GimpContainerBox *box = GIMP_CONTAINER_BOX (object);
|
2003-03-16 11:14:29 +00:00
|
|
|
|
2012-11-12 21:51:22 +01:00
|
|
|
G_OBJECT_CLASS (parent_class)->constructed (object);
|
2003-03-16 11:14:29 +00:00
|
|
|
|
2010-05-17 21:06:28 +02:00
|
|
|
tree_view->model = gimp_container_tree_store_new (view,
|
|
|
|
tree_view->n_model_columns,
|
|
|
|
tree_view->model_columns);
|
2003-03-13 22:17:31 +00:00
|
|
|
|
2004-05-11 13:44:13 +00:00
|
|
|
tree_view->view = g_object_new (GTK_TYPE_TREE_VIEW,
|
2010-05-17 21:06:28 +02:00
|
|
|
"model", tree_view->model,
|
2010-05-17 21:28:17 +02:00
|
|
|
"search-column", GIMP_CONTAINER_TREE_STORE_COLUMN_NAME,
|
2005-03-21 19:20:11 +00:00
|
|
|
"enable-search", FALSE,
|
|
|
|
"headers-visible", FALSE,
|
2007-11-09 11:17:00 +00:00
|
|
|
"has-tooltip", TRUE,
|
2019-07-19 07:29:31 +02:00
|
|
|
"show-expanders", GIMP_CONTAINER_VIEW_GET_IFACE (view)->model_is_tree,
|
2004-05-11 13:44:13 +00:00
|
|
|
NULL);
|
2003-03-20 14:34:16 +00:00
|
|
|
|
2004-05-10 11:08:51 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (box->scrolled_win),
|
2003-03-16 11:14:29 +00:00
|
|
|
GTK_WIDGET (tree_view->view));
|
|
|
|
gtk_widget_show (GTK_WIDGET (tree_view->view));
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2004-05-10 23:22:39 +00:00
|
|
|
gimp_container_view_set_dnd_widget (view, GTK_WIDGET (tree_view->view));
|
2003-02-24 20:31:14 +00:00
|
|
|
|
2003-03-16 11:14:29 +00:00
|
|
|
tree_view->main_column = gtk_tree_view_column_new ();
|
|
|
|
gtk_tree_view_insert_column (tree_view->view, tree_view->main_column, 0);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2009-08-04 00:21:07 +02:00
|
|
|
gtk_tree_view_set_expander_column (tree_view->view, tree_view->main_column);
|
2009-08-06 18:43:57 +02:00
|
|
|
gtk_tree_view_set_enable_tree_lines (tree_view->view, TRUE);
|
2009-08-04 00:21:07 +02:00
|
|
|
|
2003-03-16 11:14:29 +00:00
|
|
|
tree_view->renderer_cell = gimp_cell_renderer_viewable_new ();
|
|
|
|
gtk_tree_view_column_pack_start (tree_view->main_column,
|
|
|
|
tree_view->renderer_cell,
|
|
|
|
FALSE);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2003-03-16 11:14:29 +00:00
|
|
|
gtk_tree_view_column_set_attributes (tree_view->main_column,
|
|
|
|
tree_view->renderer_cell,
|
2010-05-17 21:28:17 +02:00
|
|
|
"renderer", GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER,
|
2003-03-16 11:14:29 +00:00
|
|
|
NULL);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2008-11-15 18:08:50 +00:00
|
|
|
tree_view->priv->name_cell = gtk_cell_renderer_text_new ();
|
|
|
|
g_object_set (tree_view->priv->name_cell, "xalign", 0.0, NULL);
|
2003-03-16 11:14:29 +00:00
|
|
|
gtk_tree_view_column_pack_end (tree_view->main_column,
|
2008-11-15 18:08:50 +00:00
|
|
|
tree_view->priv->name_cell,
|
2006-08-29 21:44:51 +00:00
|
|
|
FALSE);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2003-03-16 11:14:29 +00:00
|
|
|
gtk_tree_view_column_set_attributes (tree_view->main_column,
|
2008-11-15 18:08:50 +00:00
|
|
|
tree_view->priv->name_cell,
|
2010-05-17 21:28:17 +02:00
|
|
|
"text", GIMP_CONTAINER_TREE_STORE_COLUMN_NAME,
|
|
|
|
"attributes", GIMP_CONTAINER_TREE_STORE_COLUMN_NAME_ATTRIBUTES,
|
|
|
|
"sensitive", GIMP_CONTAINER_TREE_STORE_COLUMN_NAME_SENSITIVE,
|
2003-03-16 11:14:29 +00:00
|
|
|
NULL);
|
|
|
|
|
2012-02-06 19:28:37 +01:00
|
|
|
g_signal_connect (tree_view->priv->name_cell, "editing-started",
|
|
|
|
G_CALLBACK (gimp_container_tree_view_name_started),
|
|
|
|
tree_view);
|
2008-11-15 18:08:50 +00:00
|
|
|
g_signal_connect (tree_view->priv->name_cell, "editing-canceled",
|
2004-07-05 22:50:38 +00:00
|
|
|
G_CALLBACK (gimp_container_tree_view_name_canceled),
|
|
|
|
tree_view);
|
|
|
|
|
2010-06-03 22:09:02 +02:00
|
|
|
gimp_container_tree_view_add_renderer_cell (tree_view,
|
|
|
|
tree_view->renderer_cell);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2008-11-15 18:08:50 +00:00
|
|
|
tree_view->priv->selection = gtk_tree_view_get_selection (tree_view->view);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2008-11-15 18:08:50 +00:00
|
|
|
g_signal_connect (tree_view->priv->selection, "changed",
|
2003-02-21 19:03:19 +00:00
|
|
|
G_CALLBACK (gimp_container_tree_view_selection_changed),
|
|
|
|
tree_view);
|
2003-03-16 11:14:29 +00:00
|
|
|
|
2013-09-30 05:23:23 +13:00
|
|
|
g_signal_connect (tree_view->view, "drag-failed",
|
|
|
|
G_CALLBACK (gimp_container_tree_view_drag_failed),
|
|
|
|
tree_view);
|
2005-08-03 09:34:55 +00:00
|
|
|
g_signal_connect (tree_view->view, "drag-leave",
|
2003-03-19 15:17:13 +00:00
|
|
|
G_CALLBACK (gimp_container_tree_view_drag_leave),
|
|
|
|
tree_view);
|
2005-08-03 09:34:55 +00:00
|
|
|
g_signal_connect (tree_view->view, "drag-motion",
|
2003-03-19 15:17:13 +00:00
|
|
|
G_CALLBACK (gimp_container_tree_view_drag_motion),
|
|
|
|
tree_view);
|
2005-08-03 09:34:55 +00:00
|
|
|
g_signal_connect (tree_view->view, "drag-drop",
|
2003-03-19 15:17:13 +00:00
|
|
|
G_CALLBACK (gimp_container_tree_view_drag_drop),
|
|
|
|
tree_view);
|
2005-08-03 09:34:55 +00:00
|
|
|
g_signal_connect (tree_view->view, "drag-data-received",
|
2004-06-28 22:07:12 +00:00
|
|
|
G_CALLBACK (gimp_container_tree_view_drag_data_received),
|
|
|
|
tree_view);
|
2003-03-19 15:17:13 +00:00
|
|
|
|
2016-10-01 20:55:13 +02:00
|
|
|
/* connect_after so external code can connect to "query-tooltip" too
|
|
|
|
* and override the default tip
|
|
|
|
*/
|
|
|
|
g_signal_connect_after (tree_view->view, "query-tooltip",
|
|
|
|
G_CALLBACK (gimp_container_tree_view_tooltip),
|
|
|
|
tree_view);
|
2003-02-21 19:03:19 +00:00
|
|
|
}
|
|
|
|
|
2003-10-09 22:56:14 +00:00
|
|
|
static void
|
2008-03-30 17:20:36 +00:00
|
|
|
gimp_container_tree_view_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (object);
|
|
|
|
|
2017-07-15 18:38:01 +02:00
|
|
|
g_clear_object (&tree_view->model);
|
2014-06-06 22:41:33 +02:00
|
|
|
|
2008-11-16 20:58:53 +00:00
|
|
|
if (tree_view->priv->toggle_cells)
|
2008-03-30 17:20:36 +00:00
|
|
|
{
|
2008-11-16 20:58:53 +00:00
|
|
|
g_list_free (tree_view->priv->toggle_cells);
|
|
|
|
tree_view->priv->toggle_cells = NULL;
|
2008-03-30 17:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-11-16 20:58:53 +00:00
|
|
|
if (tree_view->priv->renderer_cells)
|
2008-03-30 17:20:36 +00:00
|
|
|
{
|
2008-11-16 20:58:53 +00:00
|
|
|
g_list_free (tree_view->priv->renderer_cells);
|
|
|
|
tree_view->priv->renderer_cells = NULL;
|
2008-03-30 17:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-11-15 18:08:50 +00:00
|
|
|
if (tree_view->priv->editable_cells)
|
2008-03-30 17:20:36 +00:00
|
|
|
{
|
2008-11-15 18:08:50 +00:00
|
|
|
g_list_free (tree_view->priv->editable_cells);
|
|
|
|
tree_view->priv->editable_cells = NULL;
|
2008-03-30 17:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2015-12-11 22:46:37 +01:00
|
|
|
static gboolean
|
2015-12-13 17:54:13 +01:00
|
|
|
gimp_container_tree_view_style_updated_foreach (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
2015-12-11 22:46:37 +01:00
|
|
|
{
|
|
|
|
GimpViewRenderer *renderer;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (renderer)
|
|
|
|
{
|
|
|
|
gimp_view_renderer_invalidate (renderer);
|
|
|
|
g_object_unref (renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-12-13 17:54:13 +01:00
|
|
|
gimp_container_tree_view_style_updated (GtkWidget *widget)
|
2015-12-11 22:46:37 +01:00
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (widget);
|
|
|
|
|
2015-12-13 17:54:13 +01:00
|
|
|
GTK_WIDGET_CLASS (parent_class)->style_updated (widget);
|
2015-12-11 22:46:37 +01:00
|
|
|
|
|
|
|
if (tree_view->model)
|
|
|
|
gtk_tree_model_foreach (tree_view->model,
|
2015-12-13 17:54:13 +01:00
|
|
|
gimp_container_tree_view_style_updated_foreach,
|
2015-12-11 22:46:37 +01:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2008-03-30 17:20:36 +00:00
|
|
|
static void
|
2003-10-09 22:56:14 +00:00
|
|
|
gimp_container_tree_view_unmap (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (widget);
|
|
|
|
|
2008-11-15 18:08:50 +00:00
|
|
|
if (tree_view->priv->scroll_timeout_id)
|
2003-10-09 22:56:14 +00:00
|
|
|
{
|
2008-11-15 18:08:50 +00:00
|
|
|
g_source_remove (tree_view->priv->scroll_timeout_id);
|
|
|
|
tree_view->priv->scroll_timeout_id = 0;
|
2003-10-09 22:56:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (parent_class)->unmap (widget);
|
|
|
|
}
|
|
|
|
|
2003-09-30 15:55:23 +00:00
|
|
|
static void
|
|
|
|
gimp_container_tree_view_menu_position (GtkMenu *menu,
|
|
|
|
gint *x,
|
|
|
|
gint *y,
|
|
|
|
gpointer data)
|
|
|
|
{
|
2004-05-11 10:01:25 +00:00
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (data);
|
|
|
|
GtkWidget *widget = GTK_WIDGET (tree_view->view);
|
2009-10-17 20:20:39 +02:00
|
|
|
GtkAllocation allocation;
|
2003-09-30 15:55:23 +00:00
|
|
|
GtkTreeIter selected_iter;
|
|
|
|
|
2009-10-17 20:20:39 +02:00
|
|
|
gtk_widget_get_allocation (widget, &allocation);
|
|
|
|
|
2009-03-22 16:35:53 +00:00
|
|
|
gdk_window_get_origin (gtk_widget_get_window (widget), x, y);
|
2003-09-30 15:55:23 +00:00
|
|
|
|
2009-10-17 20:20:39 +02:00
|
|
|
if (! gtk_widget_get_has_window (widget))
|
2003-09-30 15:55:23 +00:00
|
|
|
{
|
2009-10-17 20:20:39 +02:00
|
|
|
*x += allocation.x;
|
|
|
|
*y += allocation.y;
|
2003-09-30 15:55:23 +00:00
|
|
|
}
|
|
|
|
|
2010-03-07 18:54:20 +02:00
|
|
|
if (gimp_container_tree_view_get_selected_single (tree_view, &selected_iter))
|
2003-09-30 15:55:23 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
GdkRectangle cell_rect;
|
2004-09-15 09:34:02 +00:00
|
|
|
gint center;
|
2003-09-30 15:55:23 +00:00
|
|
|
|
|
|
|
path = gtk_tree_model_get_path (tree_view->model, &selected_iter);
|
|
|
|
gtk_tree_view_get_cell_area (tree_view->view, path,
|
|
|
|
tree_view->main_column, &cell_rect);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
2004-09-15 09:34:02 +00:00
|
|
|
center = cell_rect.y + cell_rect.height / 2;
|
2009-10-17 20:20:39 +02:00
|
|
|
center = CLAMP (center, 0, allocation.height);
|
2004-09-15 05:55:56 +00:00
|
|
|
|
2009-10-17 20:20:39 +02:00
|
|
|
*x += allocation.width / 2;
|
2004-09-15 09:34:02 +00:00
|
|
|
*y += center;
|
2003-09-30 15:55:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-12-19 13:10:51 +01:00
|
|
|
GtkStyleContext *style = gtk_widget_get_style_context (widget);
|
|
|
|
GtkBorder border;
|
2008-06-28 15:50:27 +00:00
|
|
|
|
2010-12-19 13:10:51 +01:00
|
|
|
gtk_style_context_get_border (style, 0, &border);
|
|
|
|
|
|
|
|
*x += border.left;
|
|
|
|
*y += border.top;
|
2003-09-30 15:55:23 +00:00
|
|
|
}
|
|
|
|
|
2003-11-19 18:08:15 +00:00
|
|
|
gimp_menu_position (menu, x, y);
|
2003-09-30 15:55:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_container_tree_view_popup_menu (GtkWidget *widget)
|
|
|
|
{
|
2005-09-02 21:56:20 +00:00
|
|
|
return gimp_editor_popup_menu (GIMP_EDITOR (widget),
|
|
|
|
gimp_container_tree_view_menu_position,
|
|
|
|
widget);
|
2003-09-30 15:55:23 +00:00
|
|
|
}
|
|
|
|
|
2003-02-21 19:03:19 +00:00
|
|
|
GtkWidget *
|
|
|
|
gimp_container_tree_view_new (GimpContainer *container,
|
|
|
|
GimpContext *context,
|
2006-01-17 10:08:50 +00:00
|
|
|
gint view_size,
|
2010-03-09 21:29:25 +02:00
|
|
|
gint view_border_width)
|
2003-02-21 19:03:19 +00:00
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view;
|
2004-05-10 23:22:39 +00:00
|
|
|
GimpContainerView *view;
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2003-03-26 14:56:10 +00:00
|
|
|
g_return_val_if_fail (container == NULL || GIMP_IS_CONTAINER (container),
|
|
|
|
NULL);
|
|
|
|
g_return_val_if_fail (context == NULL || GIMP_IS_CONTEXT (context), NULL);
|
2006-01-17 10:08:50 +00:00
|
|
|
g_return_val_if_fail (view_size > 0 &&
|
|
|
|
view_size <= GIMP_VIEWABLE_MAX_PREVIEW_SIZE, NULL);
|
|
|
|
g_return_val_if_fail (view_border_width >= 0 &&
|
|
|
|
view_border_width <= GIMP_VIEW_MAX_BORDER_WIDTH,
|
2003-04-08 12:39:02 +00:00
|
|
|
NULL);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2010-03-09 21:29:25 +02:00
|
|
|
tree_view = g_object_new (GIMP_TYPE_CONTAINER_TREE_VIEW, NULL);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2004-05-10 23:22:39 +00:00
|
|
|
view = GIMP_CONTAINER_VIEW (tree_view);
|
|
|
|
|
2006-01-17 10:08:50 +00:00
|
|
|
gimp_container_view_set_view_size (view, view_size, view_border_width);
|
2004-05-10 23:22:39 +00:00
|
|
|
|
|
|
|
if (container)
|
|
|
|
gimp_container_view_set_container (view, container);
|
|
|
|
|
|
|
|
if (context)
|
|
|
|
gimp_container_view_set_context (view, context);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
|
|
|
return GTK_WIDGET (tree_view);
|
|
|
|
}
|
|
|
|
|
2013-11-07 11:32:23 +01:00
|
|
|
GtkCellRenderer *
|
|
|
|
gimp_container_tree_view_get_name_cell (GimpContainerTreeView *tree_view)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTAINER_TREE_VIEW (tree_view), NULL);
|
|
|
|
|
|
|
|
return tree_view->priv->name_cell;
|
|
|
|
}
|
|
|
|
|
2008-11-16 20:58:53 +00:00
|
|
|
void
|
|
|
|
gimp_container_tree_view_set_main_column_title (GimpContainerTreeView *tree_view,
|
|
|
|
const gchar *title)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CONTAINER_TREE_VIEW (tree_view));
|
|
|
|
|
|
|
|
gtk_tree_view_column_set_title (tree_view->main_column,
|
|
|
|
title);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-28 10:59:27 +02:00
|
|
|
gimp_container_tree_view_add_toggle_cell (GimpContainerTreeView *tree_view,
|
|
|
|
GtkCellRenderer *cell)
|
2008-11-16 20:58:53 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CONTAINER_TREE_VIEW (tree_view));
|
2016-10-01 20:55:13 +02:00
|
|
|
g_return_if_fail (GIMP_IS_CELL_RENDERER_TOGGLE (cell) ||
|
|
|
|
GIMP_IS_CELL_RENDERER_BUTTON (cell));
|
2008-11-16 20:58:53 +00:00
|
|
|
|
|
|
|
tree_view->priv->toggle_cells = g_list_prepend (tree_view->priv->toggle_cells,
|
2009-08-28 10:59:27 +02:00
|
|
|
cell);
|
2008-11-16 20:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-08-28 10:59:27 +02:00
|
|
|
gimp_container_tree_view_add_renderer_cell (GimpContainerTreeView *tree_view,
|
|
|
|
GtkCellRenderer *cell)
|
2008-11-16 20:58:53 +00:00
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CONTAINER_TREE_VIEW (tree_view));
|
2009-08-28 10:59:27 +02:00
|
|
|
g_return_if_fail (GIMP_IS_CELL_RENDERER_VIEWABLE (cell));
|
2008-11-16 20:58:53 +00:00
|
|
|
|
|
|
|
tree_view->priv->renderer_cells = g_list_prepend (tree_view->priv->renderer_cells,
|
2009-08-28 10:59:27 +02:00
|
|
|
cell);
|
2010-06-03 22:09:02 +02:00
|
|
|
|
|
|
|
gimp_container_tree_store_add_renderer_cell (GIMP_CONTAINER_TREE_STORE (tree_view->model),
|
|
|
|
cell);
|
2008-11-16 20:58:53 +00:00
|
|
|
}
|
|
|
|
|
2008-11-16 19:48:54 +00:00
|
|
|
void
|
|
|
|
gimp_container_tree_view_set_dnd_drop_to_empty (GimpContainerTreeView *tree_view,
|
|
|
|
gboolean dnd_drop_to_empty)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CONTAINER_TREE_VIEW (tree_view));
|
|
|
|
|
|
|
|
tree_view->priv->dnd_drop_to_empty = dnd_drop_to_empty;
|
|
|
|
}
|
|
|
|
|
2008-06-28 16:05:05 +00:00
|
|
|
void
|
|
|
|
gimp_container_tree_view_connect_name_edited (GimpContainerTreeView *tree_view,
|
|
|
|
GCallback callback,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_CONTAINER_TREE_VIEW (tree_view));
|
|
|
|
g_return_if_fail (callback != NULL);
|
|
|
|
|
2008-11-15 18:08:50 +00:00
|
|
|
g_object_set (tree_view->priv->name_cell,
|
2008-06-28 16:05:05 +00:00
|
|
|
"mode", GTK_CELL_RENDERER_MODE_EDITABLE,
|
|
|
|
"editable", TRUE,
|
|
|
|
NULL);
|
|
|
|
|
2008-11-15 18:08:50 +00:00
|
|
|
if (! g_list_find (tree_view->priv->editable_cells, tree_view->priv->name_cell))
|
|
|
|
tree_view->priv->editable_cells = g_list_prepend (tree_view->priv->editable_cells,
|
|
|
|
tree_view->priv->name_cell);
|
2008-06-28 16:05:05 +00:00
|
|
|
|
2008-11-15 18:08:50 +00:00
|
|
|
g_signal_connect (tree_view->priv->name_cell, "edited",
|
2008-06-28 16:05:05 +00:00
|
|
|
callback,
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
2017-11-14 20:54:38 +01:00
|
|
|
gboolean
|
|
|
|
gimp_container_tree_view_name_edited (GtkCellRendererText *cell,
|
|
|
|
const gchar *path_str,
|
|
|
|
const gchar *new_name,
|
|
|
|
GimpContainerTreeView *tree_view)
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gboolean changed = FALSE;
|
|
|
|
|
|
|
|
path = gtk_tree_path_new_from_string (path_str);
|
|
|
|
|
|
|
|
if (gtk_tree_model_get_iter (tree_view->model, &iter, path))
|
|
|
|
{
|
|
|
|
GimpViewRenderer *renderer;
|
|
|
|
GimpObject *object;
|
|
|
|
const gchar *old_name;
|
|
|
|
|
|
|
|
gtk_tree_model_get (tree_view->model, &iter,
|
|
|
|
GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
object = GIMP_OBJECT (renderer->viewable);
|
|
|
|
|
|
|
|
old_name = gimp_object_get_name (object);
|
|
|
|
|
|
|
|
if (! old_name) old_name = "";
|
|
|
|
if (! new_name) new_name = "";
|
|
|
|
|
|
|
|
if (strcmp (old_name, new_name))
|
|
|
|
{
|
|
|
|
gimp_object_set_name (object, new_name);
|
|
|
|
|
|
|
|
changed = TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gchar *name = gimp_viewable_get_description (renderer->viewable,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
gtk_tree_store_set (GTK_TREE_STORE (tree_view->model), &iter,
|
|
|
|
GIMP_CONTAINER_TREE_STORE_COLUMN_NAME, name,
|
|
|
|
-1);
|
|
|
|
g_free (name);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2003-02-21 19:03:19 +00:00
|
|
|
|
|
|
|
/* GimpContainerView methods */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_tree_view_set_container (GimpContainerView *view,
|
|
|
|
GimpContainer *container)
|
|
|
|
{
|
2003-10-26 20:25:34 +00:00
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
2004-05-10 17:16:50 +00:00
|
|
|
GimpContainer *old_container;
|
|
|
|
|
|
|
|
old_container = gimp_container_view_get_container (view);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2004-05-10 17:16:50 +00:00
|
|
|
if (old_container)
|
2003-02-21 19:03:19 +00:00
|
|
|
{
|
2012-05-22 12:58:10 +02:00
|
|
|
tree_view->priv->dnd_renderer = NULL;
|
|
|
|
|
2011-09-25 21:57:20 +02:00
|
|
|
g_signal_handlers_disconnect_by_func (tree_view->view,
|
|
|
|
gimp_container_tree_view_row_expanded,
|
|
|
|
tree_view);
|
2003-02-24 20:31:14 +00:00
|
|
|
if (! container)
|
|
|
|
{
|
2020-03-24 22:06:28 +01:00
|
|
|
if (gimp_dnd_viewable_list_source_remove (GTK_WIDGET (tree_view->view),
|
|
|
|
gimp_container_get_children_type (old_container)))
|
2003-02-24 20:31:14 +00:00
|
|
|
{
|
2008-11-20 23:43:58 +00:00
|
|
|
if (GIMP_VIEWABLE_CLASS (g_type_class_peek (gimp_container_get_children_type (old_container)))->get_size)
|
2005-05-25 10:05:17 +00:00
|
|
|
gimp_dnd_pixbuf_source_remove (GTK_WIDGET (tree_view->view));
|
|
|
|
|
2003-02-24 20:31:14 +00:00
|
|
|
gtk_drag_source_unset (GTK_WIDGET (tree_view->view));
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_func (tree_view->view,
|
2020-03-22 00:15:18 +01:00
|
|
|
gimp_container_tree_view_button,
|
2003-02-24 20:31:14 +00:00
|
|
|
tree_view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (container)
|
|
|
|
{
|
|
|
|
if (gimp_dnd_drag_source_set_by_type (GTK_WIDGET (tree_view->view),
|
|
|
|
GDK_BUTTON1_MASK | GDK_BUTTON2_MASK,
|
2008-11-20 23:43:58 +00:00
|
|
|
gimp_container_get_children_type (container),
|
2003-02-24 20:31:14 +00:00
|
|
|
GDK_ACTION_COPY))
|
|
|
|
{
|
2020-03-24 22:06:28 +01:00
|
|
|
gimp_dnd_viewable_list_source_add (GTK_WIDGET (tree_view->view),
|
|
|
|
gimp_container_get_children_type (container),
|
|
|
|
gimp_container_tree_view_drag_viewable_list,
|
|
|
|
tree_view);
|
2003-11-20 16:26:15 +00:00
|
|
|
gimp_dnd_viewable_source_add (GTK_WIDGET (tree_view->view),
|
2008-11-20 23:43:58 +00:00
|
|
|
gimp_container_get_children_type (container),
|
2003-02-24 20:31:14 +00:00
|
|
|
gimp_container_tree_view_drag_viewable,
|
|
|
|
tree_view);
|
2005-05-25 10:05:17 +00:00
|
|
|
|
2008-11-20 23:43:58 +00:00
|
|
|
if (GIMP_VIEWABLE_CLASS (g_type_class_peek (gimp_container_get_children_type (container)))->get_size)
|
2005-05-25 10:05:17 +00:00
|
|
|
gimp_dnd_pixbuf_source_add (GTK_WIDGET (tree_view->view),
|
|
|
|
gimp_container_tree_view_drag_pixbuf,
|
|
|
|
tree_view);
|
2003-02-24 20:31:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* connect button_press_event after DND so we can keep the list from
|
|
|
|
* selecting the item on button2
|
|
|
|
*/
|
2005-05-27 16:51:39 +00:00
|
|
|
g_signal_connect (tree_view->view, "button-press-event",
|
2020-03-22 00:15:18 +01:00
|
|
|
G_CALLBACK (gimp_container_tree_view_button),
|
|
|
|
tree_view);
|
|
|
|
g_signal_connect (tree_view->view, "button-release-event",
|
|
|
|
G_CALLBACK (gimp_container_tree_view_button),
|
2003-02-24 20:31:14 +00:00
|
|
|
tree_view);
|
2003-02-21 19:03:19 +00:00
|
|
|
}
|
|
|
|
|
2004-05-10 23:22:39 +00:00
|
|
|
parent_view_iface->set_container (view, container);
|
2008-09-05 14:06:01 +00:00
|
|
|
|
2011-09-25 21:57:20 +02:00
|
|
|
if (container)
|
|
|
|
{
|
|
|
|
gimp_container_tree_view_expand_rows (tree_view->model,
|
|
|
|
tree_view->view,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_signal_connect (tree_view->view,
|
|
|
|
"row-collapsed",
|
|
|
|
G_CALLBACK (gimp_container_tree_view_row_expanded),
|
|
|
|
tree_view);
|
|
|
|
g_signal_connect (tree_view->view,
|
|
|
|
"row-expanded",
|
|
|
|
G_CALLBACK (gimp_container_tree_view_row_expanded),
|
|
|
|
tree_view);
|
|
|
|
}
|
|
|
|
|
2008-09-05 14:06:01 +00:00
|
|
|
gtk_tree_view_columns_autosize (tree_view->view);
|
2003-02-21 19:03:19 +00:00
|
|
|
}
|
|
|
|
|
2006-08-31 21:40:16 +00:00
|
|
|
static void
|
|
|
|
gimp_container_tree_view_set_context (GimpContainerView *view,
|
|
|
|
GimpContext *context)
|
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
|
|
|
|
|
|
|
if (tree_view->model)
|
2010-05-17 21:06:28 +02:00
|
|
|
gimp_container_tree_store_set_context (GIMP_CONTAINER_TREE_STORE (tree_view->model),
|
|
|
|
context);
|
2012-02-06 01:33:01 +01:00
|
|
|
|
|
|
|
parent_view_iface->set_context (view, context);
|
2006-08-31 21:40:16 +00:00
|
|
|
}
|
|
|
|
|
2010-03-11 17:40:00 +02:00
|
|
|
static void
|
2010-05-19 20:07:31 +02:00
|
|
|
gimp_container_tree_view_set_selection_mode (GimpContainerView *view,
|
|
|
|
GtkSelectionMode mode)
|
2010-03-11 17:40:00 +02:00
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
|
|
|
|
2010-05-19 20:07:31 +02:00
|
|
|
gtk_tree_selection_set_mode (tree_view->priv->selection, mode);
|
2010-03-11 17:40:00 +02:00
|
|
|
|
2010-05-19 20:07:31 +02:00
|
|
|
parent_view_iface->set_selection_mode (view, mode);
|
2010-03-11 17:40:00 +02:00
|
|
|
}
|
|
|
|
|
2003-02-21 19:03:19 +00:00
|
|
|
static gpointer
|
|
|
|
gimp_container_tree_view_insert_item (GimpContainerView *view,
|
2004-08-25 22:31:44 +00:00
|
|
|
GimpViewable *viewable,
|
2009-08-01 19:13:35 +02:00
|
|
|
gpointer parent_insert_data,
|
2004-08-25 22:31:44 +00:00
|
|
|
gint index)
|
2003-02-21 19:03:19 +00:00
|
|
|
{
|
2017-12-08 11:04:30 -05:00
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
|
|
|
GtkTreeIter *parent_iter = parent_insert_data;
|
2010-05-17 21:06:28 +02:00
|
|
|
GtkTreeIter *iter;
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2010-05-17 21:06:28 +02:00
|
|
|
iter = gimp_container_tree_store_insert_item (GIMP_CONTAINER_TREE_STORE (tree_view->model),
|
|
|
|
viewable,
|
2017-12-08 11:04:30 -05:00
|
|
|
parent_iter,
|
2010-05-17 21:06:28 +02:00
|
|
|
index);
|
2017-12-08 11:04:30 -05:00
|
|
|
|
|
|
|
if (parent_iter)
|
|
|
|
gimp_container_tree_view_expand_item (view, viewable, parent_iter);
|
|
|
|
|
2010-05-17 21:06:28 +02:00
|
|
|
return iter;
|
2003-02-21 19:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_tree_view_remove_item (GimpContainerView *view,
|
2004-08-25 22:31:44 +00:00
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data)
|
2003-02-21 19:03:19 +00:00
|
|
|
{
|
2003-10-26 20:25:34 +00:00
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
2004-05-11 10:01:25 +00:00
|
|
|
GtkTreeIter *iter = (GtkTreeIter *) insert_data;
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2010-05-17 21:06:28 +02:00
|
|
|
gimp_container_tree_store_remove_item (GIMP_CONTAINER_TREE_STORE (tree_view->model),
|
|
|
|
viewable,
|
|
|
|
iter);
|
|
|
|
|
2003-02-21 19:03:19 +00:00
|
|
|
if (iter)
|
2010-06-03 22:09:02 +02:00
|
|
|
gtk_tree_view_columns_autosize (tree_view->view);
|
2003-02-21 19:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_tree_view_reorder_item (GimpContainerView *view,
|
2004-08-25 22:31:44 +00:00
|
|
|
GimpViewable *viewable,
|
|
|
|
gint new_index,
|
|
|
|
gpointer insert_data)
|
2003-02-21 19:03:19 +00:00
|
|
|
{
|
2003-10-26 20:25:34 +00:00
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
2004-05-10 17:16:50 +00:00
|
|
|
GtkTreeIter *iter = (GtkTreeIter *) insert_data;
|
2017-12-08 11:04:30 -05:00
|
|
|
GtkTreeIter parent_iter;
|
2010-05-17 21:06:28 +02:00
|
|
|
gboolean selected = FALSE;
|
2003-02-21 19:03:19 +00:00
|
|
|
|
|
|
|
if (iter)
|
|
|
|
{
|
2010-05-17 21:06:28 +02:00
|
|
|
GtkTreeIter selected_iter;
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2010-03-07 18:54:20 +02:00
|
|
|
selected = gimp_container_tree_view_get_selected_single (tree_view,
|
|
|
|
&selected_iter);
|
2003-02-26 16:17:10 +00:00
|
|
|
|
2003-03-06 16:47:34 +00:00
|
|
|
if (selected)
|
|
|
|
{
|
2004-08-25 22:31:44 +00:00
|
|
|
GimpViewRenderer *renderer;
|
2003-02-26 16:17:10 +00:00
|
|
|
|
2003-03-13 22:17:31 +00:00
|
|
|
gtk_tree_model_get (tree_view->model, &selected_iter,
|
2010-05-17 21:28:17 +02:00
|
|
|
GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
|
2003-03-06 16:47:34 +00:00
|
|
|
-1);
|
2003-02-26 16:17:10 +00:00
|
|
|
|
2003-03-16 11:14:29 +00:00
|
|
|
if (renderer->viewable != viewable)
|
2003-03-06 16:47:34 +00:00
|
|
|
selected = FALSE;
|
|
|
|
|
2003-03-16 11:14:29 +00:00
|
|
|
g_object_unref (renderer);
|
2003-03-06 16:47:34 +00:00
|
|
|
}
|
2010-05-17 21:06:28 +02:00
|
|
|
}
|
2003-03-06 16:47:34 +00:00
|
|
|
|
2010-05-17 21:06:28 +02:00
|
|
|
gimp_container_tree_store_reorder_item (GIMP_CONTAINER_TREE_STORE (tree_view->model),
|
|
|
|
viewable,
|
|
|
|
new_index,
|
|
|
|
iter);
|
2003-03-06 16:47:34 +00:00
|
|
|
|
2010-05-17 21:06:28 +02:00
|
|
|
if (selected)
|
|
|
|
gimp_container_view_select_item (view, viewable);
|
2017-12-08 11:04:30 -05:00
|
|
|
|
|
|
|
if (gtk_tree_model_iter_parent (tree_view->model, &parent_iter, iter))
|
|
|
|
gimp_container_tree_view_expand_item (view, viewable, &parent_iter);
|
2003-02-21 19:03:19 +00:00
|
|
|
}
|
|
|
|
|
2004-01-29 16:34:41 +00:00
|
|
|
static void
|
|
|
|
gimp_container_tree_view_rename_item (GimpContainerView *view,
|
2004-08-25 22:31:44 +00:00
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data)
|
2004-01-29 16:34:41 +00:00
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
2004-05-11 10:01:25 +00:00
|
|
|
GtkTreeIter *iter = (GtkTreeIter *) insert_data;
|
2004-01-29 16:34:41 +00:00
|
|
|
|
2010-05-17 21:06:28 +02:00
|
|
|
if (gimp_container_tree_store_rename_item (GIMP_CONTAINER_TREE_STORE (tree_view->model),
|
|
|
|
viewable,
|
|
|
|
iter))
|
2004-01-29 16:34:41 +00:00
|
|
|
{
|
2010-05-17 21:06:28 +02:00
|
|
|
gtk_tree_view_columns_autosize (tree_view->view);
|
2004-01-29 16:34:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-22 11:50:37 -04:00
|
|
|
static void
|
|
|
|
gimp_container_tree_view_expand_item (GimpContainerView *view,
|
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data)
|
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
|
|
|
GtkTreeIter *iter = (GtkTreeIter *) insert_data;
|
|
|
|
GimpViewRenderer *renderer;
|
|
|
|
|
|
|
|
gtk_tree_model_get (tree_view->model, iter,
|
|
|
|
GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (renderer)
|
|
|
|
{
|
|
|
|
GtkTreePath *path = gtk_tree_model_get_path (tree_view->model, iter);
|
|
|
|
|
|
|
|
g_signal_handlers_block_by_func (tree_view,
|
|
|
|
gimp_container_tree_view_row_expanded,
|
|
|
|
view);
|
|
|
|
|
|
|
|
if (gimp_viewable_get_expanded (renderer->viewable))
|
|
|
|
gtk_tree_view_expand_row (tree_view->view, path, FALSE);
|
|
|
|
else
|
|
|
|
gtk_tree_view_collapse_row (tree_view->view, path);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (tree_view,
|
|
|
|
gimp_container_tree_view_row_expanded,
|
|
|
|
view);
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
g_object_unref (renderer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-18 13:28:27 +00:00
|
|
|
static gboolean
|
2003-02-21 19:03:19 +00:00
|
|
|
gimp_container_tree_view_select_item (GimpContainerView *view,
|
2004-08-25 22:31:44 +00:00
|
|
|
GimpViewable *viewable,
|
|
|
|
gpointer insert_data)
|
2003-02-21 19:03:19 +00:00
|
|
|
{
|
2003-10-26 20:25:34 +00:00
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2010-03-07 18:54:20 +02:00
|
|
|
if (viewable && insert_data)
|
2003-02-21 19:03:19 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
2010-03-14 22:57:03 +01:00
|
|
|
GtkTreePath *parent_path;
|
2010-03-07 18:54:20 +02:00
|
|
|
GtkTreeIter *iter = (GtkTreeIter *) insert_data;
|
2003-06-21 14:51:31 +00:00
|
|
|
|
2003-03-16 11:14:29 +00:00
|
|
|
path = gtk_tree_model_get_path (tree_view->model, iter);
|
|
|
|
|
2010-03-14 22:57:03 +01:00
|
|
|
parent_path = gtk_tree_path_copy (path);
|
|
|
|
|
|
|
|
if (gtk_tree_path_up (parent_path))
|
|
|
|
gtk_tree_view_expand_to_path (tree_view->view, parent_path);
|
|
|
|
|
|
|
|
gtk_tree_path_free (parent_path);
|
|
|
|
|
2008-11-15 18:08:50 +00:00
|
|
|
g_signal_handlers_block_by_func (tree_view->priv->selection,
|
2004-08-25 22:31:44 +00:00
|
|
|
gimp_container_tree_view_selection_changed,
|
|
|
|
tree_view);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2003-03-22 16:26:11 +00:00
|
|
|
gtk_tree_view_set_cursor (tree_view->view, path, NULL, FALSE);
|
2003-06-21 14:51:31 +00:00
|
|
|
|
2008-11-15 18:08:50 +00:00
|
|
|
g_signal_handlers_unblock_by_func (tree_view->priv->selection,
|
2004-08-25 22:31:44 +00:00
|
|
|
gimp_container_tree_view_selection_changed,
|
|
|
|
tree_view);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
|
|
|
gtk_tree_view_scroll_to_cell (tree_view->view, path,
|
2003-03-06 16:47:34 +00:00
|
|
|
NULL, FALSE, 0.0, 0.0);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
2010-03-07 18:54:20 +02:00
|
|
|
else if (insert_data == NULL)
|
2003-02-21 19:03:19 +00:00
|
|
|
{
|
2010-03-07 18:54:20 +02:00
|
|
|
/* viewable == NULL && insert_data != NULL means multiple selection.
|
|
|
|
* viewable == NULL && insert_data == NULL means no selection. */
|
2008-11-15 18:08:50 +00:00
|
|
|
gtk_tree_selection_unselect_all (tree_view->priv->selection);
|
2003-02-21 19:03:19 +00:00
|
|
|
}
|
2003-05-18 13:28:27 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2003-02-21 19:03:19 +00:00
|
|
|
}
|
|
|
|
|
2020-03-21 19:03:07 +01:00
|
|
|
static gboolean
|
|
|
|
gimp_container_tree_view_select_items (GimpContainerView *view,
|
|
|
|
GList *items,
|
|
|
|
GList *paths)
|
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
|
|
|
GList *item;
|
|
|
|
GList *path;
|
2020-03-26 00:33:11 +01:00
|
|
|
gboolean free_paths = FALSE;
|
2020-03-21 19:03:07 +01:00
|
|
|
|
2020-03-26 00:33:11 +01:00
|
|
|
/* If @paths is not set, compute it ourselves. */
|
|
|
|
if (g_list_length (items) != g_list_length (paths))
|
|
|
|
{
|
|
|
|
paths = NULL;
|
|
|
|
for (item = items; item; item = item->next)
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
path = gimp_container_tree_view_get_path (tree_view, item->data);
|
|
|
|
g_return_val_if_fail (path, FALSE);
|
|
|
|
paths = g_list_prepend (paths, path);
|
|
|
|
}
|
|
|
|
|
|
|
|
paths = g_list_reverse (paths);
|
|
|
|
free_paths = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_selection_unselect_all (tree_view->priv->selection);
|
2020-03-21 19:03:07 +01:00
|
|
|
for (item = items, path = paths; item && path; item = item->next, path = path->next)
|
|
|
|
{
|
|
|
|
GtkTreePath *parent_path;
|
|
|
|
|
|
|
|
/* Expand if necessary. */
|
|
|
|
parent_path = gtk_tree_path_copy (path->data);
|
|
|
|
if (gtk_tree_path_up (parent_path))
|
|
|
|
gtk_tree_view_expand_to_path (tree_view->view, parent_path);
|
|
|
|
gtk_tree_path_free (parent_path);
|
|
|
|
|
|
|
|
/* Add to the selection. */
|
|
|
|
g_signal_handlers_block_by_func (tree_view->priv->selection,
|
|
|
|
gimp_container_tree_view_selection_changed,
|
|
|
|
tree_view);
|
|
|
|
gtk_tree_selection_select_path (tree_view->priv->selection, path->data);
|
|
|
|
g_signal_handlers_unblock_by_func (tree_view->priv->selection,
|
|
|
|
gimp_container_tree_view_selection_changed,
|
|
|
|
tree_view);
|
|
|
|
|
|
|
|
|
|
|
|
/* Scroll to the top item. */
|
|
|
|
if (item == items)
|
|
|
|
gtk_tree_view_scroll_to_cell (tree_view->view, path->data,
|
|
|
|
NULL, FALSE, 0.0, 0.0);
|
|
|
|
/* TODO: better implementation: only scroll if none of the items
|
|
|
|
* are visible. */
|
|
|
|
}
|
|
|
|
|
2020-03-26 00:33:11 +01:00
|
|
|
if (free_paths)
|
|
|
|
g_list_free_full (paths, (GDestroyNotify) gtk_tree_path_free);
|
|
|
|
|
2020-03-21 19:03:07 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2003-02-21 19:03:19 +00:00
|
|
|
static void
|
|
|
|
gimp_container_tree_view_clear_items (GimpContainerView *view)
|
|
|
|
{
|
2003-10-26 20:25:34 +00:00
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2018-06-03 21:45:16 +02:00
|
|
|
g_signal_handlers_block_by_func (tree_view->priv->selection,
|
|
|
|
gimp_container_tree_view_selection_changed,
|
|
|
|
tree_view);
|
|
|
|
|
2019-04-21 09:59:24 -04:00
|
|
|
/* temporarily unset the tree-view's model, so that name editing is stopped
|
|
|
|
* now, before clearing the tree store. otherwise, name editing would stop
|
|
|
|
* when the corresponding item is removed from the store, leading us to
|
|
|
|
* rename the wrong item. see issue #3284.
|
|
|
|
*/
|
|
|
|
gtk_tree_view_set_model (tree_view->view, NULL);
|
|
|
|
|
2010-05-17 21:06:28 +02:00
|
|
|
gimp_container_tree_store_clear_items (GIMP_CONTAINER_TREE_STORE (tree_view->model));
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2019-04-21 09:59:24 -04:00
|
|
|
gtk_tree_view_set_model (tree_view->view, tree_view->model);
|
|
|
|
|
2018-06-03 21:45:16 +02:00
|
|
|
g_signal_handlers_unblock_by_func (tree_view->priv->selection,
|
|
|
|
gimp_container_tree_view_selection_changed,
|
|
|
|
tree_view);
|
|
|
|
|
2004-05-10 23:22:39 +00:00
|
|
|
parent_view_iface->clear_items (view);
|
2003-02-21 19:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-01-17 10:08:50 +00:00
|
|
|
gimp_container_tree_view_set_view_size (GimpContainerView *view)
|
2003-02-21 19:03:19 +00:00
|
|
|
{
|
2004-05-10 17:16:50 +00:00
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
2003-03-16 11:14:29 +00:00
|
|
|
GtkWidget *tree_widget;
|
|
|
|
GList *list;
|
2006-01-17 10:08:50 +00:00
|
|
|
gint view_size;
|
2004-05-10 17:16:50 +00:00
|
|
|
gint border_width;
|
2003-03-16 11:14:29 +00:00
|
|
|
|
2006-01-17 10:08:50 +00:00
|
|
|
view_size = gimp_container_view_get_view_size (view, &border_width);
|
2003-03-16 11:14:29 +00:00
|
|
|
|
2005-03-18 00:31:29 +00:00
|
|
|
if (tree_view->model)
|
2010-05-17 21:06:28 +02:00
|
|
|
gimp_container_tree_store_set_view_size (GIMP_CONTAINER_TREE_STORE (tree_view->model));
|
2005-03-18 00:31:29 +00:00
|
|
|
|
2003-03-16 11:14:29 +00:00
|
|
|
tree_widget = GTK_WIDGET (tree_view->view);
|
|
|
|
|
2005-03-18 00:31:29 +00:00
|
|
|
if (! tree_widget)
|
|
|
|
return;
|
|
|
|
|
2008-11-16 20:58:53 +00:00
|
|
|
for (list = tree_view->priv->toggle_cells; list; list = g_list_next (list))
|
2003-03-16 11:14:29 +00:00
|
|
|
{
|
2018-08-06 15:04:44 +02:00
|
|
|
gchar *icon_name;
|
|
|
|
gint icon_size;
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2014-05-07 15:30:38 +02:00
|
|
|
g_object_get (list->data, "icon-name", &icon_name, NULL);
|
2003-03-16 11:14:29 +00:00
|
|
|
|
2014-05-07 15:30:38 +02:00
|
|
|
if (icon_name)
|
2003-03-16 11:14:29 +00:00
|
|
|
{
|
2010-12-19 13:10:51 +01:00
|
|
|
GtkStyleContext *style = gtk_widget_get_style_context (tree_widget);
|
|
|
|
GtkBorder border;
|
|
|
|
|
|
|
|
gtk_style_context_save (style);
|
|
|
|
gtk_style_context_add_class (style, GTK_STYLE_CLASS_BUTTON);
|
|
|
|
gtk_style_context_get_border (style, 0, &border);
|
|
|
|
gtk_style_context_restore (style);
|
2008-06-28 15:50:27 +00:00
|
|
|
|
2018-08-06 15:04:44 +02:00
|
|
|
g_object_get (list->data, "icon-size", &icon_size, NULL);
|
|
|
|
icon_size = MIN (icon_size, MAX (view_size - (border.left + border.right),
|
|
|
|
view_size - (border.top + border.bottom)));
|
|
|
|
g_object_set (list->data, "icon-size", icon_size, NULL);
|
2003-03-16 11:14:29 +00:00
|
|
|
|
2014-05-07 15:30:38 +02:00
|
|
|
g_free (icon_name);
|
2003-03-16 11:14:29 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2003-03-13 22:17:31 +00:00
|
|
|
gtk_tree_view_columns_autosize (tree_view->view);
|
2003-02-21 19:03:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-14 20:01:08 +01:00
|
|
|
/* GimpContainerTreeView methods */
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_tree_view_real_edit_name (GimpContainerTreeView *tree_view)
|
|
|
|
{
|
|
|
|
GtkTreeIter selected_iter;
|
2016-11-16 15:13:08 +01:00
|
|
|
gboolean success = FALSE;
|
2011-02-14 20:01:08 +01:00
|
|
|
|
|
|
|
if (g_list_find (tree_view->priv->editable_cells,
|
|
|
|
tree_view->priv->name_cell) &&
|
|
|
|
gimp_container_tree_view_get_selected_single (tree_view,
|
|
|
|
&selected_iter))
|
|
|
|
{
|
2016-11-16 15:13:08 +01:00
|
|
|
GimpViewRenderer *renderer;
|
2011-02-14 20:01:08 +01:00
|
|
|
|
2016-11-16 15:13:08 +01:00
|
|
|
gtk_tree_model_get (tree_view->model, &selected_iter,
|
|
|
|
GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
|
|
|
|
-1);
|
2011-02-14 20:01:08 +01:00
|
|
|
|
2016-11-16 15:13:08 +01:00
|
|
|
if (gimp_viewable_is_name_editable (renderer->viewable))
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
2011-02-14 20:01:08 +01:00
|
|
|
|
2016-11-16 15:13:08 +01:00
|
|
|
path = gtk_tree_model_get_path (tree_view->model, &selected_iter);
|
|
|
|
|
|
|
|
gtk_tree_view_set_cursor_on_cell (tree_view->view, path,
|
|
|
|
tree_view->main_column,
|
|
|
|
tree_view->priv->name_cell,
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
success = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (renderer);
|
2011-02-14 20:01:08 +01:00
|
|
|
}
|
2016-11-16 15:13:08 +01:00
|
|
|
|
|
|
|
if (! success)
|
|
|
|
gtk_widget_error_bell (GTK_WIDGET (tree_view));
|
2011-02-14 20:01:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-21 19:03:19 +00:00
|
|
|
/* callbacks */
|
|
|
|
|
2015-06-11 19:33:58 +02:00
|
|
|
static gboolean
|
|
|
|
gimp_container_tree_view_edit_focus_out (GtkWidget *widget,
|
|
|
|
GdkEvent *event,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
2016-10-18 20:19:52 +02:00
|
|
|
/* When focusing out of a tree view, we want its content to be
|
|
|
|
* updated as though it had been activated.
|
|
|
|
*/
|
2015-06-11 19:33:58 +02:00
|
|
|
g_signal_emit_by_name (widget, "activate", 0);
|
2016-10-18 20:19:52 +02:00
|
|
|
|
2015-06-11 19:33:58 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-02-06 19:28:37 +01:00
|
|
|
static void
|
|
|
|
gimp_container_tree_view_name_started (GtkCellRendererText *cell,
|
|
|
|
GtkCellEditable *editable,
|
|
|
|
const gchar *path_str,
|
|
|
|
GimpContainerTreeView *tree_view)
|
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
path = gtk_tree_path_new_from_string (path_str);
|
|
|
|
|
2015-06-11 19:33:58 +02:00
|
|
|
g_signal_connect (GTK_ENTRY (editable), "focus-out-event",
|
|
|
|
G_CALLBACK (gimp_container_tree_view_edit_focus_out),
|
|
|
|
tree_view);
|
|
|
|
|
2012-02-06 19:28:37 +01:00
|
|
|
if (gtk_tree_model_get_iter (tree_view->model, &iter, path))
|
|
|
|
{
|
|
|
|
GimpViewRenderer *renderer;
|
|
|
|
const gchar *real_name;
|
|
|
|
|
|
|
|
gtk_tree_model_get (tree_view->model, &iter,
|
|
|
|
GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
real_name = gimp_object_get_name (renderer->viewable);
|
|
|
|
|
|
|
|
g_object_unref (renderer);
|
|
|
|
|
|
|
|
gtk_entry_set_text (GTK_ENTRY (editable), real_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
2004-07-05 22:50:38 +00:00
|
|
|
static void
|
|
|
|
gimp_container_tree_view_name_canceled (GtkCellRendererText *cell,
|
|
|
|
GimpContainerTreeView *tree_view)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
2010-03-07 18:54:20 +02:00
|
|
|
if (gimp_container_tree_view_get_selected_single (tree_view, &iter))
|
2004-07-05 22:50:38 +00:00
|
|
|
{
|
2004-08-25 22:31:44 +00:00
|
|
|
GimpViewRenderer *renderer;
|
|
|
|
gchar *name;
|
2004-07-05 22:50:38 +00:00
|
|
|
|
|
|
|
gtk_tree_model_get (tree_view->model, &iter,
|
2010-05-17 21:28:17 +02:00
|
|
|
GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
|
2004-07-05 22:50:38 +00:00
|
|
|
-1);
|
|
|
|
|
|
|
|
name = gimp_viewable_get_description (renderer->viewable, NULL);
|
|
|
|
|
2009-07-25 17:38:03 +02:00
|
|
|
gtk_tree_store_set (GTK_TREE_STORE (tree_view->model), &iter,
|
2010-05-17 21:28:17 +02:00
|
|
|
GIMP_CONTAINER_TREE_STORE_COLUMN_NAME, name,
|
2004-07-05 22:50:38 +00:00
|
|
|
-1);
|
|
|
|
|
|
|
|
g_free (name);
|
|
|
|
g_object_unref (renderer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-21 19:03:19 +00:00
|
|
|
static void
|
|
|
|
gimp_container_tree_view_selection_changed (GtkTreeSelection *selection,
|
|
|
|
GimpContainerTreeView *tree_view)
|
|
|
|
{
|
2020-03-21 19:03:07 +01:00
|
|
|
GimpContainerView *view = GIMP_CONTAINER_VIEW (tree_view);
|
|
|
|
GList *items;
|
|
|
|
GList *paths;
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2020-03-21 19:03:07 +01:00
|
|
|
gimp_container_tree_view_get_selected (view, &items, &paths);
|
|
|
|
gimp_container_view_multi_selected (view, items, paths);
|
2010-03-07 18:54:20 +02:00
|
|
|
g_list_free (items);
|
2020-03-21 19:03:07 +01:00
|
|
|
g_list_free_full (paths, (GDestroyNotify) gtk_tree_path_free);
|
2003-02-21 19:03:19 +00:00
|
|
|
}
|
|
|
|
|
2003-03-16 13:19:43 +00:00
|
|
|
static GtkCellRenderer *
|
2005-01-08 16:52:44 +00:00
|
|
|
gimp_container_tree_view_find_click_cell (GtkWidget *widget,
|
|
|
|
GList *cells,
|
2003-03-16 13:19:43 +00:00
|
|
|
GtkTreeViewColumn *column,
|
|
|
|
GdkRectangle *column_area,
|
|
|
|
gint tree_x,
|
|
|
|
gint tree_y)
|
|
|
|
{
|
2005-01-08 16:52:44 +00:00
|
|
|
GList *list;
|
|
|
|
gboolean rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
|
2003-03-16 13:19:43 +00:00
|
|
|
|
|
|
|
for (list = cells; list; list = g_list_next (list))
|
|
|
|
{
|
2003-10-26 20:25:34 +00:00
|
|
|
GtkCellRenderer *renderer = list->data;
|
2005-01-03 23:47:26 +00:00
|
|
|
gint start;
|
2003-10-26 20:25:34 +00:00
|
|
|
gint width;
|
2003-03-16 13:19:43 +00:00
|
|
|
|
2009-10-17 20:20:39 +02:00
|
|
|
if (gtk_cell_renderer_get_visible (renderer) &&
|
2003-03-16 13:19:43 +00:00
|
|
|
gtk_tree_view_column_cell_get_position (column, renderer,
|
2005-01-03 23:47:26 +00:00
|
|
|
&start, &width))
|
2003-03-16 13:19:43 +00:00
|
|
|
{
|
2009-10-17 20:20:39 +02:00
|
|
|
gint xpad, ypad;
|
2005-01-08 16:52:44 +00:00
|
|
|
gint x;
|
|
|
|
|
2009-10-17 20:20:39 +02:00
|
|
|
gtk_cell_renderer_get_padding (renderer, &xpad, &ypad);
|
|
|
|
|
2005-01-08 16:52:44 +00:00
|
|
|
if (rtl)
|
|
|
|
x = column_area->x + column_area->width - start - width;
|
|
|
|
else
|
|
|
|
x = start + column_area->x;
|
2003-03-16 13:19:43 +00:00
|
|
|
|
2009-10-17 20:20:39 +02:00
|
|
|
if (tree_x >= x + xpad &&
|
|
|
|
tree_x < x + width - xpad)
|
2005-01-07 21:46:04 +00:00
|
|
|
{
|
|
|
|
return renderer;
|
|
|
|
}
|
2003-03-16 13:19:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-02-21 19:03:19 +00:00
|
|
|
static gboolean
|
2020-03-22 00:15:18 +01:00
|
|
|
gimp_container_tree_view_button (GtkWidget *widget,
|
|
|
|
GdkEventButton *bevent,
|
|
|
|
GimpContainerTreeView *tree_view)
|
2003-02-21 19:03:19 +00:00
|
|
|
{
|
2004-05-11 10:01:25 +00:00
|
|
|
GimpContainerView *container_view = GIMP_CONTAINER_VIEW (tree_view);
|
2003-03-16 11:14:29 +00:00
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
GtkTreePath *path;
|
|
|
|
|
2008-11-15 18:08:50 +00:00
|
|
|
tree_view->priv->dnd_renderer = NULL;
|
2003-02-24 20:31:14 +00:00
|
|
|
|
2009-10-17 20:20:39 +02:00
|
|
|
if (! gtk_widget_has_focus (widget))
|
2003-03-26 14:56:10 +00:00
|
|
|
gtk_widget_grab_focus (widget);
|
|
|
|
|
2003-02-24 20:31:14 +00:00
|
|
|
if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
|
2006-07-26 09:47:05 +00:00
|
|
|
bevent->x, bevent->y,
|
2003-03-16 11:14:29 +00:00
|
|
|
&path, &column, NULL, NULL))
|
2003-02-21 19:03:19 +00:00
|
|
|
{
|
2004-08-25 22:31:44 +00:00
|
|
|
GimpViewRenderer *renderer;
|
2016-10-01 20:55:13 +02:00
|
|
|
GtkCellRenderer *toggled_cell = NULL;
|
2003-03-19 15:17:13 +00:00
|
|
|
GimpCellRendererViewable *clicked_cell = NULL;
|
2003-03-22 16:26:11 +00:00
|
|
|
GtkCellRenderer *edit_cell = NULL;
|
2003-03-19 15:17:13 +00:00
|
|
|
GdkRectangle column_area;
|
|
|
|
GtkTreeIter iter;
|
2010-03-07 18:54:20 +02:00
|
|
|
gboolean handled = TRUE;
|
2010-03-09 01:13:29 +02:00
|
|
|
gboolean multisel_mode;
|
|
|
|
|
|
|
|
multisel_mode = (gtk_tree_selection_get_mode (tree_view->priv->selection)
|
|
|
|
== GTK_SELECTION_MULTIPLE);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2016-11-16 13:02:09 +01:00
|
|
|
if (! (bevent->state & (gimp_get_extend_selection_mask () |
|
|
|
|
gimp_get_modify_selection_mask ())))
|
|
|
|
{
|
|
|
|
/* don't chain up for multi-selection handling if none of
|
|
|
|
* the participating modifiers is pressed, we implement
|
|
|
|
* button_press completely ourselves for a reason and don't
|
|
|
|
* want the default implementation mess up our state
|
|
|
|
*/
|
|
|
|
multisel_mode = FALSE;
|
|
|
|
}
|
|
|
|
|
2003-03-13 22:17:31 +00:00
|
|
|
gtk_tree_model_get_iter (tree_view->model, &iter, path);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2003-03-13 22:17:31 +00:00
|
|
|
gtk_tree_model_get (tree_view->model, &iter,
|
2010-05-17 21:28:17 +02:00
|
|
|
GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
|
2003-02-24 20:31:14 +00:00
|
|
|
-1);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2008-11-15 18:08:50 +00:00
|
|
|
tree_view->priv->dnd_renderer = renderer;
|
2003-03-16 11:14:29 +00:00
|
|
|
|
2009-07-26 14:13:30 +02:00
|
|
|
gtk_tree_view_get_cell_area (tree_view->view, path,
|
|
|
|
column, &column_area);
|
2003-03-16 11:14:29 +00:00
|
|
|
|
|
|
|
gtk_tree_view_column_cell_set_cell_data (column,
|
|
|
|
tree_view->model,
|
|
|
|
&iter,
|
|
|
|
FALSE, FALSE);
|
|
|
|
|
2009-08-26 20:25:30 +02:00
|
|
|
if (bevent->button == 1 &&
|
|
|
|
gtk_tree_model_iter_has_child (tree_view->model, &iter) &&
|
|
|
|
column == gtk_tree_view_get_expander_column (tree_view->view))
|
|
|
|
{
|
|
|
|
GList *cells;
|
|
|
|
|
|
|
|
cells = gtk_cell_layout_get_cells (GTK_CELL_LAYOUT (column));
|
|
|
|
|
|
|
|
if (! gimp_container_tree_view_find_click_cell (widget,
|
|
|
|
cells,
|
|
|
|
column, &column_area,
|
|
|
|
bevent->x, bevent->y))
|
|
|
|
{
|
|
|
|
/* we didn't click on any cell, but we clicked on empty
|
|
|
|
* space in the expander column of a row that has
|
|
|
|
* children; let GtkTreeView process the button press
|
|
|
|
* to maybe handle a click on an expander.
|
|
|
|
*/
|
|
|
|
g_list_free (cells);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
g_object_unref (renderer);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (cells);
|
|
|
|
}
|
|
|
|
|
2020-03-22 00:15:18 +01:00
|
|
|
if (bevent->type == GDK_BUTTON_RELEASE)
|
|
|
|
{
|
|
|
|
toggled_cell =
|
|
|
|
gimp_container_tree_view_find_click_cell (widget,
|
|
|
|
tree_view->priv->toggle_cells,
|
|
|
|
column, &column_area,
|
|
|
|
bevent->x, bevent->y);
|
|
|
|
|
|
|
|
if (! toggled_cell)
|
|
|
|
clicked_cell = (GimpCellRendererViewable *)
|
|
|
|
gimp_container_tree_view_find_click_cell (widget,
|
|
|
|
tree_view->priv->renderer_cells,
|
|
|
|
column, &column_area,
|
|
|
|
bevent->x, bevent->y);
|
|
|
|
}
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2003-03-22 16:26:11 +00:00
|
|
|
if (! toggled_cell && ! clicked_cell)
|
|
|
|
edit_cell =
|
2005-01-08 16:52:44 +00:00
|
|
|
gimp_container_tree_view_find_click_cell (widget,
|
2008-11-15 18:08:50 +00:00
|
|
|
tree_view->priv->editable_cells,
|
2003-03-22 16:26:11 +00:00
|
|
|
column, &column_area,
|
2005-01-08 16:35:39 +00:00
|
|
|
bevent->x, bevent->y);
|
2003-03-22 16:26:11 +00:00
|
|
|
|
|
|
|
g_object_ref (tree_view);
|
|
|
|
|
2011-10-02 16:23:59 +02:00
|
|
|
if (gdk_event_triggers_context_menu ((GdkEvent *) bevent))
|
2011-09-19 00:45:36 +02:00
|
|
|
{
|
2020-03-22 00:15:18 +01:00
|
|
|
/* If the clicked item is not selected, it becomes the new
|
|
|
|
* selection. Otherwise, we use the current selection. This
|
|
|
|
* allows to not break multiple selection when right-clicking.
|
|
|
|
*/
|
|
|
|
if (! gimp_container_view_is_item_selected (container_view, renderer->viewable))
|
|
|
|
gimp_container_view_item_selected (container_view, renderer->viewable);
|
|
|
|
/* Show the context menu. */
|
|
|
|
if (gimp_container_view_get_container (container_view))
|
|
|
|
gimp_container_view_item_context (container_view, renderer->viewable);
|
2011-09-19 00:45:36 +02:00
|
|
|
}
|
|
|
|
else if (bevent->button == 1)
|
2003-02-24 20:31:14 +00:00
|
|
|
{
|
2020-03-22 00:15:18 +01:00
|
|
|
handled = TRUE;
|
|
|
|
if (bevent->type == GDK_BUTTON_PRESS || bevent->type == GDK_BUTTON_RELEASE)
|
2003-03-06 16:47:34 +00:00
|
|
|
{
|
2003-03-22 16:26:11 +00:00
|
|
|
/* don't select item if a toggle was clicked */
|
|
|
|
if (! toggled_cell)
|
2010-03-09 01:13:29 +02:00
|
|
|
{
|
2010-06-27 21:44:29 +02:00
|
|
|
gchar *path_str = gtk_tree_path_to_string (path);
|
|
|
|
|
2010-06-28 00:13:19 +02:00
|
|
|
handled = FALSE;
|
2010-06-27 21:44:29 +02:00
|
|
|
|
2010-06-28 00:13:19 +02:00
|
|
|
if (clicked_cell)
|
|
|
|
handled =
|
|
|
|
gimp_cell_renderer_viewable_pre_clicked (clicked_cell,
|
|
|
|
path_str,
|
|
|
|
bevent->state);
|
|
|
|
|
2020-03-27 12:44:19 +01:00
|
|
|
if (! handled && ! multisel_mode)
|
2010-03-09 01:13:29 +02:00
|
|
|
{
|
2020-03-27 12:44:19 +01:00
|
|
|
if (bevent->type == GDK_BUTTON_RELEASE ||
|
|
|
|
! gimp_container_view_is_item_selected (container_view, renderer->viewable))
|
|
|
|
/* If we click on currently selected item,
|
|
|
|
* handle simple click on release only for it
|
|
|
|
* to not change a multi-selection in case this
|
|
|
|
* click becomes a drag'n drop action.
|
|
|
|
*/
|
|
|
|
handled =
|
|
|
|
gimp_container_view_item_selected (container_view,
|
|
|
|
renderer->viewable);
|
2010-03-09 01:13:29 +02:00
|
|
|
}
|
2020-03-22 00:15:18 +01:00
|
|
|
/* Multi selection will be handled by gimp_container_tree_view_selection_changed() */
|
2010-06-27 21:44:29 +02:00
|
|
|
|
|
|
|
g_free (path_str);
|
2010-03-09 01:13:29 +02:00
|
|
|
}
|
2003-03-22 16:26:11 +00:00
|
|
|
|
|
|
|
/* a callback invoked by selecting the item may have
|
|
|
|
* destroyed us, so check if the container is still there
|
|
|
|
*/
|
2004-05-10 17:16:50 +00:00
|
|
|
if (gimp_container_view_get_container (container_view))
|
2003-03-16 11:14:29 +00:00
|
|
|
{
|
2003-03-25 01:25:39 +00:00
|
|
|
/* another row may have been set by selecting */
|
|
|
|
gtk_tree_view_column_cell_set_cell_data (column,
|
|
|
|
tree_view->model,
|
|
|
|
&iter,
|
|
|
|
FALSE, FALSE);
|
|
|
|
|
2003-03-22 16:26:11 +00:00
|
|
|
if (toggled_cell || clicked_cell)
|
2003-03-16 11:14:29 +00:00
|
|
|
{
|
2004-08-05 13:43:38 +00:00
|
|
|
gchar *path_str = gtk_tree_path_to_string (path);
|
2003-07-24 17:23:56 +00:00
|
|
|
|
2003-06-21 14:51:31 +00:00
|
|
|
if (toggled_cell)
|
|
|
|
{
|
2016-10-01 20:55:13 +02:00
|
|
|
if (GIMP_IS_CELL_RENDERER_TOGGLE (toggled_cell))
|
|
|
|
{
|
|
|
|
gimp_cell_renderer_toggle_clicked (GIMP_CELL_RENDERER_TOGGLE (toggled_cell),
|
|
|
|
path_str,
|
|
|
|
bevent->state);
|
|
|
|
}
|
|
|
|
else if (GIMP_IS_CELL_RENDERER_BUTTON (toggled_cell))
|
|
|
|
{
|
|
|
|
gimp_cell_renderer_button_clicked (GIMP_CELL_RENDERER_BUTTON (toggled_cell),
|
|
|
|
path_str,
|
|
|
|
bevent->state);
|
|
|
|
}
|
2003-06-21 14:51:31 +00:00
|
|
|
}
|
|
|
|
else if (clicked_cell)
|
|
|
|
{
|
|
|
|
gimp_cell_renderer_viewable_clicked (clicked_cell,
|
|
|
|
path_str,
|
|
|
|
bevent->state);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (path_str);
|
|
|
|
}
|
2003-03-16 11:14:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (bevent->type == GDK_2BUTTON_PRESS)
|
|
|
|
{
|
2003-05-18 13:28:27 +00:00
|
|
|
gboolean success = TRUE;
|
|
|
|
|
|
|
|
/* don't select item if a toggle was clicked */
|
|
|
|
if (! toggled_cell)
|
|
|
|
success = gimp_container_view_item_selected (container_view,
|
|
|
|
renderer->viewable);
|
|
|
|
|
|
|
|
if (success)
|
2003-03-22 16:26:11 +00:00
|
|
|
{
|
2003-05-18 13:28:27 +00:00
|
|
|
if (edit_cell)
|
|
|
|
{
|
2016-11-16 15:13:08 +01:00
|
|
|
if (gimp_viewable_is_name_editable (renderer->viewable))
|
|
|
|
{
|
|
|
|
gtk_tree_view_set_cursor_on_cell (tree_view->view,
|
|
|
|
path,
|
|
|
|
column, edit_cell,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_widget_error_bell (widget);
|
|
|
|
}
|
2003-05-18 13:28:27 +00:00
|
|
|
}
|
2009-05-24 18:43:31 +02:00
|
|
|
else if (! toggled_cell &&
|
2011-10-10 00:17:20 +02:00
|
|
|
! (bevent->state & gimp_get_all_modifiers_mask ()))
|
2003-04-29 18:25:12 +00:00
|
|
|
{
|
2009-05-22 22:45:08 +02:00
|
|
|
/* Only activate if we're not in a toggled cell
|
|
|
|
* and no modifier keys are pressed
|
|
|
|
*/
|
2003-05-18 13:28:27 +00:00
|
|
|
gimp_container_view_item_activated (container_view,
|
|
|
|
renderer->viewable);
|
2003-04-29 18:25:12 +00:00
|
|
|
}
|
2003-03-22 16:26:11 +00:00
|
|
|
}
|
2003-03-06 16:47:34 +00:00
|
|
|
}
|
2011-09-19 00:45:36 +02:00
|
|
|
}
|
|
|
|
else if (bevent->button == 2)
|
|
|
|
{
|
2004-08-05 13:43:38 +00:00
|
|
|
if (bevent->type == GDK_BUTTON_PRESS)
|
|
|
|
{
|
|
|
|
if (clicked_cell)
|
|
|
|
{
|
|
|
|
gchar *path_str = gtk_tree_path_to_string (path);
|
|
|
|
|
|
|
|
gimp_cell_renderer_viewable_clicked (clicked_cell,
|
|
|
|
path_str,
|
|
|
|
bevent->state);
|
|
|
|
|
|
|
|
g_free (path_str);
|
|
|
|
}
|
|
|
|
}
|
2003-02-21 19:03:19 +00:00
|
|
|
}
|
2003-02-24 20:31:14 +00:00
|
|
|
|
2003-03-22 16:26:11 +00:00
|
|
|
g_object_unref (tree_view);
|
|
|
|
|
2003-03-16 11:14:29 +00:00
|
|
|
gtk_tree_path_free (path);
|
|
|
|
g_object_unref (renderer);
|
2010-03-07 18:54:20 +02:00
|
|
|
|
2010-03-09 01:13:29 +02:00
|
|
|
return multisel_mode ? handled : TRUE;
|
2003-02-21 19:03:19 +00:00
|
|
|
}
|
2005-09-08 18:23:14 +00:00
|
|
|
else
|
|
|
|
{
|
2011-10-02 16:23:59 +02:00
|
|
|
if (gdk_event_triggers_context_menu ((GdkEvent *) bevent))
|
2005-09-08 18:23:14 +00:00
|
|
|
{
|
|
|
|
gimp_editor_popup_menu (GIMP_EDITOR (tree_view), NULL, NULL);
|
|
|
|
}
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2010-03-07 18:54:20 +02:00
|
|
|
return TRUE;
|
|
|
|
}
|
2003-02-21 19:03:19 +00:00
|
|
|
}
|
|
|
|
|
2007-11-09 11:17:00 +00:00
|
|
|
static gboolean
|
|
|
|
gimp_container_tree_view_tooltip (GtkWidget *widget,
|
|
|
|
gint x,
|
|
|
|
gint y,
|
|
|
|
gboolean keyboard_tip,
|
|
|
|
GtkTooltip *tooltip,
|
|
|
|
GimpContainerTreeView *tree_view)
|
|
|
|
{
|
|
|
|
GimpViewRenderer *renderer;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreePath *path;
|
|
|
|
gboolean show_tip = FALSE;
|
|
|
|
|
|
|
|
if (! gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (widget), &x, &y,
|
|
|
|
keyboard_tip,
|
|
|
|
NULL, &path, &iter))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
gtk_tree_model_get (tree_view->model, &iter,
|
2010-05-17 21:28:17 +02:00
|
|
|
GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
|
2007-11-09 11:17:00 +00:00
|
|
|
-1);
|
|
|
|
|
|
|
|
if (renderer)
|
|
|
|
{
|
|
|
|
gchar *desc;
|
|
|
|
gchar *tip;
|
|
|
|
|
|
|
|
desc = gimp_viewable_get_description (renderer->viewable, &tip);
|
|
|
|
|
|
|
|
if (tip)
|
|
|
|
{
|
|
|
|
gtk_tooltip_set_text (tooltip, tip);
|
|
|
|
gtk_tree_view_set_tooltip_row (GTK_TREE_VIEW (widget), tooltip, path);
|
|
|
|
|
|
|
|
show_tip = TRUE;
|
|
|
|
|
|
|
|
g_free (tip);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (desc);
|
|
|
|
g_object_unref (renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
return show_tip;
|
|
|
|
}
|
|
|
|
|
2003-02-24 20:31:14 +00:00
|
|
|
static GimpViewable *
|
2006-08-29 21:44:51 +00:00
|
|
|
gimp_container_tree_view_drag_viewable (GtkWidget *widget,
|
|
|
|
GimpContext **context,
|
|
|
|
gpointer data)
|
2003-02-24 20:31:14 +00:00
|
|
|
{
|
2003-10-26 20:25:34 +00:00
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (data);
|
2003-02-21 19:03:19 +00:00
|
|
|
|
2006-08-29 21:44:51 +00:00
|
|
|
if (context)
|
|
|
|
*context = gimp_container_view_get_context (GIMP_CONTAINER_VIEW (data));
|
|
|
|
|
2008-11-15 18:08:50 +00:00
|
|
|
if (tree_view->priv->dnd_renderer)
|
|
|
|
return tree_view->priv->dnd_renderer->viewable;
|
2006-08-29 21:44:51 +00:00
|
|
|
|
|
|
|
return NULL;
|
2003-02-21 19:03:19 +00:00
|
|
|
}
|
2005-05-25 10:05:17 +00:00
|
|
|
|
2020-03-24 22:06:28 +01:00
|
|
|
static GList *
|
|
|
|
gimp_container_tree_view_drag_viewable_list (GtkWidget *widget,
|
|
|
|
GimpContext **context,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GList *items = NULL;
|
|
|
|
|
|
|
|
if (context)
|
|
|
|
*context = gimp_container_view_get_context (GIMP_CONTAINER_VIEW (data));
|
|
|
|
|
|
|
|
gimp_container_tree_view_get_selected (GIMP_CONTAINER_VIEW (data), &items, NULL);
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
2005-05-25 10:05:17 +00:00
|
|
|
static GdkPixbuf *
|
|
|
|
gimp_container_tree_view_drag_pixbuf (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (data);
|
2008-11-15 18:08:50 +00:00
|
|
|
GimpViewRenderer *renderer = tree_view->priv->dnd_renderer;
|
2005-05-25 10:05:17 +00:00
|
|
|
gint width;
|
|
|
|
gint height;
|
|
|
|
|
2006-08-29 21:44:51 +00:00
|
|
|
if (renderer && gimp_viewable_get_size (renderer->viewable, &width, &height))
|
|
|
|
return gimp_viewable_get_new_pixbuf (renderer->viewable,
|
|
|
|
renderer->context,
|
|
|
|
width, height);
|
2005-05-25 10:05:17 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-03-07 18:54:20 +02:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_container_tree_view_get_selected_single (GimpContainerTreeView *tree_view,
|
2020-03-22 12:29:51 +01:00
|
|
|
GtkTreeIter *iter)
|
2010-03-07 18:54:20 +02:00
|
|
|
{
|
2020-03-22 12:29:51 +01:00
|
|
|
GtkTreeSelection *selection;
|
2010-03-07 18:54:20 +02:00
|
|
|
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view->view));
|
|
|
|
|
|
|
|
if (gtk_tree_selection_count_selected_rows (selection) == 1)
|
|
|
|
{
|
|
|
|
GList *selected_rows;
|
|
|
|
|
|
|
|
selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);
|
|
|
|
|
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_view->model), iter,
|
|
|
|
(GtkTreePath *) selected_rows->data);
|
|
|
|
|
2011-03-07 17:10:18 +01:00
|
|
|
g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
|
2010-03-07 18:54:20 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gint
|
|
|
|
gimp_container_tree_view_get_selected (GimpContainerView *view,
|
2020-03-21 19:03:07 +01:00
|
|
|
GList **items,
|
|
|
|
GList **paths)
|
2010-03-07 18:54:20 +02:00
|
|
|
{
|
2010-04-04 15:00:26 +02:00
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
|
|
|
GtkTreeSelection *selection;
|
|
|
|
gint selected_count;
|
2020-03-21 19:03:07 +01:00
|
|
|
GList *selected_paths;
|
|
|
|
GList *removed_paths = NULL;
|
2010-04-04 15:00:26 +02:00
|
|
|
GList *current_row;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GimpViewRenderer *renderer;
|
2010-03-07 18:54:20 +02:00
|
|
|
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view->view));
|
|
|
|
selected_count = gtk_tree_selection_count_selected_rows (selection);
|
|
|
|
|
|
|
|
if (items == NULL)
|
|
|
|
{
|
2020-03-21 19:03:07 +01:00
|
|
|
if (paths)
|
|
|
|
*paths = NULL;
|
|
|
|
|
2010-03-07 18:54:20 +02:00
|
|
|
/* just provide selected count */
|
|
|
|
return selected_count;
|
|
|
|
}
|
|
|
|
|
2020-03-21 19:03:07 +01:00
|
|
|
selected_paths = gtk_tree_selection_get_selected_rows (selection, NULL);
|
|
|
|
*items = NULL;
|
2010-03-07 18:54:20 +02:00
|
|
|
|
2020-03-21 19:03:07 +01:00
|
|
|
for (current_row = selected_paths;
|
2010-03-07 18:54:20 +02:00
|
|
|
current_row;
|
|
|
|
current_row = g_list_next (current_row))
|
|
|
|
{
|
|
|
|
gtk_tree_model_get_iter (GTK_TREE_MODEL (tree_view->model), &iter,
|
|
|
|
(GtkTreePath *) current_row->data);
|
|
|
|
|
|
|
|
gtk_tree_model_get (tree_view->model, &iter,
|
2010-05-17 21:28:17 +02:00
|
|
|
GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
|
2010-03-07 18:54:20 +02:00
|
|
|
-1);
|
|
|
|
|
|
|
|
if (renderer->viewable)
|
2010-04-04 15:00:26 +02:00
|
|
|
*items = g_list_prepend (*items, renderer->viewable);
|
2020-03-21 19:03:07 +01:00
|
|
|
else
|
|
|
|
/* Remove from the selected_paths list but at the end, in order not
|
|
|
|
* to break the for loop.
|
|
|
|
*/
|
|
|
|
removed_paths = g_list_prepend (removed_paths, current_row);
|
2010-03-07 18:54:20 +02:00
|
|
|
|
|
|
|
g_object_unref (renderer);
|
|
|
|
}
|
2020-03-21 19:03:07 +01:00
|
|
|
*items = g_list_reverse (*items);
|
|
|
|
|
|
|
|
for (current_row = removed_paths; current_row; current_row = current_row->next)
|
|
|
|
{
|
|
|
|
GList *remove_list = current_row->data;
|
2010-03-07 18:54:20 +02:00
|
|
|
|
2020-03-21 19:03:07 +01:00
|
|
|
selected_paths = g_list_remove_link (selected_paths, remove_list);
|
|
|
|
gtk_tree_path_free (remove_list->data);
|
|
|
|
}
|
|
|
|
g_list_free_full (removed_paths, (GDestroyNotify) g_list_free);
|
2010-03-07 18:54:20 +02:00
|
|
|
|
2020-03-21 19:03:07 +01:00
|
|
|
if (paths)
|
|
|
|
*paths = selected_paths;
|
|
|
|
else
|
|
|
|
g_list_free_full (selected_paths, (GDestroyNotify) gtk_tree_path_free);
|
2010-03-07 18:54:20 +02:00
|
|
|
|
|
|
|
return selected_count;
|
|
|
|
}
|
2011-09-25 21:57:20 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_tree_view_row_expanded (GtkTreeView *tree_view,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GimpContainerTreeView *view)
|
|
|
|
{
|
|
|
|
GimpViewRenderer *renderer;
|
|
|
|
|
|
|
|
gtk_tree_model_get (view->model, iter,
|
|
|
|
GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
|
|
|
|
-1);
|
|
|
|
if (renderer)
|
|
|
|
{
|
|
|
|
gboolean expanded = gtk_tree_view_row_expanded (tree_view, path);
|
|
|
|
|
|
|
|
gimp_viewable_set_expanded (renderer->viewable,
|
|
|
|
expanded);
|
|
|
|
if (expanded)
|
|
|
|
{
|
|
|
|
g_signal_handlers_block_by_func (tree_view,
|
|
|
|
gimp_container_tree_view_row_expanded,
|
|
|
|
view);
|
|
|
|
|
|
|
|
gimp_container_tree_view_expand_rows (view->model, tree_view, iter);
|
|
|
|
|
|
|
|
g_signal_handlers_unblock_by_func (tree_view,
|
|
|
|
gimp_container_tree_view_row_expanded,
|
|
|
|
view);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref (renderer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_tree_view_expand_rows (GtkTreeModel *model,
|
|
|
|
GtkTreeView *view,
|
|
|
|
GtkTreeIter *parent)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
if (gtk_tree_model_iter_children (model, &iter, parent))
|
|
|
|
do
|
|
|
|
if (gtk_tree_model_iter_has_child (model, &iter))
|
|
|
|
{
|
|
|
|
GimpViewRenderer *renderer;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, &iter,
|
|
|
|
GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
|
|
|
|
-1);
|
|
|
|
if (renderer)
|
|
|
|
{
|
|
|
|
GtkTreePath *path = gtk_tree_model_get_path (model, &iter);
|
|
|
|
|
|
|
|
if (gimp_viewable_get_expanded (renderer->viewable))
|
|
|
|
gtk_tree_view_expand_row (view, path, FALSE);
|
|
|
|
else
|
|
|
|
gtk_tree_view_collapse_row (view, path);
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
g_object_unref (renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
gimp_container_tree_view_expand_rows (model, view, &iter);
|
|
|
|
}
|
|
|
|
while (gtk_tree_model_iter_next (model, &iter));
|
|
|
|
}
|
2016-06-01 22:38:58 +02:00
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_container_tree_view_monitor_changed_foreach (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpViewRenderer *renderer;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (renderer)
|
|
|
|
{
|
|
|
|
gimp_view_renderer_free_color_transform (renderer);
|
|
|
|
g_object_unref (renderer);
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_container_tree_view_monitor_changed (GimpContainerTreeView *view)
|
|
|
|
{
|
|
|
|
gtk_tree_model_foreach (view->model,
|
|
|
|
gimp_container_tree_view_monitor_changed_foreach,
|
|
|
|
NULL);
|
|
|
|
}
|
2020-03-26 00:33:11 +01:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GimpViewable *viewable;
|
|
|
|
GtkTreePath *path;
|
|
|
|
} SearchData;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gimp_container_tree_view_search_path_foreach (GtkTreeModel *model,
|
|
|
|
GtkTreePath *path,
|
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
SearchData *search_data = data;
|
|
|
|
GimpViewRenderer *renderer;
|
|
|
|
|
|
|
|
gtk_tree_model_get (model, iter,
|
|
|
|
GIMP_CONTAINER_TREE_STORE_COLUMN_RENDERER, &renderer,
|
|
|
|
-1);
|
|
|
|
|
|
|
|
if (renderer->viewable == search_data->viewable)
|
|
|
|
search_data->path = gtk_tree_path_copy (path);
|
|
|
|
|
|
|
|
g_object_unref (renderer);
|
|
|
|
|
|
|
|
return (search_data->path != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkTreePath *
|
|
|
|
gimp_container_tree_view_get_path (GimpContainerTreeView *tree_view,
|
|
|
|
GimpViewable *viewable)
|
|
|
|
{
|
|
|
|
SearchData search_data;
|
|
|
|
|
|
|
|
search_data.viewable = viewable;
|
|
|
|
search_data.path = NULL;
|
|
|
|
|
|
|
|
gtk_tree_model_foreach (GTK_TREE_MODEL (tree_view->model),
|
|
|
|
(GtkTreeModelForeachFunc) gimp_container_tree_view_search_path_foreach,
|
|
|
|
&search_data);
|
|
|
|
|
|
|
|
return search_data.path;
|
|
|
|
}
|