internal async void OnCommit() { if (tracker == null) { return; } try { if (chkNewBranch.IsChecked == true) { if (string.IsNullOrWhiteSpace(txtNewBranch.Text)) { MessageBox.Show("Please enter new branch name.", "Commit", MessageBoxButton.OK, MessageBoxImage.Exclamation); txtNewBranch.Focus(); return; } tracker.CheckOutBranch(txtNewBranch.Text, true); } var isAmend = chkAmend.IsChecked == true; if (string.IsNullOrWhiteSpace(Comments)) { Comments = tracker.GetCommitTemplate(); if (string.IsNullOrWhiteSpace(Comments)) { MessageBox.Show("Please enter comments for the commit.", "Commit", MessageBoxButton.OK, MessageBoxImage.Exclamation); } return; } var changed = this.listUnstaged.ItemsSource.Cast <GitFile>(); var count = changed.Count(); ShowStatusMessage("Staging files ..."); if (!isAmend) { tracker.Refresh(); bool hasStaged = tracker == null ? false : tracker.ChangedFiles.Any(f => f.X != ' ') || count > 0; if (!hasStaged) { MessageBox.Show("No file has been selected/staged for commit.", "Commit", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } } else { const string amendMsg = @"You are about to amend a commit that has tags or remotes, which could cause issues in local and remote repositories. Are you sure you want to continue?"; if (tracker.CurrentCommitHasRefs() && MessageBox.Show(amendMsg, "Amend Last Commit", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { return; } } service.NoRefresh = true; int i = 1; bool signoff = chkSignOff.IsChecked == true; await Task.Run(() => { if (changed.Count() > 0 && listStaged.Items.Count == 0) { // auto stage all changes if nothing is staged foreach (var item in changed) { tracker.StageFile(item.FileName); ShowStatusMessage(string.Format("Staged ({0}/{1}): {2}", i++, count, item.FileName)); } } var id = tracker.Commit(Comments, isAmend, signoff); ShowStatusMessage("Commit successfully. Commit Hash: " + id); }); ClearUI(); Comments = tracker.GetCommitTemplate(); tracker.Refresh(); if (tracker.ChangedFiles.Count() == 0) { HistoryViewCommands.CloseCommitDetails.Execute("PendingChanges", this); } service.NoRefresh = false; HistoryViewCommands.RefreshGraph.Execute(null, this); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); ShowStatusMessage(ex.Message); } }
internal void Refresh(GitFileStatusTracker tracker) { this.tracker = tracker; if (this.activeListView == null) { this.activeListView = this.listStaged; } if (tracker == null) { ClearUI(); return; } Action act = () => { if (string.IsNullOrEmpty(Comments)) { Comments = tracker.GetCommitTemplate(); } lblMessage.Content = "Commit to: " + tracker.CurrentBranch; //service.NoRefresh = true; ShowStatusMessage("Getting changed files ..."); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); //var selectedFile = GetSelectedFileName(); //var selectedFiles = this.dataGrid1.Items.Cast<GitFile>() // .Where(i => i.IsSelected) // .Select(i => i.FileName).ToList(); //this.dataGrid1.BeginInit(); var selectedFile = GetSelectedFileName(); var selectedFiles = this.activeListView.Items.Cast <GitFile>() .Where(i => i.IsSelected) .Select(i => i.FileName).ToList(); try { //this.dataGrid1.ItemsSource = tracker.ChangedFiles; //ICollectionView view = CollectionViewSource.GetDefaultView(this.dataGrid1.ItemsSource); //if (view != null) //{ // view.SortDescriptions.Clear(); // view.SortDescriptions.Add(new SortDescription(sortMemberPath, sortDirection)); // view.Refresh(); //} //this.dataGrid1.SelectedValue = selectedFile; //selectedFiles.ForEach(fn => //{ // var item = this.dataGrid1.Items.Cast<GitFile>() // .Where(i => i.FileName == fn) // .FirstOrDefault(); // if (item != null) item.IsSelected = true; //}); //ShowStatusMessage(""); //this.label3.Content = string.Format("Changed files: ({0}) {1}", tracker.CurrentBranch, tracker.ChangedFilesStatus); this.listStaged.ItemsSource = tracker.ChangedFiles.Where(f => f.X != ' ' && f.X != '?'); this.listUnstaged.ItemsSource = tracker.ChangedFiles.Where(f => f.Y != ' '); this.activeListView.SelectedValue = selectedFile; selectedFiles.ForEach(fn => { var item = this.activeListView.Items.Cast <GitFile>() .Where(i => i.FileName == fn) .FirstOrDefault(); if (item != null) { item.IsSelected = true; } }); this.label3.Content = string.Format("Git Status: {0}", tracker.ChangedFilesStatus); } catch (Exception ex) { ShowStatusMessage(ex.Message); } //this.dataGrid1.EndInit(); stopwatch.Stop(); Debug.WriteLine("**** PendingChangesView Refresh: " + stopwatch.ElapsedMilliseconds); }; this.Dispatcher.BeginInvoke(act, DispatcherPriority.ApplicationIdle); }