[gtkmm] Builder: Wrap the GResource convenience API.



commit 1c378f765fdb567975f0f0d38c892b7b6efb5a05
Author: Kalev Lember <kalevlember gmail com>
Date:   Fri Apr 20 22:04:12 2012 +0300

    Builder: Wrap the GResource convenience API.
    
    * builder.[hg|ccg]: Added create_from_resource() and
    add_from_resource() with their many overloads.
    Bug #674545.

 ChangeLog           |    8 ++++
 gtk/src/builder.ccg |   53 ++++++++++++++++++++++++
 gtk/src/builder.hg  |  111 +++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 172 insertions(+), 0 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 05bc22d..c5ee2b1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-04-21  Kalev Lember  <kalevlember gmail com>
+
+	Builder: Wrap the GResource convenience API.
+
+	* builder.[hg|ccg]: Added create_from_resource() and
+	add_from_resource() with their many overloads.
+	Bug #674545.
+
 2012-04-19  Murray Cumming  <murrayc murrayc com>
 
 	Application: add_window(): Correct the documentation.
diff --git a/gtk/src/builder.ccg b/gtk/src/builder.ccg
index 1d1a402..ff2e054 100644
--- a/gtk/src/builder.ccg
+++ b/gtk/src/builder.ccg
@@ -88,6 +88,46 @@ Glib::RefPtr<Builder> Builder::create_from_file(const std::string& filename, con
     return Glib::RefPtr<Builder>();
 }
 
