Index: base/gameDetector.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/base/gameDetector.cpp,v
retrieving revision 1.68
diff -u -3 -p -r1.68 gameDetector.cpp
--- base/gameDetector.cpp	9 Feb 2004 01:27:26 -0000	1.68
+++ base/gameDetector.cpp	12 Feb 2004 11:06:14 -0000
@@ -175,21 +175,22 @@ void listTargets() {
 	using namespace Common;
 	const ConfigManager::DomainMap &domains = ConfMan.getGameDomains();
 
-	printf("Target               Description                                           \n"
-	       "-------------------- ------------------------------------------------------\n");
+	printf("Target Game ID              Description                         \n"
+	       "------ -------------------- ------------------------------------\n");
 
 	ConfigManager::DomainMap::const_iterator iter = domains.begin();
 	for (iter = domains.begin(); iter != domains.end(); ++iter) {
 		String name(iter->_key);
+		String gameId(iter->_value.get("gameid"));
 		String description(iter->_value.get("description"));
 
 		if (description.isEmpty()) {
-			GameSettings g = GameDetector::findGame(name);
+			GameSettings g = GameDetector::findGame(gameId);
 			if (g.description)
 				description = g.description;
 		}
 
-		printf("%-20s %s\n", name.c_str(), description.c_str());
+		printf("%-6s %-20s %s\n", name.c_str(), gameId.c_str(), description.c_str());
 	}
 }
 
