Ejemplo n.º 1
0
        private TabItem NewTab(string title, object content = null)
        {
            TabItem tab = new TabItem();

            tab.Header   = title;
            tab.Margin   = new Thickness(0d);
            tab.MaxWidth = 100;
            tab.Opacity  = 0.9;

            MenuItem _deleteMenuItem = new MenuItem();

            _deleteMenuItem.Header = "Delete this event";
            _deleteMenuItem.Click += (object sender, RoutedEventArgs e) =>
            {
                RemoveTab(tab);
            };

            ContextMenu _contextMenu = new ContextMenu();

            _contextMenu.Items.Add(_deleteMenuItem);

            tab.ContextMenu = _contextMenu;

            if (content == null)
            {
                content = new XmlEditorPanel(new CityEventXmlContainer(), _itemPath, tab);
            }

            tab.Content = content;

            _eventTabs.Items.Add(tab);
            _eventTabs.SelectedItem = tab;

            return(tab);
        }
Ejemplo n.º 2
0
        private List <XmlEditorPanel> GetAllXmlEditors()
        {
            List <XmlEditorPanel> returnList = new List <XmlEditorPanel>();

            foreach (TabItem tab in _eventTabs.Items)
            {
                if (tab != null)
                {
                    XmlEditorPanel xmlEditor = tab.Content as XmlEditorPanel;

                    if (xmlEditor != null)
                    {
                        returnList.Add(xmlEditor);
                    }
                }
            }

            return(returnList);
        }
Ejemplo n.º 3
0
        private void FindEvents()
        {
            if (_itemPath != null)
            {
                string _eventsPath = _itemPath + Path.DirectorySeparatorChar + "RushHour Events";

                if (Directory.Exists(_eventsPath))
                {
                    string[] files = Directory.GetFiles(_eventsPath);

                    foreach (string file in files)
                    {
                        try
                        {
                            XmlSerializer _xmlSerialiser = new XmlSerializer(typeof(CityEventXml));
                            CityEventXml  xmlEvent       = _xmlSerialiser.Deserialize(new FileStream(file, FileMode.Open)) as CityEventXml;

                            if (xmlEvent != null)
                            {
                                foreach (CityEventXmlContainer xmlContainer in xmlEvent._containedEvents)
                                {
                                    string tabName = xmlContainer._userEventName == "" ? (xmlContainer._name == "" ? Constants.EMPTY_EVENT_TAB_NAME : xmlContainer._name) : xmlContainer._userEventName;

                                    XmlEditorPanel panel      = new XmlEditorPanel(xmlContainer, _itemPath);
                                    TabItem        createdTab = NewTab(tabName, panel);

                                    panel.ParentTab = createdTab;
                                }
                            }
                        }
                        catch
                        {
                            MessageBox.Show(this, "Couldn't load up the event data.", "Failed to load", MessageBoxButton.OK, MessageBoxImage.Error);
                        }
                    }
                }
            }

            if (_eventTabs.Items.Count <= 0)
            {
                NewTab(Constants.EMPTY_EVENT_TAB_NAME);
            }
        }