[latexila] Use GResource for the stock icons



commit 05eb36c7782bc47e517d21e6bbd26e4317318dfc
Author: SÃbastien Wilmet <swilmet src gnome org>
Date:   Tue May 1 07:40:16 2012 +0200

    Use GResource for the stock icons
    
    This is not a really good example of a micro-commitâ But split it into
    lots of smaller commits would have involved more work.
    
    - Move the icons in the stock-icons/ directory. Now all the file names
      match the icon name, so a matching between the filename and the icon
      name is no longer required.
    
    - Add a CMake function to build a .gresource.xml.
    
    - To be able to use the new CMake function, there has been lots of code
      clean-up in the CMake files.
    
    - Adapt the Vala code to use the GResource. Obviously the new function
      is not already in the vapi of Vala, so a custom .vapi is used.

 CMakeLists.txt                                     |   84 ++++++---
 cmake/gresource.cmake                              |   37 ++++
 cmake/use_vala.cmake                               |  194 +++++---------------
 data/images/{icons => stock-icons}/accent0.png     |  Bin 465 -> 465 bytes
 data/images/{icons => stock-icons}/accent1.png     |  Bin 471 -> 471 bytes
 data/images/{icons => stock-icons}/accent10.png    |  Bin 418 -> 418 bytes
 data/images/{icons => stock-icons}/accent11.png    |  Bin 430 -> 430 bytes
 data/images/{icons => stock-icons}/accent12.png    |  Bin 404 -> 404 bytes
 data/images/{icons => stock-icons}/accent13.png    |  Bin 398 -> 398 bytes
 data/images/{icons => stock-icons}/accent14.png    |  Bin 425 -> 425 bytes
 data/images/{icons => stock-icons}/accent15.png    |  Bin 402 -> 402 bytes
 data/images/{icons => stock-icons}/accent2.png     |  Bin 477 -> 477 bytes
 data/images/{icons => stock-icons}/accent3.png     |  Bin 475 -> 475 bytes
 data/images/{icons => stock-icons}/accent4.png     |  Bin 481 -> 481 bytes
 data/images/{icons => stock-icons}/accent5.png     |  Bin 453 -> 453 bytes
 data/images/{icons => stock-icons}/accent6.png     |  Bin 459 -> 459 bytes
 data/images/{icons => stock-icons}/accent7.png     |  Bin 487 -> 487 bytes
 data/images/{icons => stock-icons}/accent8.png     |  Bin 480 -> 480 bytes
 data/images/{icons => stock-icons}/accent9.png     |  Bin 487 -> 487 bytes
 data/images/{icons => stock-icons}/badbox.png      |  Bin 841 -> 841 bytes
 data/images/stock-icons/blackboard.png             |  Bin 0 -> 382 bytes
 .../{icons/textbf.png => stock-icons/bold.png}     |  Bin 387 -> 387 bytes
 .../{icons => stock-icons}/character-size.png      |  Bin 514 -> 514 bytes
 data/images/{icons => stock-icons}/compile_dvi.png |  Bin 1792 -> 1792 bytes
 data/images/{icons => stock-icons}/compile_pdf.png |  Bin 1728 -> 1728 bytes
 data/images/{icons => stock-icons}/compile_ps.png  |  Bin 1751 -> 1751 bytes
 .../{icons => stock-icons}/completion_choice.png   |  Bin 212 -> 212 bytes
 .../{icons => stock-icons}/completion_cmd.png      |  Bin 327 -> 327 bytes
 .../{icons => stock-icons}/delimiters-left.png     |  Bin 286 -> 286 bytes
 .../{icons => stock-icons}/delimiters-right.png    |  Bin 281 -> 281 bytes
 .../{icons/textit.png => stock-icons/italic.png}   |  Bin 288 -> 288 bytes
 .../{icons => stock-icons}/list-description.png    |  Bin 439 -> 439 bytes
 .../{icons => stock-icons}/list-enumerate.png      |  Bin 496 -> 496 bytes
 data/images/{icons => stock-icons}/list-item.png   |  Bin 590 -> 590 bytes
 .../images/{icons => stock-icons}/list-itemize.png |  Bin 469 -> 469 bytes
 data/images/{icons => stock-icons}/math-array.png  |  Bin 469 -> 469 bytes
 .../{icons => stock-icons}/math-centered.png       |  Bin 413 -> 413 bytes
 data/images/{icons => stock-icons}/math-frac.png   |  Bin 391 -> 391 bytes
 .../{icons => stock-icons}/math-nth-root.png       |  Bin 527 -> 527 bytes
 .../{icons => stock-icons}/math-numbered-array.png |  Bin 514 -> 514 bytes
 .../{icons => stock-icons}/math-numbered.png       |  Bin 423 -> 423 bytes
 .../{icons => stock-icons}/math-square-root.png    |  Bin 477 -> 477 bytes
 .../{icons => stock-icons}/math-subscript.png      |  Bin 443 -> 443 bytes
 .../{icons => stock-icons}/math-superscript.png    |  Bin 463 -> 463 bytes
 data/images/{icons => stock-icons}/math.png        |  Bin 973 -> 973 bytes
 data/images/{icons => stock-icons}/mathaccent0.png |  Bin 417 -> 417 bytes
 data/images/{icons => stock-icons}/mathaccent1.png |  Bin 418 -> 418 bytes
 .../images/{icons => stock-icons}/mathaccent10.png |  Bin 443 -> 443 bytes
 data/images/{icons => stock-icons}/mathaccent2.png |  Bin 409 -> 409 bytes
 data/images/{icons => stock-icons}/mathaccent3.png |  Bin 397 -> 397 bytes
 data/images/{icons => stock-icons}/mathaccent4.png |  Bin 422 -> 422 bytes
 data/images/{icons => stock-icons}/mathaccent5.png |  Bin 413 -> 413 bytes
 data/images/{icons => stock-icons}/mathaccent6.png |  Bin 423 -> 423 bytes
 data/images/{icons => stock-icons}/mathaccent7.png |  Bin 431 -> 431 bytes
 data/images/{icons => stock-icons}/mathaccent8.png |  Bin 406 -> 406 bytes
 data/images/{icons => stock-icons}/mathaccent9.png |  Bin 417 -> 417 bytes
 data/images/{icons => stock-icons}/mathcal.png     |  Bin 424 -> 424 bytes
 data/images/{icons => stock-icons}/mathfrak.png    |  Bin 491 -> 491 bytes
 data/images/{icons => stock-icons}/references.png  |  Bin 337 -> 337 bytes
 data/images/{icons => stock-icons}/roman.png       |  Bin 401 -> 401 bytes
 .../textsf.png => stock-icons/sans_serif.png}      |  Bin 464 -> 464 bytes
 .../{icons => stock-icons}/sectioning-chapter.png  |  Bin 471 -> 471 bytes
 .../sectioning-paragraph.png                       |  Bin 499 -> 499 bytes
 .../{icons => stock-icons}/sectioning-part.png     |  Bin 445 -> 445 bytes
 .../{icons => stock-icons}/sectioning-section.png  |  Bin 478 -> 478 bytes
 .../sectioning-subsection.png                      |  Bin 484 -> 484 bytes
 .../sectioning-subsubsection.png                   |  Bin 485 -> 485 bytes
 .../{icons/textsl.png => stock-icons/slanted.png}  |  Bin 424 -> 424 bytes
 .../textsc.png => stock-icons/small_caps.png}      |  Bin 427 -> 427 bytes
 data/images/stock-icons/stock-icons.gresource.xml  |   93 ++++++++++
 data/images/stock-icons/symbol_alpha.png           |  Bin 0 -> 303 bytes
 data/images/{icons => stock-icons}/table.png       |  Bin 311 -> 311 bytes
 .../images/{icons => stock-icons}/tree_chapter.png |  Bin 247 -> 247 bytes
 .../{icons => stock-icons}/tree_label.license      |    0
 data/images/{icons => stock-icons}/tree_label.png  |  Bin 752 -> 752 bytes
 .../{icons => stock-icons}/tree_paragraph.png      |  Bin 1121 -> 1121 bytes
 data/images/{icons => stock-icons}/tree_part.png   |  Bin 116 -> 116 bytes
 .../images/{icons => stock-icons}/tree_section.png |  Bin 1121 -> 1121 bytes
 .../{icons => stock-icons}/tree_subsection.png     |  Bin 1121 -> 1121 bytes
 .../{icons => stock-icons}/tree_subsubsection.png  |  Bin 1121 -> 1121 bytes
 data/images/{icons => stock-icons}/tree_todo.png   |  Bin 380 -> 380 bytes
 .../texttt.png => stock-icons/typewriter.png}      |  Bin 290 -> 290 bytes
 data/images/{icons => stock-icons}/underline.png   |  Bin 335 -> 335 bytes
 data/images/{icons => stock-icons}/view_dvi.png    |  Bin 1449 -> 1449 bytes
 .../logviewer.png => stock-icons/view_log.png}     |  Bin 762 -> 762 bytes
 data/images/{icons => stock-icons}/view_pdf.png    |  Bin 1131 -> 1131 bytes
 data/images/{icons => stock-icons}/view_ps.png     |  Bin 1703 -> 1703 bytes
 src/C/CMakeLists.txt                               |    3 -
 src/CMakeLists.txt                                 |   21 --
 src/latexila.vala                                  |    2 +-
 src/stock_icons.vala                               |  164 +++++------------
 vapi/gdk-pixbuf.vapi                               |    8 +
 92 files changed, 292 insertions(+), 314 deletions(-)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 58c763b..c783865 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,12 +1,24 @@
 cmake_minimum_required (VERSION 2.6.4)
 
