/*
PROGRAM NAME	UMDnames.DLL

USED BY			BBC Academy Studio C installation

VERSION			1.0
DATE			24th July 2017
PROGRAMMER		Andy Woodhouse

Overview
========
The function of this module is to allow a user to select and edit the name sets used on the Studio C Multiviewer UMD displays. The displayed 
names are selected between the matrix names, one of eight user-editable name sets, or showing the multiviewer input functions. 
The user editable name sets are held in a conventional BNCS driver DEV_XXX.INI file. 9 databases are used, database 1 to database 8 hold the
UMD display names indexed by matrix source number. Database 9 Holds the name of each of the eight user editable name sets.
There is also a diagnostics display mode which shows the TSL UMD address in place of the normal text.

The matrix short names are stored in database 2 of the Studio C SDI DEV_XXX.INI file. These names are not editable by this module, but they can be
edited by the the packages and names editor.
*/

#include <windows.h>
#include <stdio.h>
#include <bncs_string.h>
#include <bncs_config.h>
#include "UMDnames.h"

#define MAIN_PANEL	1
#define MAIN_PANEL_NAME "Selector.bncs_ui"
#define EDIT_PANEL	2
#define EDIT_PANEL_NAME "NameEdit.bncs_ui"

#define SELECTED	"WNSourceSelected"
#define DESELECTED	"WNSourceDeselected"
#define FLASHLOW	"WN_TakeLow"
#define FLASHHIGH	"WN_TakeHigh"

#define NAMES_DRIVER	"StC_UMD_Names_DriverID"

#define UMDNAMEMODE		210
#define UMDBRIGHTNESS	211
#define UMDACTIVENAMES	212

#define TIMEOUT 10
#define TIMER_CONFIRM	1
#define TIMEOUTEDIT 20
#define TIMER_EDIT 2

// Make our class visible to the outside world
EXPORT_BNCS_SCRIPT( UMDnames )


