📄 find.cs
字号:
// Find.cs
// Copyright (C) 2000 Andrea Paatz
// Copyright (C) 2000 Mike Krueger
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using SharpDevelop.Gui;
using SharpDevelop.Gui.Edit.Text;
using SharpDevelop.Gui.Window;
namespace SharpDevelop.Internal.Text.Search {
public class Find
{
public static MainWindow Main;
public static Search search = new Search("");
// public static bool WholeWords = false;
public static bool WrapAtTheEnd = true;
public bool hadfirstindex = false;
protected bool Found(TextAreaControl area, Point here, Point end)
{
int length = search.What.Length;
if (here.Y < end.Y || (here.Y == end.Y && here.X < end.X)){
area.Caret.CaretPos = new Point(here.X + length, here.Y);
area.Selection.SetNoSelection();
area.Selection.SelectionStart = here;
area.Selection.SelectionEnd = new Point(here.X + length, here.Y);
area.UpdateSelection(null, null);
area.ScrollToCaret();
return true;
} else {
return false;
}
}
public bool SelectionEqualsPattern()
{
TextAreaControl area = Main.ActiveContentWindow.TextArea;
string text = area.Buffer.GetText(area.Selection.SelectionStart, area.Selection.SelectionEnd);
return text.Equals(search.What);
}
protected bool FindInFile(ContentWindow window, Point begin, Point end, bool wrap)
{
if (window != null) {
TextBuffer b = window.TextArea.Buffer;
Point here = search.Find(b, begin, end);
TextAreaControl area = Main.ActiveContentWindow.TextArea;
if(!Found(area, here, end)){
if(wrap){
here = search.Find(b, new Point(0, 0), begin);
if(!Found(area, here, begin)) {
return false;
}
}else {
return false;
}
}
return true;
}
return false;
}
public virtual bool FindNext()
{
return false;
}
}
public class FindInWholeProject : Find
{
public void FindProject()
{
// System.String[] files = Main.ProjectBrowser.Project.File;
}
public override bool FindNext()
{
MessageBox.Show("TODO : FindInWholeProject");
return false;
}
}
public class FindInAllOpenFiles : Find
{
private int index = 0;
private int firstIndex = 0;
private Point begin = new Point (0, 0);
private Point firstBegin;
public FindInAllOpenFiles()
{
index = 0;
foreach (ContentWindow w in Main.MdiChildren){
if (w == Main.ActiveContentWindow)
break;
++index;
}
firstIndex = index;
begin = firstBegin = Main.ActiveContentWindow.TextArea.Caret.CaretPos;
}
private void FindOpenLast(){/*
System.Console.WriteLine("fol begin");
System.Collections.ArrayList window = Main.ActiveContentWindow;
ContentWindow w = (ContentWindow)window[index];
TextBuffer b = w.TextArea.Buffer;
Point end = new Point(0, b.Length);
Point p = end;
System.Console.WriteLine("1");
while (index != firstIndex) {
System.Console.WriteLine("bla " + index);
w = (ContentWindow)window[index];
b = w.TextArea.TextBuffer;
end = new Point(0, b.Length);
if(FindInFile(w, begin, end, false))
break;
// p = search.Find(b, begin, end);
// if(p != end){
// break;
// }
begin = new Point(0, 0);
index = (index + 1) % window.Count;
}
System.Console.WriteLine("2 " + index);
if (index == firstIndex){
w = (ContentWindow)window[index];
if(!FindInFile(w, begin, firstBegin, false)){
MessageBox.Show("!not found!");
return;
}
}
System.Console.WriteLine("3");
w.Select();
System.Console.WriteLine("4");
begin = w.TextArea.Caret.CaretPos;
System.Console.WriteLine("fol end");*/
}
public void FindOpenFirst()
{/*
System.Console.WriteLine("fof begin");
System.Collections.ArrayList window = Main.textWindow;
ContentWindow w = (ContentWindow)window[index];
TextBuffer b = w.TextArea.TextBuffer;
Point end = new Point(0, b.Length);
Point p = end;
// while (index < window.Count){
w = (ContentWindow)window[firstIndex];
b = w.TextArea.TextBuffer;
end = new Point(0, b.Length);
if(FindInFile(w, begin, end, false)) {
break;
} else {
begin = new Point(0, 0);
index = (firstIndex + 1) % window.Count;
FindOpenLast();
}
System.Console.WriteLine("fof end");*/
}
public override bool FindNext()
{
// bool ret = false;
if (index == firstIndex && hadfirstindex) {
// MessageBox.Show("!not found!");
return false;
}
Point begin = ((ContentWindow)Main.MdiChildren[index]).TextArea.Caret.CaretPos;
Point end = new Point(0, ((ContentWindow)Main.MdiChildren[index]).TextArea.Buffer.Length);
if (FindInFile(((ContentWindow)Main.MdiChildren[index]), begin, end, false)) {
((ContentWindow)Main.MdiChildren[index]).Select();
return true;
}
if (index == firstIndex && !WrapAtTheEnd) {
hadfirstindex = true;
}
index = (index + 1) % Main.MdiChildren.Length;
((ContentWindow)Main.MdiChildren[index]).TextArea.Caret.CaretPos = new Point(0, 0);
// ret = this.FindNext();
return this.FindNext();
}
}
public class FindInBuffer : Find
{
public override bool FindNext()
{
ContentWindow w = Main.ActiveContentWindow;
Point begin = w.TextArea.Caret.CaretPos;
if(!FindInFile(w, begin, new Point(0, w.TextArea.Buffer.Length), WrapAtTheEnd)){
// MessageBox.Show("!not found!");
return false;
}else
return true;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -