Пример #1
0
        private void ChooseBackgroundFile(ITagModuleScreen module, int pageIndex)
        {
            // If cancel, do nothing
            // If not in the project directory, copy it in and continue with that as the new path
            // Check that it's json
            //  - if not, delete the file and go back to the old one (if present)
            //  - if OK, set the sample value and save

            var ok = module.PickAFile(out var filePath);

            if (!ok || filePath == null)
            {
                return;
            }

            if (Path.GetDirectoryName(filePath) != _project.BasePath)
            {
                var newPath = Path.Combine(_project.BasePath, Path.GetFileName(filePath));
                File.Copy(filePath, newPath);
                filePath = newPath;
            }

            _project.Pages[pageIndex].BackgroundImage = Path.GetFileName(filePath);
            _project.Save();
        }
Пример #2
0
        public void InterpretCommand(ITagModuleScreen moduleScreen, string command)
        {
            switch (command)
            {
            case NewTemplate:
                moduleScreen.ShowNewTemplate();
                break;

            case LoadTemplate:
                moduleScreen.ShowLoadTemplate();
                break;
            }
        }
Пример #3
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}");
            }
        }
Пример #4
0
        private void ChooseSampleFile(ITagModuleScreen module)
        {
            // If cancel, do nothing
            // If not in the project directory, copy it in and continue with that as the new path
            // Check that it's json
            //  - if not, delete the file and go back to the old one (if present)
            //  - if OK, set the sample value and save

            var ok = module.PickAFile(out var filePath);

            if (!ok || filePath == null)
            {
                return;
            }
            string?newPath = null;

            if (Path.GetDirectoryName(filePath) != _project.BasePath)
            {
                newPath = Path.Combine(_project.BasePath, Path.GetFileName(filePath));
                File.Copy(filePath, newPath);
                filePath = newPath;
            }

            try
            {
                var test = Json.DefrostDynamic(File.ReadAllText(filePath) !);
                if (test == null)
                {
                    throw new Exception("Serialiser returned unexpected empty result");
                }
            }
            catch (Exception ex)
            {
                if (newPath != null && File.Exists(newPath))
                {
                    File.Delete(newPath);
                }
                throw new Exception($"Could not read sample data: {ex.Message}", ex);
            }

            _project.Index.SampleFileName = Path.GetFileName(filePath);
            _project.Save();
        }
Пример #5
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}");
            }
        }