Ejemplo n.º 1
0
        /// <summary>
        /// Import from another railway package
        /// </summary>
        private void tbImport_Click(object sender, EventArgs e)
        {
            var filters = ImportFilters.Filters.ToList();

            using (var dialog = new OpenFileDialog())
            {
                dialog.Filter      = string.Join("|", filters.Select(x => x.OpenFileDialogFilter).ToArray());
                dialog.FilterIndex = 1;
                if (dialog.ShowDialog(this) != DialogResult.OK)
                {
                    return;
                }
                try
                {
                    var filter = filters[dialog.FilterIndex - 1];
                    if (filter.Import(appState.Package, dialog.FileName))
                    {
                        ReloadPackage();
                        UpdateAppTitle.Fire(this);
                        viewEditor.ReloadView();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(string.Format(Strings.ImportOfXFailedBecauseY, dialog.FileName, ex.Message), Strings.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add a new connection between modules
        /// </summary>
        private void tbAddModuleConnection_Click(object sender, EventArgs e)
        {
            var connection = appState.Package.Railway.ModuleConnections.AddNew();
            var node       = new EntityNode(connection, null);

            moduleConnectionsRoot.Nodes.Add(node);
            tvItems.SelectedNode = node;
            UpdateAppTitle.Fire(this);
            ValidateRailway();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// A value has changed.
 /// Update treenode.
 /// </summary>
 private void propertyGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
 {
     foreach (var node in tvItems.SelectedNodes.OfType <EntityNode>())
     {
         node.UpdateFromEntity();
     }
     propertyGrid.Refresh();
     ValidateRailway();
     UpdateAppTitle.Fire(this);
     viewEditor.ReloadView();
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Add a new loc group
        /// </summary>
        private void tbAddLocGroup_Click(object sender, EventArgs e)
        {
            var group = appState.Package.Railway.LocGroups.AddNew();

            group.Description = Strings.NewLocGroupDescription;
            var node = new EntityNode(group, null);

            locGroupsRoot.Nodes.Add(node);
            tvItems.SelectedNode = node;
            UpdateAppTitle.Fire(this);
            ValidateRailway();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Add P50x command station
        /// </summary>
        private void tbbAddP50x_Click(object sender, EventArgs e)
        {
            var cs = appState.Package.AddNewP50xCommandStation();

            cs.Description = Strings.NewP50xCommandStationDescription;
            var csRef = appState.Package.Railway.CommandStations.Add(cs);
            var node  = new EntityRefNode <ICommandStation>(csRef, cs);

            activeCommandStationsRoot.Nodes.Add(node);
            tvItems.SelectedNode = node;
            UpdateAppTitle.Fire(this);
            ValidateRailway();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Add a new module
        /// </summary>
        private void tbAddModule_Click(object sender, EventArgs e)
        {
            var module = appState.Package.AddNewModule();

            module.Description = Strings.NewModuleDescription;
            var moduleRef = appState.Package.Railway.Modules.Add(module);
            var node      = new EntityRefNode <IModule>(moduleRef, module);

            activeModulesRoot.Nodes.Add(node);
            tvItems.SelectedNode = node;
            UpdateAppTitle.Fire(this);
            ValidateRailway();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Add a new locomotive
        /// </summary>
        private void tbAddLoc_Click(object sender, EventArgs e)
        {
            var loc = appState.Package.AddNewLoc();

            loc.Description = Strings.NewLocDescription;
            var locRef = appState.Package.Railway.Locs.Add(loc);
            var node   = new EntityRefNode <ILoc>(locRef, loc);

            activeLocsRoot.Nodes.Add(node);
            tvItems.SelectedNode = node;
            UpdateAppTitle.Fire(this);
            ValidateRailway();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Activate the selected entity.
        /// </summary>
        private void tbActivate_Click(object sender, EventArgs e)
        {
            var selection = tvItems.SelectedNodes.OfType <EntityNode>().Where(x => x.IsArchived).ToList();

            if (selection.Any())
            {
                foreach (var node in selection)
                {
                    node.Entity.Accept(Default <ActivateVisitor> .Instance, appState.Package.Railway);
                }
                UpdateAppTitle.Fire(this);
                ReloadPackage();
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Edit the module contained in the given node (if any)
        /// </summary>
        private void EditModule(EntityNode node)
        {
            var module = (node != null) ? node.Entity as IModule : null;

            if (module != null)
            {
                using (var dialog = new EditModuleForm(appState, module, viewEditor.Context))
                {
                    dialog.ShowDialog(this);
                }
                viewEditor.ReloadView();
                ValidateRailway();
                UpdateAppTitle.Fire(this);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Remove the entity completely from the package.
        /// </summary>
        private void tbRemove_Click(object sender, EventArgs e)
        {
            var selection = tvItems.SelectedNodes.OfType <EntityNode>().Select(x => x.GetEntityRefOrEntity()).ToList();

            if (selection.Any())
            {
                var msg = (selection.Count == 1) ?
                          string.Format(Strings.SuretoRemoveXFromPackage, selection[0]) :
                          string.Format(Strings.SuretoRemoveAllXEntitiesFromPackage, selection.Count);
                if (MessageBox.Show(msg, Strings.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                {
                    foreach (var entity in selection)
                    {
                        entity.Accept(Default <RemoveFromPackageVisitor> .Instance, appState.Package);
                    }
                    UpdateAppTitle.Fire(this);
                    ReloadPackage();
                }
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// View requests a full reload.
 /// </summary>
 private void viewEditor_Reload(object sender, EventArgs e)
 {
     ReloadPackage();
     UpdateAppTitle.Fire(this);
 }