* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
GtkCssSection *
_gtk_css_section_new (GtkCssSection *parent,
GtkCssSectionType type,
- GtkCssParser *parser,
- GFile *file)
+ GtkCssParser *parser)
{
GtkCssSection *section;
g_return_val_if_fail (parser != NULL, NULL);
- g_return_val_if_fail (file == NULL || G_IS_FILE (file), NULL);
section = g_slice_new0 (GtkCssSection);
section->section_type = type;
if (parent)
section->parent = gtk_css_section_ref (parent);
- if (file)
- section->file = g_object_ref (file);
+ section->file = _gtk_css_parser_get_file (parser);
+ if (section->file)
+ g_object_ref (section->file);
section->start_line = _gtk_css_parser_get_line (parser);
section->start_position = _gtk_css_parser_get_position (parser);
section->parser = parser;
*
* Gets the parent section for the given @section. The parent section is
* the section that contains this @section. A special case are sections of
- * type #GTK_CSS_SECTION_TYPE_DOCUMENT. Their parent will either be %NULL
+ * type #GTK_CSS_SECTION_DOCUMENT. Their parent will either be %NULL
* if they are the original CSS document that was loaded by
* gtk_css_provider_load_from_file() or a section of type
- * #GTK_CSS_SECTION_TYPE_IMPORT if it was loaded with an import rule from
+ * #GTK_CSS_SECTION_IMPORT if it was loaded with an import rule from
* a different file.
*
* Returns: the parent section or %NULL if none
* @section: the section
*
* Gets the file that @section was parsed from. If no such file exists,
- * for example because the CSS was loaded via
+ * for example because the CSS was loaded via
* @gtk_css_provider_load_from_data(), then %NULL is returned.
*
- * Returns: the #GFile that @section was parsed from or %NULL if
- * @section was parsed from other data.
+ * Returns: (transfer none): the #GFile that @section was parsed from
+ * or %NULL if @section was parsed from other data
*
* Since: 3.2
**/
return section->end_position;
}
+void
+_gtk_css_section_print (const GtkCssSection *section,
+ GString *string)
+{
+ if (section->file)
+ {
+ GFileInfo *info;
+
+ info = g_file_query_info (section->file, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME, 0, NULL, NULL);
+
+ if (info)
+ {
+ g_string_append (string, g_file_info_get_display_name (info));
+ g_object_unref (info);
+ }
+ else
+ {
+ g_string_append (string, "<broken file>");
+ }
+ }
+ else
+ {
+ g_string_append (string, "<data>");
+ }
+
+ g_string_append_printf (string, ":%u:%u",
+ gtk_css_section_get_end_line (section) + 1,
+ gtk_css_section_get_end_position (section));
+}
+
+char *
+_gtk_css_section_to_string (const GtkCssSection *section)
+{
+ GString *string;
+
+ g_return_val_if_fail (section != NULL, NULL);
+
+ string = g_string_new (NULL);
+ _gtk_css_section_print (section, string);
+
+ return g_string_free (string, FALSE);
+}