示例#1
0
        protected void UpdateView()
        {
            var root = new RootElement(Title) { UnevenRows = true };
            var section = new Section();
            root.Add(section);

            var desc = new Gistacular.Elements.MultilinedElement("Description") { Value = _model.Description };
            desc.Tapped += ChangeDescription;
            section.Add(desc);

            if (_public == null)
                _public = new Gistacular.Elements.TrueFalseElement("Public"); 
            _public.Value = _model.Public;

            if (_publicEditable)
                section.Add(_public);

            var fileSection = new Section();
            root.Add(fileSection);

            foreach (var file in _model.Files.Keys)
            {
                var key = file;
                if (!_model.Files.ContainsKey(key) || _model.Files[file].Content == null)
                    continue;

                var size = System.Text.ASCIIEncoding.UTF8.GetByteCount(_model.Files[file].Content);
                var el = new StyledElement(file, size + " bytes", UITableViewCellStyle.Subtitle) { Accessory = UITableViewCellAccessory.DisclosureIndicator };
                el.Tapped += () => {
                    if (!_model.Files.ContainsKey(key))
                        return;
                    var createController = new ModifyGistFileController(key, _model.Files[key].Content);
                    createController.Save = (name, content) => {

                        if (string.IsNullOrEmpty(name))
                            throw new InvalidOperationException("Please enter a name for the file");

                        //If different name & exists somewhere else
                        if (!name.Equals(key) && _model.Files.ContainsKey(name))
                            throw new InvalidOperationException("A filename by that type already exists");

                        //Remove old
                        _model.Files.Remove(key);

                        //Put new
                        _model.Files[name] = new GistCreateModel.File { Content = content };
                    };

                    NavigationController.PushViewController(createController, true);
                };
                fileSection.Add(el);
            }

            fileSection.Add(new StyledElement("Add New File", AddFile));

            Root = root;
        }
示例#2
0
        protected void UpdateView()
        {
            var root = new RootElement(Title)
            {
                UnevenRows = true
            };
            var section = new Section();

            root.Add(section);

            var desc = new Gistacular.Elements.MultilinedElement("Description")
            {
                Value = _model.Description
            };

            desc.Tapped += ChangeDescription;
            section.Add(desc);

            if (_public == null)
            {
                _public = new Gistacular.Elements.TrueFalseElement("Public");
            }
            _public.Value = _model.Public;

            if (_publicEditable)
            {
                section.Add(_public);
            }

            var fileSection = new Section();

            root.Add(fileSection);

            foreach (var file in _model.Files.Keys)
            {
                var key = file;
                if (!_model.Files.ContainsKey(key) || _model.Files[file].Content == null)
                {
                    continue;
                }

                var size = System.Text.ASCIIEncoding.UTF8.GetByteCount(_model.Files[file].Content);
                var el   = new StyledElement(file, size + " bytes", UITableViewCellStyle.Subtitle)
                {
                    Accessory = UITableViewCellAccessory.DisclosureIndicator
                };
                el.Tapped += () => {
                    if (!_model.Files.ContainsKey(key))
                    {
                        return;
                    }
                    var createController = new ModifyGistFileController(key, _model.Files[key].Content);
                    createController.Save = (name, content) => {
                        if (string.IsNullOrEmpty(name))
                        {
                            throw new InvalidOperationException("Please enter a name for the file");
                        }

                        //If different name & exists somewhere else
                        if (!name.Equals(key) && _model.Files.ContainsKey(name))
                        {
                            throw new InvalidOperationException("A filename by that type already exists");
                        }

                        //Remove old
                        _model.Files.Remove(key);

                        //Put new
                        _model.Files[name] = new GistCreateModel.File {
                            Content = content
                        };
                    };

                    NavigationController.PushViewController(createController, true);
                };
                fileSection.Add(el);
            }

            fileSection.Add(new StyledElement("Add New File", AddFile));

            Root = root;
        }