Improved title seeking (used from CLI when seeking for window by title).

This commit is contained in:
Lorenz Cuno Klopfenstein 2013-10-16 16:09:28 +02:00
parent 6cd21971cf
commit dc031dcdb1

View file

@ -16,7 +16,7 @@ namespace OnTopReplica.WindowSeekers {
if (titleSeekString == null)
throw new ArgumentNullException();
TitleMatch = titleSeekString.Trim();
TitleMatch = titleSeekString.Trim().ToLowerInvariant();
}
public string TitleMatch { get; private set; }
@ -30,15 +30,19 @@ namespace OnTopReplica.WindowSeekers {
if (!WindowManagerMethods.IsTopLevel(handle.Handle))
return -1;
string handleTitle = handle.Title.ToLowerInvariant();
int points = 0;
//Give points for partial match
if (handle.Title.StartsWith(TitleMatch, StringComparison.InvariantCultureIgnoreCase))
points += 10;
//Give points for exact match
if (handle.Title.Equals(TitleMatch, StringComparison.InvariantCultureIgnoreCase))
if (handleTitle.Equals(TitleMatch)) {
points += 20;
}
else if (handleTitle.StartsWith(TitleMatch)) {
points += 15;
}
else if (handleTitle.Contains(TitleMatch)) {
points += 10;
}
return points;
}