ModelAttribute.h
Go to the documentation of this file.00001 #ifndef MODELATTRIBUTE_H_
00002 #define MODELATTRIBUTE_H_
00003
00004 class ModelAttribute: public EntityAttribute
00005 {
00006 std::string m_classname;
00007 std::string m_key;
00008 BrowsedPathEntry m_entry;
00009 NonModalEntry m_nonModal;
00010 public:
00011 ModelAttribute (const std::string& classname, const std::string& key) :
00012 m_classname(classname), m_key(key), m_entry(BrowseCaller(*this)), m_nonModal(ApplyCaller(*this),
00013 UpdateCaller(*this))
00014 {
00015 m_nonModal.connect(m_entry.m_entry.m_entry);
00016 }
00017
00018 GtkWidget* getWidget () const
00019 {
00020 return GTK_WIDGET(m_entry.m_entry.m_frame);
00021 }
00022 void apply (void)
00023 {
00024 StringOutputStream value(64);
00025 value << ConvertUTF8ToLocale(gtk_entry_get_text(GTK_ENTRY(m_entry.m_entry.m_entry)));
00026 entitySetValue(m_classname, m_key, value.c_str());
00027 }
00028 typedef MemberCaller<ModelAttribute, &ModelAttribute::apply> ApplyCaller;
00029 void update (void)
00030 {
00031 const std::string value = entityGetValueForKey(m_key);
00032 gtk_entry_set_text(GTK_ENTRY(m_entry.m_entry.m_entry), value.c_str());
00033 }
00034 typedef MemberCaller<ModelAttribute, &ModelAttribute::update> UpdateCaller;
00035 void browse (const BrowsedPathEntry::SetPathCallback& setPath)
00036 {
00037 ui::ModelAndSkin modelAndSkin = ui::ModelSelector::chooseModel();
00038 if (!modelAndSkin.model.empty()) {
00039 if (modelAndSkin.skin != -1)
00040 entitySetValue(m_classname, "skin", string::toString(modelAndSkin.skin));
00041 setPath(modelAndSkin.model);
00042 apply();
00043 }
00044 }
00045 typedef MemberCaller1<ModelAttribute, const BrowsedPathEntry::SetPathCallback&, &ModelAttribute::browse>
00046 BrowseCaller;
00047 };
00048
00049 #endif