Commit 2bb23a44 authored by Murray Cumming's avatar Murray Cumming
Browse files

Field Definition: Move Default formatting into a separate window.

* glom/mode_dsign/fields/dialog_fielddefinition.[h|cc]:
* data/ui/developer/window_field_definition_edit.glade:
  Move the Default Formatting notebook tab into:
* glom/mode_design/fields/dialog_defaultformatting.[h|cc]:
* data/ui/developer/window_default_formatting.glade:

* glom/utility_widgets/adddel/adddel.[h|cc]:
  Add signal_user_requested_extra.
* glom/utility_widgets/adddel/adddel_withbuttons.[h|cc]:
  Add set_edit_button_label() and set_extra_button_label()
  and override show_all_vfunc() to not show the extra button if
  it has no label.

* glom/mode_design/fields/box_db_table_definition.[h|cc]:
  Use the new button to show the new dialog.
parent 508d61d5
......@@ -140,6 +140,7 @@ EXTRA_DIST += \
data/ui/developer/window_button_script.glade \
data/ui/developer/window_data_layout_export.glade \
data/ui/developer/window_data_layout.glade \
data/ui/developer/window_default_formatting.glade \
data/ui/developer/window_design.glade \
data/ui/developer/window_field_calculation.glade \
data/ui/developer/window_field_definition_edit.glade \
......
......@@ -298,6 +298,8 @@ glom_source_files += \
glom/mode_design/fields/box_db_table_definition.h \
glom/mode_design/fields/combo_fieldtype.cc \
glom/mode_design/fields/combo_fieldtype.h \
glom/mode_design/fields/dialog_defaultformatting.cc \
glom/mode_design/fields/dialog_defaultformatting.h \
glom/mode_design/fields/dialog_fieldcalculation.cc \
glom/mode_design/fields/dialog_fieldcalculation.h \
glom/mode_design/fields/dialog_fielddefinition.cc \
......
......@@ -28,6 +28,7 @@
<file preprocess="xml-stripblanks">data/ui/developer/window_button_script.glade</file>
<file preprocess="xml-stripblanks">data/ui/developer/window_data_layout_export.glade</file>
<file preprocess="xml-stripblanks">data/ui/developer/window_data_layout.glade</file>
<file preprocess="xml-stripblanks">data/ui/developer/window_default_formatting.glade</file>
<file preprocess="xml-stripblanks">data/ui/developer/window_design.glade</file>
<file preprocess="xml-stripblanks">data/ui/developer/window_field_calculation.glade</file>
<file preprocess="xml-stripblanks">data/ui/developer/window_field_definition_edit.glade</file>
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.16.0 on Fri Oct 25 11:09:31 2013 -->
<!-- Generated with glade 3.15.4 on Sun Oct 27 15:01:29 2013 -->
<interface>
<!-- interface-requires gtk+ 3.6 -->
<object class="GtkWindow" id="window_formatting">
......@@ -148,7 +148,7 @@
<object class="GtkLabel" id="label10">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">&lt;b&gt;Numeric Formatting&lt;/b&gt;</property>
<property name="label" translatable="yes">Numeric Formatting</property>
<property name="use_markup">True</property>
</object>
<packing>
......@@ -396,7 +396,7 @@
<object class="GtkLabel" id="label5">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">&lt;b&gt;Text Formatting&lt;/b&gt;</property>
<property name="label" translatable="yes">Text Formatting</property>
<property name="use_markup">True</property>
</object>
<packing>
......@@ -669,9 +669,6 @@
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
</child>
</object>
......@@ -796,7 +793,7 @@
<object class="GtkLabel" id="label9">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">&lt;b&gt;Choices&lt;/b&gt;</property>
<property name="label" translatable="yes">Choices</property>
<property name="use_markup">True</property>
</object>
<packing>
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.15.4 on Sun Oct 27 14:36:19 2013 -->
<interface>
<!-- interface-requires gtk+ 3.6 -->
<object class="GtkWindow" id="window_default_formatting">
<property name="can_focus">False</property>
<property name="border_width">12</property>
<property name="title" translatable="yes">Default Formatting</property>
<property name="window_position">center-on-parent</property>
<child>
<object class="GtkBox" id="vbox11">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox" id="box_formatting_placeholder">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButtonBox" id="hbuttonbox8">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="spacing">6</property>
<property name="layout_style">end</property>
<child>
<object class="GtkButton" id="button_cancel">
<property name="label">gtk-cancel</property>
<property name="use_action_appearance">False</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_stock">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="button_save">
<property name="label">gtk-save</property>
<property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="has_default">True</property>
<property name="receives_default">False</property>
<property name="use_stock">True</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">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
......@@ -484,32 +484,6 @@
<property name="tab_fill">False</property>
</packing>
</child>
<child>
<object class="GtkBox" id="box_formatting_placeholder">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">6</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
<child type="tab">
<object class="GtkLabel" id="label188">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Default Formatting</property>
<property name="use_underline">True</property>
</object>
<packing>
<property name="position">2</property>
<property name="tab_fill">False</property>
</packing>
</child>
</object>
<packing>
<property name="expand">True</property>
......
......@@ -31,6 +31,8 @@ namespace Glom
{
Box_DB_Table_Definition::Box_DB_Table_Definition()
: m_dialog_field_definition(0),
m_dialog_default_formatting(0)
{
init();
}
......@@ -45,20 +47,29 @@ void Box_DB_Table_Definition::init()
{
//m_strHint = _("Click [Edit] to edit the field definition in more detail.\nUse the Mode menu to see Data or perform a Find.");
Utils::get_glade_widget_derived_with_warning(m_pDialog);
Utils::get_glade_widget_derived_with_warning(m_dialog_field_definition);
add_view(m_dialog_field_definition); //Give it access to the document.
Utils::get_glade_widget_derived_with_warning(m_dialog_default_formatting);
add_view(m_dialog_default_formatting);
m_dialog_default_formatting->signal_apply().connect(sigc::mem_fun(*this, &Box_DB_Table_Definition::on_field_definition_apply));
add_view(m_pDialog); //Give it access to the document.
pack_start(m_AddDel);
m_colName = m_AddDel.add_column(_("Name"));
m_AddDel.prevent_duplicates(m_colName); //Don't allow adding of fields that already exist.
m_AddDel.set_prevent_duplicates_warning(_("This field already exists. Please choose a different field name"));
m_AddDel.set_prevent_duplicates_warning(_("This field already exists. Please choose a different field name."));
m_colTitle = m_AddDel.add_column(_("Title"));
m_colType = m_AddDel.add_column(_("Type"), AddDelColumnInfo::STYLE_Choices);
m_AddDel.set_column_width(m_colType, 100); //TODO: Auto-size columns.
//Setup the buttons:
m_AddDel.set_edit_button_label(_("_Field Definition"));
m_AddDel.set_extra_button_label(_("_Default Formatting"));
//Set Type choices:
Field::type_map_type_names mapFieldTypes = Field::get_usable_type_names();
......@@ -79,17 +90,24 @@ void Box_DB_Table_Definition::init()
m_AddDel.signal_user_requested_delete().connect(sigc::mem_fun(*this, &Box_DB_Table_Definition::on_adddel_delete));
m_AddDel.signal_user_changed().connect(sigc::mem_fun(*this, &Box_DB_Table_Definition::on_adddel_changed));
m_AddDel.signal_user_requested_edit().connect(sigc::mem_fun(*this, &Box_DB_Table_Definition::on_adddel_edit));
m_AddDel.signal_user_requested_extra().connect(sigc::mem_fun(*this, &Box_DB_Table_Definition::on_adddel_extra));
//React to changes in the field properties:
m_pDialog->signal_apply().connect(sigc::mem_fun(*this, &Box_DB_Table_Definition::on_Properties_apply));
m_dialog_field_definition->signal_apply().connect(sigc::mem_fun(*this, &Box_DB_Table_Definition::on_field_definition_apply));
}
Box_DB_Table_Definition::~Box_DB_Table_Definition()
{
if(m_pDialog)
if(m_dialog_field_definition)
{
remove_view(m_pDialog);
delete m_pDialog;
remove_view(m_dialog_field_definition);
delete m_dialog_field_definition;
}
if(m_dialog_default_formatting)
{
remove_view(m_dialog_default_formatting);
delete m_dialog_default_formatting;
}
}
......@@ -395,15 +413,31 @@ void Box_DB_Table_Definition::on_adddel_edit(const Gtk::TreeModel::iterator& row
sharedptr<const Field> constfield = get_field_definition(row);
m_Field_BeingEdited = constfield;
m_pDialog->set_field(m_Field_BeingEdited, m_table_name);
m_dialog_field_definition->set_field(m_Field_BeingEdited, m_table_name);
//m_dialog_field_definition->set_modified(false); //Disable [Apply] at start.
Gtk::Window* parent_window = get_app_window();
if(parent_window)
m_dialog_field_definition->set_transient_for(*parent_window);
m_dialog_field_definition->show();
}
void Box_DB_Table_Definition::on_adddel_extra(const Gtk::TreeModel::iterator& row)
{
sharedptr<const Field> constfield = get_field_definition(row);
m_Field_BeingEdited = constfield;
m_dialog_default_formatting->set_field(m_Field_BeingEdited, m_table_name);
//m_pDialog->set_modified(false); //Disable [Apply] at start.
//m_dialog_field_definition->set_modified(false); //Disable [Apply] at start.
Gtk::Window* parent_window = get_app_window();
if(parent_window)
m_pDialog->set_transient_for(*parent_window);
m_dialog_default_formatting->set_transient_for(*parent_window);
m_pDialog->show();
m_dialog_default_formatting->show();
}
sharedptr<Field> Box_DB_Table_Definition::get_field_definition(const Gtk::TreeModel::iterator& row)
......@@ -482,9 +516,29 @@ sharedptr<Field> Box_DB_Table_Definition::get_field_definition(const Gtk::TreeMo
return fieldResult;
}
void Box_DB_Table_Definition::on_Properties_apply()
void Box_DB_Table_Definition::on_field_definition_apply()
{
sharedptr<Field> field_New = m_dialog_field_definition->get_field();
if(*m_Field_BeingEdited != *field_New)
{
const bool bcontinue = check_field_change(m_Field_BeingEdited, field_New);
if(bcontinue)
{
change_definition(m_Field_BeingEdited, field_New);
m_Field_BeingEdited = field_New;
}
//Update the list:
fill_from_database();
}
m_dialog_field_definition->hide();
}
void Box_DB_Table_Definition::on_default_formatting_apply()
{
sharedptr<Field> field_New = m_pDialog->get_field();
sharedptr<Field> field_New = m_dialog_default_formatting->get_field();
if(*m_Field_BeingEdited != *field_New)
{
......@@ -499,7 +553,7 @@ void Box_DB_Table_Definition::on_Properties_apply()
fill_from_database();
}
m_pDialog->hide();
m_dialog_default_formatting->hide();
}
sharedptr<Field> Box_DB_Table_Definition::change_definition(const sharedptr<const Field>& fieldOld, const sharedptr<const Field>& field)
......
......@@ -21,8 +21,9 @@
#ifndef GLOM_MODE_DESIGN_BOX_DB_TABLE_DEFINITION_H
#define GLOM_MODE_DESIGN_BOX_DB_TABLE_DEFINITION_H
#include "../../box_db_table.h"
#include "dialog_fielddefinition.h"
#include <glom/box_db_table.h>
#include <glom/mode_design/fields/dialog_fielddefinition.h>
#include <glom/mode_design/fields/dialog_defaultformatting.h>
namespace Glom
{
......@@ -53,8 +54,10 @@ private:
void on_adddel_delete(const Gtk::TreeModel::iterator& rowStart, const Gtk::TreeModel::iterator& rowEnd);
void on_adddel_changed(const Gtk::TreeModel::iterator& row, guint col);
void on_adddel_edit(const Gtk::TreeModel::iterator& row);
void on_adddel_extra(const Gtk::TreeModel::iterator& row);
void on_Properties_apply();
void on_field_definition_apply();
void on_default_formatting_apply();
bool check_field_change(const sharedptr<const Field>& field_old, const sharedptr<const Field>& field_new);
......@@ -62,7 +65,10 @@ private:
guint m_colName, m_colTitle, m_colType, m_colUnique, m_colPrimaryKey;
Dialog_FieldDefinition* m_pDialog;
Dialog_FieldDefinition* m_dialog_field_definition;
Dialog_DefaultFormatting* m_dialog_default_formatting;
sharedptr<const Field> m_Field_BeingEdited; //TODO_FieldShared
type_vec_fields m_vecFields;
};
......
/* 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., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*/
#include "dialog_defaultformatting.h"
#include <glom/glade_utils.h>
#include <glom/utils_ui.h>
#include <glom/appwindow.h>
#include "../../box_db_table.h"
#include <libglom/db_utils.h>
//#include <libgnome/gnome-i18n.h>
#include <glibmm/i18n.h>
namespace Glom
{
const char* Dialog_DefaultFormatting::glade_id("window_default_formatting");
const bool Dialog_DefaultFormatting::glade_developer(true);
Dialog_DefaultFormatting::Dialog_DefaultFormatting(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder)
: Dialog_Properties(cobject, builder),
m_box_formatting_placeholder(0),
m_box_formatting(0)
{
//Get the place to put the Formatting stuff:
builder->get_widget("box_formatting_placeholder", m_box_formatting_placeholder);
//Get the formatting stuff:
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);
add_view(m_box_formatting);
if(m_box_formatting)
{
on_foreach_connect(*m_box_formatting);
//Plus an extra signal for the related extra show-also fields:
m_box_formatting->signal_modified().connect(
sigc::mem_fun(*this, &Dialog_DefaultFormatting::on_anything_changed));
}
Dialog_Properties::set_modified(false);
show_all_children();
}
Dialog_DefaultFormatting::~Dialog_DefaultFormatting()
{
remove_view(m_box_formatting);
}
void Dialog_DefaultFormatting::set_field(const sharedptr<const Field>& field, const Glib::ustring& table_name)
{
set_blocked();
m_Field = glom_sharedptr_clone(field); //Remember it so we save any details that are not in our UI.
m_table_name = table_name; //Used for lookup combo boxes.
//Formatting:
m_box_formatting->set_formatting_for_field(field->m_default_formatting, m_table_name, field);
set_blocked(false);
Dialog_Properties::set_modified(false);
}
sharedptr<Field> Dialog_DefaultFormatting::get_field() const
{
sharedptr<Field> field = glom_sharedptr_clone(m_Field); //Start with the old details, to preserve anything that is not in our UI.
// const_cast is necessary and save here for the window (jhs)
sharedptr<SharedConnection> sharedcnc = connect_to_server(const_cast<Dialog_DefaultFormatting*>(this));
Glib::RefPtr<Gnome::Gda::Connection> cnc = sharedcnc->get_gda_connection();
//Get the field info from the widgets:
//Formatting:
m_box_formatting->get_formatting(field->m_default_formatting);
return field;
}
} //namespace Glom
/* 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., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA.
*/
#ifndef GLOM_MODE_DESIGN_DIALOG_DEFAULTFORMATTING_H
#define GLOM_MODE_DESIGN_DIALOG_DEFAULTFORMATTING_H
#include <gtkmm/dialog.h>
#include <gtkmm/checkbutton.h>
#include <gtkmm/comboboxtext.h>
#include <gtkmm/alignment.h>
#include <gtkmm/entry.h>
#include <glom/mode_design/layout/combobox_relationship.h>
//#include "../../utility_widgets/entry_numerical.h"
#include "../../utility_widgets/dialog_properties.h"
#include <glom/mode_data/datawidget/datawidget.h>
#include <libglom/data_structure/field.h>
#include <glom/mode_design/layout/layout_item_dialogs/box_formatting.h>
#include <glom/base_db.h>
namespace Glom
{
class Dialog_DefaultFormatting
: public Dialog_Properties,
public Base_DB //Give this class access to the current document, and to some utility methods.
{
public:
static const char* glade_id;
static const bool glade_developer;
Dialog_DefaultFormatting(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder);
virtual ~Dialog_DefaultFormatting();
virtual void set_field(const sharedptr<const Field>& field, const Glib::ustring& table_name);
virtual sharedptr<Field> get_field() const; //TODO_FieldShared
private:
Gtk::Box* m_box_formatting_placeholder;
Box_Formatting* m_box_formatting;
sharedptr<Field> m_Field;
Glib::ustring m_table_name;
};
} //namespace Glom
#endif // GLOM_MODE_DESIGN_DIALOG_DEFAULTFORMATTING_H
......@@ -36,9 +36,7 @@ const bool Dialog_FieldDefinition::glade_developer(true);
Dialog_FieldDefinition::Dialog_FieldDefinition(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder)
: Dialog_Properties(cobject, builder),
m_pDataWidget_DefaultValueSimple(0),
m_box_formatting_placeholder(0),
m_box_formatting(0)
m_pDataWidget_DefaultValueSimple(0)
{
builder->get_widget_derived("combobox_type", m_pCombo_Type);
......@@ -84,32 +82,11 @@ Dialog_FieldDefinition::Dialog_FieldDefinition(BaseObjectType* cobject, const Gl
//Make sure that the correct Type Details are showing:
on_combo_type_changed();
//Formatting:
//Get the place to put the Formatting stuff:
builder->get_widget("box_formatting_placeholder", m_box_formatting_placeholder);
//Get the formatting stuff:
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);
add_view(m_box_formatting);
on_foreach_connect(*this);
on_foreach_connect(*m_pBox_DefaultValueSimple);
on_foreach_connect(*m_pBox_ValueTab);
if(m_box_formatting)
{
on_foreach_connect(*m_box_formatting);
//Plus an extra signal for the related extra show-also fields:
m_box_formatting->signal_modified().connect(
sigc::mem_fun(*this, &Dialog_FieldDefinition::on_anything_changed));
}
Dialog_Properties::set_modified(false);
show_all_children();
......@@ -117,7 +94,6 @@ Dialog_FieldDefinition::Dialog_FieldDefinition(BaseObjectType* cobject, const Gl
Dialog_FieldDefinition::~Dialog_FieldDefinition()
{
remove_view(m_box_formatting);
}
void Dialog_FieldDefinition::set_field(const sharedptr<const Field>& field, const Glib::ustring& table_name)
......@@ -215,9 +191,6 @@ void Dialog_FieldDefinition::set_field(const sharedptr<const Field>& field, cons
m_pEntry_Title->set_text(item_get_title(field));
//Formatting:
m_box_formatting->set_formatting_for_field(field->m_default_formatting, m_table_name, field);
set_blocked(false);
enforce_constraints();
......@@ -275,9 +248,6 @@ sharedptr<Field> Dialog_FieldDefinition::get_field() const
field->set_title(m_pEntry_Title->get_text(), AppWindow::get_current_locale());
//Formatting:
m_box_formatting->get_formatting(field->m_default_formatting);
return field;
}