-project ("latexila" C)
-
+# Some variables
 set (APP_NAME "LaTeXila")
 set (APP_VERSION "2.5.1")
+set (SCHEMA_DIR "${CMAKE_INSTALL_PREFIX}/share")
+set (ICONS_DIR "${CMAKE_INSTALL_PREFIX}/share/icons/hicolor")
 
 message (STATUS "*** Building ${APP_NAME} ${APP_VERSION} ***")
 
+project ("latexila" C)
+
+# Include custom functions
+list (APPEND CMAKE_MODULE_PATH "${latexila_SOURCE_DIR}/cmake")
+include ("${latexila_SOURCE_DIR}/cmake/itstool.cmake")
+include ("${latexila_SOURCE_DIR}/cmake/gresource.cmake")
+include ("${latexila_SOURCE_DIR}/cmake/find_vala.cmake")
+include ("${latexila_SOURCE_DIR}/cmake/use_vala.cmake")
+include ("${latexila_SOURCE_DIR}/cmake/build_vala.cmake")
+
+# Build options
 set (DATA_DIR "${CMAKE_INSTALL_PREFIX}/share/latexila"
 	CACHE PATH "The directory where the data is")
 set (BUILD_VALA ON CACHE BOOL "Generate the C code from Vala files")
@@ -19,16 +31,10 @@ set (VALAC "" CACHE FILEPATH "The valac executable to use")
 set (GETTEXT_PACKAGE "latexila")
 set (LOCALE_DIR "${CMAKE_INSTALL_PREFIX}/share/locale")
 find_package (Gettext REQUIRED)
-list (APPEND CMAKE_MODULE_PATH "${latexila_SOURCE_DIR}/cmake")
 find_package (Itstool REQUIRED)
 
-set (SCHEMA_DIR "${CMAKE_INSTALL_PREFIX}/share")
-set (ICONS_DIR "${CMAKE_INSTALL_PREFIX}/share/icons/hicolor")
-
+# Vala
 if (BUILD_VALA)
-	include ("${latexila_SOURCE_DIR}/cmake/find_vala.cmake")
-	include ("${latexila_SOURCE_DIR}/cmake/use_vala.cmake")
-
 	set (_vala_main_version "0.16")
 	set (_vala_min_version "0.16.0")
 
@@ -46,6 +52,7 @@ if (BUILD_VALA)
 	endif ()
 endif ()
 
+# Dependencies
 find_package (PkgConfig)
 pkg_check_modules (GTK REQUIRED "gtk+-3.0 >= 3.4")
 pkg_check_modules (GTKSOURCEVIEW REQUIRED "gtksourceview-3.0 >= 3.4.1")
@@ -53,17 +60,6 @@ pkg_check_modules (GEE REQUIRED "gee-1.0")
 pkg_check_modules (GIO REQUIRED "gio-2.0 >= 2.32")
 pkg_check_modules (GTKSPELL REQUIRED "gtkspell-3.0")
 
