[glom] Load whole glade files, to get secondary objects without listing them.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] Load whole glade files, to get secondary objects without listing them.
- Date: Mon, 29 Aug 2011 11:12:04 +0000 (UTC)
commit 3835455538cbc9a2c55418a6233bf84859a4c20f
Author: Murray Cumming <murrayc murrayc com>
Date: Mon Aug 29 12:50:09 2011 +0200
Load whole glade files, to get secondary objects without listing them.
* glom/glade_utils.h: helper_get_glade_widget_derived_with_warning():
Add a bool so we can choose to load the whole .glade file.
get_glade_widget_derived_with_warning(): Load the whole file.
Add get_child_glade_child_widget_derived_with_warning(), which does not load
the whole file.
* glom/frame_glom.cc:
* glom/mode_design/fields/dialog_fielddefinition.cc:
* glom/mode_design/layout/layout_item_dialogs/dialog_field_layout.cc:
* glom/mode_design/layout/layout_item_dialogs/dialog_formatting.cc:
* glom/mode_design/print_layouts/dialog_text_formatting.cc: Use this to load
boxes when we do not want the whole window that they are in.
This was the main reason for splitting the .glade files up - to work
around GtkBuilder's inability to automatically load secondary objects.
ChangeLog | 19 +++++++++++
glom/frame_glom.cc | 6 ++--
glom/glade_utils.h | 35 +++++++++++++++++--
glom/mode_design/fields/dialog_fielddefinition.cc | 2 +-
.../layout_item_dialogs/dialog_field_layout.cc | 2 +-
.../layout_item_dialogs/dialog_formatting.cc | 2 +-
.../layout_item_dialogs/dialog_textobject.cc | 1 -
.../print_layouts/dialog_text_formatting.cc | 2 +-
8 files changed, 57 insertions(+), 12 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 95d0c00..ff9eaff 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2011-08-29 Murray Cumming <murrayc murrayc com>
+
+ Load whole glade files, to get secondary objects without listing them.
+
+ * glom/glade_utils.h: helper_get_glade_widget_derived_with_warning():
+ Add a bool so we can choose to load the whole .glade file.
+ get_glade_widget_derived_with_warning(): Load the whole file.
+ Add get_child_glade_child_widget_derived_with_warning(), which does not load
+ the whole file.
+ * glom/frame_glom.cc:
+ * glom/mode_design/fields/dialog_fielddefinition.cc:
+ * glom/mode_design/layout/layout_item_dialogs/dialog_field_layout.cc:
+ * glom/mode_design/layout/layout_item_dialogs/dialog_formatting.cc:
+ * glom/mode_design/print_layouts/dialog_text_formatting.cc: Use this to load
+ boxes when we do not want the whole window that they are in.
+
+ This was the main reason for splitting the .glade files up - to work
+ around GtkBuilder's inability to automatically load secondary objects.
+
2011-08-28 Murray Cumming <murrayc murrayc com>
Remove unused .glade file.
diff --git a/glom/frame_glom.cc b/glom/frame_glom.cc
index 234a6af..68319a9 100644
--- a/glom/frame_glom.cc
+++ b/glom/frame_glom.cc
@@ -1293,7 +1293,7 @@ void Frame_Glom::do_menu_Navigate_Table(bool open_default)
//Create the dialog, if it has not already been created:
if(!m_pBox_Tables)
{
- Utils::get_glade_widget_derived_with_warning(m_pBox_Tables);
+ Utils::get_glade_child_widget_derived_with_warning(m_pBox_Tables);
m_pDialog_Tables = new Window_BoxHolder(m_pBox_Tables, _("Edit Tables"));
m_pDialog_Tables->signal_hide().connect(sigc::mem_fun(*this, &Frame_Glom::on_dialog_tables_hide));
@@ -1739,7 +1739,7 @@ void Frame_Glom::on_menu_developer_reports()
//Create the widget if necessary:
if(!m_pBox_Reports)
{
- Utils::get_glade_widget_derived_with_warning(m_pBox_Reports);
+ Utils::get_glade_child_widget_derived_with_warning(m_pBox_Reports);
m_pDialog_Reports = new Window_BoxHolder(m_pBox_Reports);
m_pDialog_Reports->set_transient_for(*(get_app_window()));
m_pDialog_Reports->set_title(_("Reports"));
@@ -1769,7 +1769,7 @@ void Frame_Glom::on_menu_developer_print_layouts()
//Create the widget if necessary:
if(!m_pBox_PrintLayouts)
{
- Utils::get_glade_widget_derived_with_warning(m_pBox_PrintLayouts);
+ Utils::get_glade_child_widget_derived_with_warning(m_pBox_PrintLayouts);
m_pDialog_PrintLayouts = new Window_BoxHolder(m_pBox_PrintLayouts);
m_pDialog_PrintLayouts->set_transient_for(*get_app_window());
diff --git a/glom/glade_utils.h b/glom/glade_utils.h
index 0453217..e6d07a8 100644
--- a/glom/glade_utils.h
+++ b/glom/glade_utils.h
@@ -56,14 +56,22 @@ inline std::string get_glade_file_path(const std::string& filename)
return Glib::build_filename(GLOM_PKGDATADIR_NOTINSTALLED, filename);
}
+/** This assumes that there are no other top-level windows in the glade file.
+ * This allows us to get all object, including any necessary secondary objects,
+ * such as a GtkSpinButton's GtkAdjustment.
+ */
template<class T_Widget>
-void helper_get_glade_widget_derived_with_warning(const std::string& filename, const Glib::ustring& id, T_Widget*& widget)
+void helper_get_glade_widget_derived_with_warning(const std::string& filename, const Glib::ustring& id, T_Widget*& widget, bool load_all)
{
Glib::RefPtr<Gtk::Builder> refXml;
try
{
- refXml = Gtk::Builder::create_from_file(Utils::get_glade_file_path(filename), id);
+ const std::string filepath = Utils::get_glade_file_path(filename);
+ if(load_all)
+ refXml = Gtk::Builder::create_from_file(filepath);
+ else
+ refXml = Gtk::Builder::create_from_file(filepath, id);
}
catch(const Gtk::BuilderError& ex)
{
@@ -85,9 +93,10 @@ void helper_get_glade_widget_derived_with_warning(const std::string& filename, c
}
/** This should be used with classes that have a static glade_id member.
+ * This loads only the widget's own object, as specified by its ID.
*/
template<class T_Widget>
-void get_glade_widget_derived_with_warning(T_Widget*& widget)
+void get_glade_child_widget_derived_with_warning(T_Widget*& widget)
{
widget = 0;
@@ -97,9 +106,27 @@ void get_glade_widget_derived_with_warning(T_Widget*& widget)
(T_Widget::glade_developer ? "developer" : "operator"),
std::string(T_Widget::glade_id) + ".glade");
- helper_get_glade_widget_derived_with_warning(filename, T_Widget::glade_id, widget);
+ helper_get_glade_widget_derived_with_warning(filename, T_Widget::glade_id, widget, false /* load just this */);
}
+/** This should be used with classes that have a static glade_id member.
+ * This assumes that there are no other top-level windows in the glade file.
+ * This allows us to get all object, including any necessary secondary objects,
+ * such as a GtkSpinButton's GtkAdjustment.
+ */
+template<class T_Widget>
+void get_glade_widget_derived_with_warning(T_Widget*& widget)
+{
+ widget = 0;
+
+ // Check the path to the installed .glade file:
+ // The id is the same as the filename, in a developer/operator sub-directory:
+ const std::string filename = Glib::build_filename(
+ (T_Widget::glade_developer ? "developer" : "operator"),
+ std::string(T_Widget::glade_id) + ".glade");
+
+ helper_get_glade_widget_derived_with_warning(filename, T_Widget::glade_id, widget, true /* load_all */);
+}
template<class T_Widget>
void get_glade_widget_with_warning(const std::string& filename, const Glib::ustring& id, T_Widget*& widget)
diff --git a/glom/mode_design/fields/dialog_fielddefinition.cc b/glom/mode_design/fields/dialog_fielddefinition.cc
index 76c9ee6..5be6478 100644
--- a/glom/mode_design/fields/dialog_fielddefinition.cc
+++ b/glom/mode_design/fields/dialog_fielddefinition.cc
@@ -87,7 +87,7 @@ Dialog_FieldDefinition::Dialog_FieldDefinition(BaseObjectType* cobject, const Gl
builder->get_widget("box_formatting_placeholder", m_box_formatting_placeholder);
//Get the formatting stuff:
- Utils::get_glade_widget_derived_with_warning(m_box_formatting);
+ Utils::get_glade_child_widget_derived_with_warning(m_box_formatting);
if(m_box_formatting) ////Unlikely to fail and it already warns on stderr.
m_box_formatting_placeholder->pack_start(*m_box_formatting);
diff --git a/glom/mode_design/layout/layout_item_dialogs/dialog_field_layout.cc b/glom/mode_design/layout/layout_item_dialogs/dialog_field_layout.cc
index d7a80ad..4e06915 100644
--- a/glom/mode_design/layout/layout_item_dialogs/dialog_field_layout.cc
+++ b/glom/mode_design/layout/layout_item_dialogs/dialog_field_layout.cc
@@ -54,7 +54,7 @@ Dialog_FieldLayout::Dialog_FieldLayout(BaseObjectType* cobject, const Glib::RefP
builder->get_widget("box_formatting_placeholder", m_box_formatting_placeholder);
//Get the formatting stuff:
- Utils::get_glade_widget_derived_with_warning(m_box_formatting);
+ Utils::get_glade_child_widget_derived_with_warning(m_box_formatting);
m_box_formatting_placeholder->pack_start(*m_box_formatting);
add_view(m_box_formatting);
diff --git a/glom/mode_design/layout/layout_item_dialogs/dialog_formatting.cc b/glom/mode_design/layout/layout_item_dialogs/dialog_formatting.cc
index 366fec6..4227e81 100644
--- a/glom/mode_design/layout/layout_item_dialogs/dialog_formatting.cc
+++ b/glom/mode_design/layout/layout_item_dialogs/dialog_formatting.cc
@@ -33,7 +33,7 @@ Dialog_Formatting::Dialog_Formatting()
set_border_width(6);
//Get the formatting stuff:
- Utils::get_glade_widget_derived_with_warning(m_box_formatting);
+ Utils::get_glade_child_widget_derived_with_warning(m_box_formatting);
get_content_area()->pack_start(*m_box_formatting, Gtk::PACK_EXPAND_WIDGET);
add_view(m_box_formatting);
diff --git a/glom/mode_design/layout/layout_item_dialogs/dialog_textobject.cc b/glom/mode_design/layout/layout_item_dialogs/dialog_textobject.cc
index 443ccb7..72655ab 100644
--- a/glom/mode_design/layout/layout_item_dialogs/dialog_textobject.cc
+++ b/glom/mode_design/layout/layout_item_dialogs/dialog_textobject.cc
@@ -20,7 +20,6 @@
#include "dialog_textobject.h"
-#include <glom/python_embed/glom_python.h>
#include <libglom/data_structure/glomconversions.h>
//#include <libgnome/gnome-i18n.h>
diff --git a/glom/mode_design/print_layouts/dialog_text_formatting.cc b/glom/mode_design/print_layouts/dialog_text_formatting.cc
index 4ed8816..de52592 100644
--- a/glom/mode_design/print_layouts/dialog_text_formatting.cc
+++ b/glom/mode_design/print_layouts/dialog_text_formatting.cc
@@ -42,7 +42,7 @@ Dialog_TextFormatting::Dialog_TextFormatting(BaseObjectType* cobject, const Glib
//Get the place to put the Formatting stuff:
builder->get_widget("box_formatting_placeholder", m_box_formatting_placeholder);
- Utils::get_glade_widget_derived_with_warning(m_box_formatting);
+ Utils::get_glade_child_widget_derived_with_warning(m_box_formatting);
m_box_formatting_placeholder->pack_start(*m_box_formatting);
add_view(m_box_formatting);
m_box_formatting->set_is_for_non_editable();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]