public void Edit()
        {
            FtpConnectionItemViewModel newItem;
            bool replace;
            var  ftpconn = SelectedItem as FtpConnectionItemViewModel;

            if (ftpconn != null)
            {
                newItem = ftpconn.Clone();
                replace = true;
            }
            else if (SelectedItem is NewConnectionPlaceholderViewModel)
            {
                var model = new FtpConnection
                {
                    Port            = 21,
                    ConnectionImage = (int)ConnectionImage.Fat,
                };
                newItem = new FtpConnectionItemViewModel(model);
                replace = false;
            }
            else
            {
                throw new NotSupportedException();
            }

            var dialog = new NewConnectionDialog(Items.OfType <FtpConnectionItemViewModel>().Select(item => item.Name).ToList(), newItem);

            if (dialog.ShowDialog() != true)
            {
                return;
            }

            newItem.Name = newItem.Name.Trim();
            if (newItem.Username != null)
            {
                newItem.Username = newItem.Username.Trim();
            }
            if (newItem.Password != null)
            {
                newItem.Password = newItem.Password.Trim();
            }
            if (replace)
            {
                Items.Remove(ftpconn);
            }

            var i = 0;

            while (i < Items.Count - 1 && String.Compare(newItem.Name, Items[i].Name, StringComparison.InvariantCultureIgnoreCase) == 1)
            {
                i++;
            }
            Items.Insert(i, newItem);
            Save(newItem);
            SelectedItem = newItem;
        }
 public static ConsoleProfile ShowNewConnectionWindow(Form owner, ConsoleProfile consoleProfile,
                                                      bool isEditingProfile)
 {
     using (var newConnectionDialog = new NewConnectionDialog
     {
         ConsoleProfile = consoleProfile, IsEditingProfile = isEditingProfile
     })
     {
         return(newConnectionDialog.ShowDialog(owner) == DialogResult.OK
             ? newConnectionDialog.ConsoleProfile
             : null);
     }
 }
        public void Edit()
        {
            FtpConnectionItemViewModel newItem;
            bool replace;
            var ftpconn = SelectedItem as FtpConnectionItemViewModel;
            if (ftpconn != null)
            {
                newItem = ftpconn.Clone();
                replace = true;
            } 
            else if (SelectedItem is NewConnectionPlaceholderViewModel)
            {
                var model = new FtpConnection
                                {
                                    Port = 21,
                                    ConnectionImage = (int) ConnectionImage.Fat,
                                };
                newItem = new FtpConnectionItemViewModel(model);
                replace = false;
            }
            else
            {
                throw new NotSupportedException();
            }

            var dialog = new NewConnectionDialog(Items.OfType<FtpConnectionItemViewModel>().Select(item => item.Name).ToList(), newItem);
            if (dialog.ShowDialog() != true) return;

            newItem.Name = newItem.Name.Trim();
            if (newItem.Username != null) newItem.Username = newItem.Username.Trim();
            if (newItem.Password != null) newItem.Password = newItem.Password.Trim();
            if (replace) Items.Remove(ftpconn);

            var i = 0;
            while (i < Items.Count - 1 && String.Compare(newItem.Name, Items[i].Name, StringComparison.InvariantCultureIgnoreCase) == 1) i++;
            Items.Insert(i, newItem);
            Save(newItem);
            SelectedItem = newItem;
        }