Exemplo n.º 1
0
 private void DeleteFilter(string name)
 {
     if (string.IsNullOrWhiteSpace(name))
     {
         return;
     }
     _project.Index.DataFilters.Remove(name);
     _project.Save();
 }
Exemplo n.º 2
0
        private void BoxPlacer_MouseUp(object sender, MouseEventArgs e)
        {
            if (_drawingBox && _validDraw)
            {
                AddBox();
            }
            if (_resizingBox || _movingBox)
            {
                _project?.Save();
            }

            _drag        = false;
            _drawingBox  = false;
            _movingBox   = false;
            _resizingBox = false;
        }
Exemplo n.º 3
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}");
            }
        }
Exemplo n.º 4
0
 private void saveButton_Click(object sender, EventArgs e)
 {
     UpdateBoxDefinition();
     _project?.Save();
     Close();
 }