PositionGotoDialog.Result Command_Position_Goto_Dialog(GotoType gotoType) { int line = 1, column = 1, index = 1, position = 0; var range = Selections.FirstOrDefault(); if (range != null) { line = Data.GetOffsetLine(range.Start) + 1; index = Data.GetOffsetIndex(range.Start, line - 1) + 1; column = Data.GetColumnFromIndex(line - 1, index - 1) + 1; position = range.Start; } int startValue; switch (gotoType) { case GotoType.Line: startValue = Data.GetDiffLine(line - 1) + 1; break; case GotoType.Column: startValue = column; break; case GotoType.Index: startValue = index; break; case GotoType.Position: startValue = position; break; default: throw new ArgumentException("GotoType invalid"); } return(PositionGotoDialog.Run(WindowParent, gotoType, startValue, GetVariables())); }
/// <summary> /// Select another file /// </summary> public void GetNextFile(GotoType direction) { if (FilesInCurrentDir.Length == 0) { CurrentFile = string.Empty; return; } switch (direction) { case GotoType.Random: CurrentFile = FilesInCurrentDir[_r.Next(FilesInCurrentDir.Length)]; break; case GotoType.Next: CurrentFile = FilesInCurrentDir[Wrap(FilesInCurrentDir.GetPositionOfElement(CurrentFile) + 1, 0, FilesInCurrentDir.Length - 1)]; break; case GotoType.Previous: CurrentFile = FilesInCurrentDir[Wrap(FilesInCurrentDir.GetPositionOfElement(CurrentFile) - 1, 0, FilesInCurrentDir.Length - 1)]; break; } }
public GotoButton(string gotoScreen, string gotoState = "", bool back = false, GotoType gotoType = GotoType.Default) { this.gotoScreen = gotoScreen; this.gotoState = gotoState; this.back = back; this.gotoType = gotoType; }
void Command_Position_Copy(GotoType gotoType, bool withLine) { var starts = new Dictionary <GotoType, List <int> >(); var ends = new Dictionary <GotoType, List <int> >(); var count = Selections.Count; starts[GotoType.Position] = Selections.Select(range => range.Start).ToList(); ends[GotoType.Position] = Selections.Select(range => range.End).ToList(); if ((gotoType == GotoType.Line) || (gotoType == GotoType.Column) || (gotoType == GotoType.Index)) { starts[GotoType.Line] = starts[GotoType.Position].Select(pos => Data.GetOffsetLine(pos)).ToList(); ends[GotoType.Line] = ends[GotoType.Position].Select(pos => Data.GetOffsetLine(pos)).ToList(); } if ((gotoType == GotoType.Column) || (gotoType == GotoType.Index)) { starts[GotoType.Index] = Enumerable.Range(0, count).Select(x => Data.GetOffsetIndex(starts[GotoType.Position][x], starts[GotoType.Line][x])).ToList(); ends[GotoType.Index] = Enumerable.Range(0, count).Select(x => Data.GetOffsetIndex(ends[GotoType.Position][x], ends[GotoType.Line][x])).ToList(); if (gotoType == GotoType.Column) { starts[GotoType.Column] = Enumerable.Range(0, count).Select(x => Data.GetColumnFromIndex(starts[GotoType.Line][x], starts[GotoType.Index][x])).ToList(); ends[GotoType.Column] = Enumerable.Range(0, count).Select(x => Data.GetColumnFromIndex(ends[GotoType.Line][x], ends[GotoType.Index][x])).ToList(); } } var delta = gotoType == GotoType.Position ? 0 : 1; SetClipboardStrings(Enumerable.Range(0, count).Select(index => $"{(withLine ? $"{starts[GotoType.Line][index] + 1}:" : "")}{starts[gotoType][index] + delta}{(starts[GotoType.Position][index] != ends[GotoType.Position][index] ? $"-{((withLine) && (starts[GotoType.Line][index] != ends[GotoType.Line][index]) ? $"{ends[GotoType.Line][index] + 1}:" : "")}{ends[gotoType][index] + delta}" : "")}")); }
void Command_Position_Goto(GotoType gotoType, bool selecting, GotoDialog.Result result) { var offsets = GetVariableExpressionResults<int>(result.Expression); if (!offsets.Any()) return; var sels = Selections.ToList(); if ((sels.Count == 0) && (gotoType == GotoType.Line)) sels.Add(BeginRange); if (sels.Count == 1) sels = sels.Resize(offsets.Count, sels[0]).ToList(); if (offsets.Count == 1) offsets = offsets.Expand(sels.Count, offsets[0]).ToList(); if (offsets.Count != sels.Count) throw new Exception("Expression count doesn't match selection count"); if (gotoType != GotoType.Position) offsets = offsets.Select(ofs => ofs - 1).ToList(); switch (gotoType) { case GotoType.Line: Selections.Replace(sels.AsParallel().AsOrdered().Select((range, ctr) => MoveCursor(range, Data.GetNonDiffLine(offsets[ctr]), 0, selecting, false, false)).ToList()); break; case GotoType.Column: Selections.Replace(sels.AsParallel().AsOrdered().Select((range, ctr) => MoveCursor(range, 0, offsets[ctr], selecting, true, false)).ToList()); break; case GotoType.Position: Selections.Replace(sels.AsParallel().AsOrdered().Select((range, ctr) => MoveCursor(range, offsets[ctr], selecting)).ToList()); break; } }
GotoDialog(GotoType gotoType, int value, NEVariables variables) { Variables = variables; InitializeComponent(); Title = $"Go To {gotoType}"; Expression = value.ToString(); }
PositionGotoDialog(GotoType gotoType, int value, NEVariables variables) { Variables = variables; InitializeComponent(); Title = $"Go To {gotoType}"; Expression = value.ToString(); OpenFilesOnce = true; }
public static Result Run(Window parent, GotoType gotoType, int startValue, NEVariables variables) { var dialog = new PositionGotoDialog(gotoType, startValue, variables) { Owner = parent }; return(dialog.ShowDialog() ? dialog.result : null); }
/// <summary> /// Select another folder /// </summary> public void GetNextFolder(GotoType direction) { if (_matchedDirectories.Count == 0) { SetCurrentFolder(string.Empty); return; } switch (direction) { case GotoType.Random: { string randomDir; if (PreventDuplicates) { while (true) { if (_directoryHistory.Count == _matchedDirectories.Count) { _directoryHistory.RemoveRange(0, (int)Math.Ceiling(_directoryHistory.Count / 2.0)); } randomDir = _matchedDirectories[_r.Next(_matchedDirectories.Count)]; if (!_directoryHistory.Contains(randomDir)) { _directoryHistory.Add(randomDir); break; } } } else { randomDir = _matchedDirectories[_r.Next(_matchedDirectories.Count)]; } SetCurrentFolder(randomDir); } break; case GotoType.Next: SetCurrentFolder( _matchedDirectories[Wrap(_matchedDirectories.IndexOf(CurrentDirectory) + 1, 0, _matchedDirectories.Count - 1)]); break; case GotoType.Previous: SetCurrentFolder( _matchedDirectories[Wrap(_matchedDirectories.IndexOf(CurrentDirectory) - 1, 0, _matchedDirectories.Count - 1)]); break; } }
void Command_Position_Copy(GotoType gotoType) { if (gotoType == GotoType.Position) { SetClipboardStrings(Selections.Select(range => $"{range.Start}{(range.HasSelection ? $"-{range.End}" : "")}")); return; } var starts = Selections.Select(range => range.Start).ToList(); var lines = starts.Select(pos => Data.GetOffsetLine(pos)).ToList(); if (gotoType == GotoType.Line) { SetClipboardStrings(lines.Select(pos => (Data.GetDiffLine(pos) + 1).ToString())); return; } var indexes = starts.Select((pos, line) => Data.GetOffsetIndex(pos, lines[line])).ToList(); SetClipboardStrings(indexes.Select(pos => (pos + 1).ToString())); }
GotoDialog.Result Command_Position_Goto_Dialog(GotoType gotoType) { int line = 1, index = 1, position = 0; var range = Selections.FirstOrDefault(); if (range != null) { line = Data.GetOffsetLine(range.Start) + 1; index = Data.GetOffsetIndex(range.Start, line - 1) + 1; position = range.Start; } int startValue; switch (gotoType) { case GotoType.Line: startValue = Data.GetDiffLine(line - 1) + 1; break; case GotoType.Column: startValue = index; break; case GotoType.Position: startValue = position; break; default: throw new ArgumentException("GotoType invalid"); } return GotoDialog.Run(WindowParent, gotoType, startValue, GetVariables()); }
protected void Goto(GotoType type = GotoType.All, string des = "") { if (type == GotoType.All) { if (outputKnobs.Any()) { foreach (var output in outputKnobs.FindAll(T => T.outputType.Equals("工作状态"))) { output.SetValue <TreeNodeResult>(TreeNodeResult.Start); } } } else if (type == GotoType.Single) { if (outputKnobs.Any()) { var output = outputKnobs.Find(T => T.Name.Equals(des)); output.SetValue <TreeNodeResult>(TreeNodeResult.Start); } } }
public GotoStatement(GotoType gotoType) { this.GotoType = gotoType; }
public static Result Run(Window parent, GotoType gotoType, int startValue, NEVariables variables) { var dialog = new GotoDialog(gotoType, startValue, variables) { Owner = parent }; return dialog.ShowDialog() ? dialog.result : null; }
public static List <GotoRange> GetPositionsData(IEnumerable <string> strs, GotoType gotoType) { void setFile(GotoRange pd, string value) => pd.File = value; void setStartLine(GotoRange pd, string value) => pd.Start.Line = int.Parse(value) - 1; void setEndLine(GotoRange pd, string value) => pd.End.Line = int.Parse(value) - 1; void setStartIndex(GotoRange pd, string value) => pd.Start.Index = int.Parse(value) - 1; void setEndIndex(GotoRange pd, string value) => pd.End.Index = int.Parse(value) - 1; void setStartColumn(GotoRange pd, string value) => pd.Start.Column = int.Parse(value) - 1; void setEndColumn(GotoRange pd, string value) => pd.End.Column = int.Parse(value) - 1; void setStartPosition(GotoRange pd, string value) => pd.Start.Position = int.Parse(value); void setEndPosition(GotoRange pd, string value) => pd.End.Position = int.Parse(value); string regexPattern; List <Action <GotoRange, string> > actions; switch (gotoType) { case GotoType.Line: regexPattern = @"^(?:((?:[a-z]:)?[\w\s,\\.-]+):)?(\d+)(?:-(\d+))?|((?:[a-z]:)?[\w\s,\\.-]+)\((\d+)\)$"; actions = new List <Action <GotoRange, string> > { setFile, setStartLine, setEndLine, setFile, setStartLine }; break; case GotoType.Column: regexPattern = @"^(?:(?:((?:[a-z]:)?[\w\s,\\.-]+):)?(\d+):)?(\d+)(?:-(?:(\d+):)?(\d+))?$"; actions = new List <Action <GotoRange, string> > { setFile, setStartLine, setStartColumn, setEndLine, setEndColumn }; break; case GotoType.Index: regexPattern = @"^(?:(?:((?:[a-z]:)?[\w\s,\\.-]+):)?(\d+):)?(\d+)(?:-(?:(\d+):)?(\d+))?|((?:[a-z]:)?[\w\s,\\.-]+)\((\d+),(\d+),(\d+),(\d+)\)$"; actions = new List <Action <GotoRange, string> > { setFile, setStartLine, setStartIndex, setEndLine, setEndIndex, setFile, setStartLine, setStartIndex, setEndLine, setEndIndex }; break; case GotoType.Position: regexPattern = @"^(?:((?:[a-z]:)?[\w\s,\\.-]+):)?(\d+)(?:-(\d+))?$"; actions = new List <Action <GotoRange, string> > { setFile, setStartPosition, setEndPosition }; break; default: throw new Exception("Invalid gototype"); } var regex = new Regex(regexPattern, RegexOptions.IgnoreCase); var result = new List <GotoRange>(); foreach (var str in strs) { var pd = new GotoRange(); var match = regex.Match(str); if (!match.Success) { throw new Exception($"Invalid location: {str} ({gotoType})"); } for (var ctr = 0; ctr < actions.Count; ++ctr) { if (match.Groups[ctr + 1].Success) { actions[ctr](pd, match.Groups[ctr + 1].Value); } } result.Add(pd); } return(result); }
void Command_Position_Goto(GotoType gotoType, bool selecting, PositionGotoDialog.Result result) { var values = GotoRange.GetPositionsData(GetVariableExpressionResults <string>(result.Expression), gotoType); if (!values.Any()) { return; } var hasFiles = values.First().File != null; if (values.Any(x => (x.File != null) != hasFiles)) { throw new Exception("Either all locations must have files or none"); } var valuesByFile = new List <List <GotoRange> >(); var fileMap = new Dictionary <string, List <GotoRange> >(StringComparer.OrdinalIgnoreCase); foreach (var value in values) { List <GotoRange> list; if (result.OpenFilesOnce) { var key = value.File ?? ""; if (!fileMap.ContainsKey(key)) { fileMap[key] = list = new List <GotoRange>(); valuesByFile.Add(list); } else { list = fileMap[key]; } } else { list = new List <GotoRange>(); valuesByFile.Add(list); } list.Add(value); } if (hasFiles) { var invalidFiles = valuesByFile.Select(list => list.First().File).NonNull().Where(file => !File.Exists(file)).ToList(); if (invalidFiles.Any()) { throw new Exception($"The following files could not be found: {string.Join("\n", invalidFiles)}"); } } var active = new HashSet <TextEditor>(); foreach (var list in valuesByFile) { var useTE = list.First().File == null ? this : TabsParent.Add(list.First().File); active.Add(useTE); var sels = useTE.Selections.ToList(); var positions = list; if ((sels.Count == 0) && ((gotoType == GotoType.Line) || (gotoType == GotoType.Position))) { sels.Add(useTE.BeginRange); } if (sels.Count == 1) { sels = sels.Resize(positions.Count, sels[0]).ToList(); } if (positions.Count == 1) { positions = positions.Expand(sels.Count, positions[0]).ToList(); } if (positions.Count != sels.Count) { throw new Exception("Expression count doesn't match selection count"); } useTE.SetSelections(sels.AsParallel().AsOrdered().Select((range, ctr) => positions[ctr].GetRange(useTE, range, selecting)).ToList()); } if (hasFiles) { foreach (var item in TabsParent.Items) { item.Active = active.Contains(item); } TabsParent.TopMost = active.First(); } }
public GotoButton(string gotoScreen, string gotoState, GotoType gotoType) { this.gotoScreen = gotoScreen; this.gotoState = gotoState; this.gotoType = gotoType; }
internal GotoExpression(GotoType gotoType, Expression value) : base(ExpressionType.Goto) { this.gotoType = gotoType; this.value = value; }