#include "stdafx.h"

#include <grts/structs.db.h>

#include <grtpp_util.h>
#include <grtpp_undo_manager.h>

#include "grt/common.h"

//================================================================================
// db_DatabaseObject


void db_DatabaseObject::init()
{
}

db_DatabaseObject::~db_DatabaseObject()
{
}

void db_DatabaseObject::lastChangeDate(const grt::StringRef &value)
{
  grt::ValueRef ovalue(_lastChangeDate);

  _lastChangeDate= value;
  
  member_changed("lastChangeDate", ovalue, value);

  if (_owner.is_valid() && _owner.is_instance(db_Schema::static_class_name()))
  {
    db_SchemaRef schema(db_SchemaRef::cast_from(_owner));
    schema->signal_refreshDisplay().emit(this);
  }
}


void db_DatabaseObject::name(const grt::StringRef &value)
{
  grt::StringRef oname(_name);

  grt::AutoUndo undo(get_grt(), !is_global());

  _name= value;
  _lastChangeDate= bec::fmttime(0, DATETIME_FMT);

  member_changed("name", oname, value);

  undo.end(strfmt(_("Rename '%s' to '%s'"), 
                  oname.c_str(), value.c_str()));

  if (_owner.is_valid() && _owner.is_instance(db_Schema::static_class_name()))
  {
    db_SchemaRef schema(db_SchemaRef::cast_from(_owner));
    schema->signal_refreshDisplay().emit(this);
  }
}





