Exemplo n.º 1
0
        private void Rename_Click(object sender, RoutedEventArgs e)
        {
            if (WorldTree.SelectedItem != null)
            {
                object dataContext = ((TreeViewItem)WorldTree.SelectedItem).DataContext;

                if (dataContext is LevelInfo)
                {
                    LevelInfo levelInfo    = dataContext as LevelInfo;
                    string    previousName = levelInfo.Name;

                    string newName = InputWindow.GetInput("Rename level", levelInfo.Name);
                    if (newName != null)
                    {
                        LevelInfo existingInfo = _levelService.AllLevels().Where(l => l.Name.Equals(newName, System.StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                        if (existingInfo == null)
                        {
                            _levelService.RenameLevel(levelInfo.Name, newName);
                            levelInfo.Name = newName;

                            _levelService.NotifyUpdate(levelInfo);
                            NameUpdated(new NameUpdate((IInfo)levelInfo, previousName, levelInfo.Name));
                            ((TreeViewItem)WorldTree.SelectedItem).Header = levelInfo.Name;
                        }
                        else
                        {
                            AlertWindow.Alert(newName + " already exists!");
                        }
                    }
                }
                else if (dataContext is WorldInfo)
                {
                    WorldInfo worldInfo    = dataContext as WorldInfo;
                    string    previousName = worldInfo.Name;

                    string newName = InputWindow.GetInput("Rename map", worldInfo.Name);
                    if (newName != null)
                    {
                        WorldInfo existingInfo = _worldService.AllWorlds().Where(w => w.Name.Equals(newName, System.StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                        if (existingInfo == null)
                        {
                            _worldService.RenameWorld(worldInfo.Name, newName);
                            worldInfo.Name = newName;

                            NameUpdated(new NameUpdate((IInfo)worldInfo, previousName, worldInfo.Name));
                            ((TreeViewItem)WorldTree.SelectedItem).Header = worldInfo.Name;
                        }
                        else
                        {
                            AlertWindow.Alert(newName + " already exists!");
                        }
                    }
                }
            }
        }