-if (WITH_GNOME)
-	pkg_check_modules (DESKTOP-SCHEMAS REQUIRED "gsettings-desktop-schemas")
-	set (DESKTOP_SCHEMAS "1")
-else ()
-	set (DESKTOP_SCHEMAS "0")
-endif ()
-
-configure_file (${latexila_SOURCE_DIR}/src/config.h.in
-	${latexila_BINARY_DIR}/src/config.h)
-add_definitions (-include config.h)
-
 add_definitions (
 	${GTK_CFLAGS}
 	${GTKSOURCEVIEW_CFLAGS}
@@ -80,17 +76,57 @@ link_libraries (
 	${GTKSPELL_LIBRARIES}
 )
 
-include ("${latexila_SOURCE_DIR}/cmake/itstool.cmake")
+if (WITH_GNOME)
+	pkg_check_modules (DESKTOP-SCHEMAS REQUIRED "gsettings-desktop-schemas")
+	set (DESKTOP_SCHEMAS "1")
+else ()
+	set (DESKTOP_SCHEMAS "0")
+endif ()
 
+# Execute CMake in sub-directories
 add_subdirectory (data)
 add_subdirectory (help)
 add_subdirectory (man)
 add_subdirectory (po)
 add_subdirectory (src/ui)
 
-include_directories (vapi src/C ${latexila_BINARY_DIR}/src src/gedit)
+# Config file
+set (config_file "${latexila_BINARY_DIR}/src/config.h")
+
+configure_file (
+	${latexila_SOURCE_DIR}/src/config.h.in
+	${config_file}
+)
+
+add_definitions (-include config.h)
+
+# Resources
+gresource (
+	"${latexila_SOURCE_DIR}/data/images/stock-icons" # resource dir
+	"stock-icons.gresource.xml" # resource file
+	"${latexila_BINARY_DIR}/src" # output dir
+	generated_resource
+)
+
+set (generated_resources ${generated_resource})
+
+# Build the source code
+include_directories (src/C src/gedit ${latexila_BINARY_DIR}/src)
+
+file (GLOB gedit_source_code "${latexila_SOURCE_DIR}/src/gedit/*")
+
 if (BUILD_VALA)
-	add_subdirectory (src)
+	build_vala (generated_code)
 else ()
-	add_subdirectory (src/C)
+	file (GLOB generated_code "${latexila_SOURCE_DIR}/src/C/*.c")
 endif ()
+
+add_executable (
+	"latexila"
+	${generated_code}
+	${generated_resources}
+	${config_file}
+	${gedit_source_code}
+)
+
+install (TARGETS "latexila" DESTINATION "bin")
diff --git a/cmake/gresource.cmake b/cmake/gresource.cmake
new file mode 100644
index 0000000..efa37ff
--- /dev/null
+++ b/cmake/gresource.cmake
@@ -0,0 +1,37 @@
+# Used for GResource.
+#
+# resource_dir: Directory where the .gresource.xml is located.
+# resource_file: Filename of the .gresource.xml file (just the
+#                filename, not the complete path).
+# output_dir: Directory where the C output file is written.
+# output_file: This variable will be set with the complete path of the
+#              output C file.
+
+function (gresource resource_dir resource_file output_dir output_file)
+	# Get the output file path
+	get_filename_component (resource_name ${resource_file} NAME_WE)
+	set (output "${output_dir}/${resource_name}-resources.c")
+	set (${output_file} ${output} PARENT_SCOPE)
+
+	# Get the dependencies of the gresource
+	execute_process (
+		OUTPUT_VARIABLE _files
+		WORKING_DIRECTORY ${resource_dir}
+		COMMAND glib-compile-resources --generate-dependencies ${resource_file}
+	)
+
+	string (REPLACE "\n" ";" files ${_files})
+
+	set (depends "")
+	foreach (cur_file ${files})
+		list (APPEND depends "${resource_dir}/${cur_file}")
+	endforeach ()
+
+	# Command to compile the resources
+	add_custom_command (
+		OUTPUT ${output}
+		DEPENDS "${resource_dir}/${resource_file}" ${depends}
+		WORKING_DIRECTORY ${resource_dir}
+		COMMAND glib-compile-resources --generate-source --target=${output} ${resource_file}
+	)
+endfunction ()
diff --git a/cmake/use_vala.cmake b/cmake/use_vala.cmake
index 436d1d0..001f8e1 100644
--- a/cmake/use_vala.cmake
+++ b/cmake/use_vala.cmake
@@ -1,91 +1,16 @@
 ##
-# Compile vala files to their c equivalents for further processing.
-#
-# The "vala_precompile" function takes care of calling the valac executable on
-# the given source to produce c files which can then be processed further using
-# default cmake functions.
-#
-# The first parameter provided is a variable, which will be filled with a list
-# of c files outputted by the vala compiler. This list can than be used in
-# conjuction with functions like "add_executable" or others to create the
-# neccessary compile rules with CMake.
-#
-# The following sections may be specified afterwards to provide certain options
-# to the vala compiler:
-#
-# SOURCES
-#   A list of .vala files to be compiled. Please take care to add every vala
-#   file belonging to the currently compiled project or library as Vala will
-#   otherwise not be able to resolve all dependencies.
-#
-# PACKAGES
-#   A list of vala packages/libraries to be used during the compile cycle. The
-#   package names are exactly the same, as they would be passed to the valac
-#   "--pkg=" option.
-#
-# OPTIONS
-#   A list of optional options to be passed to the valac executable. This can be
-#   used to pass "--thread" for example to enable multi-threading support.
-#
-# CUSTOM_VAPIS
-#   A list of custom vapi files to be included for compilation. This can be
-#   useful to include freshly created vala libraries without having to install
-#   them in the system.
-#
-# GENERATE_VAPI
-#   Pass all the needed flags to the compiler to create an internal vapi for
-#   the compiled library. The provided name will be used for this and a
-#   <provided_name>.vapi file will be created.
-#
-# GENERATE_HEADER
-#   Let the compiler generate a header file for the compiled code. There will
-#   be a header file as well as an internal header file being generated called
-#   <provided_name>.h and <provided_name>_internal.h
-#
-# The following call is a simple example to the vala_precompile macro showing
-# an example to every of the optional sections:
-#
-#   find_package(Vala "0.12" REQUIRED)
-#   inlcude(${VALA_USE_FILE})
-#
-#   vala_precompile(VALA_C
-#     SOURCES
-#       source1.vala
-#       source2.vala
-#       source3.vala
-#     PACKAGES
-#       gtk+-2.0
-#       gio-1.0
-#       posix
-#     DIRECTORY
-#       gen
-#     OPTIONS
-#       --thread
-#     CUSTOM_VAPIS
-#       some_vapi.vapi
-#     GENERATE_VAPI
-#       myvapi
-#     GENERATE_HEADER
-#       myheader
-#     )
-#
-# Most important is the variable VALA_C which will contain all the generated c
-# file names after the call.
-##
-
-##
 # Copyright 2009-2010 Jakob Westhoff. All rights reserved.
 # Copyright 2010-2011 Daniel Pfeifer
 #
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions are met:
 #
-#    1. Redistributions of source code must retain the above copyright notice,
-#       this list of conditions and the following disclaimer.
+#	1. Redistributions of source code must retain the above copyright notice,
+#	   this list of conditions and the following disclaimer.
 #
-#    2. Redistributions in binary form must reproduce the above copyright notice,
-#       this list of conditions and the following disclaimer in the documentation
-#       and/or other materials provided with the distribution.
+#	2. Redistributions in binary form must reproduce the above copyright notice,
+#	   this list of conditions and the following disclaimer in the documentation
+#	   and/or other materials provided with the distribution.
 #
 # THIS SOFTWARE IS PROVIDED BY JAKOB WESTHOFF ``AS IS'' AND ANY EXPRESS OR
 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
@@ -103,78 +28,49 @@
 # either expressed or implied, of Jakob Westhoff
 ##
 
-include(CMakeParseArguments)
-
-function(vala_precompile output)
-    cmake_parse_arguments(ARGS "" "DIRECTORY;GENERATE_HEADER;GENERATE_VAPI"
-        "SOURCES;PACKAGES;OPTIONS;CUSTOM_VAPIS" ${ARGN})
+##
+# Compile vala files to their C equivalents for further processing.
+#
+# Adapted to better fit with LaTeXila. Original sources can be found there:
+# https://github.com/jakobwesthoff/Vala_CMake
+##
 
-    if(ARGS_DIRECTORY)
-        set(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${ARGS_DIRECTORY})
-    else(ARGS_DIRECTORY)
-        set(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
-    endif(ARGS_DIRECTORY)
-    include_directories(${DIRECTORY})
-    set(vala_pkg_opts "")
-    foreach(pkg ${ARGS_PACKAGES})
-        list(APPEND vala_pkg_opts "--pkg=${pkg}")
-    endforeach(pkg ${ARGS_PACKAGES})
-    set(in_files "")
-    set(out_files "")
-    foreach(src ${ARGS_SOURCES} ${ARGS_UNPARSED_ARGUMENTS})
-        list(APPEND in_files "${CMAKE_CURRENT_SOURCE_DIR}/${src}")
-        string(REPLACE ".vala" ".c" src ${src})
-        string(REPLACE ".gs" ".c" src ${src})
-        set(out_file "${DIRECTORY}/${src}")
-        list(APPEND out_files "${DIRECTORY}/${src}")
-    endforeach(src ${ARGS_SOURCES} ${ARGS_UNPARSED_ARGUMENTS})
+include(CMakeParseArguments)
 
-    set(custom_vapi_arguments "")
-    if(ARGS_CUSTOM_VAPIS)
-        foreach(vapi ${ARGS_CUSTOM_VAPIS})
-            if(${vapi} MATCHES ${CMAKE_SOURCE_DIR} OR ${vapi} MATCHES ${CMAKE_BINARY_DIR})
-                list(APPEND custom_vapi_arguments ${vapi})
-            else (${vapi} MATCHES ${CMAKE_SOURCE_DIR} OR ${vapi} MATCHES ${CMAKE_BINARY_DIR})
-                list(APPEND custom_vapi_arguments ${CMAKE_CURRENT_SOURCE_DIR}/${vapi})
-            endif(${vapi} MATCHES ${CMAKE_SOURCE_DIR} OR ${vapi} MATCHES ${CMAKE_BINARY_DIR})
-        endforeach(vapi ${ARGS_CUSTOM_VAPIS})
-    endif(ARGS_CUSTOM_VAPIS)
+function(vala_precompile)
+	cmake_parse_arguments(
+		ARGS
+		""
+		"OUTPUT;OUTPUT_DIR"
+		"SOURCES;PACKAGES;VAPIS"
+		${ARGN}
+	)
 
-    set(vapi_arguments "")
-    if(ARGS_GENERATE_VAPI)
-        list(APPEND out_files "${DIRECTORY}/${ARGS_GENERATE_VAPI}.vapi")
-        set(vapi_arguments "--internal-vapi=${ARGS_GENERATE_VAPI}.vapi")
+	set(pkg_opts "")
+	foreach(pkg ${ARGS_PACKAGES})
+		list(APPEND pkg_opts "--pkg=${pkg}")
+	endforeach()
 
-        # Header and internal header is needed to generate internal vapi
-        if (NOT ARGS_GENERATE_HEADER)
-            set(ARGS_GENERATE_HEADER ${ARGS_GENERATE_VAPI})
-        endif(NOT ARGS_GENERATE_HEADER)
-    endif(ARGS_GENERATE_VAPI)
+	set(out_files "")
+	foreach(src ${ARGS_SOURCES})
+		get_filename_component (filename ${src} NAME_WE)
+		list(APPEND out_files "${ARGS_OUTPUT_DIR}/${filename}.c")
+	endforeach()
 
-    set(header_arguments "")
-    if(ARGS_GENERATE_HEADER)
-        list(APPEND out_files "${DIRECTORY}/${ARGS_GENERATE_HEADER}.h")
-        list(APPEND out_files "${DIRECTORY}/${ARGS_GENERATE_HEADER}_internal.h")
-        list(APPEND header_arguments "--header=${DIRECTORY}/${ARGS_GENERATE_HEADER}.h")
-        list(APPEND header_arguments "--internal-header=${DIRECTORY}/${ARGS_GENERATE_HEADER}_internal.h")
-    endif(ARGS_GENERATE_HEADER)
+	add_custom_command(
+		OUTPUT
+			${out_files}
+		COMMAND
+			${VALA_EXECUTABLE}
+			"-C"
+			"-d" ${ARGS_OUTPUT_DIR}
+			${pkg_opts}
+			${ARGS_SOURCES}
+			${ARGS_VAPIS}
+		DEPENDS
+			${ARGS_SOURCES}
+			${ARGS_VAPIS}
+	)
 
-    add_custom_command(OUTPUT ${out_files}
-    COMMAND
-        ${VALA_EXECUTABLE}
-    ARGS
-        "-C"
-        ${header_arguments}
-        ${vapi_arguments}
-        "-b" ${CMAKE_CURRENT_SOURCE_DIR}
-        "-d" ${DIRECTORY}
-        ${vala_pkg_opts}
-        ${ARGS_OPTIONS}
-        ${in_files}
-        ${custom_vapi_arguments}
-    DEPENDS
-        ${in_files}
-        ${ARGS_CUSTOM_VAPIS}
-    )
-    set(${output} ${out_files} PARENT_SCOPE)
-endfunction(vala_precompile)
+	set(${ARGS_OUTPUT} ${out_files} PARENT_SCOPE)
+endfunction()
diff --git a/data/images/icons/accent0.png b/data/images/stock-icons/accent0.png
similarity index 100%
rename from data/images/icons/accent0.png
rename to data/images/stock-icons/accent0.png
diff --git a/data/images/icons/accent1.png b/data/images/stock-icons/accent1.png
similarity index 100%
rename from data/images/icons/accent1.png
rename to data/images/stock-icons/accent1.png
diff --git a/data/images/icons/accent10.png b/data/images/stock-icons/accent10.png
similarity index 100%
rename from data/images/icons/accent10.png
rename to data/images/stock-icons/accent10.png
diff --git a/data/images/icons/accent11.png b/data/images/stock-icons/accent11.png
similarity index 100%
rename from data/images/icons/accent11.png
rename to data/images/stock-icons/accent11.png
diff --git a/data/images/icons/accent12.png b/data/images/stock-icons/accent12.png
similarity index 100%
rename from data/images/icons/accent12.png
rename to data/images/stock-icons/accent12.png
diff --git a/data/images/icons/accent13.png b/data/images/stock-icons/accent13.png
similarity index 100%
rename from data/images/icons/accent13.png
rename to data/images/stock-icons/accent13.png
diff --git a/data/images/icons/accent14.png b/data/images/stock-icons/accent14.png
similarity index 100%
rename from data/images/icons/accent14.png
rename to data/images/stock-icons/accent14.png
diff --git a/data/images/icons/accent15.png b/data/images/stock-icons/accent15.png
similarity index 100%
rename from data/images/icons/accent15.png
rename to data/images/stock-icons/accent15.png
diff --git a/data/images/icons/accent2.png b/data/images/stock-icons/accent2.png
similarity index 100%
rename from data/images/icons/accent2.png
rename to data/images/stock-icons/accent2.png
diff --git a/data/images/icons/accent3.png b/data/images/stock-icons/accent3.png
similarity index 100%
rename from data/images/icons/accent3.png
rename to data/images/stock-icons/accent3.png
diff --git a/data/images/icons/accent4.png b/data/images/stock-icons/accent4.png
similarity index 100%
rename from data/images/icons/accent4.png
rename to data/images/stock-icons/accent4.png
diff --git a/data/images/icons/accent5.png b/data/images/stock-icons/accent5.png
similarity index 100%
rename from data/images/icons/accent5.png
rename to data/images/stock-icons/accent5.png
diff --git a/data/images/icons/accent6.png b/data/images/stock-icons/accent6.png
similarity index 100%
rename from data/images/icons/accent6.png
rename to data/images/stock-icons/accent6.png
diff --git a/data/images/icons/accent7.png b/data/images/stock-icons/accent7.png
similarity index 100%
rename from data/images/icons/accent7.png
rename to data/images/stock-icons/accent7.png
diff --git a/data/images/icons/accent8.png b/data/images/stock-icons/accent8.png
similarity index 100%
rename from data/images/icons/accent8.png
rename to data/images/stock-icons/accent8.png
diff --git a/data/images/icons/accent9.png b/data/images/stock-icons/accent9.png
similarity index 100%
rename from data/images/icons/accent9.png
rename to data/images/stock-icons/accent9.png
diff --git a/data/images/icons/badbox.png b/data/images/stock-icons/badbox.png
similarity index 100%
rename from data/images/icons/badbox.png
rename to data/images/stock-icons/badbox.png
diff --git a/data/images/stock-icons/blackboard.png b/data/images/stock-icons/blackboard.png
new file mode 100644
index 0000000..d71509f
Binary files /dev/null and b/data/images/stock-icons/blackboard.png differ
diff --git a/data/images/icons/textbf.png b/data/images/stock-icons/bold.png
similarity index 100%
rename from data/images/icons/textbf.png
rename to data/images/stock-icons/bold.png
diff --git a/data/images/icons/character-size.png b/data/images/stock-icons/character-size.png
similarity index 100%
rename from data/images/icons/character-size.png
rename to data/images/stock-icons/character-size.png
diff --git a/data/images/icons/compile_dvi.png b/data/images/stock-icons/compile_dvi.png
similarity index 100%
rename from data/images/icons/compile_dvi.png
rename to data/images/stock-icons/compile_dvi.png
diff --git a/data/images/icons/compile_pdf.png b/data/images/stock-icons/compile_pdf.png
similarity index 100%
rename from data/images/icons/compile_pdf.png
rename to data/images/stock-icons/compile_pdf.png
diff --git a/data/images/icons/compile_ps.png b/data/images/stock-icons/compile_ps.png
similarity index 100%
rename from data/images/icons/compile_ps.png
rename to data/images/stock-icons/compile_ps.png
diff --git a/data/images/icons/completion_choice.png b/data/images/stock-icons/completion_choice.png
similarity index 100%
rename from data/images/icons/completion_choice.png
rename to data/images/stock-icons/completion_choice.png
diff --git a/data/images/icons/completion_cmd.png b/data/images/stock-icons/completion_cmd.png
similarity index 100%
rename from data/images/icons/completion_cmd.png
rename to data/images/stock-icons/completion_cmd.png
diff --git a/data/images/icons/delimiters-left.png b/data/images/stock-icons/delimiters-left.png
similarity index 100%
rename from data/images/icons/delimiters-left.png
rename to data/images/stock-icons/delimiters-left.png
diff --git a/data/images/icons/delimiters-right.png b/data/images/stock-icons/delimiters-right.png
similarity index 100%
rename from data/images/icons/delimiters-right.png
rename to data/images/stock-icons/delimiters-right.png
diff --git a/data/images/icons/textit.png b/data/images/stock-icons/italic.png
similarity index 100%
rename from data/images/icons/textit.png
rename to data/images/stock-icons/italic.png
diff --git a/data/images/icons/list-description.png b/data/images/stock-icons/list-description.png
similarity index 100%
rename from data/images/icons/list-description.png
rename to data/images/stock-icons/list-description.png
diff --git a/data/images/icons/list-enumerate.png b/data/images/stock-icons/list-enumerate.png
similarity index 100%
rename from data/images/icons/list-enumerate.png
rename to data/images/stock-icons/list-enumerate.png
diff --git a/data/images/icons/list-item.png b/data/images/stock-icons/list-item.png
similarity index 100%
rename from data/images/icons/list-item.png
rename to data/images/stock-icons/list-item.png
diff --git a/data/images/icons/list-itemize.png b/data/images/stock-icons/list-itemize.png
similarity index 100%
rename from data/images/icons/list-itemize.png
rename to data/images/stock-icons/list-itemize.png
diff --git a/data/images/icons/math-array.png b/data/images/stock-icons/math-array.png
similarity index 100%
rename from data/images/icons/math-array.png
rename to data/images/stock-icons/math-array.png
diff --git a/data/images/icons/math-centered.png b/data/images/stock-icons/math-centered.png
similarity index 100%
rename from data/images/icons/math-centered.png
rename to data/images/stock-icons/math-centered.png
diff --git a/data/images/icons/math-frac.png b/data/images/stock-icons/math-frac.png
similarity index 100%
rename from data/images/icons/math-frac.png
rename to data/images/stock-icons/math-frac.png
diff --git a/data/images/icons/math-nth-root.png b/data/images/stock-icons/math-nth-root.png
similarity index 100%
rename from data/images/icons/math-nth-root.png
rename to data/images/stock-icons/math-nth-root.png
diff --git a/data/images/icons/math-numbered-array.png b/data/images/stock-icons/math-numbered-array.png
similarity index 100%
rename from data/images/icons/math-numbered-array.png
rename to data/images/stock-icons/math-numbered-array.png
diff --git a/data/images/icons/math-numbered.png b/data/images/stock-icons/math-numbered.png
similarity index 100%
rename from data/images/icons/math-numbered.png
rename to data/images/stock-icons/math-numbered.png
diff --git a/data/images/icons/math-square-root.png b/data/images/stock-icons/math-square-root.png
similarity index 100%
rename from data/images/icons/math-square-root.png
rename to data/images/stock-icons/math-square-root.png
diff --git a/data/images/icons/math-subscript.png b/data/images/stock-icons/math-subscript.png
similarity index 100%
rename from data/images/icons/math-subscript.png
rename to data/images/stock-icons/math-subscript.png
diff --git a/data/images/icons/math-superscript.png b/data/images/stock-icons/math-superscript.png
similarity index 100%
rename from data/images/icons/math-superscript.png
rename to data/images/stock-icons/math-superscript.png
diff --git a/data/images/icons/math.png b/data/images/stock-icons/math.png
similarity index 100%
rename from data/images/icons/math.png
rename to data/images/stock-icons/math.png
diff --git a/data/images/icons/mathaccent0.png b/data/images/stock-icons/mathaccent0.png
similarity index 100%
rename from data/images/icons/mathaccent0.png
rename to data/images/stock-icons/mathaccent0.png
diff --git a/data/images/icons/mathaccent1.png b/data/images/stock-icons/mathaccent1.png
similarity index 100%
rename from data/images/icons/mathaccent1.png
rename to data/images/stock-icons/mathaccent1.png
diff --git a/data/images/icons/mathaccent10.png b/data/images/stock-icons/mathaccent10.png
similarity index 100%
rename from data/images/icons/mathaccent10.png
rename to data/images/stock-icons/mathaccent10.png
diff --git a/data/images/icons/mathaccent2.png b/data/images/stock-icons/mathaccent2.png
similarity index 100%
rename from data/images/icons/mathaccent2.png
rename to data/images/stock-icons/mathaccent2.png
diff --git a/data/images/icons/mathaccent3.png b/data/images/stock-icons/mathaccent3.png
similarity index 100%
rename from data/images/icons/mathaccent3.png
rename to data/images/stock-icons/mathaccent3.png
diff --git a/data/images/icons/mathaccent4.png b/data/images/stock-icons/mathaccent4.png
similarity index 100%
rename from data/images/icons/mathaccent4.png
rename to data/images/stock-icons/mathaccent4.png
diff --git a/data/images/icons/mathaccent5.png b/data/images/stock-icons/mathaccent5.png
similarity index 100%
rename from data/images/icons/mathaccent5.png
rename to data/images/stock-icons/mathaccent5.png
diff --git a/data/images/icons/mathaccent6.png b/data/images/stock-icons/mathaccent6.png
similarity index 100%
rename from data/images/icons/mathaccent6.png
rename to data/images/stock-icons/mathaccent6.png
diff --git a/data/images/icons/mathaccent7.png b/data/images/stock-icons/mathaccent7.png
similarity index 100%
rename from data/images/icons/mathaccent7.png
rename to data/images/stock-icons/mathaccent7.png
diff --git a/data/images/icons/mathaccent8.png b/data/images/stock-icons/mathaccent8.png
similarity index 100%
rename from data/images/icons/mathaccent8.png
rename to data/images/stock-icons/mathaccent8.png
diff --git a/data/images/icons/mathaccent9.png b/data/images/stock-icons/mathaccent9.png
similarity index 100%
rename from data/images/icons/mathaccent9.png
rename to data/images/stock-icons/mathaccent9.png
diff --git a/data/images/icons/mathcal.png b/data/images/stock-icons/mathcal.png
similarity index 100%
rename from data/images/icons/mathcal.png
rename to data/images/stock-icons/mathcal.png
diff --git a/data/images/icons/mathfrak.png b/data/images/stock-icons/mathfrak.png
similarity index 100%
rename from data/images/icons/mathfrak.png
rename to data/images/stock-icons/mathfrak.png
diff --git a/data/images/icons/references.png b/data/images/stock-icons/references.png
similarity index 100%
rename from data/images/icons/references.png
rename to data/images/stock-icons/references.png
diff --git a/data/images/icons/roman.png b/data/images/stock-icons/roman.png
similarity index 100%
rename from data/images/icons/roman.png
rename to data/images/stock-icons/roman.png
diff --git a/data/images/icons/textsf.png b/data/images/stock-icons/sans_serif.png
similarity index 100%
rename from data/images/icons/textsf.png
rename to data/images/stock-icons/sans_serif.png
diff --git a/data/images/icons/sectioning-chapter.png b/data/images/stock-icons/sectioning-chapter.png
similarity index 100%
rename from data/images/icons/sectioning-chapter.png
rename to data/images/stock-icons/sectioning-chapter.png
diff --git a/data/images/icons/sectioning-paragraph.png b/data/images/stock-icons/sectioning-paragraph.png
similarity index 100%
rename from data/images/icons/sectioning-paragraph.png
rename to data/images/stock-icons/sectioning-paragraph.png
diff --git a/data/images/icons/sectioning-part.png b/data/images/stock-icons/sectioning-part.png
similarity index 100%
rename from data/images/icons/sectioning-part.png
rename to data/images/stock-icons/sectioning-part.png
diff --git a/data/images/icons/sectioning-section.png b/data/images/stock-icons/sectioning-section.png
similarity index 100%
rename from data/images/icons/sectioning-section.png
rename to data/images/stock-icons/sectioning-section.png
diff --git a/data/images/icons/sectioning-subsection.png b/data/images/stock-icons/sectioning-subsection.png
similarity index 100%
rename from data/images/icons/sectioning-subsection.png
rename to data/images/stock-icons/sectioning-subsection.png
diff --git a/data/images/icons/sectioning-subsubsection.png b/data/images/stock-icons/sectioning-subsubsection.png
similarity index 100%
rename from data/images/icons/sectioning-subsubsection.png
rename to data/images/stock-icons/sectioning-subsubsection.png
diff --git a/data/images/icons/textsl.png b/data/images/stock-icons/slanted.png
similarity index 100%
rename from data/images/icons/textsl.png
rename to data/images/stock-icons/slanted.png
diff --git a/data/images/icons/textsc.png b/data/images/stock-icons/small_caps.png
similarity index 100%
rename from data/images/icons/textsc.png
rename to data/images/stock-icons/small_caps.png
diff --git a/data/images/stock-icons/stock-icons.gresource.xml b/data/images/stock-icons/stock-icons.gresource.xml
new file mode 100644
index 0000000..5e606d2
--- /dev/null
+++ b/data/images/stock-icons/stock-icons.gresource.xml
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+List of icons that are registered as new stock icons, so it can be used
+in menus for example.
+-->
+
+<gresources>
+  <gresource prefix="/org/gnome/latexila/stock-icons">
+    <file preprocess="to-pixdata">accent0.png</file>
+    <file preprocess="to-pixdata">accent1.png</file>
+    <file preprocess="to-pixdata">accent2.png</file>
+    <file preprocess="to-pixdata">accent3.png</file>
+    <file preprocess="to-pixdata">accent4.png</file>
+    <file preprocess="to-pixdata">accent5.png</file>
+    <file preprocess="to-pixdata">accent6.png</file>
+    <file preprocess="to-pixdata">accent7.png</file>
+    <file preprocess="to-pixdata">accent8.png</file>
+    <file preprocess="to-pixdata">accent9.png</file>
+    <file preprocess="to-pixdata">accent10.png</file>
+    <file preprocess="to-pixdata">accent11.png</file>
+    <file preprocess="to-pixdata">accent12.png</file>
+    <file preprocess="to-pixdata">accent13.png</file>
+    <file preprocess="to-pixdata">accent14.png</file>
+    <file preprocess="to-pixdata">accent15.png</file>
+    <file preprocess="to-pixdata">badbox.png</file>
+    <file preprocess="to-pixdata">blackboard.png</file>
+    <file preprocess="to-pixdata">bold.png</file>
+    <file preprocess="to-pixdata">character-size.png</file>
+    <file preprocess="to-pixdata">compile_dvi.png</file>
+    <file preprocess="to-pixdata">compile_pdf.png</file>
+    <file preprocess="to-pixdata">compile_ps.png</file>
+    <file preprocess="to-pixdata">completion_choice.png</file>
+    <file preprocess="to-pixdata">completion_cmd.png</file>
+    <file preprocess="to-pixdata">delimiters-left.png</file>
+    <file preprocess="to-pixdata">delimiters-right.png</file>
+    <file preprocess="to-pixdata">italic.png</file>
+    <file preprocess="to-pixdata">list-description.png</file>
+    <file preprocess="to-pixdata">list-enumerate.png</file>
+    <file preprocess="to-pixdata">list-item.png</file>
+    <file preprocess="to-pixdata">list-itemize.png</file>
+    <file preprocess="to-pixdata">math-array.png</file>
+    <file preprocess="to-pixdata">math-centered.png</file>
+    <file preprocess="to-pixdata">math-frac.png</file>
+    <file preprocess="to-pixdata">math-nth-root.png</file>
+    <file preprocess="to-pixdata">math-numbered-array.png</file>
+    <file preprocess="to-pixdata">math-numbered.png</file>
+    <file preprocess="to-pixdata">math-square-root.png</file>
+    <file preprocess="to-pixdata">math-subscript.png</file>
+    <file preprocess="to-pixdata">math-superscript.png</file>
+    <file preprocess="to-pixdata">math.png</file>
+    <file preprocess="to-pixdata">mathaccent0.png</file>
+    <file preprocess="to-pixdata">mathaccent1.png</file>
+    <file preprocess="to-pixdata">mathaccent2.png</file>
+    <file preprocess="to-pixdata">mathaccent3.png</file>
+    <file preprocess="to-pixdata">mathaccent4.png</file>
+    <file preprocess="to-pixdata">mathaccent5.png</file>
+    <file preprocess="to-pixdata">mathaccent6.png</file>
+    <file preprocess="to-pixdata">mathaccent7.png</file>
+    <file preprocess="to-pixdata">mathaccent8.png</file>
+    <file preprocess="to-pixdata">mathaccent9.png</file>
+    <file preprocess="to-pixdata">mathaccent10.png</file>
+    <file preprocess="to-pixdata">mathcal.png</file>
+    <file preprocess="to-pixdata">mathfrak.png</file>
+    <file preprocess="to-pixdata">references.png</file>
+    <file preprocess="to-pixdata">roman.png</file>
+    <file preprocess="to-pixdata">sans_serif.png</file>
+    <file preprocess="to-pixdata">sectioning-chapter.png</file>
+    <file preprocess="to-pixdata">sectioning-paragraph.png</file>
+    <file preprocess="to-pixdata">sectioning-part.png</file>
+    <file preprocess="to-pixdata">sectioning-section.png</file>
+    <file preprocess="to-pixdata">sectioning-subsection.png</file>
+    <file preprocess="to-pixdata">sectioning-subsubsection.png</file>
+    <file preprocess="to-pixdata">slanted.png</file>
+    <file preprocess="to-pixdata">small_caps.png</file>
+    <file preprocess="to-pixdata">symbol_alpha.png</file>
+    <file preprocess="to-pixdata">table.png</file>
+    <file preprocess="to-pixdata">tree_chapter.png</file>
+    <file preprocess="to-pixdata">tree_label.png</file>
+    <file preprocess="to-pixdata">tree_paragraph.png</file>
+    <file preprocess="to-pixdata">tree_part.png</file>
+    <file preprocess="to-pixdata">tree_section.png</file>
+    <file preprocess="to-pixdata">tree_subsection.png</file>
+    <file preprocess="to-pixdata">tree_subsubsection.png</file>
+    <file preprocess="to-pixdata">tree_todo.png</file>
+    <file preprocess="to-pixdata">typewriter.png</file>
+    <file preprocess="to-pixdata">underline.png</file>
+    <file preprocess="to-pixdata">view_dvi.png</file>
+    <file preprocess="to-pixdata">view_log.png</file>
+    <file preprocess="to-pixdata">view_pdf.png</file>
+    <file preprocess="to-pixdata">view_ps.png</file>
+  </gresource>
+</gresources>
diff --git a/data/images/stock-icons/symbol_alpha.png b/data/images/stock-icons/symbol_alpha.png
new file mode 100644
index 0000000..fb31745
Binary files /dev/null and b/data/images/stock-icons/symbol_alpha.png differ
diff --git a/data/images/icons/table.png b/data/images/stock-icons/table.png
similarity index 100%
rename from data/images/icons/table.png
rename to data/images/stock-icons/table.png
diff --git a/data/images/icons/tree_chapter.png b/data/images/stock-icons/tree_chapter.png
similarity index 100%
rename from data/images/icons/tree_chapter.png
rename to data/images/stock-icons/tree_chapter.png
diff --git a/data/images/icons/tree_label.license b/data/images/stock-icons/tree_label.license
similarity index 100%
rename from data/images/icons/tree_label.license
rename to data/images/stock-icons/tree_label.license
diff --git a/data/images/icons/tree_label.png b/data/images/stock-icons/tree_label.png
similarity index 100%
rename from data/images/icons/tree_label.png
rename to data/images/stock-icons/tree_label.png
diff --git a/data/images/icons/tree_paragraph.png b/data/images/stock-icons/tree_paragraph.png
similarity index 100%
rename from data/images/icons/tree_paragraph.png
rename to data/images/stock-icons/tree_paragraph.png
diff --git a/data/images/icons/tree_part.png b/data/images/stock-icons/tree_part.png
similarity index 100%
rename from data/images/icons/tree_part.png
rename to data/images/stock-icons/tree_part.png
diff --git a/data/images/icons/tree_section.png b/data/images/stock-icons/tree_section.png
similarity index 100%
rename from data/images/icons/tree_section.png
rename to data/images/stock-icons/tree_section.png
diff --git a/data/images/icons/tree_subsection.png b/data/images/stock-icons/tree_subsection.png
similarity index 100%
rename from data/images/icons/tree_subsection.png
rename to data/images/stock-icons/tree_subsection.png
diff --git a/data/images/icons/tree_subsubsection.png b/data/images/stock-icons/tree_subsubsection.png
similarity index 100%
rename from data/images/icons/tree_subsubsection.png
rename to data/images/stock-icons/tree_subsubsection.png
diff --git a/data/images/icons/tree_todo.png b/data/images/stock-icons/tree_todo.png
similarity index 100%
rename from data/images/icons/tree_todo.png
rename to data/images/stock-icons/tree_todo.png
diff --git a/data/images/icons/texttt.png b/data/images/stock-icons/typewriter.png
similarity index 100%
rename from data/images/icons/texttt.png
rename to data/images/stock-icons/typewriter.png
diff --git a/data/images/icons/underline.png b/data/images/stock-icons/underline.png
similarity index 100%
rename from data/images/icons/underline.png
rename to data/images/stock-icons/underline.png
diff --git a/data/images/icons/view_dvi.png b/data/images/stock-icons/view_dvi.png
similarity index 100%
rename from data/images/icons/view_dvi.png
rename to data/images/stock-icons/view_dvi.png
diff --git a/data/images/icons/logviewer.png b/data/images/stock-icons/view_log.png
similarity index 100%
rename from data/images/icons/logviewer.png
rename to data/images/stock-icons/view_log.png
diff --git a/data/images/icons/view_pdf.png b/data/images/stock-icons/view_pdf.png
similarity index 100%
rename from data/images/icons/view_pdf.png
rename to data/images/stock-icons/view_pdf.png
diff --git a/data/images/icons/view_ps.png b/data/images/stock-icons/view_ps.png
similarity index 100%
rename from data/images/icons/view_ps.png
rename to data/images/stock-icons/view_ps.png
diff --git a/src/latexila.vala b/src/latexila.vala
index e0aaaab..41626af 100644
--- a/src/latexila.vala
+++ b/src/latexila.vala
@@ -116,7 +116,7 @@ public class Latexila : Gtk.Application
     {
         hold ();
         set_application_icons ();
-        StockIcons.add_custom ();
+        new StockIcons ();
 
         AppSettings.get_default ();
         create_window ();
diff --git a/src/stock_icons.vala b/src/stock_icons.vala
index b54217a..76a8ca9 100644
--- a/src/stock_icons.vala
+++ b/src/stock_icons.vala
@@ -19,142 +19,74 @@
  * Author: SÃbastien Wilmet
  */
 
-namespace StockIcons
+// Add some icons to the stock icons, so it can be used e.g. in menus.
+
+// See also:
+// data/images/stock-icons/stock-icons.gresource.xml
+
+public class StockIcons
 {
-    // Add some icons to the stock icons, so it can be used e.g. in menus.
-    public void add_custom ()
+    public StockIcons ()
     {
-        register_my_stock_icons ();
+        register_new_stock_icons ();
+
         add_theme_icon_to_stock ("image-x-generic", "image");
         add_theme_icon_to_stock ("x-office-presentation", "presentation");
     }
 
-    private struct StockIcon
+    private void add_theme_icon_to_stock (string icon_name, string stock_id)
     {
-        string filename;
-        string stock_id;
+        Gtk.IconSource icon_source = new Gtk.IconSource ();
+        icon_source.set_icon_name (icon_name);
+
+        Gtk.IconSet icon_set = new Gtk.IconSet ();
+        icon_set.add_source (icon_source);
+
+        Gtk.IconFactory icon_factory = new Gtk.IconFactory ();
+        icon_factory.add (stock_id, icon_set);
+        icon_factory.add_default ();
     }
 
-    // TODO: use GResource
-    private const StockIcon[] stock_icons =
+    private void register_new_stock_icons ()
     {
-        { Config.DATA_DIR + "/images/icons/compile_dvi.png", "compile_dvi" },
-        { Config.DATA_DIR + "/images/icons/compile_pdf.png", "compile_pdf" },
-        { Config.DATA_DIR + "/images/icons/compile_ps.png", "compile_ps" },
-        { Config.DATA_DIR + "/images/icons/view_dvi.png", "view_dvi" },
-        { Config.DATA_DIR + "/images/icons/view_pdf.png", "view_pdf" },
-        { Config.DATA_DIR + "/images/icons/view_ps.png", "view_ps" },
-        { Config.DATA_DIR + "/images/icons/textbf.png", "bold" },
-        { Config.DATA_DIR + "/images/icons/textit.png", "italic" },
-        { Config.DATA_DIR + "/images/icons/texttt.png", "typewriter" },
-        { Config.DATA_DIR + "/images/icons/textsl.png", "slanted" },
-        { Config.DATA_DIR + "/images/icons/textsc.png", "small_caps" },
-        { Config.DATA_DIR + "/images/icons/textsf.png", "sans_serif" },
-        { Config.DATA_DIR + "/images/icons/roman.png", "roman" },
-        { Config.DATA_DIR + "/images/icons/underline.png", "underline" },
-        { Config.DATA_DIR + "/images/misc-math/set-R.png", "blackboard" },
-        { Config.DATA_DIR + "/images/icons/sectioning-part.png", "sectioning-part" },
-        { Config.DATA_DIR + "/images/icons/sectioning-chapter.png",
-            "sectioning-chapter" },
-        { Config.DATA_DIR + "/images/icons/sectioning-section.png",
-            "sectioning-section" },
-        { Config.DATA_DIR + "/images/icons/sectioning-subsection.png",
-            "sectioning-subsection" },
-        { Config.DATA_DIR + "/images/icons/sectioning-subsubsection.png",
-            "sectioning-subsubsection" },
-        { Config.DATA_DIR + "/images/icons/sectioning-paragraph.png",
-            "sectioning-paragraph" },
-        { Config.DATA_DIR + "/images/icons/character-size.png", "character-size" },
-        { Config.DATA_DIR + "/images/icons/list-itemize.png", "list-itemize" },
-        { Config.DATA_DIR + "/images/icons/list-enumerate.png", "list-enumerate" },
-        { Config.DATA_DIR + "/images/icons/list-description.png", "list-description" },
-        { Config.DATA_DIR + "/images/icons/list-item.png", "list-item" },
-        { Config.DATA_DIR + "/images/icons/references.png", "references" },
-        { Config.DATA_DIR + "/images/icons/math.png", "math" },
-        { Config.DATA_DIR + "/images/icons/math-centered.png", "math-centered" },
-        { Config.DATA_DIR + "/images/icons/math-numbered.png", "math-numbered" },
-        { Config.DATA_DIR + "/images/icons/math-array.png", "math-array" },
-        { Config.DATA_DIR + "/images/icons/math-numbered-array.png",
-            "math-numbered-array" },
-        { Config.DATA_DIR + "/images/icons/math-superscript.png", "math-superscript" },
-        { Config.DATA_DIR + "/images/icons/math-subscript.png", "math-subscript" },
-        { Config.DATA_DIR + "/images/icons/math-frac.png", "math-frac" },
-        { Config.DATA_DIR + "/images/icons/math-square-root.png", "math-square-root" },
-        { Config.DATA_DIR + "/images/icons/math-nth-root.png", "math-nth-root" },
-        { Config.DATA_DIR + "/images/icons/mathcal.png", "mathcal" },
-        { Config.DATA_DIR + "/images/icons/mathfrak.png", "mathfrak" },
-        { Config.DATA_DIR + "/images/icons/delimiters-left.png", "delimiters-left" },
-        { Config.DATA_DIR + "/images/icons/delimiters-right.png", "delimiters-right" },
-        { Config.DATA_DIR + "/images/icons/badbox.png", "badbox" },
-        { Config.DATA_DIR + "/images/icons/logviewer.png", "view_log" },
-        { Config.DATA_DIR + "/images/greek/01.png", "symbol_alpha" },
-        { Config.DATA_DIR + "/images/icons/accent0.png", "accent0" },
-        { Config.DATA_DIR + "/images/icons/accent1.png", "accent1" },
-        { Config.DATA_DIR + "/images/icons/accent2.png", "accent2" },
-        { Config.DATA_DIR + "/images/icons/accent3.png", "accent3" },
-        { Config.DATA_DIR + "/images/icons/accent4.png", "accent4" },
-        { Config.DATA_DIR + "/images/icons/accent5.png", "accent5" },
-        { Config.DATA_DIR + "/images/icons/accent6.png", "accent6" },
-        { Config.DATA_DIR + "/images/icons/accent7.png", "accent7" },
-        { Config.DATA_DIR + "/images/icons/accent8.png", "accent8" },
-        { Config.DATA_DIR + "/images/icons/accent9.png", "accent9" },
-        { Config.DATA_DIR + "/images/icons/accent10.png", "accent10" },
-        { Config.DATA_DIR + "/images/icons/accent11.png", "accent11" },
-        { Config.DATA_DIR + "/images/icons/accent12.png", "accent12" },
-        { Config.DATA_DIR + "/images/icons/accent13.png", "accent13" },
-        { Config.DATA_DIR + "/images/icons/accent14.png", "accent14" },
-        { Config.DATA_DIR + "/images/icons/accent15.png", "accent15" },
-        { Config.DATA_DIR + "/images/icons/mathaccent0.png", "mathaccent0" },
-        { Config.DATA_DIR + "/images/icons/mathaccent1.png", "mathaccent1" },
-        { Config.DATA_DIR + "/images/icons/mathaccent2.png", "mathaccent2" },
-        { Config.DATA_DIR + "/images/icons/mathaccent3.png", "mathaccent3" },
-        { Config.DATA_DIR + "/images/icons/mathaccent4.png", "mathaccent4" },
-        { Config.DATA_DIR + "/images/icons/mathaccent5.png", "mathaccent5" },
-        { Config.DATA_DIR + "/images/icons/mathaccent6.png", "mathaccent6" },
-        { Config.DATA_DIR + "/images/icons/mathaccent7.png", "mathaccent7" },
-        { Config.DATA_DIR + "/images/icons/mathaccent8.png", "mathaccent8" },
-        { Config.DATA_DIR + "/images/icons/mathaccent9.png", "mathaccent9" },
-        { Config.DATA_DIR + "/images/icons/mathaccent10.png", "mathaccent10" },
-        { Config.DATA_DIR + "/images/icons/completion_choice.png", "completion_choice" },
-        { Config.DATA_DIR + "/images/icons/completion_cmd.png", "completion_cmd" },
-        { Config.DATA_DIR + "/images/icons/tree_part.png", "tree_part" },
-        { Config.DATA_DIR + "/images/icons/tree_chapter.png", "tree_chapter" },
-        { Config.DATA_DIR + "/images/icons/tree_section.png", "tree_section" },
-        { Config.DATA_DIR + "/images/icons/tree_subsection.png", "tree_subsection" },
-        { Config.DATA_DIR + "/images/icons/tree_subsubsection.png",
-            "tree_subsubsection" },
-        { Config.DATA_DIR + "/images/icons/tree_paragraph.png", "tree_paragraph" },
-        { Config.DATA_DIR + "/images/icons/tree_todo.png", "tree_todo" },
-        { Config.DATA_DIR + "/images/icons/tree_label.png", "tree_label" },
-        { Config.DATA_DIR + "/images/icons/table.png", "table" }
-    };
+        string resource_path = "/org/gnome/latexila/stock-icons/";
+        string[] icon_files;
+
+        try
+        {
+            icon_files = resources_enumerate_children (resource_path, 0);
+        }
+        catch (Error e)
+        {
+            warning ("Failed to register new stock icons: %s", e.message);
+            return;
+        }
 
-    private void register_my_stock_icons ()
-    {
         Gtk.IconFactory icon_factory = new Gtk.IconFactory ();
 
-        foreach (StockIcon icon in stock_icons)
+        foreach (string icon_file in icon_files)
         {
             Gtk.IconSet icon_set = new Gtk.IconSet ();
             Gtk.IconSource icon_source = new Gtk.IconSource ();
-            icon_source.set_filename (icon.filename);
-            icon_set.add_source (icon_source);
-            icon_factory.add (icon.stock_id, icon_set);
-        }
+            Gdk.Pixbuf pixbuf;
 
-        icon_factory.add_default ();
-    }
+            try
+            {
+                pixbuf = Gdk.MyPixbuf.from_resource (resource_path + icon_file);
+            }
+            catch (Error e)
+            {
+                warning ("Failed to register stock icon: %s", e.message);
+                continue;
+            }
 
-    private void add_theme_icon_to_stock (string icon_name, string stock_id)
-    {
-        Gtk.IconSource icon_source = new Gtk.IconSource ();
-        icon_source.set_icon_name (icon_name);
+            icon_source.set_pixbuf (pixbuf);
+            icon_set.add_source (icon_source);
 
-        Gtk.IconSet icon_set = new Gtk.IconSet ();
-        icon_set.add_source (icon_source);
+            string icon_name = Utils.get_shortname (icon_file);
+            icon_factory.add (icon_name, icon_set);
+        }
 
-        Gtk.IconFactory icon_factory = new Gtk.IconFactory ();
-        icon_factory.add (stock_id, icon_set);
         icon_factory.add_default ();
     }
 }
diff --git a/vapi/gdk-pixbuf.vapi b/vapi/gdk-pixbuf.vapi
new file mode 100644
index 0000000..0bb0574
--- /dev/null
+++ b/vapi/gdk-pixbuf.vapi
@@ -0,0 +1,8 @@
+namespace Gdk
+{
+    namespace MyPixbuf
+    {
+        [CCode (cname = "gdk_pixbuf_new_from_resource", cheader_filename = "gdk-pixbuf/gdk-pixbuf.h")]
+        public static Gdk.Pixbuf from_resource (string resource_path) throws GLib.Error;
+    }
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]