void DisplayFile(VCFile file, int index, bool staged, List<VCFile> filteredList) { if (index % 2 == 0) GUI.backgroundColor = Color.gray; else GUI.backgroundColor = Color.white; GUILayout.BeginHorizontal(); string statusString = file.fileState1 != FileState.Unmodified ? file.fileState1.ToString() : file.fileState2.ToString(); string filePathString = !string.IsNullOrEmpty(file.path2) ? file.path2 : file.path1; bool t1 = GUILayout.Toggle(file.selected, statusString, selectionStyle, GUILayout.Width(75)); bool t2 = false; if (viewMode != BrowserViewMode.ArtistMode) { string fileNameString = !string.IsNullOrEmpty(file.name2) ? file.name2 : file.name1; t2 = GUILayout.Toggle(file.selected, fileNameString, selectionStyle, GUILayout.Width(295)); } bool t3 = GUILayout.Toggle(file.selected, filePathString, selectionStyle, GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); GUI.backgroundColor = Color.white; if (viewMode != BrowserViewMode.ArtistMode && t2 != file.selected) { BrowserUtility.ValidateSelection(file, t2, false, index, lastSelectedIndex, filteredList); if (file.selected) { lastSelectedIndex = index; } } else if (t3 != file.selected) { BrowserUtility.ValidateSelection(file, t3, false, index, lastSelectedIndex, filteredList); lastSelectedIndex = file.selected ? index : -1; } else if (t1 != file.selected) { BrowserUtility.ValidateSelection(file, t1, false, index, lastSelectedIndex, filteredList); lastSelectedIndex = file.selected ? index : -1; } }
internal static VCFile[] ParseFiles(string input) { // Split the input. string[] inputSplit = input.Split('\0'); List <VCFile> files = new List <VCFile>(); for (int i = 0; i < inputSplit.Length; i++) { if (string.IsNullOrEmpty(inputSplit[i])) { continue; } // Create the file var file = new VCFile(); // Add it to the list files.Add(file); bool increase = false; #region parse - staged switch (inputSplit[i][0]) { case ' ': file.fileState1 = FileState.Unmodified; file.path1 = inputSplit[i].Substring(3); break; case 'M': file.fileState1 = FileState.Modified; file.path1 = inputSplit[i].Substring(3); break; case 'A': file.fileState1 = FileState.Added; file.path1 = inputSplit[i].Substring(3); break; case 'D': file.fileState1 = FileState.Deleted; file.path1 = inputSplit[i].Substring(3); break; case 'R': file.fileState1 = FileState.Renamed; file.path1 = inputSplit[i + 1]; file.path2 = inputSplit[i].Substring(3); increase = true; break; case 'C': file.fileState1 = FileState.Copied; file.path1 = inputSplit[i + 1]; file.path2 = inputSplit[i].Substring(3); i++; break; case 'U': file.fileState1 = FileState.Unmerged; file.path1 = inputSplit[i].Substring(3); break; case '?': file.fileState1 = FileState.Untracked; file.path1 = inputSplit[i].Substring(3); break; case '!': file.fileState1 = FileState.Ignored; file.path1 = inputSplit[i].Substring(3); break; } #endregion #region parse - index switch (inputSplit[i][1]) { case ' ': file.fileState2 = FileState.Unmodified; break; case 'M': file.fileState2 = FileState.Modified; break; case 'A': file.fileState2 = FileState.Added; break; case 'D': file.fileState2 = FileState.Deleted; break; case 'R': file.fileState2 = FileState.Renamed; break; case 'C': file.fileState2 = FileState.Copied; break; case 'U': file.fileState2 = FileState.Unmerged; break; case '?': file.fileState2 = FileState.Untracked; break; case '!': file.fileState2 = FileState.Ignored; break; } #endregion #region parse - file name string sep = System.IO.Path.DirectorySeparatorChar.ToString(); if (file.path1.Contains(sep)) { if (file.path1.LastIndexOf(sep) != file.path1.Length - 1) { file.name1 = file.path1.Substring(file.path1.LastIndexOf(sep) + 1); } else { file.name1 = file.path1; } } else { file.name1 = file.path1; } if (file.path2.Contains(sep)) { if (file.path2.LastIndexOf(sep) != file.path2.Length - 1) { file.name2 = file.path2.Substring(file.path2.LastIndexOf(sep) + 1); } else { file.name2 = file.path2; } } else { file.name2 = file.path2; } #endregion // Increase by 1 if we renamed or copied if (increase) { i++; } } return(files.ToArray()); }
internal static Process ResetLast(System.EventHandler exitEventHandler, VCFile[] files) { var sb = new StringBuilder().Append("checkout -- "); foreach(var file in files) { if (string.IsNullOrEmpty(file.path2)) { sb.Append('"').Append(file.path1).Append('"').Append(' '); } else { sb.Append(file.path2).Append(' '); } } return RunGit(sb.ToString(0, sb.Length - 1), exitEventHandler); }
/// <summary> /// Validates the selection. /// </summary> public static void ValidateSelection(VCFile file, bool toggle, bool overrideMultiSelect, int index, int lastSelectedIndex, List<VCFile> filteredList) { if (file != null) file.selected = toggle; foreach(var f in stagedFiles.Values) { if (f.selected) { mStagedFileSelected = true; break; } } foreach(var f in workingTree.Values) { if (f.selected) { mWorkingTreeSelected = true; break; } } bool ctrlPressed = false || overrideMultiSelect; if (!overrideMultiSelect) { if (Event.current != null) { if (Application.platform == RuntimePlatform.WindowsEditor) ctrlPressed = Event.current.control; else if (Application.platform == RuntimePlatform.OSXEditor) ctrlPressed = Event.current.command; } } // Only run if selecting a file if (file != null && toggle) { bool switched = false; if (stagedFiles.ContainsValue(file)) { if (!ctrlPressed) { foreach(var f in stagedFiles.Values) { if (f != file) f.selected = false; } } // Selecting a staged file with working tree files selected (not allowed) if (mWorkingTreeSelected) { switched = true; foreach(var f in workingTree.Values) { f.selected = false; } mWorkingTreeSelected = false; } } else if (workingTree.ContainsValue(file)) { if (!ctrlPressed) { foreach(var f in workingTree.Values) { if (f != file) f.selected = false; } } // Selecting a working tree file with staged files selected (not allowed) if (mStagedFileSelected) { switched = true; foreach(var f in stagedFiles.Values) { f.selected = false; } mStagedFileSelected = false; } } // Detect shift clicks if (lastSelectedIndex != -1) { if (Event.current != null && !switched) { if (Event.current.shift) { bool goBackwards = lastSelectedIndex > index; if (goBackwards) { for(int i = lastSelectedIndex; i >= index; i--) { if (i < filteredList.Count) { filteredList[i].selected = true; } } } else { for(int i = lastSelectedIndex; i <= index; i++) { if (i < filteredList.Count) { filteredList[i].selected = true; } } } } } } } mAnyFileSelected = mStagedFileSelected || mWorkingTreeSelected; CacheSelectedFiles(); UpdateDiffPanel(); }
internal static VCFile[] ParseFiles(string input) { // Split the input. string[] inputSplit = input.Split('\0'); List<VCFile> files = new List<VCFile>(); for(int i = 0; i < inputSplit.Length; i++) { if (string.IsNullOrEmpty(inputSplit[i])) continue; // Create the file var file = new VCFile(); // Add it to the list files.Add(file); bool increase = false; #region parse - staged switch(inputSplit[i][0]) { case ' ': file.fileState1 = FileState.Unmodified; file.path1 = inputSplit[i].Substring(3); break; case 'M': file.fileState1 = FileState.Modified; file.path1 = inputSplit[i].Substring(3); break; case 'A': file.fileState1 = FileState.Added; file.path1 = inputSplit[i].Substring(3); break; case 'D': file.fileState1 = FileState.Deleted; file.path1 = inputSplit[i].Substring(3); break; case 'R': file.fileState1 = FileState.Renamed; file.path1 = inputSplit[i+1]; file.path2 = inputSplit[i].Substring(3); increase = true; break; case 'C': file.fileState1 = FileState.Copied; file.path1 = inputSplit[i+1]; file.path2 = inputSplit[i].Substring(3); i++; break; case 'U': file.fileState1 = FileState.Unmerged; file.path1 = inputSplit[i].Substring(3); break; case '?': file.fileState1 = FileState.Untracked; file.path1 = inputSplit[i].Substring(3); break; case '!': file.fileState1 = FileState.Ignored; file.path1 = inputSplit[i].Substring(3); break; } #endregion #region parse - index switch(inputSplit[i][1]) { case ' ': file.fileState2 = FileState.Unmodified; break; case 'M': file.fileState2 = FileState.Modified; break; case 'A': file.fileState2 = FileState.Added; break; case 'D': file.fileState2 = FileState.Deleted; break; case 'R': file.fileState2 = FileState.Renamed; break; case 'C': file.fileState2 = FileState.Copied; break; case 'U': file.fileState2 = FileState.Unmerged; break; case '?': file.fileState2 = FileState.Untracked; break; case '!': file.fileState2 = FileState.Ignored; break; } #endregion #region parse - file name string sep = System.IO.Path.DirectorySeparatorChar.ToString(); if (file.path1.Contains(sep)) { if (file.path1.LastIndexOf(sep) != file.path1.Length - 1) { file.name1 = file.path1.Substring(file.path1.LastIndexOf(sep) + 1); } else { file.name1 = file.path1; } } else { file.name1 = file.path1; } if (file.path2.Contains(sep)) { if (file.path2.LastIndexOf(sep) != file.path2.Length - 1) { file.name2 = file.path2.Substring(file.path2.LastIndexOf(sep) + 1); } else { file.name2 = file.path2; } } else { file.name2 = file.path2; } #endregion // Increase by 1 if we renamed or copied if (increase) i++; } return files.ToArray(); }