[glom] New ID in progress
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glom] New ID in progress
- Date: Fri, 23 Dec 2011 12:14:50 +0000 (UTC)
commit e3231b2a09cfe2042296411a882e2fb0fd5d257d
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Dec 21 21:56:53 2011 +0100
New ID in progress
Makefile_glom.am | 4 +-
glom/mode_data/box_data_details.cc | 1 -
glom/mode_data/datawidget/datawidget.cc | 67 ++++++++++++
glom/mode_data/datawidget/datawidget.h | 5 +
glom/mode_data/datawidget/dialog_new_record.cc | 90 ++++++++++++++++
glom/mode_data/datawidget/dialog_new_record.h | 67 ++++++++++++
po/POTFILES.in | 1 +
tests/test_glade_derived_instantiation.cc | 34 +++---
ui/operator/dialog_new_record.glade | 133 ++++++++++++++++++++++++
9 files changed, 384 insertions(+), 18 deletions(-)
---
diff --git a/Makefile_glom.am b/Makefile_glom.am
index b756d3f..ce853b6 100644
--- a/Makefile_glom.am
+++ b/Makefile_glom.am
@@ -173,7 +173,9 @@ glom_source_files = \
glom/mode_data/datawidget/dialog_choose_date.cc \
glom/mode_data/datawidget/dialog_choose_date.h \
glom/mode_data/datawidget/dialog_choose_id.cc \
- glom/mode_data/datawidget/dialog_choose_id.h \
+ glom/mode_data/datawidget/dialog_choose_id.h \
+ glom/mode_data/datawidget/dialog_new_record.cc \
+ glom/mode_data/datawidget/dialog_new_record.h \
glom/mode_data/datawidget/combo.cc \
glom/mode_data/datawidget/combo.h \
glom/mode_data/datawidget/combochoices.cc \
diff --git a/glom/mode_data/box_data_details.cc b/glom/mode_data/box_data_details.cc
index 3ebfd75..8ac054a 100644
--- a/glom/mode_data/box_data_details.cc
+++ b/glom/mode_data/box_data_details.cc
@@ -864,7 +864,6 @@ void Box_Data_Details::on_flowtable_field_edited(const sharedptr<const LayoutIte
else
{
//It is not auto-generated:
-
if(m_field_primary_key && strFieldName == m_field_primary_key->get_name()) //if it is the primary key that is being edited.
{
if(!check_entered_value_for_uniqueness(m_table_name, layout_field, field_value, window))
diff --git a/glom/mode_data/datawidget/datawidget.cc b/glom/mode_data/datawidget/datawidget.cc
index 39fbd7b..5b21033 100644
--- a/glom/mode_data/datawidget/datawidget.cc
+++ b/glom/mode_data/datawidget/datawidget.cc
@@ -32,6 +32,7 @@
#include <glom/mode_design/layout/dialog_choose_field.h>
#include <glom/mode_data/datawidget/dialog_choose_id.h>
#include <glom/mode_data/datawidget/dialog_choose_date.h>
+#include <glom/mode_data/datawidget/dialog_new_record.h>
#include <glom/mode_design/layout/layout_item_dialogs/dialog_field_layout.h>
#include <glom/utils_ui.h>
#include <glom/glade_utils.h>
@@ -231,6 +232,11 @@ DataWidget::DataWidget(const sharedptr<LayoutItem_Field>& field, const Glib::ust
button_select->set_tooltip_text(_("Enter search criteria to identify records in the other table, to choose an ID for this field."));
hbox_parent->pack_start(*button_select, Gtk::PACK_SHRINK);
button_select->signal_clicked().connect(sigc::mem_fun(*this, &DataWidget::on_button_select_id));
+
+ Gtk::Button* button_new = Gtk::manage(new Gtk::Button(Gtk::Stock::NEW));
+ button_new->set_tooltip_text(_("Enter details for a new record in the other table, then use its ID for this field."));
+ hbox_parent->pack_start(*button_new, Gtk::PACK_SHRINK);
+ button_new->signal_clicked().connect(sigc::mem_fun(*this, &DataWidget::on_button_new_id));
}
}
@@ -587,6 +593,18 @@ const Gtk::Widget* DataWidget::get_data_child_widget() const
}
}
+void DataWidget::on_button_new_id()
+{
+ Gnome::Gda::Value chosen_id;
+ const bool chosen = offer_related_record_id_new(chosen_id);
+ std::cout << "debug: chosen_id=" << chosen_id.to_string() << std::endl;
+ if(chosen)
+ {
+ set_value(chosen_id);
+ m_signal_edited.emit(chosen_id);
+ }
+}
+
void DataWidget::on_button_choose_date()
{
DataWidgetChildren::Dialog_ChooseDate* dialog = 0;
@@ -668,4 +686,53 @@ bool DataWidget::offer_related_record_id_find(Gnome::Gda::Value& chosen_id)
return result;
}
+
+bool DataWidget::offer_related_record_id_new(Gnome::Gda::Value& chosen_id)
+{
+ bool result = false;
+
+ //Initialize output variable:
+ chosen_id = Gnome::Gda::Value();
+
+ DataWidgetChildren::Dialog_NewRecord* dialog = 0;
+ Glom::Utils::get_glade_widget_derived_with_warning(dialog);
+
+ if(dialog)
+ {
+ //dialog->set_document(get_document(), table_name, field);
+ Gtk::Window* parent = get_application();
+ if(parent)
+ dialog->set_transient_for(*parent);
+ add_view(dialog);
+
+ //Discover the related table, in the relationship that uses this ID field:
+ Glib::ustring related_table_name;
+ sharedptr<const LayoutItem_Field> layoutField = sharedptr<LayoutItem_Field>::cast_dynamic(get_layout_item());
+ if(layoutField)
+ {
+ sharedptr<const Relationship> relationship = get_document()->get_field_used_in_relationship_to_one(m_table_name, layoutField);
+ if(relationship)
+ related_table_name = relationship->get_to_table();
+ }
+ else
+ g_warning("get_layout_item() was not a LayoutItem_Field");
+
+ dialog->init_db_details(related_table_name, Base_DB::get_active_layout_platform(get_document()));
+
+
+ const int response = dialog->run();
+ dialog->hide();
+ if(response == Gtk::RESPONSE_OK)
+ {
+ //Get the chosen field:
+ result = dialog->get_id_chosen(chosen_id);
+ }
+
+ remove_view(dialog);
+ delete dialog;
+ }
+
+ return result;
+}
+
} //namespace Glom
diff --git a/glom/mode_data/datawidget/datawidget.h b/glom/mode_data/datawidget/datawidget.h
index 16e9000..6d0d422 100644
--- a/glom/mode_data/datawidget/datawidget.h
+++ b/glom/mode_data/datawidget/datawidget.h
@@ -92,6 +92,7 @@ private:
#endif // !GLOM_ENABLE_CLIENT_ONLY
void on_button_open_details();
void on_button_select_id();
+ void on_button_new_id();
void on_button_choose_date();
// Don't call it on_style_changed, otherwise we would override a virtual
@@ -115,6 +116,10 @@ private:
*/
bool offer_related_record_id_find(Gnome::Gda::Value& chosen_id);
+ /** Show a dialog with Details so that the user can add a new record and then use that ID value to indicate that related record.
+ */
+ bool offer_related_record_id_new(Gnome::Gda::Value& chosen_id);
+
private:
void update_go_to_details_button_sensitivity();
diff --git a/glom/mode_data/datawidget/dialog_new_record.cc b/glom/mode_data/datawidget/dialog_new_record.cc
new file mode 100644
index 0000000..f6f987b
--- /dev/null
+++ b/glom/mode_data/datawidget/dialog_new_record.cc
@@ -0,0 +1,90 @@
+/* Glom
+ *
+ * Copyright (C) 2001-2004 Murray Cumming
+ *
+ * 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.
+ */
+
+#include "dialog_new_record.h"
+#include <glom/utils_ui.h> //For bold_message()).
+//#include <libgnome/gnome-i18n.h>
+#include <glibmm/i18n.h>
+
+namespace Glom
+{
+
+namespace DataWidgetChildren
+{
+
+const char* Dialog_NewRecord::glade_id("dialog_new_record");
+const bool Dialog_NewRecord::glade_developer(false);
+
+Dialog_NewRecord::Dialog_NewRecord()
+: m_label_table_name(0),
+ m_alignment_parent(0)
+{
+}
+
+Dialog_NewRecord::Dialog_NewRecord(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder)
+: Gtk::Dialog(cobject),
+ m_label_table_name(0),
+ m_alignment_parent(0)
+{
+ builder->get_widget("label_table_name", m_label_table_name);
+ builder->get_widget("alignment_parent", m_alignment_parent);
+
+ setup();
+}
+
+Dialog_NewRecord::~Dialog_NewRecord()
+{
+ remove_view(&m_box_details);
+}
+
+void Dialog_NewRecord::setup()
+{
+ m_alignment_parent->add(m_box_details);
+
+ //Fill composite view:
+ add_view(&m_box_details);
+}
+
+bool Dialog_NewRecord::get_id_chosen(Gnome::Gda::Value& chosen_id) const
+{
+ chosen_id = m_box_details.get_primary_key_value_selected();
+ return true;
+}
+
+bool Dialog_NewRecord::init_db_details(const Glib::ustring& table_name, const Glib::ustring& layout_platform)
+{
+ m_table_name = table_name;
+ m_layout_platform = layout_platform;
+
+ m_label_table_name->set_text( get_document()->get_table_title(m_table_name) );
+
+ FoundSet found_set;
+ found_set.m_table_name = m_table_name;
+ const Gnome::Gda::Value primary_key_for_details;
+ const bool result = m_box_details.init_db_details(found_set, layout_platform, primary_key_for_details);
+ m_box_details.do_new_record();
+
+ m_table_name = table_name;
+
+ return result;
+}
+
+} //namespace DataWidetChildren
+} //namespace Glom
diff --git a/glom/mode_data/datawidget/dialog_new_record.h b/glom/mode_data/datawidget/dialog_new_record.h
new file mode 100644
index 0000000..f64a521
--- /dev/null
+++ b/glom/mode_data/datawidget/dialog_new_record.h
@@ -0,0 +1,67 @@
+/* Glom
+ *
+ * Copyright (C) 2001-2004 Murray Cumming
+ *
+ * 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.
+ */
+
+#ifndef GLOM_MODE_DATA_DIALOG_NEW_RECORD_H
+#define GLOM_MODE_DATA_DIALOG_NEW_RECORD_H
+
+#include <gtkmm/dialog.h>
+#include <libglom/document/document.h>
+#include <glom/base_db.h>
+#include <glom/mode_data/box_data_details.h>
+
+namespace Glom
+{
+
+namespace DataWidgetChildren
+{
+
+class Dialog_NewRecord
+ : public Gtk::Dialog,
+ public View_Composite_Glom
+{
+public:
+ static const char* glade_id;
+ static const bool glade_developer;
+
+ Dialog_NewRecord();
+ Dialog_NewRecord(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder);
+ virtual ~Dialog_NewRecord();
+
+ virtual bool init_db_details(const Glib::ustring& table_name, const Glib::ustring& layout_platform);
+
+ bool get_id_chosen(Gnome::Gda::Value& chosen_id) const;
+
+private:
+
+ void setup();
+
+ Gtk::Label* m_label_table_name;
+ Gtk::Alignment* m_alignment_parent;
+
+ Glib::ustring m_table_name;
+ Glib::ustring m_layout_platform;
+
+ Box_Data_Details m_box_details;
+};
+
+} //namespace DataWidetChildren
+} //namespace Glom
+
+#endif //GLOM_MODE_DATA_DIALOG_NEW_RECORD_H
diff --git a/po/POTFILES.in b/po/POTFILES.in
index f056d39..4af0307 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -144,6 +144,7 @@ ui/operator/dialog_connection.glade
ui/operator/dialog_data_invalid_format.glade
ui/operator/dialog_existing_or_new.glade
ui/operator/dialog_find_id.glade
+ui/operator/dialog_new_record.glade
ui/operator/dialog_image_load_progress.glade
ui/operator/dialog_image_save_progress.glade
ui/operator/dialog_import_csv.glade
diff --git a/tests/test_glade_derived_instantiation.cc b/tests/test_glade_derived_instantiation.cc
index a7cc090..98160ac 100644
--- a/tests/test_glade_derived_instantiation.cc
+++ b/tests/test_glade_derived_instantiation.cc
@@ -1,19 +1,3 @@
-#include <glom/glade_utils.h>
-#include <glom/application.h>
-#include <glom/dialog_existing_or_new.h>
-#include <glom/mode_design/print_layouts/box_print_layouts.h>
-#include <glom/mode_design/relationships_overview/dialog_relationships_overview.h>
-#include <glom/mode_design/dialog_relationships.h>
-#include <glom/mode_design/report_layout/dialog_layout_report.h>
-#include <glom/box_reports.h>
-#include <glom/navigation/box_tables.h>
-#include <glom/import_csv/dialog_import_csv.h>
-#include <glom/import_csv/dialog_import_csv_progress.h>
-#include <glom/mode_data/datawidget/dialog_choose_date.h>
-#include <glom/mode_data/datawidget/dialog_choose_id.h>
-#include <glom/utility_widgets/dialog_flowtable.h>
-#include <glom/utility_widgets/dialog_image_load_progress.h>
-#include <glom/utility_widgets/dialog_image_save_progress.h>
/* Glom
*
* Copyright (C) 2010-2011 Murray Cumming
@@ -34,6 +18,23 @@
* Boston, MA 02111-1307, USA.
*/
+#include <glom/glade_utils.h>
+#include <glom/application.h>
+#include <glom/dialog_existing_or_new.h>
+#include <glom/mode_design/print_layouts/box_print_layouts.h>
+#include <glom/mode_design/relationships_overview/dialog_relationships_overview.h>
+#include <glom/mode_design/dialog_relationships.h>
+#include <glom/mode_design/report_layout/dialog_layout_report.h>
+#include <glom/box_reports.h>
+#include <glom/navigation/box_tables.h>
+#include <glom/import_csv/dialog_import_csv.h>
+#include <glom/import_csv/dialog_import_csv_progress.h>
+#include <glom/mode_data/datawidget/dialog_choose_date.h>
+#include <glom/mode_data/datawidget/dialog_choose_id.h>
+#include <glom/mode_data/datawidget/dialog_new_record.h>
+#include <glom/utility_widgets/dialog_flowtable.h>
+#include <glom/utility_widgets/dialog_image_load_progress.h>
+#include <glom/utility_widgets/dialog_image_save_progress.h>
#include <glom/mode_design/layout/dialog_choose_field.h>
#include <glom/mode_design/dialog_add_related_table.h>
#include <glom/mode_design/layout/layout_item_dialogs/dialog_buttonscript.h>
@@ -127,6 +128,7 @@ int main(int argc, char *argv[])
instantiate_widget<Dialog_Import_CSV_Progress>();
instantiate_widget<DataWidgetChildren::Dialog_ChooseID>();
instantiate_widget<DataWidgetChildren::Dialog_ChooseDate>();
+ instantiate_widget<DataWidgetChildren::Dialog_NewRecord>();
instantiate_widget<Dialog_InvalidData>();
instantiate_widget<DialogImageLoadProgress>();
instantiate_widget<DialogImageSaveProgress>();
diff --git a/ui/operator/dialog_new_record.glade b/ui/operator/dialog_new_record.glade
new file mode 100644
index 0000000..e906d8e
--- /dev/null
+++ b/ui/operator/dialog_new_record.glade
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <requires lib="gtk+" version="2.16"/>
+ <object class="GtkDialog" id="dialog_new_record">
+ <property name="can_focus">False</property>
+ <property name="border_width">6</property>
+ <property name="title" translatable="yes">Find Related Record</property>
+ <property name="default_width">300</property>
+ <property name="default_height">500</property>
+ <property name="type_hint">dialog</property>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="vbox81">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="hbuttonbox39">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="button_close">
+ <property name="label">gtk-close</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="receives_default">False</property>
+ <property name="use_action_appearance">False</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkVBox" id="vbox82">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="border_width">6</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkAlignment" id="alignment_parent_top">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <object class="GtkVBox" id="vbox83">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">12</property>
+ <child>
+ <object class="GtkHBox" id="hbox81">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="label203">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes"><b>Table:</b></property>
+ <property name="use_markup">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel" id="label_table_name">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">table_name</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkAlignment" id="alignment_parent">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <child>
+ <placeholder/>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="-5">button_close</action-widget>
+ </action-widgets>
+ </object>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]