Tables and Edit-In-Place


#1

Jules,

was there an intent for editing table data? I don’t see any edit code in there now, so did you have in mind:

[list]Create a custom edit field when user double-clicks

Create a custom edit field for each editable field, and hide them as needed

Use properties and avoid the whole thing

None of the above?
[/list]

Can I presume some people are already doing this? What worked out well?

Thanks,

Bruce


#2

I’ve done one of these by popping up a modal text-editor when you click the box - then when you click somewhere else, the editor will get an inputAttemptWhenModal() callback, which it uses to destroy itself.


#3

So - sorry, still getting used to your style (although I like it) - that would be a new class, inheriting from a TextEditor and - ah I see the modal thing is in the component superclass so just a TextEditor,

Then show the texteditor exactly on the table and call runmodalloop on it, then when the user moves on hide it again etc. etc.?

Don’t need to even tie that into the table custom component stuff at all then?

Thanks!


#4

Yes, that’s the idea.


#5

Don’t mean to be a dunce, but how do I get the bounds of the clicked cell?

The closest I can see is the mouse or the column’s width - which is a bit obscure to find.

Bruce


#6

I think I was using a custom component in the cell, so I just got the position from that. It’s a very good point, though - I should add some methods to get a cell’s bounds…


#7

Just FYI - I couldn’t get the position, so I went back and made a custom component to stick in the cell.

In short - I keep row and col of the currently editing cell, on return component, that cell gets an editor.

when another row is selected or double-clicked then another editor is created. One thing that doesn’t feel quite right - when returning a zero component, I delete any found text editor found. It seems to work, and why would you need two editors? Don’t know. AnywaY, it works.

[code]void SourceTableComponent::cellDoubleClicked(int rowNumber, int columnId, const MouseEvent & e)
{
// Is it one of the editable columns?
if (columnId == SourceColumns::sourceID ||
columnId == SourceColumns::name ||
(columnId == SourceColumns::input && getConnection(rowNumber, SourceColumns::connection) <= 1000) ||
columnId == SourceColumns::tally ||
columnId == SourceColumns::config)
{
rowBeingEdited = rowNumber;

	colBeingEdited	= columnId;

	

	table->updateContent(); // Force a redraw, now with a new edit field

void SourceTableComponent::selectedRowsChanged(int lastRowselected)

{

if (rowBeingEdited != -1 && lastRowselected != rowBeingEdited)

{

	rowBeingEdited	= -1;

	colBeingEdited	= -1;

	table->updateContent(); // Force a redraw, edit field will be released

Component* SourceTableComponent::refreshComponentForCell (int rowNumber, int columnId, bool isRowSelected,
Component* existingComponentToUpdate)
{
if (columnId == SourceColumns::thumbnail) // we’ll return our custom component…
{

else
{
// If we have a text editor, but don’t need it, get rid of it

	InplaceEditorComponent* textField = dynamic_cast<InplaceEditorComponent*> (existingComponentToUpdate);

	if (textField)

	{

		delete textField;

		existingComponentToUpdate = 0;

	}

	

	// for any other column, just return 0, as we'll be painting these columns directly.
	
	jassert (existingComponentToUpdate == 0);
	return 0;

[/code]

Bruce


#8