// ++++++++++++++++++++++++++++++++++++++++++++ //
// Constructor - Equivalent to ApplCore STARTUP //
// ++++++++++++++++++++++++++++++++++++++++++++ //
UMDnames::UMDnames(bncs_client_callback * parent, const char * path) : bncs_script_helper(parent, path)
{
	// Initialise variables to "safe" values
	sdi_id = 0;
	umd_names_id = 0;
	umd_brightness = 0;
	umd_active_names = 0;
	new_names = 0;
	select_active = false;
	setname_edit = false;
	edit_active = false;

	// Set the names matricies to null strings
	for (int i = 0; i <= SDI_MTX_SIZE; i++)	
	{
		LongNames[i] = "";
		Mtx_Name[i] = "";	
		UserNames_1[i] = "";
		UserNames_2[i] = "";
		UserNames_3[i] = "";
		UserNames_4[i] = "";
		UserNames_5[i] = "";
		UserNames_6[i] = "";
		UserNames_7[i] = "";
		UserNames_8[i] = "";
	}

	for (int i = 0; i <= NAMESETS; i++)	name_names[i] = "";
	
	// Prepare the panels for use.
	panelInit(MAIN_PANEL, MAIN_PANEL_NAME);
	panelInit(EDIT_PANEL, EDIT_PANEL_NAME);

	// Hide the edit information data blocks on the edit panel
	hideEditInfo();

	// Get the BNCS id for the Studio C SDI router.
	getDev("StC SDI Router", &sdi_id);
	getDev("CTA Tally Infodriver", &tally_info_id);

	getDev(NAMES_DRIVER, &umd_names_id);

	// Look up the BNCS id for the User Names store using an entry in wn_academy.xml
	myVals = bncs_config("wn_academy.StA_UMD_Names_DriverID");	// Fixed package ID, CAR to CTA line 1. There are 8 sucessive packages
	umd_names_id = myVals.attr("value").toInt();				// Extract the first package Id

	// Read the name sets, including the names of the name sets.
	for (int i = 1; i <= SDI_MTX_SIZE; i++)		routerName(sdi_id, 0, i, LongNames[i]);		// 16 character matrix names
	for (int i = 1; i <= SDI_MTX_SIZE; i++)		routerName(sdi_id, 2, i, Mtx_Name[i]);
	for (int i = 1; i <= SDI_MTX_SIZE; i++)		routerName(umd_names_id, 1, i, UserNames_1[i]);
	for (int i = 1; i <= SDI_MTX_SIZE; i++)		routerName(umd_names_id, 2, i, UserNames_2[i]);
	for (int i = 1; i <= SDI_MTX_SIZE; i++)		routerName(umd_names_id, 3, i, UserNames_3[i]);
	for (int i = 1; i <= SDI_MTX_SIZE; i++)		routerName(umd_names_id, 4, i, UserNames_4[i]);
	for (int i = 1; i <= SDI_MTX_SIZE; i++)		routerName(umd_names_id, 5, i, UserNames_5[i]);
	for (int i = 1; i <= SDI_MTX_SIZE; i++)		routerName(umd_names_id, 6, i, UserNames_6[i]);
	for (int i = 1; i <= SDI_MTX_SIZE; i++)		routerName(umd_names_id, 7, i, UserNames_7[i]);
	for (int i = 1; i <= SDI_MTX_SIZE; i++)		routerName(umd_names_id, 8, i, UserNames_8[i]);
	for (int i = 1; i <= NAMESETS; i++)			routerName(umd_names_id, 9, i, name_names[i]);
	name_names[0] = "Matrix Short Names";
	
	// Start by showing the main selector panel
	panelShow(MAIN_PANEL, MAIN_PANEL_NAME);

	// Show the names of the UMD name sets.
	for (int i = 1; i <= NAMESETS; i++)
	{
		textPut("text", name_names[i], MAIN_PANEL, bncs_string("Names_%1").arg(i));
	}

	// Set the names edit panel ready for display
	controlDisable(EDIT_PANEL, "KB_1");							// Disable the keyboard
	textPut("button.001=released", EDIT_PANEL, "SrcGroup");		// Select the first bank of names.
	textPut("statesheet", SELECTED, EDIT_PANEL, "NameSet_1");	// Pre-select name set 1 for edit
	edit_set = 1;												// Set the initial nameset to edit
	activeNames();
	textPut("text", name_names[1], EDIT_PANEL, "NamesetName");	// Show the namset name
	controlDisable(EDIT_PANEL, "Cancel");						// Disable the Cancel and Update buttons
	controlDisable(EDIT_PANEL, "Update");

	// Register for revertives from the Tally Infodriver.
	infoRegister(tally_info_id, UMDBRIGHTNESS, UMDACTIVENAMES);
	// Get the current state.
	infoPoll(tally_info_id, UMDBRIGHTNESS, UMDACTIVENAMES);

	// Have to resgister for revertives from the UMD names BNCS ID, otherwise the 
	// database update from routerModify() does not invoke callback function.
	routerRegister(umd_names_id, 1, SDI_MTX_SIZE);
}

// +++++++++++++++++++++++++++++++++++++++++++++ //
// Destructor - equivalent to ApplCore CLOSEDOWN //
// +++++++++++++++++++++++++++++++++++++++++++++ //
UMDnames::~UMDnames()
{
	infoUnregister(tally_info_id);
	if (select_active) timerStop(TIMER_CONFIRM);
}

