Esempio n. 1
0
Button* Interpreter::AddButton( const ButtonClickedSignature::Delegate& listener )
{
    ButtonPtr control = new Button ();
    control->ButtonClickedEvent().Add( listener );

    m_ContainerStack.Get().top()->AddChild(control);

    return control;
}
ButtonPtr ReflectStlVectorInterpreter::AddMoveDownButton( List* list )
{
    ButtonPtr downButton = CreateControl< Button >();
    downButton->a_Icon.Set( TXT( "actions/go-down" ) );
    downButton->ButtonClickedEvent().Add( ButtonClickedSignature::Delegate ( this, &ReflectStlVectorInterpreter::OnMoveDown ) );
    downButton->SetClientData( new ClientData( list ) );
    downButton->a_HelpText.Set( TXT( "Move the selected item(s) down the list." ) );

    return downButton;
}
ButtonPtr ReflectStlVectorInterpreter::AddRemoveButton( List* list )
{
    ButtonPtr removeButton = CreateControl< Button >();
    removeButton->a_Label.Set( TXT( "Remove" ) );
    removeButton->ButtonClickedEvent().Add( ButtonClickedSignature::Delegate ( this, &ReflectStlVectorInterpreter::OnRemove ) );
    removeButton->SetClientData( new ClientData( list ) );
    removeButton->a_HelpText.Set( TXT( "Remove the selected item(s) from the list." ) );

    return removeButton;
}
ButtonPtr ReflectStlVectorInterpreter::AddAddButton( List* list )
{
    ButtonPtr addButton =CreateControl< Button >();
    addButton->ButtonClickedEvent().Add( ButtonClickedSignature::Delegate ( this, &ReflectStlVectorInterpreter::OnAdd ) );
    addButton->SetClientData( new ClientData( list ) );
    addButton->a_Label.Set( TXT( "Add" ) );
    addButton->a_HelpText.Set( TXT( "Add an item to the list." ) );

    return addButton;
}
///////////////////////////////////////////////////////////////////////////////
// Creates UI for the field variable specified.
// 
void ReflectStlSetInterpreter::InterpretField( const Reflect::Field* field, const std::vector<Reflect::Object*>& instances, Container* parent )
{
    if ( field->m_Flags & Reflect::FieldFlags::Hide )
    {
        return;
    }

    // create the container
    ContainerPtr container = CreateControl< Container >();
    parent->AddChild( container );

    tstring temp;
    field->GetProperty( TXT( "UIName" ), temp );
    if ( temp.empty() )
    {
        bool converted = Helium::ConvertString( field->m_Name, temp );
        HELIUM_ASSERT( converted );
    }

    container->a_Name.Set( temp );

    // create the data objects
    std::vector< Reflect::Object* >::const_iterator itr = instances.begin();
    std::vector< Reflect::Object* >::const_iterator end = instances.end();
    for ( ; itr != end; ++itr )
    {
        Reflect::DataPtr ser = Reflect::AssertCast< Reflect::Data >( Reflect::Registry::GetInstance()->CreateInstance( field->m_DataClass ) );
        uintptr_t fieldAddress = ( uintptr_t )( *itr ) + field->m_Offset;
        ser->ConnectData( ( void* )fieldAddress );
        m_Datas.push_back( ser );
    }

    // create the list
    ListPtr list = CreateControl< List >();
    list->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) );
    container->AddChild( list );

    // bind the ui to the serialiers
    list->Bind( new MultiStringFormatter< Reflect::Data >( (std::vector<Reflect::Data*>&)m_Datas ) );

    // create the buttons if we are not read only
    if ( !( field->m_Flags & Reflect::FieldFlags::ReadOnly ) )
    {
        ContainerPtr buttonContainer = CreateControl< Container >();
        container->AddChild( buttonContainer );

        ButtonPtr buttonAdd = CreateControl< Button >();
        buttonContainer->AddChild( buttonAdd );
        buttonAdd->a_Label.Set( TXT( "Add" ) );
        buttonAdd->a_HelpText.Set( TXT( "Add an item to the list." ) );
        buttonAdd->ButtonClickedEvent().Add( ButtonClickedSignature::Delegate ( this, &ReflectStlSetInterpreter::OnAdd ) );
        buttonAdd->SetClientData( new ClientData( list ) );

        ButtonPtr buttonRemove = CreateControl< Button >();
        buttonContainer->AddChild( buttonRemove );
        buttonRemove->a_Label.Set( TXT( "Remove" ) );
        buttonRemove->a_HelpText.Set( TXT( "Remove the selected item(s) from the list." ) );
        buttonRemove->ButtonClickedEvent().Add( ButtonClickedSignature::Delegate ( this, &ReflectStlSetInterpreter::OnRemove ) );
        buttonRemove->SetClientData( new ClientData( list ) );
    }

    // for now let's just disable this container if there is more than one item selected. I'm not sure if it will behave properly in this case.
    if ( instances.size() > 1 )
    {
        container->a_IsEnabled.Set( false );
    }
}
Esempio n. 6
0
void ReflectInterpreter::InterpretFilePathField( const std::vector< Reflect::Pointer >& pointers, Reflect::Translator* translator, const Reflect::Field* field, Container* parent )
{
#if INSPECT_REFACTOR
	if (field->m_Flags & FieldFlags::Hide)
	{
		return;
	}

	//
	// Create the ui we are generating
	//

	std::vector< ContainerPtr > groups;

	ContainerPtr container = CreateControl<Container>();
	groups.push_back( container );

	bool pathField = field->m_DataClass == Reflect::GetMetaClass< PathData >();
	bool readOnly = ( field->m_Flags & FieldFlags::ReadOnly ) == FieldFlags::ReadOnly;

	DataChangingSignature::Delegate changingDelegate;

	FileDialogButtonPtr fileDialogButton;

	//
	// Parse
	//
	std::string fieldUI;
	field->GetProperty( TXT( "UIScript" ), fieldUI );
	bool result = Script::Parse(fieldUI, this, parent->GetCanvas(), container, field->m_Flags);

	if (!result)
	{
		if ( pathField || field->m_DataClass == Reflect::GetMetaClass<StlStringData>() )
		{
			ContainerPtr valueContainer = CreateControl<Container>();
			ValuePtr value = CreateControl< Value >();
			value->a_Justification.Set( Justifications::Right );
			value->a_IsReadOnly.Set( readOnly );
			value->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) );
			valueContainer->AddChild( value );
			groups.push_back( valueContainer );

			if ( !readOnly )
			{
				changingDelegate = DataChangingSignature::Delegate(this, &PathInterpreter::DataChanging);

				// File dialog button
				fileDialogButton = CreateControl< FileDialogButton >();
				fileDialogButton->a_HelpText.Set( TXT( "Open a file dialog to choose a new file." ) );

				field->GetProperty( TXT( "FileFilter" ), m_FileFilter );

				if ( !m_FileFilter.empty() )
				{
					fileDialogButton->a_Filter.Set( m_FileFilter );
				}
				container->AddChild( fileDialogButton );

				value->SetProperty( TXT( "FileFilter" ), m_FileFilter );
			}

			if ( objects.size() == 1 )
			{
				// File edit button
				ButtonPtr editButton = CreateControl< Button >();
				editButton->ButtonClickedEvent().Add( ButtonClickedSignature::Delegate ( this, &PathInterpreter::Edit ) );
				editButton->a_Label.Set( TXT( "Edit" ) );
				editButton->a_HelpText.Set( TXT( "Attempt to edit the file using its associated default application." ) );
				container->AddChild( editButton );
			}
		}
	}
	else
	{
		ValuePtr value = CreateControl< Value >();
		value->a_IsReadOnly.Set( readOnly );
		value->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) );
		container->AddChild( value );
	}


	//
	// Setup label
	//

	LabelPtr label = NULL;

	{
		std::vector< ControlPtr >::const_iterator itr = container->GetChildren().begin();
		std::vector< ControlPtr >::const_iterator end = container->GetChildren().end();
		for( ; itr != end; ++itr )
		{
			Label* label = Reflect::SafeCast<Label>( *itr );
			if (label)
			{
				break;
			}
		}
	}

	if (!label.ReferencesObject())
	{
		label = CreateControl< Label >();

		std::string temp;
		field->GetProperty( TXT( "UIName" ), temp );
		if ( temp.empty() )
		{
			bool converted = Helium::ConvertString( field->m_Name, temp );
			HELIUM_ASSERT( converted );
		}

		label->BindText( temp );
		label->a_HelpText.Set( field->GetProperty( TXT( "HelpText" ) ) );

		container->InsertChild(0, label);
	}

	//
	// Create type m_FinderSpecific data bound to this and additional objects
	//

	std::vector<Data*> datas;

	{
		std::vector<Reflect::Object*>::const_iterator itr = objects.begin();
		std::vector<Reflect::Object*>::const_iterator end = objects.end();
		for ( ; itr != end; ++itr )
		{
			Data s = field->CreateData();

			if (s->IsA(Reflect::GetMetaClass<ContainerData>()))
			{
				return;
			}

			s->ConnectField(*itr, field);

			datas.push_back(s);

			m_Datas.push_back(s);
		}
	}

	//
	// Create data and bind
	//

	Helium::SmartPtr< MultiStringFormatter<Data> > data = new MultiStringFormatter<Data>( datas );

	if (changingDelegate.Valid())
	{
		data->AddChangingListener( changingDelegate );
	}

	{
		std::vector<ContainerPtr>::const_iterator itr = groups.begin();
		std::vector<ContainerPtr>::const_iterator end = groups.end();
		for ( ; itr != end; ++itr )
		{
			(*itr)->Bind( data );
		}
	}

	//
	// Set default
	//

	Data defaultData = field->CreateDefaultData();
	if (defaultData.ReferencesObject())
	{
		std::stringstream defaultStream;
		*defaultData >> defaultStream;
		container->a_Default.Set( defaultStream.str() );
	}