Index: gui/launcher.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/launcher.cpp,v
retrieving revision 1.88
diff -u -3 -p -r1.88 launcher.cpp
--- gui/launcher.cpp	9 Feb 2004 07:52:21 -0000	1.88
+++ gui/launcher.cpp	12 Feb 2004 11:06:17 -0000
@@ -57,6 +57,8 @@ enum {
 	kEditGameCmd = 'EDTG',
 	kRemoveGameCmd = 'REMG',
 	kQuitCmd = 'QUIT',
+	kMoveUpCmd = 'MVUP',
+	kMoveDownCmd = 'MVDN',
 	
 	
 	kCmdGlobalGraphicsOverride = 'OGFX',
@@ -92,7 +94,7 @@ public:
 
 protected:
 	EditTextWidget *_descriptionWidget;
-	EditTextWidget *_domainWidget;
+	EditTextWidget *_gameIdWidget;
 
 	PopUpWidget *_langPopUp;
 	PopUpWidget *_platformPopUp;
@@ -120,6 +122,9 @@ EditGameDialog::EditGameDialog(const Str
 		description = target.description;
 	}
 
+	// GAME: Determine the gameid string
+	String gameId(ConfMan.get("gameid", domain));	
+
 	// GUI:  Add tab widget
 	TabWidget *tab = new TabWidget(this, 0, vBorder, _w, _h - 24 - 2*vBorder);
 
@@ -129,11 +134,6 @@ EditGameDialog::EditGameDialog(const Str
 	tab->addTab("Game");
 	yoffset = vBorder;
 
-	// GUI:  Label & edit widget for the game ID
-	new StaticTextWidget(tab, x, yoffset + 2, labelWidth, kLineHeight, "ID: ", kTextAlignRight);
-	_domainWidget = new EditTextWidget(tab, x + labelWidth, yoffset, _w - labelWidth - 10, kLineHeight, _domain);
-	yoffset += 16;
-
 	// GUI:  Label & edit widget for the description
 	new StaticTextWidget(tab, x, yoffset + 2, labelWidth, kLineHeight, "Name: ", kTextAlignRight);
 	_descriptionWidget = new EditTextWidget(tab, x + labelWidth, yoffset, _w - labelWidth - 10, kLineHeight, description);
@@ -144,6 +144,11 @@ EditGameDialog::EditGameDialog(const Str
 	new StaticTextWidget(tab, x + labelWidth, yoffset, _w - labelWidth - 10, kLineHeight, path, kTextAlignLeft);
 	yoffset += 16;
 
+	// GUI:  Label & edit widget for the game ID
+	new StaticTextWidget(tab, x, yoffset + 2, labelWidth, kLineHeight, "Game Id: ", kTextAlignRight);
+	_gameIdWidget = new EditTextWidget(tab, x + labelWidth, yoffset, _w - labelWidth - 10, kLineHeight, gameId);
+	yoffset += 16;
+
 	// Languag popup
 	_langPopUp = new PopUpWidget(tab, x, yoffset, w, kLineHeight, "Language: ", labelWidth);
 	yoffset += 16;
@@ -254,6 +259,7 @@ void EditGameDialog::open() {
 
 void EditGameDialog::close() {
 	if (getResult()) {
+		ConfMan.set("gameid", _gameIdWidget->getLabel(), _domain);
 		ConfMan.set("description", _descriptionWidget->getLabel(), _domain);
 
 		Common::Language lang = (Common::Language)_langPopUp->getSelectedTag();
@@ -285,9 +291,9 @@ void EditGameDialog::handleCommand(Comma
 		setVolumeSettingsState(data != 0);
 		draw();
 		break;
-	case kOKCmd: {
-		// Write back changes made to config object
-		String newDomain(_domainWidget->getLabel());
+	case kOKCmd: /* {
+		// Write Back is handled by close()
+		String newDomain(_gameIdWidget->getLabel());
 		if (newDomain != _domain) {
 			if (newDomain.isEmpty() || ConfMan.hasGameDomain(newDomain)) {
 				MessageDialog alert("This game ID is already taken. Please choose another one.");
@@ -297,7 +303,7 @@ void EditGameDialog::handleCommand(Comma
 			ConfMan.renameGameDomain(_domain, newDomain);
 			_domain = newDomain;
 		}
-		}
+		} */
 		// FALL THROUGH to default case
 	default:
 		OptionsDialog::handleCommand(sender, cmd, data);
@@ -331,16 +337,26 @@ LauncherDialog::LauncherDialog(GameDetec
 	_list->setNumberingMode(kListNumberingOff);
 
 	// Two more buttons directly below the list box
-	const int kBigButtonWidth = 90;
-	new ButtonWidget(this, 10, 144, kBigButtonWidth, 16, "Add Game...", kAddGameCmd, 'A');
-	_editButton = new ButtonWidget(this, (320-kBigButtonWidth) / 2, 144, kBigButtonWidth, 16, "Edit Game...", kEditGameCmd, 'E');
-	_removeButton = new ButtonWidget(this, 320-kBigButtonWidth - 10, 144, kBigButtonWidth, 16, "Remove Game", kRemoveGameCmd, 'R');
+	const int kBigButtonWidth = 80;
+	new ButtonWidget(this, 8, 144, kBigButtonWidth, 16, "Add Game...", kAddGameCmd, 'A');
+	_editButton = new ButtonWidget(this, 2*8+kBigButtonWidth, 144, kBigButtonWidth, 16, "Edit Game...", kEditGameCmd, 'E');
+	_removeButton = new ButtonWidget(this, 3*8+2*kBigButtonWidth, 144, kBigButtonWidth, 16, "Remove Game", kRemoveGameCmd, 'R');
+	_moveUpButton = new ButtonWidget( this, 4*8+3*kBigButtonWidth , 144, 16, 16, "U", kMoveUpCmd, 'U');
+	_moveDownButton = new ButtonWidget( this, 5*8+3*kBigButtonWidth+16 , 144, 16, 16, "D", kMoveDownCmd, 'D');
 
 	// Populate the list
 	updateListing();
 
-	// TODO - make a default selection (maybe the game user played last?)
-	//_list->setSelected(0);
+	// Restore last selection
+	String last = ConfMan.get(String("lastselectedgame"), ConfigManager::kApplicationDomain);
+	if (!last.isEmpty()) {
+	    int itemToSelect = 0;
+	    StringList::const_iterator iter;
+	    for (iter = _domains.begin(); iter != _domains.end(); ++iter, ++itemToSelect)
+		if (last == *iter) {
+		    _list->setSelected(itemToSelect);
+		}
+        }
 
 	// En-/Disable the buttons depending on the list selection
 	updateButtons();
@@ -361,26 +377,21 @@ void LauncherDialog::updateListing() {
 	const ConfigManager::DomainMap &domains = ConfMan.getGameDomains();
 	ConfigManager::DomainMap::const_iterator iter = domains.begin();
 	for (iter = domains.begin(); iter != domains.end(); ++iter) {
-		String name(iter->_value.get("gameid"));
+		String gameid(iter->_value.get("gameid"));
+		if (gameid.isEmpty())
+		    continue;
+		
 		String description(iter->_value.get("description"));
-
-		if (name.isEmpty())
-			name = iter->_key;
 		if (description.isEmpty()) {
-			GameSettings g = GameDetector::findGame(name);
-			if (g.description)
-				description = g.description;
+		    GameSettings g = GameDetector::findGame(gameid);
+		    if (g.description)
+			description = g.description;
+		    else
+			description = gameid;
 		}
 
-		if (!name.isEmpty() && !description.isEmpty()) {
-			// Insert the game into the launcher list
-			int pos = 0, size = l.size();
-
-			while (pos < size && (description > l[pos]))
-				pos++;
-			l.insert_at(pos, description);
-			_domains.insert_at(pos, iter->_key);
-		}
+		l.push_back(description);
+		_domains.push_back(iter->_key);
 	}
 
 	_list->setList(l);
@@ -430,22 +441,20 @@ void LauncherDialog::addGame() {
 		if (0 <= idx && idx < (int)candidates.size()) {
 			DetectedGame result = candidates[idx];
 
-			// The auto detector or the user made a choice.
-			// Pick a domain name which does not yet exist (after all, we
-			// are *adding* a game to the config, not replacing).
-			String domain(result.name);
-			if (ConfMan.hasGameDomain(domain)) {
-				char suffix = 'a';
-				domain += suffix;
-				while (ConfMan.hasGameDomain(domain)) {
-					assert(suffix < 'z');
-					domain.deleteLastChar();
-					suffix++;
-					domain += suffix;
-				}
-				ConfMan.set("gameid", result.name, domain);
-				ConfMan.set("description", result.description, domain);
-			}
+			// We need to find a free domain
+			// We search starting at numDomains
+			int nextNumber = ConfMan.numGameDomains();
+			String domain;
+			char tmp[10];			
+
+			do {
+			    nextNumber++;
+			    sprintf( tmp, "%06i", nextNumber );
+			    domain = tmp; 			
+			} while (ConfMan.hasGameDomain(domain));
+		
+			ConfMan.set("gameid", result.name, domain);
+			ConfMan.set("description", result.description, domain);
 			ConfMan.set("path", dir->path(), domain);
 			
 			const bool customLanguage = (result.language != Common::UNK_LANG);
@@ -557,11 +566,33 @@ void LauncherDialog::handleCommand(Comma
 		about.runModal();
 		}
 		break;
+	case kMoveUpCmd: {		    		    
+		    String lower = _domains[item];
+		    String upper = _domains[item-1];		    
+		    ConfMan.swapDomains( lower, upper );
+		    ConfMan.flushToDisk();
+		    updateListing();
+		    _list->setSelected(item-1);
+		    draw();		    
+		}
+		break;
+	case kMoveDownCmd: {
+		    String lower = _domains[item+1];
+		    String upper = _domains[item];		    
+		    ConfMan.swapDomains( lower, upper );
+		    ConfMan.flushToDisk();
+		    updateListing();
+		    _list->setSelected(item+1);
+		    draw();		    	
+		}
+		break;
 	case kStartCmd:
 	case kListItemActivatedCmd:
 	case kListItemDoubleClickedCmd:
 		// Print out what was selected
 		assert(item >= 0);
+		ConfMan.set(String("lastselectedgame"), _domains[item], ConfigManager::kApplicationDomain);
+		ConfMan.flushToDisk();
 		_detector.setTarget(_domains[item]);
 		close();
 		break;
@@ -569,6 +600,8 @@ void LauncherDialog::handleCommand(Comma
 		updateButtons();
 		break;
 	case kQuitCmd:
+		ConfMan.set(String("lastselectedgame"), _domains[item], ConfigManager::kApplicationDomain);
+		ConfMan.flushToDisk();
 #ifdef __PALM_OS__
 		close();
 #endif
@@ -592,6 +625,17 @@ void LauncherDialog::updateButtons() {
 	if (enable != _removeButton->isEnabled()) {
 		_removeButton->setEnabled(enable);
 		_removeButton->draw();
+	}
+
+	bool upState = (_list->getSelected() >= 1);
+	if (upState != _moveUpButton->isEnabled()) {
+		_moveUpButton->setEnabled(upState);
+		_moveUpButton->draw();
+	}
+	bool downState = (_list->getSelected() >= 0 && _list->getSelected()+1 < (int)_list->getList().size());
+	if (downState != _moveDownButton->isEnabled()) {
+		_moveDownButton->setEnabled(downState);
+		_moveDownButton->draw();
 	}
 }
 
Index: gui/launcher.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/gui/launcher.h,v
retrieving revision 1.18
diff -u -3 -p -r1.18 launcher.h
--- gui/launcher.h	5 Feb 2004 11:59:04 -0000	1.18
+++ gui/launcher.h	12 Feb 2004 11:06:17 -0000
@@ -45,6 +45,8 @@ protected:
 	Widget			*_startButton;
 	Widget			*_editButton;
 	Widget			*_removeButton;
+	Widget			*_moveUpButton;
+	Widget			*_moveDownButton;
 	StringList		_domains;
 	GameDetector 	&_detector;
 	BrowserDialog	*_browser;