// +++++++++++++++++++++++++++++++++++++++++++++ //
// All button pushes and notifications come here //
// +++++++++++++++++++++++++++++++++++++++++++++ //
void UMDnames::buttonCallback( buttonNotify *b )
{
	// ******************** //
	// NAME SELECTION PANEL //
	// ******************** //
	if(b->panel() == MAIN_PANEL)
	{
		// Is the pushed button one of the name selectors?
		if (b->id().startsWith("Select_"))
		{
			if (select_active)	textPut("statesheet", DESELECTED, MAIN_PANEL, bncs_string("Select_") + bncs_string(new_names));

			textPut("statesheet", SELECTED, MAIN_PANEL, b->id());		// Highlight the new button
			new_names = b->id().right(1).toInt();						// Keep a note of the active button number
			select_active = true;										// Note that there is an active selection
			timeout = TIMEOUT;											// Initialise the timeout counter
			timerStart(TIMER_CONFIRM, 1000);							// Start a timer with a 1 second period
			controlEnable(MAIN_PANEL, "Confirm");						// Enable the confirm button.
			return;
		}

		// Is the button a UMD brightness change?
		if (b->id().startsWith("UMDBright_"))
		{
			// Update the Tally Infodriver Brightness slot. Note that the button name rightmost character is a number equal to the vakue we need
			infoWrite(tally_info_id, b->id().right(1), UMDBRIGHTNESS);
			return;
		}

		if (b->id() == "Confirm")
		{
			timerStop(TIMER_CONFIRM);
			select_active = false;
			textPut("statesheet", DESELECTED, MAIN_PANEL, bncs_string("Select_%1").arg(new_names));
			controlDisable(MAIN_PANEL, "Confirm");
			infoWrite(tally_info_id, bncs_string(new_names), UMDACTIVENAMES);
			return;
		}

		if (b->id() == "Name_Editor")
		{
			// Request to change to the names editing panel
			panelRemove(MAIN_PANEL);
			panelShow(EDIT_PANEL, EDIT_PANEL_NAME);
			return;
		}
	}	// End of Name Selection Panel button processing


	// *************** //
	// NAME EDIT PANEL //
	// *************** //
	if (b->panel() == EDIT_PANEL)
	{
		// SrcGroup
		if (b->id() == "SrcGroup")
		{
			// Change of name group
			textPut("page",bncs_string(b->value()) , EDIT_PANEL, "SrcName");
			return;
		}

		if ((b->id() == "SrcName") && (b->value().toInt() >= 0))
		{
			// Have selected a name to edit.
			disableButtons_1();													// Disable the source and destination selection keypads etc.
			setname_edit = false;												// We are not editing the name of a user name set.
			edit_active = true;													// Set flag used by database update callback
			edit_index = b->value();											// Keep a note of the source name index into name set
			max_namelength = 8;													// Set the maximum supported name length
			myedit = current[edit_index];										// Get the existing name of the current source to edit
			showEditInfo();														// Enable the display of the old name/new name info labels
			textPut("text",bncs_string(edit_set) , EDIT_PANEL, "Nameset_id");	// Update information displays
			textPut("text", LongNames[edit_index], EDIT_PANEL, "LongName");
			textPut("text", myedit, EDIT_PANEL, "PreEdit");
			textPut("text", bncs_string(""), EDIT_PANEL, "PostEdit");
			textPut("text", myedit, EDIT_PANEL, "KB_1");
			controlEnable(EDIT_PANEL, "KB_1");									// Enable the keyboard
			return;
		}

		// Check for a Keyboard key press
		if (b->id() == "KB_1")
		{
			if (b->subs() == 1)		// Check for single value return
			{
				if (b->sub(0) == "return")
				{
					// User has pressed the return key. Get the string from the keyboard. Enable the Cancel and Update buttons, disable the keyboard
					textGet("text", EDIT_PANEL, "KB_1", myedit);	// myedit now contains the updated string
					textPut("text", myedit, EDIT_PANEL, "PostEdit");
					controlDisable(EDIT_PANEL, "KB_1");
					controlEnable(EDIT_PANEL, "Cancel");
					controlEnable(EDIT_PANEL, "Update");
					textPut("statesheet", FLASHLOW, EDIT_PANEL, "Cancel");
					textPut("statesheet", FLASHHIGH, EDIT_PANEL, "Update");
					timeoutedit = TIMEOUTEDIT;						// Set the timeout counter to initial value.
					timerStart(TIMER_EDIT, 500);					// Start the timeout timer
					return;
				}
				else
				{
					// User has pressed a key other than the return key. Get the string and check the length.
					// If length > 8 characters, trim length to 8 characters and reset string in keyboard control.
					textGet("text", EDIT_PANEL, "KB_1", myedit);
					if (int(myedit.length()) > max_namelength)
					{
						myedit.truncate(max_namelength);
						textPut("text", myedit, EDIT_PANEL, "KB_1");
					}
				}	// End else clause
			}
			return;
		}	// End of if (b->id() == "KB_1")


		// Check for the Cancel button.
		if (b->id() == "Cancel")
		{
			cancelAction();
			return;
		}


		// Check for the Update button
		if (b->id() == "Update")
		{
			// Processing depends on if we are updating a source short name or a dataset name.
			// In all instances we need to stop the timeout timer, disable the cancel and update buttons etc.
			timerStop(TIMER_EDIT);
			controlDisable(EDIT_PANEL, "Cancel");
			controlDisable(EDIT_PANEL, "Update");
			textGet("text", EDIT_PANEL, "KB_1", myedit);			// Read edited string from keyboard
			textPut("text=", EDIT_PANEL, "KB_1");					// Clear the keyboard buffer

			// Next actions depend on the edit mod that is active - signalled by boolean variable setname_edit
			if (setname_edit)
			{
				// Edited the name of a nameset
				textPut("text", myedit, EDIT_PANEL,"NamesetName");		// Update the display on this panel
				edit_active = false;
				routerModify(umd_names_id, 9, edit_set, myedit, false);	// Tell the network about the change. Database change callback will update displays
			}
			else
			{
				// Update the name of a source
				current[edit_index] = myedit;										// Update memory copy of the strings
				routerModify(umd_names_id, edit_set, edit_index, myedit, false);	// Update network copies
				hideEditInfo();														// Hide the  name information panels
				textPut("index=0", EDIT_PANEL, "SrcName");							// De-select source in SrcPanel
				edit_active = false;
			}

			// Re-enable the edit selection controls
			controlEnable(EDIT_PANEL, "SrcGroup");
			controlEnable(EDIT_PANEL, "SrcName");
			controlEnable(EDIT_PANEL, "Nameset_Select");
			controlEnable(EDIT_PANEL, "NamesetName");
			for (int i = 1; i <= NAMESETS; i++) controlEnable(EDIT_PANEL, bncs_string("NameSet_%1").arg(i));
			return;
		}

		// Select name set names to edit.
		if (b->id().startsWith("NameSet_"))
		{
			// Name set selection buttons
			textPut("statesheet", DESELECTED, EDIT_PANEL, bncs_string("NameSet_%1").arg(edit_set));		// Clear old highlight
			edit_set = b->id().right(1).toInt();														// Get new id
			textPut("statesheet", SELECTED, EDIT_PANEL, b->id());
			textPut("text", name_names[edit_set], EDIT_PANEL, "NamesetName");
			activeNames();
			return;
		}

		// Does the user want to edit the name of one of the namesets?
		if (b->id() == "NamesetName")
		{
			// Variable edit_set has the dataset number whose name is to be changed.
			setname_edit = true;		// Set state flag to show what we are editing (needed by the Accept button actions)
			edit_active = true;			// Set flag used by database update callback
			disableButtons_1();			// Disable the keypads etc.
			max_namelength = 16;		// Nameset names may be 16 characters long
			textPut("text", name_names[edit_set], EDIT_PANEL, "KB_1");	// Copy current name to keyboard
			controlEnable(EDIT_PANEL, "KB_1");							// Enable the keyboard
			return;
		}
		
		// Switch display to the Nameset Selection Panel.
		if (b->id() == "Nameset_Select")
		{
			// Request to change to control of active name set
			panelRemove(EDIT_PANEL);
			panelShow(MAIN_PANEL, MAIN_PANEL_NAME);
			return;
		}
	}	// End of Name Edit panel button processing
}	// End of button callback processing.


