public string GetSelectedText(TextFormatOption opt) { //if(_owner==null || _disabledTemporary) return null; StringBuilder bld = new StringBuilder(); TextPoint a = HeadPoint; TextPoint b = TailPoint; GLine l = _owner.CharacterDocument.FindLineOrEdge(a.Line); int pos = a.Column; if (pos < 0) { return(""); } do { bool eol_required = (opt == TextFormatOption.AsLook || l.EOLType != EOLType.Continue); if (l.ID == b.Line) //最終行 //末尾にNULL文字が入るケースがあるようだ { AppendTrim(bld, l, pos, b.Column - pos); if (_pivotType == RangeType.Line && eol_required) { bld.Append("\r\n"); } break; } else //最終以外の行 { if (l.Length - pos > 0) //l.CharLength==posとなるケースがあった。真の理由は納得していないが { AppendTrim(bld, l, pos, l.Length - pos); } if (eol_required && bld.Length > 0) //bld.Length>0は行単位選択で余計な改行が入るのを避けるための処置 { bld.Append("\r\n"); //LFのみをクリップボードに持っていっても他のアプリの混乱があるだけなのでやめておく } l = l.NextLine; if (l == null) { break; //!!本来これはないはずだがクラッシュレポートのため回避 } pos = 0; } } while (true); //Debug.WriteLine("Selected Text Len="+bld.Length); return(bld.ToString()); }
private static CommandResult CmdCopyWithOption(ICommandTarget target, TextFormatOption opt) { string t = GetSelectedText(target, opt); if (t == null) { return(CommandResult.Ignored); } if (t.Length > 0) { CopyToClipboard(t); } return(CommandResult.Succeeded); }
private static string GetSelectedText(ICommandTarget target, TextFormatOption opt) { CharacterDocumentViewer c = TerminalCommandTarget.AsCharacterDocumentViewer(target); if (c == null) { return(null); } ITextSelection s = c.ITextSelection; if (s.IsEmpty || !c.EnabledEx) { return(null); } return(s.GetSelectedText(opt)); }
public string GetSelectedText(TextFormatOption opt) { StringBuilder bld = new StringBuilder(); TextPoint selStart = HeadPoint; TextPoint selEnd = TailPoint; GLine l = _owner.CharacterDocument.FindLineOrEdge(selStart.Line); int pos = selStart.Column; if (pos < 0) { return(""); } while (true) { bool eolRequired = (opt == TextFormatOption.AsLook || l.EOLType != EOLType.Continue); if (l.ID == selEnd.Line) // the last line { CopyGLineContent(l, bld, pos, selEnd.Column); if (eolRequired && _pivotType == RangeType.Line) { bld.Append("\r\n"); } break; } CopyGLineContent(l, bld, pos, null); if (eolRequired) { bld.Append("\r\n"); } l = l.NextLine; if (l == null) { // this should not be happened... break; } pos = 0; } return(bld.ToString()); }
public void OnSelectionFixed() { if (WindowManagerPlugin.Instance.WindowPreference.OriginalPreference.AutoCopyByLeftButton) { ICommandTarget ct = (ICommandTarget)this.GetAdapter(typeof(ICommandTarget)); if (ct != null) { CommandManagerPlugin cm = CommandManagerPlugin.Instance; Keys mods = Control.ModifierKeys; //KM: (CharacterDocumentViewer.OnMouseMove): // ■bug: Keys.Control と Keys.Shift は 単語単位・行単位の選択として既に使われている if (mods == Keys.Shift) { //Debug.WriteLine("NormalCopy"); IGeneralViewCommands gv = (IGeneralViewCommands)GetAdapter(typeof(IGeneralViewCommands)); if (gv != null) { cm.Execute(gv.Copy, ct); } } else if (mods == 0) { //Debug.WriteLine("CopyAsLook"); cm.Execute(cm.Find("org.poderosa.terminalemulator.copyaslook"), ct); } else { TextFormatOption option = TextFormatOption.AsLook | TextFormatOption.TrimEol; if ((mods & Keys.Alt) != 0) { option |= TextFormatOption.Rectangle; } if ((mods & Keys.Shift) != 0) { option &= ~TextFormatOption.AsLook; } if ((mods & Keys.Control) != 0) { option &= ~TextFormatOption.TrimEol; } cm.Execute(new Poderosa.Commands.SelectedTextCopyCommand(option), ct); } } } }
private static string GetSelectedText(ICommandTarget target, TextFormatOption opt) { CharacterDocumentViewer c = TerminalCommandTarget.AsCharacterDocumentViewer(target); if (c == null) return null; ITextSelection s = c.ITextSelection; if (s.IsEmpty || !c.EnabledEx) return null; return s.GetSelectedText(opt); }
public SelectedTextCopyCommand(TextFormatOption option) { this.option = option; }
public string GetSelectedText(TextFormatOption opt) { //if(_owner==null || _disabledTemporary) return null; StringBuilder bld = new StringBuilder(); TextPoint a = HeadPoint; TextPoint b = TailPoint; GLine l = _owner.CharacterDocument.FindLineOrEdge(a.Line); int pos = a.Column; if (pos < 0) return ""; do { bool eol_required = (opt == TextFormatOption.AsLook || l.EOLType != EOLType.Continue); if (l.ID == b.Line) { //�ŏI�s //������NULL����������P�[�X������悤�� AppendTrim(bld, l, pos, b.Column - pos); if (_pivotType == RangeType.Line && eol_required) bld.Append("\r\n"); break; } else { //�ŏI�ȊO�̍s if (l.Length - pos > 0) { //l.CharLength==pos�ƂȂ�P�[�X���������B�^�̗��R�͔[�����Ă��Ȃ��� AppendTrim(bld, l, pos, l.Length - pos); } if (eol_required && bld.Length > 0) //bld.Length>0�͍s�P�ʑI��ŗ]�v�ȉ��s������̂����邽�߂̏��u bld.Append("\r\n"); //LF�݂̂�N���b�v�{�[�h�Ɏ����Ă����Ă���̃A�v���̍��������邾���Ȃ̂ł�߂Ă��� l = l.NextLine; if (l == null) break; //!!�{������͂Ȃ��͂������N���b�V�����|�[�g�̂��߉�� pos = 0; } } while (true); //Debug.WriteLine("Selected Text Len="+bld.Length); return bld.ToString(); }
public string GetSelectedText(TextFormatOption opt) { //if(_owner==null || _disabledTemporary) return null; StringBuilder bld = new StringBuilder(); TextPoint a = HeadPoint; TextPoint b = TailPoint; GLine l = _owner.CharacterDocument.FindLineOrEdge(a.Line); int pos = a.Column; if (pos < 0) return ""; do { bool eol_required = (opt == TextFormatOption.AsLook || l.EOLType != EOLType.Continue); if (l.ID == b.Line) { //最終行 //末尾にNULL文字が入るケースがあるようだ AppendTrim(bld, l, pos, b.Column - pos); if (_pivotType == RangeType.Line && eol_required) bld.Append("\r\n"); break; } else { //最終以外の行 if (l.Length - pos > 0) { //l.CharLength==posとなるケースがあった。真の理由は納得していないが AppendTrim(bld, l, pos, l.Length - pos); } if (eol_required && bld.Length > 0) //bld.Length>0は行単位選択で余計な改行が入るのを避けるための処置 bld.Append("\r\n"); //LFのみをクリップボードに持っていっても他のアプリの混乱があるだけなのでやめておく l = l.NextLine; if (l == null) break; //!!本来これはないはずだがクラッシュレポートのため回避 pos = 0; } } while (true); //Debug.WriteLine("Selected Text Len="+bld.Length); return bld.ToString(); }
public string GetSelectedText(TextFormatOption opt) { System.Text.StringBuilder b = new StringBuilder(); TextPoint head = HeadPoint; TextPoint tail = TailPoint; GLine l = _owner.CharacterDocument.FindLineOrEdge(head.Line); int p0 = head.Column; if (l.Text[p0] == GLine.WIDECHAR_PAD) { p0--; } if (p0 < 0) { return(""); } bool isrect = (opt & TextFormatOption.Rectangle) != 0; int p1 = 0; if (isrect) { p1 = tail.Column; GLine tl = _owner.CharacterDocument.FindLineOrEdge(tail.Line); if (tl.Text[p1] == GLine.WIDECHAR_PAD) { p1--; } if (p0 == p1) { return(""); } if (p0 > p1) { l = tl; int p3 = p0; p0 = p1; p1 = p3; } } int start = p0; for (; l != null && l.ID <= tail.Line; l = l.NextLine) { //note: 本来 l==null はないはずだがクラッシュレポートのため回避 bool fCRLF = (opt & (TextFormatOption.AsLook | TextFormatOption.Rectangle)) != 0 || l.EOLType != EOLType.Continue; char[] text = l.Text; int end; if (isrect) { start = p0; if (text[start] == GLine.WIDECHAR_PAD) { start--; } end = p1 < l.Length?p1:l.Length; } else { if (l.ID == tail.Line) //最終行 { end = tail.Column; fCRLF = fCRLF && _pivotType == RangeType.Line; } else //最終以外の行 { end = l.Length; //nl=eol_required&&b.Length>0; //b.Length>0は行単位選択で余計な改行が入るのを避けるための処置 //↑KM: 意図して先頭の改行も含む様に囲まなければ、これらの行は入らないのでは? } } if (end > text.Length) { end = text.Length; } if (fCRLF && (opt & TextFormatOption.TrimEol) != 0 && l.ID != tail.Line) { // TrimEol for (; end > start; end--) { if (!char.IsWhiteSpace(text[end - 1]) && text[end - 1] != GLine.WIDECHAR_PAD && text[end - 1] != '\0') { break; } } } for (int i = start; i < end; i++) { char ch = text[i]; if (ch != GLine.WIDECHAR_PAD && ch != '\0') { b.Append(ch); } //末尾にNULL文字が入るケースがあるようだ } //note: LFのみをクリップボードに持っていっても他のアプリの混乱があるだけなのでやめておく if (fCRLF) { b.Append("\r\n"); } start = 0; } return(b.ToString()); }