Esempio n. 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;
        }
Esempio n. 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);

            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] == null || _model.Files[file].Content == null)
                {
                    continue;
                }

                var elName = key;
                if (_model.Files[key].Filename != null)
                {
                    elName = _model.Files[key].Filename;
                }

                var el = new FileElement(elName, key, _model.Files[key]);
                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))
                        {
                            if (IsDuplicateName(name))
                            {
                                throw new InvalidOperationException("A filename by that type already exists");
                            }
                        }

                        if (_originalGist.Files.ContainsKey(key))
                        {
                            _model.Files[key] = new GistEditModel.File {
                                Content = content, Filename = name
                            }
                        }
                        ;
                        else
                        {
                            _model.Files.Remove(key);
                            _model.Files[name] = new GistEditModel.File {
                                Content = content
                            };
                        }
                    };

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

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

            Root = root;
        }
Esempio n. 3
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;
        }
Esempio n. 4
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);

            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] == null || _model.Files[file].Content == null)
                    continue;

                var elName = key;
                if (_model.Files[key].Filename != null)
                    elName = _model.Files[key].Filename;

                var el = new FileElement(elName, key, _model.Files[key]);
                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))
                            if (IsDuplicateName(name))
                                throw new InvalidOperationException("A filename by that type already exists");

                        if (_originalGist.Files.ContainsKey(key))
                            _model.Files[key] = new GistEditModel.File { Content = content, Filename = name };
                        else
                        {
                            _model.Files.Remove(key);
                            _model.Files[name] = new GistEditModel.File { Content = content };
                        }
                    };

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

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

            Root = root;
        }