private void _btnAddLocalRepo_LinkClicked(object sender, EventArgs e) { var path = Utility.ShowPickFolderDialog(this); if (!string.IsNullOrWhiteSpace(path)) { var prov = WorkingEnvironment.FindProviderForDirectory(path); if (prov == null) { GitterApplication.MessageBoxService.Show( this, Resources.ErrPathIsNotValidRepository.UseAsFormat(path), Resources.ErrInvalidPath, MessageBoxButton.Close, MessageBoxIcon.Error); return; } var item = new RepositoryListItem(new RepositoryLink(path, prov.Name)); _lstLocalRepositories.Items.Add(item); } }
private void OnLocalRepositoriesDragDrop(object sender, DragEventArgs e) { if (e.Effect != DragDropEffects.None) { if (e.Data.GetDataPresent(DataFormats.FileDrop)) { var data = (string[])(e.Data.GetData(DataFormats.FileDrop)); for (int i = 0; i < data.Length; ++i) { var di = new DirectoryInfo(data[i]); if (di.Exists) { var path = di.FullName; if (!IsPresentInLocalRepositoryList(path)) { var provider = WorkingEnvironment.FindProviderForDirectory(data[i]); if (provider != null) { var link = new RepositoryLink(path, provider.Name); var point = _lstLocalRepositories.PointToClient(new Point(e.X, e.Y)); CustomListBoxItemsCollection itemsCollection; var index = _lstLocalRepositories.GetInsertIndexFormPoint(point.X, point.Y, false, out itemsCollection); if (index != -1) { itemsCollection.Insert(index, new RepositoryListItem(link)); } } } } } } else if (e.Data.GetDataPresent(typeof(RepositoryListItem))) { var itemToMove = (RepositoryListItem)e.Data.GetData(typeof(RepositoryListItem)); var point = _lstLocalRepositories.PointToClient(new Point(e.X, e.Y)); CustomListBoxItemsCollection itemsCollection; var index = _lstLocalRepositories.GetInsertIndexFormPoint(point.X, point.Y, false, out itemsCollection); if (index == -1) { return; } var currentIndex = _lstLocalRepositories.Items.IndexOf(itemToMove); if (index == currentIndex) { return; } if (currentIndex == -1) { itemsCollection.Insert(index, itemToMove); } else { if (index > _lstLocalRepositories.Items.Count - 1) { --index; } itemToMove.Remove(); itemsCollection.Insert(index, itemToMove); } } else if (e.Data.GetDataPresent(typeof(RecentRepositoryListItem))) { var itemToMove = (RecentRepositoryListItem)e.Data.GetData(typeof(RecentRepositoryListItem)); var path = itemToMove.DataContext.Path; if (IsPresentInLocalRepositoryList(path)) { return; } var point = _lstLocalRepositories.PointToClient(new Point(e.X, e.Y)); CustomListBoxItemsCollection itemsCollection; var index = _lstLocalRepositories.GetInsertIndexFormPoint(point.X, point.Y, false, out itemsCollection); if (index == -1) { return; } var itemToInsert = new RepositoryListItem(new RepositoryLink(path, string.Empty)); itemsCollection.Insert(index, itemToInsert); } } }