// ++++++++++++++++++++++++ //
// All revertives come here //
// ++++++++++++++++++++++++ //
int UMDnames::revertiveCallback( revertiveNotify * r )
{
	// Only expecting revertives from the tally infodriver
	if (r->device() == tally_info_id)
	{
		switch (r->index())
		{
		case UMDBRIGHTNESS:
			// Validate the range for the setting, then update the button with active level.
			if ((r->sInfo().toInt() > 0) && (r->sInfo().toInt() <= 3))
			{
				// Clear old highlight
				if (umd_brightness != 0)
					textPut("statesheet", DESELECTED, MAIN_PANEL, bncs_string("UMDBright_%1").arg(umd_brightness));
				// Set new highlight
				umd_brightness = r->sInfo().toInt();	// Remember new value
				textPut("statesheet", SELECTED, MAIN_PANEL, bncs_string("UMDBright_") + r->sInfo());
			}
			break;

		case UMDACTIVENAMES:
			// Validate the range for the setting, then update the mimic with the data.
			if ((r->sInfo().toInt() >= 0) && (r->sInfo().toInt() <= NAMESETS))
			{
				umd_active_names = r->sInfo().toInt();
				// Update the mimic
				textPut("text", name_names[umd_active_names], MAIN_PANEL, "Current");
			}
			break;

		default:
			break;
		}
	}
	
	return 0;
}