+// static
+Glib::RefPtr<Builder> Builder::create_from_resource(const std::string& resource_path)
+{
+  Glib::RefPtr<Builder> builder = Builder::create();
+  if(builder->add_from_resource(resource_path))
+    return builder;
+  else
+    return Glib::RefPtr<Builder>();
+}
+
+// static
+Glib::RefPtr<Builder> Builder::create_from_resource(const std::string& resource_path, const char* object_id)
+{
+  Glib::RefPtr<Builder> builder = Builder::create();
+  if(builder->add_from_resource(resource_path, object_id))
+    return builder;
+  else
+    return Glib::RefPtr<Builder>();
+}
+
+//static
+Glib::RefPtr<Builder> Builder::create_from_resource(const std::string& resource_path, const Glib::ustring& object_id)
+{
+  Glib::RefPtr<Builder> builder = Builder::create();
+  if(builder->add_from_resource(resource_path, object_id))
+    return builder;
+  else
+    return Glib::RefPtr<Builder>();
+}
+
+//static
+Glib::RefPtr<Builder> Builder::create_from_resource(const std::string& resource_path, const std::vector<Glib::ustring>& object_ids)
+{
+  Glib::RefPtr<Builder> builder = Builder::create();
+  if(builder->add_from_resource(resource_path, object_ids))
+    return builder;
+  else
+    return Glib::RefPtr<Builder>();
+}
+
 //static
 Glib::RefPtr<Builder> Builder::create_from_string(const Glib::ustring& buffer)
 {
@@ -145,6 +185,19 @@ bool Builder::add_from_file(const std::string& filename, const Glib::ustring& ob
   return add_from_file(filename, object_ids);
 }
 
+bool Builder::add_from_resource(const std::string& resource_path, const char* object_id)
+{
+  std::vector<Glib::ustring> object_ids (1, object_id);
+
+  return add_from_resource(resource_path, object_ids);
+}
+
+bool Builder::add_from_resource(const std::string& resource_path, const Glib::ustring& object_id)
+{
+  std::vector<Glib::ustring> object_ids (1, object_id);
+
+  return add_from_resource(resource_path, object_ids);
+}
 
 bool Builder::add_from_string(const Glib::ustring& buffer)
 {
diff --git a/gtk/src/builder.hg b/gtk/src/builder.hg
index 8b771ab..54a53b4 100644
--- a/gtk/src/builder.hg
+++ b/gtk/src/builder.hg
@@ -109,6 +109,65 @@ public:
    */
   static Glib::RefPtr<Builder> create_from_file(const std::string& filename, const std::vector<Glib::ustring>& object_ids);
 
+
+  /** Parses a resource file containing a GtkBuilder UI definition.
+   *
+   * @param resource_path The path of the resource file to parse.
+   * @result A new Builder object, or a null pointer if an error occurred.
+   * @throws BuilderError, Glib::MarkupError, Gio::ResourceError
+   *
+   * @newin{3,6}
+   */
+  static Glib::RefPtr<Builder> create_from_resource(const std::string& resource_path);
+
+  /** Parses a resource file containing a GtkBuilder UI definition, building only the requested object.
+   *
+   * If you are adding an object that depends on an object that is not
+   * its child (for instance a GtkTreeView that depends on its
+   * GtkTreeModel), you have to explicitely list all of them.
+   *
+   * @param resource_path The path of the resource file to parse.
+   * @param object_id The object to build.
+   * @result A new Builder object, or a null pointer if an error occurred.
+   * @throws BuilderError, Glib::MarkupError, Gio::ResourceError
+   *
+   * @newin{3,6}
+   */
+  static Glib::RefPtr<Builder> create_from_resource(const std::string& resource_path, const Glib::ustring& object_id);
+
+  //This is just to avoid the ambiguous call when using a string literal,
+  //caused by the overload that takes a std::vector<Glib::ustring>.
+  /** Parses a resource file containing a GtkBuilder UI definition, building only the requested object.
+   *
+   * If you are adding an object that depends on an object that is not
+   * its child (for instance a GtkTreeView that depends on its
+   * GtkTreeModel), you have to explicitely list all of them.
+   *
+   * @param resource_path The path of the resource file to parse.
+   * @param object_id The object to build.
+   * @result A new Builder object, or a null pointer if an error occurred.
+   * @throws BuilderError, Glib::MarkupError, Gio::ResourceError
+   *
+   * @newin{3,6}
+   */
+  static Glib::RefPtr<Builder> create_from_resource(const std::string& resource_path, const char* object_id);
+
+  /** Parses a resource file containing a GtkBuilder UI definition, building only the requested objects.
+   *
+   * If you are adding an object that depends on an object that is not
+   * its child (for instance a GtkTreeView that depends on its
+   * GtkTreeModel), you have to explicitely list all of them.
+   *
+   * @param resource_path The path of the resource file to parse.
+   * @param object_ids The objects to build.
+   * @result A new Builder object, or a null pointer if an error occurred.
+   * @throws BuilderError, Glib::MarkupError, Gio::ResourceError
+   *
+   * @newin{3,6}
+   */
+  static Glib::RefPtr<Builder> create_from_resource(const std::string& resource_path, const std::vector<Glib::ustring>& object_ids);
+
+
   /** Parses a string containing a GtkBuilder UI definition.
    *
    * @param buffer: the string to parse
@@ -208,6 +267,58 @@ public:
 #m4 _CONVERSION(`const std::vector<Glib::ustring>&',`gchar**',`const_cast<char**>(Glib::ArrayHandler<Glib::ustring>::vector_to_array($3).data())')
   _WRAP_METHOD(bool add_from_file(const std::string& filename, const std::vector<Glib::ustring>& object_ids),  gtk_builder_add_objects_from_file, errthrow)
 
+
+  /** Parses a resource file containing a GtkBuilder UI definition,
+   * and merges it with the current contents of the builder.
+   *
+   * @param resource_path The path of the resource file to parse.
+   * @result true on success or false if an error occurred.
+   * @throws BuilderError, Glib::MarkupError, Gio::ResourceError
+   *
+   * @newin{3,6}
+   */
+  _WRAP_METHOD(bool add_from_resource(const std::string& resource_path), gtk_builder_add_from_resource, errthrow)
+
+  //This is just to avoid the ambiguous call when using a string literal,
+  //caused by the overload that takes a std::vector<Glib::ustring>.
+  /** Parses a resource file containing a GtkBuilder UI definition,
+   * building only the requested object,
+   * and merges it with the current contents of the builder.
+   *
+   * If you are adding an object that depends on an object that is not
+   * its child (for instance a GtkTreeView that depends on its
+   * GtkTreeModel), you have to explicitely list all of them.
+   *
+   * @param resource_path The path of the resource file to parse.
+   * @param object_id The object to build.
+   * @result true on success or false if an error occurred.
+   * @throws BuilderError, Glib::MarkupError, Gio::ResourceError
+   *
+   * @newin{3,6}
+   */
+  bool add_from_resource(const std::string& resource_path, const char* object_id);
+
+  /** Parses a resource file containing a GtkBuilder UI definition,
+   * building only the requested object,
+   * and merges it with the current contents of the builder.
+   *
+   * If you are adding an object that depends on an object that is not
+   * its child (for instance a GtkTreeView that depends on its
+   * GtkTreeModel), you have to explicitely list all of them.
+   *
+   * @param resource_path The path of the resource file to parse.
+   * @param object_id The object to build.
+   * @result true on success or false if an error occurred.
+   * @throws BuilderError, Glib::MarkupError, Gio::ResourceError
+   *
+   * @newin{3,6}
+   */
+  bool add_from_resource(const std::string& resource_path, const Glib::ustring& object_id);
+
+#m4 _CONVERSION(`const std::vector<Glib::ustring>&',`gchar**',`const_cast<char**>(Glib::ArrayHandler<Glib::ustring>::vector_to_array($3).data())')
+  _WRAP_METHOD(bool add_from_resource(const std::string& resource_path, const std::vector<Glib::ustring>& object_ids),  gtk_builder_add_objects_from_resource, errthrow)
+
+
   //This is just to avoid the ambiguous call when using a string literal, 
   //caused by the overload that takes a std::vector<Glib::ustring>.
   /** Parses a string containing a GtkBuilder UI definition 



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