summaryrefslogtreecommitdiff
path: root/thunar/thunar-component.c
blob: 29cd68497798f308d111e9680a14376fe72e9436 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* vi:set et ai sw=2 sts=2 ts=2: */
/*-
 * Copyright (c) 2006 Benedikt Meurer <benny@xfce.org>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (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 along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <exo/exo.h>

#include <thunar/thunar-component.h>
#include <thunar/thunar-private.h>



static void thunar_component_class_init (gpointer klass);



GType
thunar_component_get_type (void)
{
  static volatile gsize type__volatile = 0;
  GType                 type;

  if (g_once_init_enter (&type__volatile))
    {
      type = g_type_register_static_simple (G_TYPE_INTERFACE,
                                            I_("ThunarComponent"),
                                            sizeof (ThunarComponentIface),
                                            (GClassInitFunc) (void (*)(void)) thunar_component_class_init,
                                            0,
                                            NULL,
                                            0);

      g_type_interface_add_prerequisite (type, THUNAR_TYPE_NAVIGATOR);

      g_once_init_leave (&type__volatile, type);
    }

  return type__volatile;
}



static void
thunar_component_class_init (gpointer klass)
{
  /**
   * ThunarComponent:selected-files:
   *
   * The list of currently selected files for the #ThunarWindow to
   * which this #ThunarComponent belongs.
   *
   * The exact semantics of this property depend on the implementor
   * of this interface. For example, #ThunarComponent<!---->s will update
   * the property depending on the users selection with the
   * #GtkTreeComponent or #ExoIconComponent. While other components in a window,
   * like the #ThunarShortcutsPane, will not update this property on
   * their own, but rely on #ThunarWindow to synchronize the selected
   * files list with the selected files list from the active #ThunarComponent.
   *
   * This way all components can behave properly depending on the
   * set of selected files even though they don't have direct access
   * to the #ThunarComponent.
   **/
  g_object_interface_install_property (klass,
                                       g_param_spec_boxed ("selected-files",
                                                           "selected-files",
                                                           "selected-files",
                                                           THUNARX_TYPE_FILE_INFO_LIST,
                                                           EXO_PARAM_READWRITE));

G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  /**
   * ThunarComponent:ui-manager:
   *
   * The UI manager used by the surrounding #ThunarWindow. The
   * #ThunarComponent implementations may connect additional actions
   * to the UI manager.
   **/
  g_object_interface_install_property (klass,
                                       g_param_spec_object ("ui-manager",
                                                            "ui-manager",
                                                            "ui-manager",
                                                            GTK_TYPE_UI_MANAGER,
                                                            EXO_PARAM_READWRITE));
G_GNUC_END_IGNORE_DEPRECATIONS
}



/**
 * thunar_component_get_selected_files:
 * @component : a #ThunarComponent instance.
 *
 * Returns the set of selected files. Check the description
 * of the :selected-files property for details.
 *
 * Return value: the set of selected files.
 **/
GList*
thunar_component_get_selected_files (ThunarComponent *component)
{
  _thunar_return_val_if_fail (THUNAR_IS_COMPONENT (component), NULL);
  return (*THUNAR_COMPONENT_GET_IFACE (component)->get_selected_files) (component);
}



/**
 * thunar_component_set_selected_files:
 * @component      : a #ThunarComponent instance.
 * @selected_files : a #GList of #ThunarFile<!---->s.
 *
 * Sets the selected files for @component to @selected_files.
 * Check the description of the :selected-files property for
 * details.
 **/
void
thunar_component_set_selected_files (ThunarComponent *component,
                                     GList           *selected_files)
{
  _thunar_return_if_fail (THUNAR_IS_COMPONENT (component));
  (*THUNAR_COMPONENT_GET_IFACE (component)->set_selected_files) (component, selected_files);
}



/**
 * thunar_component_restore_selection:
 * @component      : a #ThunarComponent instance.
 *
 * Make sure that the @selected_files stay selected when a @component
 * updates. This may be necessary on row changes etc.
 **/
void
thunar_component_restore_selection (ThunarComponent *component)
{
  GList           *selected_files;

  _thunar_return_if_fail (THUNAR_IS_COMPONENT (component));

  selected_files = thunar_g_file_list_copy (thunar_component_get_selected_files (component));
  thunar_component_set_selected_files (component, selected_files);
  thunar_g_file_list_free (selected_files);
}



/**
 * thunar_component_get_ui_manager:
 * @component : a #ThunarComponent instance.
 *
 * Returns the #GtkUIManager associated with @component or
 * %NULL if @component has no #GtkUIManager associated with
 * it.
 *
 * Return value: the #GtkUIManager associated with @component
 *               or %NULL.
 **/
GtkUIManager*
thunar_component_get_ui_manager (ThunarComponent *component)
{
  _thunar_return_val_if_fail (THUNAR_IS_COMPONENT (component), NULL);
  return (*THUNAR_COMPONENT_GET_IFACE (component)->get_ui_manager) (component);
}



/**
 * thunar_component_set_ui_manager:
 * @component  : a #ThunarComponent instance.
 * @ui_manager : a #GtkUIManager or %NULL.
 *
 * Installs a new #GtkUIManager for @component or resets the ::ui-manager
 * property.
 *
 * Implementations of the #ThunarComponent interface must first disconnect
 * from any previously set #GtkUIManager and then connect to the
 * @ui_manager if not %NULL.
 **/
void
thunar_component_set_ui_manager (ThunarComponent *component,
                                 GtkUIManager    *ui_manager)
{
  _thunar_return_if_fail (THUNAR_IS_COMPONENT (component));
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
  _thunar_return_if_fail (ui_manager == NULL || GTK_IS_UI_MANAGER (ui_manager));
G_GNUC_END_IGNORE_DEPRECATIONS
  (*THUNAR_COMPONENT_GET_IFACE (component)->set_ui_manager) (component, ui_manager);
}