// +++++++++++++++++++++++++++++++++++++++++ //
// All database name changes come back here. //
// +++++++++++++++++++++++++++++++++++++++++ //
void UMDnames::databaseCallback(revertiveNotify *r)
{
	// We have interests in only two types of name updates:
	// 1) Changes to the user names in databases 1 to 9
	// 2) Changes to the long source names in the SDI router, database 0.
	// The second instance is managed by the smart control functions, so this callback
	// only has to manage the user names database.

	if (r->device() == umd_names_id)
	{
		if ((r->database() >= 1) && (r->database() <= 8))	// Look for a change to the source names databases
		{
			bncs_string *update_set;

			switch (r->database())
			{
			case 1: update_set = UserNames_1; break;
			case 2: update_set = UserNames_2; break;
			case 3: update_set = UserNames_3; break;
			case 4: update_set = UserNames_4; break;
			case 5: update_set = UserNames_5; break;
			case 6: update_set = UserNames_6; break;
			case 7: update_set = UserNames_7; break;
			case 8: update_set = UserNames_8; break;
			}
			update_set[r->index()] = r->sInfo();	// Update the memory copy

			// If the updated name is in edit in the keyboard, update the keyboard buffer and the PreEdit displays
			if (edit_active && !setname_edit)		// Are we doing a name edit?
			{
				if ((r->database() == edit_set) && (r->index() == edit_index))	// Is the name we are editing changed by another panel?
				{
					// Yes - so update the Pre-Edit info and Keyboard buffer
					textPut("text", r->sInfo(), EDIT_PANEL, "PreEdit");
					textPut("text", r->sInfo(), EDIT_PANEL, "KB_1");
				}
			}
			return;
		}	// End of if ((r->database() >= 1) && (r->database() <= 8))

		if (r->database() == 9)
		{
			// Nameset name change. Be defensive and ensure the changed index is between 1 and 8.
			if ((r->index() >= 1) && (r->index() <= 8))
			{
				// Update the in-memory copy
				name_names[r->index()] = r->sInfo();

				// Update the name display.
				textPut("text", r->sInfo(), MAIN_PANEL, bncs_string("Names_%1").arg(r->index()));	

				// Update the display in the Currnt name indicator if the changed database matches the active name set
				if (r->index() == umd_active_names) textPut("text", r->sInfo(), MAIN_PANEL, "Current");
			}
			return;
		}
		
	}	// End of if (r->device() == umd_names_id)
}	// End of databaseCallback(revertiveNotify *r)


// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// All parent notifications come here i.e. when this script is just one    //
// component of another dialog then our host might want to tell us things. //
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
bncs_string UMDnames::parentCallback( parentNotify *p )
{
	if( p->command() == "return" )
	{
		if( p->value() == "all" )
		{	// Persisting values for bncs_vis_ed
			bncs_stringlist sl;
			
			sl << bncs_string( "myParam=%1" ).arg( m_myParam );
			
			return sl.toString( '\n' );
		}

		else if( p->value() == "myParam" )
		{	// Specific value being asked for by a textGet
			return( bncs_string( "%1=%2" ).arg( p->value() ).arg( m_myParam ) );
		}

	}
	else if( p->command() == "instance" && p->value() != m_instance )
	{	// Our instance is being set/changed
		m_instance = p->value();
		//Do something instance-change related here
	}

	else if( p->command() == "myParam" )
	{	// Persisted value or 'Command' being set here
		m_myParam = p->value();
	}

	// ***** CONNECTIONS EVENTS HELPER LIST *****
	else if( p->command() == "_events" )
	{	// Helper-list of everything in this component generated by hostNotify's
		bncs_stringlist sl;

		sl << "notify=*";		
		
		return sl.toString( '\n' );
	}

	// ***** CONNECTIONS COMMANDS HELPER LIST *****
	else if( p->command() == "_commands" )
	{	// Helper-list of any commands/parameters you might want to set at run-time
		bncs_stringlist sl;
		
		sl << "myParam=[value]";
		
		return sl.toString( '\n' );
	}

	return "";
}


