Exemple #1
0
        private bool SenderToFileStatusList(object sender, out FileStatusList list)
        {
            list = null;
            ToolStripMenuItem item = sender as ToolStripMenuItem;
            if (item == null)
                return false;

            ContextMenuStrip menu = item.Owner as ContextMenuStrip;
            if (menu == null)
                return false;

            ListView lv = menu.SourceControl as ListView;
            if (lv == null)
                return false;

            list = lv.Parent as FileStatusList;
            return (list != null);
        }
Exemple #2
0
 /// <summary>Helper method that moves the focus to the supplied FileStatusList</summary>
 private void FocusFileList(FileStatusList fileStatusList)
 {
     fileStatusList.Focus();
 }
Exemple #3
0
 private void Unstaged_Enter(object sender, EventArgs e)
 {
     if (_currentFilesList != Unstaged)
     {
         _currentFilesList = Unstaged;
         _skipUpdate = false;
         UnstagedSelectionChanged(Unstaged, null);
     }
 }
Exemple #4
0
        private void OpenContainingFolder(FileStatusList list)
        {
            foreach (var item in list.SelectedItems)
            {
                var fileNames = new StringBuilder();
                fileNames.Append((Path.Combine(Module.WorkingDir, item.Name)).Replace(Settings.PathSeparatorWrong, Settings.PathSeparator));

                string filePath = fileNames.ToString();
                if (File.Exists(filePath))
                {
                    OsShellUtil.SelectPathInFileExplorer(filePath);
                }
            }
        }
Exemple #5
0
        private void UnstageAllToolStripMenuItemClick(object sender, EventArgs e)
        {
            var lastSelection = new List<GitItemStatus>();
            if (_currentFilesList != null)
                lastSelection = _currentSelection;

            Action stageAreaLoaded = null;
            stageAreaLoaded = () =>
            {
                _currentFilesList = Unstaged;
                RestoreSelectedFiles(Unstaged.GitItemStatuses, Staged.GitItemStatuses, lastSelection);
                Unstaged.Focus();

                OnStageAreaLoaded -= stageAreaLoaded;
            };

            OnStageAreaLoaded += stageAreaLoaded;

            Module.ResetMixed("HEAD");
            Initialize();
        }
Exemple #6
0
 void Unstaged_DoubleClick(object sender, EventArgs e)
 {
     _currentFilesList = Unstaged;
     Stage(Unstaged.SelectedItems.ToList());
     if (Unstaged.IsEmpty)
         Staged.Focus();
 }
Exemple #7
0
 void Staged_DoubleClick(object sender, EventArgs e)
 {
     _currentFilesList = Staged;
     Unstage();
 }
