void ResourceEditWindow::Load(const char *resource_file) { m_resource_filename.Set(resource_file); SetText(resource_file); // Set the text of the source view m_source_edit->SetText(""); if (TBFile *file = TBFile::Open(m_resource_filename, TBFile::MODE_READ)) { TBTempBuffer buffer; if (buffer.Reserve(file->Size())) { uint32 size_read = file->Read(buffer.GetData(), 1, buffer.GetCapacity()); m_source_edit->SetText(buffer.GetData(), size_read); } delete file; } else // Error, show message { TBStr text; text.SetFormatted("Could not load file %s", resource_file); if (TBMessageWindow *msg_win = new TBMessageWindow(GetParentRoot(), TBIDC(""))) msg_win->Show("Error loading resource", text); } RefreshFromSource(); }
bool ResourceEditWindow::OnEvent(const TBWidgetEvent &ev) { if (ev.type == EVENT_TYPE_CHANGED && ev.target->GetID() == TBIDC("widget_list_search")) { m_widget_list->SetFilter(ev.target->GetText()); return true; } else if (ev.type == EVENT_TYPE_CHANGED && ev.target == m_widget_list) { if (m_widget_list->GetValue() >= 0 && m_widget_list->GetValue() < m_widget_list_source.GetNumItems()) if (ResourceItem *item = m_widget_list_source.GetItem(m_widget_list->GetValue())) SetSelectedWidget(item->GetWidget()); } else if (ev.type == EVENT_TYPE_CHANGED && ev.target == m_source_edit) { RefreshFromSource(); return true; } else if (ev.type == EVENT_TYPE_CLICK && ev.target->GetID() == TBIDC("test")) { // Create a window containing the current layout, resize and center it. if (TBWindow *win = new TBWindow()) { win->SetText("Test window"); g_widgets_reader->LoadData(win->GetContentRoot(), m_source_edit->GetText()); TBRect bounds(0, 0, GetParent()->GetRect().w, GetParent()->GetRect().h); win->SetRect(win->GetResizeToFitContentRect().CenterIn(bounds).MoveIn(bounds).Clip(bounds)); GetParent()->AddChild(win); } return true; } else if (ev.target->GetID() == TBIDC("constrained")) { m_scroll_container->SetAdaptContentSize(ev.target->GetValue() ? true : false); return true; } else if (ev.type == EVENT_TYPE_FILE_DROP) { return OnDropFileEvent(ev); } return TBWindow::OnEvent(ev); }