コード例 #1
0
        // Prompt the user to add a new account
        private void OnAddAccount(object o, EventArgs args)
        {
            var dialog = new AccountDialog();

            if (dialog.Run() == (int)ResponseType.Accept)
            {
                // it's not already there
                if (!AccountList.Contains(dialog.Result))
                {
                    AccountList.Add(dialog.Result);
                    // set defaults
                    if (dialog.DefaultAnime)
                    {
                        DefAnime = dialog.Result;
                    }
                    if (dialog.DefaultManga)
                    {
                        DefManga = dialog.Result;
                    }
                    AddToStore(dialog.Result); // add account and update default display
                }
                else                           // whoops
                {
                    using (var md = new MessageDialog(null, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.Ok,
                                                      "That account already exists.")) {
                        md.WindowPosition = WindowPosition.Center;
                        md.Run();
                        md.Destroy();
                    }
                }
            }
            dialog.Destroy();
        }
コード例 #2
0
        // We want to edit an entry!
        private void EditAccount(TreeModel model, TreeIter i)
        {
            var a = AccountList.First(x =>
                                      (string)model.GetValue(i, (int)Columns.Username) == x.Username &&
                                      (string)model.GetValue(i, (int)Columns.Service) == x.Provider);
            var dialog = new AccountDialog(a, GetDefaultAccounts(a));

            if (dialog.Run() == (int)ResponseType.Accept)
            {
                a.Credentials.Password = dialog.Result.Credentials.Password;
                if (dialog.DefaultAnime)
                {
                    DefAnime = a;
                }
                else if (DefAnime == a)
                {
                    DefAnime = null;                                    // We have deselected this account as the default!
                }
                if (dialog.DefaultManga)
                {
                    DefManga = a;
                }
                else if (DefManga == a)
                {
                    DefManga = null;                                    // We have deselected this account asthe default!
                }
                model.SetValue(i, (int)Columns.Used, GetDefaultAccounts(a));
            }
            dialog.Destroy();
        }