1
// FirstSearchController.cs
3
// GNOME Do is the legal property of its developers. Please refer to the
4
// COPYRIGHT file distributed with this source distribution.
6
// This program is free software: you can redistribute it and/or modify
7
// it under the terms of the GNU General Public License as published by
8
// the Free Software Foundation, either version 3 of the License, or
9
// (at your option) any later version.
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21
using System.Collections.Generic;
31
public class FirstSearchController : SimpleSearchController
33
public FirstSearchController() : base ()
37
public override bool ToggleSecondaryCursor (int cursorLocation)
39
bool update = (SecondaryCursors.Length == 0);
40
bool result = base.ToggleSecondaryCursor (cursorLocation);
42
if (update && result) {
49
public override void Reset ()
55
public override Type[] SearchTypes {
58
return new Type[] {typeof (ITextItem)};
59
} else if (context.SecondaryCursors.Length > 0) {
60
return new Type[] {(Results[SecondaryCursors[0]] as DoObject).Inner.GetType ()};
67
public override bool TextMode {
69
bool implicit_text_mode = false;
70
implicit_text_mode = Results.Length == 1 && Results[0] is ITextItem;
71
return (textMode || implicit_text_mode);
74
if (context.ParentContext != null) return;
77
BuildNewContextFromQuery ();
81
protected override void UpdateResults ()
83
List<IObject> results;
85
results = InitialResults ();
87
results = new List<IObject> ();
90
if (context.ParentContext == null) {
92
results.Add (new DoTextItem (Query));
94
foreach (Type t in SearchTypes) {
95
if (t == typeof (IItem) || t == typeof (ITextItem)) {
96
results.Add (new DoTextItem (Query));
102
context.Results = results.ToArray ();
103
//Do.PrintPerf ("FirstControllerResultsAssigned");
105
if (context.LastContext == null || context.LastContext.Selection != context.Selection) {
106
base.OnSelectionChanged ();
107
base.OnSearchFinished (true);
109
base.OnSearchFinished (false);
113
private void BuildNewContextFromQuery ()
115
string query = Query;
117
context = new SimpleSearchContext ();
118
List<IObject> results;
119
foreach (char c in query.ToCharArray ()) {
120
context.LastContext = context.Clone () as SimpleSearchContext;
123
results = InitialResults ();
125
results.Add (new DoTextItem (Query));
126
context.Results = results.ToArray ();
128
base.OnSelectionChanged ();