コード例 #1
0
        private static Action <object> MakeCallback(GistEditViewController ctrl, string key)
        {
            var weakCtrl = new WeakReference <GistEditViewController>(ctrl);

            return(new Action <object>(_ =>
            {
                var model = weakCtrl.Get()?._model;
                if (model == null || !model.Files.ContainsKey(key))
                {
                    return;
                }

                var originalGist = weakCtrl.Get()?._originalGist;

                var createController = new GistFileEditViewController {
                    Filename = key, Content = model.Files[key].Content
                };
                createController.SaveCommand.Subscribe(__ => weakCtrl.Get()?.NavigationController.PopToViewController(weakCtrl.Get(), true));
                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 (weakCtrl.Get()?.IsDuplicateName(name) == true)
                        {
                            throw new InvalidOperationException("A filename by that type already exists");
                        }
                    }

                    if (originalGist?.Files.ContainsKey(key) == true)
                    {
                        model.Files[key] = new GistFileUpdate {
                            Content = content, NewFileName = name
                        }
                    }
                    ;
                    else
                    {
                        model.Files.Remove(key);
                        model.Files[name] = new GistFileUpdate {
                            Content = content
                        };
                    }
                };

                weakCtrl.Get()?.NavigationController.PushViewController(createController, true);
            }));
        }
コード例 #2
0
 public EditSource(GistEditViewController dvc)
     : base(dvc)
 {
 }