// +++++++++++++++++++++++ //
// Timer events come here. //
// +++++++++++++++++++++++ //
void UMDnames::timerCallback( int id )
{
	switch( id )
	{
	case TIMER_CONFIRM:
		timeout--;		// Decrement timeout counter
		if (timeout == 0)
		{
			controlDisable(MAIN_PANEL, "Confirm");
			textPut("statesheet", DESELECTED, MAIN_PANEL, bncs_string("Select_") + bncs_string(new_names));
			timerStop(id);
			select_active = false;
		}
		break;


	case TIMER_EDIT:
		timeoutedit--;
		if ((timeoutedit & 0x1) == 0)
		{
			textPut("statesheet", FLASHLOW, EDIT_PANEL, "Cancel");  // Initial on even
			textPut("statesheet", FLASHHIGH, EDIT_PANEL, "Update");
		}
		else
		{
			textPut("statesheet", FLASHHIGH, EDIT_PANEL, "Cancel");  // Initial on even
			textPut("statesheet", FLASHLOW, EDIT_PANEL, "Update");
		}

		if (timeoutedit == 0)
		{
			// Timed out without button push. So do an auto cancel.
			timerStop(TIMER_EDIT);
			cancelAction();
		}
		break;

	default:	// Unhandled timer event
		timerStop(id);
		break;
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////// Callbacks above - Methods below ///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// function disableButtons_1() is called to disable the nameset //
// selection buttons, the panel switch button, the name group   //
// buttons and the name selector button.                        //
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
void UMDnames::disableButtons_1(void)
{
	// Called to disable the nameset selection buttons, the panel switch button, the name group buttons and the name selector button
	controlDisable(EDIT_PANEL, "SrcGroup");
	controlDisable(EDIT_PANEL, "SrcName");
	controlDisable(EDIT_PANEL, "Nameset_Select");
	for (int i = 1; i <= NAMESETS; i++) controlDisable(EDIT_PANEL, bncs_string("NameSet_%1").arg(i));
	controlDisable(EDIT_PANEL, "NamesetName");
}

// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// function activeNames() is called to set up a pointer to //
// the array of names that are currently active. Prior to  //
// the call variable edit_set must be assigned the current //
// nameset index.                                          //
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
void UMDnames::activeNames(void)
{
	if ((edit_set < 1) || (edit_set > 8)) return; // Defensive programming.

	switch (edit_set)
	{
	case 1: current = UserNames_1; break;
	case 2: current = UserNames_2; break;
	case 3: current = UserNames_3; break;
	case 4: current = UserNames_4; break;
	case 5: current = UserNames_5; break;
	case 6: current = UserNames_6; break;
	case 7: current = UserNames_7; break;
	case 8: current = UserNames_8; break;
	}
}

// ++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// function cancelAction() is called to cancel any edit //
// actions and restore the various buttons and panels.  //
// ++++++++++++++++++++++++++++++++++++++++++++++++++++ //
void UMDnames::cancelAction(void)
{
	timerStop(TIMER_EDIT);
	textPut("text=", EDIT_PANEL, "Nameset_id");
	textPut("text=", EDIT_PANEL, "LongName");
	textPut("text=", EDIT_PANEL, "PreEdit");
	textPut("text=", EDIT_PANEL, "PostEdit");
	textPut("text=", EDIT_PANEL, "KB_1");
	controlDisable(EDIT_PANEL, "Cancel");
	controlDisable(EDIT_PANEL, "Update");
	controlEnable(EDIT_PANEL, "SrcGroup");
	controlEnable(EDIT_PANEL, "SrcName");
	controlEnable(EDIT_PANEL, "Nameset_Select");
	for (int i = 1; i <= NAMESETS; i++) controlEnable(EDIT_PANEL, bncs_string("NameSet_%1").arg(i));
	controlEnable(EDIT_PANEL, "NamesetName");
	// Deselect the source in SrcName
	textPut("index=0", EDIT_PANEL, "SrcName");
	edit_active = false;
	hideEditInfo();
}


// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// function showEditInfo() is called to reveal the information //
// labels and current settings for an edit of a source name.   //
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
void UMDnames::showEditInfo(void)
{
	controlShow(EDIT_PANEL, "L1");
	controlShow(EDIT_PANEL, "L2");
	controlShow(EDIT_PANEL, "L3");
	controlShow(EDIT_PANEL, "L4");
	controlShow(EDIT_PANEL, "Nameset_id");
	controlShow(EDIT_PANEL, "LongName");
	controlShow(EDIT_PANEL, "PreEdit");
	controlShow(EDIT_PANEL, "PostEdit");
}


// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
// function hideEditInfo() is called to hide the information //
// labels and current settings for an edit of a source name. //
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //
void UMDnames::hideEditInfo(void)
{
	controlHide(EDIT_PANEL, "L1");
	controlHide(EDIT_PANEL, "L2");
	controlHide(EDIT_PANEL, "L3");
	controlHide(EDIT_PANEL, "L4");
	controlHide(EDIT_PANEL, "Nameset_id");
	controlHide(EDIT_PANEL, "LongName");
	controlHide(EDIT_PANEL, "PreEdit");
	controlHide(EDIT_PANEL, "PostEdit");
}