Exemple #8
0
        private void Unstage()
        {
            if (Staged.GitItemStatuses.Count() > 10 && Staged.SelectedItems.Count() == Staged.GitItemStatuses.Count())
            {
                UnstageAllToolStripMenuItemClick(null, null);
                return;
            }

            Cursor.Current = Cursors.WaitCursor;
            EnableStageButtons(false);
            try
            {
                var lastSelection = new List<GitItemStatus>();
                if (_currentFilesList != null)
                    lastSelection = _currentSelection;

                    toolStripProgressBar1.Visible = true;
                    toolStripProgressBar1.Maximum = Staged.SelectedItems.Count() * 2;
                    toolStripProgressBar1.Value = 0;
                    Staged.StoreNextIndexToSelect();

                    var files = new List<GitItemStatus>();
                    var allFiles = new List<GitItemStatus>();

                    foreach (var item in Staged.SelectedItems)
                    {
                        toolStripProgressBar1.Value = Math.Min(toolStripProgressBar1.Maximum - 1, toolStripProgressBar1.Value + 1);
                        if (!item.IsNew)
                        {
                            toolStripProgressBar1.Value = Math.Min(toolStripProgressBar1.Maximum - 1, toolStripProgressBar1.Value + 1);
                            Module.UnstageFileToRemove(item.Name);

                            if (item.IsRenamed)
                                Module.UnstageFileToRemove(item.OldName);
                        }
                        else
                        {
                            files.Add(item);
                        }
                        allFiles.Add(item);
                    }

                    Module.UnstageFiles(files);

                    _skipUpdate = true;
                    InitializedStaged();
                    var stagedFiles = Staged.GitItemStatuses.ToList();
                    var unStagedFiles = Unstaged.GitItemStatuses.ToList();
                    foreach (var item in allFiles)
                    {
                        var item1 = item;
                        if (stagedFiles.Exists(i => i.Name == item1.Name))
                            continue;

                        var item2 = item;
                        if (unStagedFiles.Exists(i => i.Name == item2.Name))
                            continue;

                        if (item.IsNew && !item.IsChanged && !item.IsDeleted)
                            item.IsTracked = false;
                        else
                            item.IsTracked = true;

                        if (item.IsRenamed)
                        {
                            var clone = new GitItemStatus
                            {
                                Name = item.OldName,
                                IsDeleted = true,
                                IsTracked = true,
                                IsStaged = false
                            };
                            unStagedFiles.Add(clone);

                            item.IsRenamed = false;
                            item.IsNew = true;
                            item.IsTracked = false;
                            item.OldName = string.Empty;
                        }

                        item.IsStaged = false;
                        unStagedFiles.Add(item);
                    }
                    Staged.GitItemStatuses = stagedFiles;
                    Unstaged.GitItemStatuses = unStagedFiles;
                    _skipUpdate = false;
                    Staged.SelectStoredNextIndex();

                    toolStripProgressBar1.Value = toolStripProgressBar1.Maximum;

                toolStripProgressBar1.Visible = false;

                if (Staged.IsEmpty)
                {
                    _currentFilesList = Unstaged;
                    RestoreSelectedFiles(Unstaged.GitItemStatuses, Staged.GitItemStatuses, lastSelection);
                    Unstaged.Focus();
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
            EnableStageButtons(true);
            Cursor.Current = Cursors.Default;

            if (AppSettings.RevisionGraphShowWorkingDirChanges)
                UICommands.RepoChangedNotifier.Notify();
        }
Exemple #9
0
        /// <summary>
        ///   Loads the unstaged output.
        ///   This method is passed in to the SetTextCallBack delegate
        ///   to set the Text property of textBox1.
        /// </summary>
        private void LoadUnstagedOutput(IList<GitItemStatus> allChangedFiles)
        {
            var lastSelection = new List<GitItemStatus>();
            if (_currentFilesList != null)
                lastSelection = _currentSelection;

            var unStagedFiles = new List<GitItemStatus>();
            var stagedFiles = new List<GitItemStatus>();

            foreach (var fileStatus in allChangedFiles)
            {
                if (fileStatus.IsStaged)
                    stagedFiles.Add(fileStatus);
                else
                    unStagedFiles.Add(fileStatus);
            }
            Unstaged.GitItemStatuses = unStagedFiles;
            Staged.GitItemStatuses = stagedFiles;

            Loading.Visible = false;
            LoadingStaged.Visible = false;
            Commit.Enabled = true;
            CommitAndPush.Enabled = true;
            Amend.Enabled = true;
            Reset.Enabled = DoChangesExist();

            EnableStageButtons(true);
            workingToolStripMenuItem.Enabled = true;

            var inTheMiddleOfConflictedMerge = Module.InTheMiddleOfConflictedMerge();
            SolveMergeconflicts.Visible = inTheMiddleOfConflictedMerge;

            if (Staged.IsEmpty)
            {
                _currentFilesList = Unstaged;
                if (Staged.ContainsFocus)
                    Unstaged.Focus();
            }
            else if (Unstaged.IsEmpty)
            {
                _currentFilesList = Staged;
                if (Unstaged.ContainsFocus)
                    Staged.Focus();
            }

            RestoreSelectedFiles(unStagedFiles, stagedFiles, lastSelection);

            if (OnStageAreaLoaded != null)
                OnStageAreaLoaded();

            if (_loadUnstagedOutputFirstTime)
            {
                var fc = this.FindFocusedControl();

                if (fc == this.Ok)
                {
                    if (Unstaged.GitItemStatuses.Any())
                        Unstaged.Focus();
                    else if (Staged.GitItemStatuses.Any())
                        Message.Focus();
                    else
                        Amend.Focus();
                }

                _loadUnstagedOutputFirstTime = false;
            }
        }
Exemple #10
0
        private void Stage(IList<GitItemStatus> gitItemStatusses)
        {
            EnableStageButtons(false);
            try
            {
                var lastSelection = new List<GitItemStatus>();
                if (_currentFilesList != null)
                    lastSelection = _currentSelection;

                Cursor.Current = Cursors.WaitCursor;
                Unstaged.StoreNextIndexToSelect();
                toolStripProgressBar1.Visible = true;
                toolStripProgressBar1.Maximum = gitItemStatusses.Count() * 2;
                toolStripProgressBar1.Value = 0;

                var files = new List<GitItemStatus>();

                foreach (var gitItemStatus in gitItemStatusses)
                {
                    toolStripProgressBar1.Value = Math.Min(toolStripProgressBar1.Maximum - 1, toolStripProgressBar1.Value + 1);
                    if (gitItemStatus.Name.EndsWith("/"))
                        gitItemStatus.Name = gitItemStatus.Name.TrimEnd('/');
                    files.Add(gitItemStatus);
                }

                bool wereErrors = false;
                if (AppSettings.ShowErrorsWhenStagingFiles)
                {
                    FormStatus.ProcessStart processStart =
                        form =>
                        {
                            form.AppendMessageCrossThread(string.Format(_stageFiles.Text + "\n",
                                                         files.Count));
                            var output = Module.StageFiles(files, out wereErrors);
                            form.AppendMessageCrossThread(output);
                            form.Done(string.IsNullOrEmpty(output));
                        };
                    using (var process = new FormStatus(processStart, null) { Text = _stageDetails.Text })
                        process.ShowDialogOnError(this);
                }
                else
                {
                    Module.StageFiles(files, out wereErrors);
                }
                if (wereErrors)
                    RescanChanges();
                else
                {
                    InitializedStaged();
                    var unStagedFiles = Unstaged.GitItemStatuses.ToList();
                    _skipUpdate = true;
                    var names = new HashSet<string>();
                    foreach (var item in files)
                    {
                        names.Add(item.Name);
                        names.Add(item.OldName);
                    }
                    var unstagedItems = new HashSet<GitItemStatus>();
                    foreach (var item in unStagedFiles)
                    {
                        if (names.Contains(item.Name))
                            unstagedItems.Add(item);
                    }
                    unStagedFiles.RemoveAll(item => !item.IsSubmodule && unstagedItems.Contains(item));
                    unStagedFiles.RemoveAll(item => item.IsSubmodule && item.SubmoduleStatus.IsCompleted &&
                        !item.SubmoduleStatus.Result.IsDirty && unstagedItems.Contains(item));
                    foreach (var item in unstagedItems.Where(item => item.IsSubmodule &&
                        item.SubmoduleStatus.IsCompleted && item.SubmoduleStatus.Result.IsDirty))
                    {
                        item.SubmoduleStatus.Result.Status = SubmoduleStatus.Unknown;
                    }
                    Unstaged.GitItemStatuses = unStagedFiles;
                    Unstaged.ClearSelected();
                    _skipUpdate = false;
                    Unstaged.SelectStoredNextIndex();
                }

                toolStripProgressBar1.Value = toolStripProgressBar1.Maximum;

                toolStripProgressBar1.Visible = false;

                if (Unstaged.IsEmpty)
                {
                    _currentFilesList = Staged;
                    RestoreSelectedFiles(Unstaged.GitItemStatuses, Staged.GitItemStatuses, lastSelection);
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }

            EnableStageButtons(true);

            Commit.Enabled = true;
            Amend.Enabled = true;
            AcceptButton = Commit;
            Cursor.Current = Cursors.Default;

            if (AppSettings.RevisionGraphShowWorkingDirChanges)
                UICommands.RepoChangedNotifier.Notify();
        }
Exemple #11
0
        public static void OpenContainingFolder(FileStatusList diffFiles, GitModule module)
        {
            if (!diffFiles.SelectedItems.Any())
                return;

            foreach (var item in diffFiles.SelectedItems)
            {
                string filePath = FormBrowseUtil.GetFullPathFromGitItemStatus(module, item);
                FormBrowseUtil.ShowFileOrParentFolderInFileExplorer(filePath);
            }
        }
Exemple #12
0
        public static void CopyFullPathToClipboard(FileStatusList diffFiles, GitModule module)
        {
            if (!diffFiles.SelectedItems.Any())
                return;

            var fileNames = new StringBuilder();
            foreach (var item in diffFiles.SelectedItems)
            {
                //Only use append line when multiple items are selected.
                //This to make it easier to use the text from clipboard when 1 file is selected.
                if (fileNames.Length > 0)
                    fileNames.AppendLine();

                fileNames.Append(Path.Combine(module.WorkingDir, item.Name).ToNativePath());
            }
            Clipboard.SetText(fileNames.ToString());
        }
Exemple #13
0
        private bool SenderToFileStatusList(object sender, out FileStatusList list)
        {
            if (sender is ToolStripMenuItem)
            {
                ToolStripMenuItem item = sender as ToolStripMenuItem;
                if (item.Owner is ContextMenuStrip)
                {
                    ContextMenuStrip menu = item.Owner as ContextMenuStrip;
                    if (menu.SourceControl is ListBox)
                    {
                        ListBox lb = menu.SourceControl as ListBox;
                        if (lb.Parent is FileStatusList)
                        {
                            list = lb.Parent as FileStatusList;
                            return true;
                        }
                    }
                }

            }
            list = null;
            return false;
        }
Exemple #14
0
 private void Staged_Enter(object sender, EventArgs e)
 {
     if (_currentFilesList != Staged)
     {
         _currentFilesList = Staged;
         StagedSelectionChanged(Staged, null);
     }
 }
Exemple #15
0
 void Staged_DoubleClick(object sender, EventArgs e)
 {
     Unstage();
     if (!Staged.IsEmpty)
         _currentFilesList = Staged;
     else
         Unstaged.Focus();
 }