Beispiel #1
0
        public void InterpretCommand(ITagModuleScreen moduleScreen, string command)
        {
            var prefix = Url.Prefix(command);

            switch (prefix)
            {
            case BackToTemplateCommand:
            {
                moduleScreen.SwitchToModule(new MainProjectScreen(_project, -1));
                break;
            }

            case AddNewFilterCommand:
            {
                AddNewFilter();
                moduleScreen.ShowPage(StartScreen());
                break;
            }

            case DeleteFilterCommand:
            {
                var name = Url.GetValueFromQuery(command, "filter");
                DeleteFilter(name);
                moduleScreen.ShowPage(StartScreen());
                break;
            }

            case EditFilterCommand:
            {
                var name = Url.GetValueFromQuery(command, "filter");
                if (string.IsNullOrWhiteSpace(name))
                {
                    return;
                }

                _stateChange = StateChangePermission.NotAllowed;
                var ed = new FilterEditor(this, _project, name, null);
                ed.ShowDialog();

                _project.Reload();
                moduleScreen.ShowPage(StartScreen());
                break;
            }

            default:
                throw new Exception($"Unhandled command: {command}");
            }
        }
Beispiel #2
0
        public void InterpretCommand(ITagModuleScreen moduleScreen, string command)
        {
            var prefix = Url.Prefix(command);

            _lastPageIndex = -1; // by default, go back to the top of the screen

            switch (prefix)
            {
                #region Project commands

            case AddPageAtEndCommand:
            {
                _project.Pages.Add(new TemplatePage {
                        Name = "Untitled"
                    });
                _project.Save();
                moduleScreen.ShowPage(StartScreen());
                break;
            }

            case EditProjectNotesCommand:
            {
                // show a mini-edit screen for name and notes
                _stateChange = StateChangePermission.NotAllowed;
                var screen = new EditProjectNotes(this, _project);
                screen.ShowDialog();
                moduleScreen.ShowPage(StartScreen());
                break;
            }

            case SetSampleFileCommand:
            {
                ChooseSampleFile(moduleScreen);
                moduleScreen.ShowPage(StartScreen());
                break;
            }

            case RenderSampleCommand:
            {
                if (string.IsNullOrWhiteSpace(_project.Index.SampleFileName))
                {
                    moduleScreen.ShowPage(StartScreen());
                    return;
                }

                var file = moduleScreen.PickNewFile();
                if (!string.IsNullOrWhiteSpace(file))
                {
                    var fileSource = new FileSource(_project.BasePath);
                    var result     = new RenderProject(fileSource).ToFile(file, Path.Combine(_project.BasePath, _project.Index.SampleFileName), _project.Index);

                    if (result.Success)
                    {
                        MessageBox.Show($"Render complete\r\n\r\nloading images: {result.LoadingTime}\r\ntotal time: {result.OverallTime}");
                    }
                    else
                    {
                        MessageBox.Show($"Render failed: {result.ErrorMessage ?? "<unknown>"}");
                    }
                }

                moduleScreen.ShowPage(StartScreen());
                break;
            }

            case SetDataFiltersCommand:
            {
                moduleScreen.SwitchToModule(new ProjectFiltersScreen(_project));
                break;
            }

                #endregion

                #region Page commands

            case DeletePageCommand:
            {
                var pageIndex = Url.GetIndexFromQuery(command);
                _lastPageIndex = pageIndex;
                var result = MessageBox.Show("Are you sure", "Delete", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    _project.Index.Pages.RemoveAt(pageIndex);
                    _project.Save();
                    _lastPageIndex = Math.Max(0, pageIndex - 1);
                }

                moduleScreen.ShowPage(StartScreen());
                break;
            }

            case EditBackgroundCommand:
            {
                var pageIndex = Url.GetIndexFromQuery(command);
                ChooseBackgroundFile(moduleScreen, pageIndex);
                _lastPageIndex = pageIndex;
                moduleScreen.ShowPage(StartScreen());
                break;
            }

            case EditMetaDataCommand:
            {
                var pageIndex = Url.GetIndexFromQuery(command);
                _stateChange = StateChangePermission.NotAllowed;

                new EditPageMeta(this, _project, pageIndex).ShowDialog();

                _lastPageIndex = pageIndex;
                moduleScreen.ShowPage(StartScreen());
                break;
            }

            case EditBoxesCommand:
            {
                var pageIndex = Url.GetIndexFromQuery(command);
                _stateChange = StateChangePermission.NotAllowed;

                new BoxPlacer(this, _project, pageIndex).ShowDialog();

                _lastPageIndex = pageIndex;
                moduleScreen.ShowPage(StartScreen());
                break;
            }

            case EditPageFiltersCommand:
            {
                var pageIndex = Url.GetIndexFromQuery(command);
                moduleScreen.SwitchToModule(new PageFiltersScreen(_project, pageIndex));
                break;
            }

            case ChangePageRepeatCommand:
            {
                var pageIndex = Url.GetIndexFromQuery(command);
                if (string.IsNullOrWhiteSpace(_project.Index.SampleFileName))
                {
                    MessageBox.Show("Please add a sample file before setting repeat mappings");
                    moduleScreen.ShowPage(StartScreen());
                    return;
                }
                _stateChange = StateChangePermission.NotAllowed;

                new RepeatModePicker(this, _project, pageIndex).ShowDialog();

                _project.Reload();
                _lastPageIndex = pageIndex;
                moduleScreen.ShowPage(StartScreen());
                break;
            }

            case InsertPageCommand:
            {
                var idx = Url.GetIndexFromQuery(command);
                _project.Pages.Insert(idx, new TemplatePage {
                        Name = "Untitled"
                    });
                _project.Save();
                _lastPageIndex = idx;
                moduleScreen.ShowPage(StartScreen());
                break;
            }

            case MovePageUpCommand:
            {
                var idx = Url.GetIndexFromQuery(command);
                if (idx <= 0)
                {
                    return;               // ignore up past top
                }
                var tmp = _project.Pages[idx];
                _project.Pages[idx]     = _project.Pages[idx - 1];
                _project.Pages[idx - 1] = tmp;
                _project.Save();
                _lastPageIndex = idx - 1;
                moduleScreen.ShowPage(StartScreen());
                return;
            }

            case MovePageDownCommand:
            {
                var idx = Url.GetIndexFromQuery(command);
                if (idx >= _project.Pages.Count - 1)
                {
                    return;                                      // ignore down past bottom
                }
                var tmp = _project.Pages[idx];
                _project.Pages[idx]     = _project.Pages[idx + 1];
                _project.Pages[idx + 1] = tmp;
                _project.Save();
                _lastPageIndex = idx + 1;
                moduleScreen.ShowPage(StartScreen());
                return;
            }

                #endregion

            default:
                throw new Exception($"Unexpected command: {command}");
            }
        }