Better title and subtitle

This commit is contained in:
bao-qian 2016-08-20 18:50:14 +01:00
parent fe85ce5885
commit 8de84f03a0
3 changed files with 58 additions and 23 deletions

View file

@ -58,34 +58,47 @@ namespace Wox.Plugin.Program
return result; return result;
} }
public Result ResultFromWin32(Win32 p) public Result ResultFromWin32(Win32 program)
{ {
var result = new Result var result = new Result
{ {
Title = p.FullName, SubTitle = program.FullPath,
SubTitle = p.FullPath, IcoPath = program.IcoPath,
IcoPath = p.IcoPath, Score = program.Score,
Score = p.Score, ContextData = program,
ContextData = p,
Action = e => Action = e =>
{ {
var info = new ProcessStartInfo var info = new ProcessStartInfo
{ {
FileName = p.FullPath, FileName = program.FullPath,
WorkingDirectory = p.ParentDirectory WorkingDirectory = program.ParentDirectory
}; };
var hide = StartProcess(info); var hide = StartProcess(info);
return hide; return hide;
} }
}; };
if (program.Description.Length >= program.Name.Length &&
program.Description.Substring(0, program.Name.Length) == program.Name)
{
result.Title = program.Description;
}
else if (!string.IsNullOrEmpty(program.Description))
{
result.Title = $"{program.Name}: {program.Description}";
}
else
{
result.Title = program.Name;
}
return result; return result;
} }
public Result ResultFromUWP(UWP.Application app) public Result ResultFromUWP(UWP.Application app)
{ {
var result = new Result var result = new Result
{ {
Title = app.DisplayName, SubTitle = $"{app.Location}",
SubTitle = $"Windows Store app: {app.Description}",
Icon = app.Logo, Icon = app.Logo,
Score = app.Score, Score = app.Score,
ContextData = app, ContextData = app,
@ -95,16 +108,32 @@ namespace Wox.Plugin.Program
return true; return true;
} }
}; };
if (app.Description.Length >= app.DisplayName.Length &&
app.Description.Substring(0, app.DisplayName.Length) == app.DisplayName)
{
result.Title = app.Description;
}
else if (!string.IsNullOrEmpty(app.Description))
{
result.Title = $"{app.DisplayName}: {app.Description}";
}
else
{
result.Title = app.DisplayName;
}
return result; return result;
} }
private int Score(Win32 program, string query) private int Score(Win32 program, string query)
{ {
var score1 = StringMatcher.Score(program.FullName, query); var score1 = StringMatcher.Score(program.Name, query);
var score2 = StringMatcher.ScoreForPinyin(program.FullName, query); var score2 = StringMatcher.ScoreForPinyin(program.Name, query);
var score3 = StringMatcher.Score(program.ExecutableName, query); var score3 = StringMatcher.Score(program.Description, query);
var score = new[] { score1, score2, score3 }.Max(); var score4 = StringMatcher.ScoreForPinyin(program.Description, query);
var score5 = StringMatcher.Score(program.ExecutableName, query);
var score = new[] { score1, score2, score3, score4, score5 }.Max();
program.Score = score; program.Score = score;
return score; return score;
} }

View file

@ -81,6 +81,7 @@ namespace Wox.Plugin.Program.Programs
Apps[i].Executable = currentApp.GetStringValue("Executable"); Apps[i].Executable = currentApp.GetStringValue("Executable");
Apps[i].BackgroundColor = currentApp.GetStringValue("BackgroundColor"); Apps[i].BackgroundColor = currentApp.GetStringValue("BackgroundColor");
Apps[i].LogoPath = Path.Combine(Location, currentApp.GetStringValue("Square44x44Logo")); Apps[i].LogoPath = Path.Combine(Location, currentApp.GetStringValue("Square44x44Logo"));
Apps[i].Location = Location;
apps.MoveNext(); apps.MoveNext();
i++; i++;
@ -204,7 +205,10 @@ namespace Wox.Plugin.Program.Programs
public string PublisherDisplayName { get; set; } public string PublisherDisplayName { get; set; }
public string BackgroundColor { get; set; } public string BackgroundColor { get; set; }
public string LogoPath { get; set; } public string LogoPath { get; set; }
public int Score { get; set; } public int Score { get; set; }
public string Location { get; set; }
// todo: wrap with try exception // todo: wrap with try exception
public void Launch() public void Launch()

View file

@ -13,11 +13,12 @@ namespace Wox.Plugin.Program.Programs
[Serializable] [Serializable]
public class Win32 public class Win32
{ {
public string FullName { get; set; } public string Name { get; set; }
public string IcoPath { get; set; } public string IcoPath { get; set; }
public string FullPath { get; set; } public string FullPath { get; set; }
public string ParentDirectory { get; set; } public string ParentDirectory { get; set; }
public string ExecutableName { get; set; } public string ExecutableName { get; set; }
public string Description { get; set; }
public int Score { get; set; } public int Score { get; set; }
private const string ShortcutExtension = "lnk"; private const string ShortcutExtension = "lnk";
@ -33,10 +34,11 @@ namespace Wox.Plugin.Program.Programs
{ {
var p = new Win32 var p = new Win32
{ {
FullName = Path.GetFileNameWithoutExtension(path), Name = Path.GetFileNameWithoutExtension(path),
IcoPath = path, IcoPath = path,
FullPath = path, FullPath = path,
ParentDirectory = Directory.GetParent(path).FullName, ParentDirectory = Directory.GetParent(path).FullName,
Description = string.Empty
}; };
return p; return p;
} }
@ -59,7 +61,7 @@ namespace Wox.Plugin.Program.Programs
var description = buffer.ToString(); var description = buffer.ToString();
if (!string.IsNullOrEmpty(description)) if (!string.IsNullOrEmpty(description))
{ {
program.FullName += $": {description}"; program.Description = description;
} }
else else
{ {
@ -73,7 +75,7 @@ namespace Wox.Plugin.Program.Programs
var info = FileVersionInfo.GetVersionInfo(target); var info = FileVersionInfo.GetVersionInfo(target);
if (!string.IsNullOrEmpty(info.FileDescription)) if (!string.IsNullOrEmpty(info.FileDescription))
{ {
program.FullName += $": {info.FileDescription}"; program.Description = info.FileDescription;
} }
} }
} }
@ -92,7 +94,7 @@ namespace Wox.Plugin.Program.Programs
var info = FileVersionInfo.GetVersionInfo(path); var info = FileVersionInfo.GetVersionInfo(path);
if (!string.IsNullOrEmpty(info.FileDescription)) if (!string.IsNullOrEmpty(info.FileDescription))
{ {
program.FullName += $": {info.FileDescription}"; program.Description = info.FileDescription;
} }
return program; return program;
} }
@ -179,7 +181,7 @@ namespace Wox.Plugin.Program.Programs
{ {
var programs = root.GetSubKeyNames() var programs = root.GetSubKeyNames()
.Select(subkey => ProgramFromRegistrySubkey(root, subkey)) .Select(subkey => ProgramFromRegistrySubkey(root, subkey))
.Where(p => !string.IsNullOrEmpty(p.FullName)); .Where(p => !string.IsNullOrEmpty(p.Name));
return programs; return programs;
} }
@ -215,17 +217,17 @@ namespace Wox.Plugin.Program.Programs
var doc = new[] { "帮助", "help", "文档", "documentation" }; var doc = new[] { "帮助", "help", "文档", "documentation" };
var uninstall = new[] { "卸载", "uninstall" }; var uninstall = new[] { "卸载", "uninstall" };
var contained = start.Any(s => p.FullName.ToLower().Contains(s)); var contained = start.Any(s => p.Name.ToLower().Contains(s));
if (contained) if (contained)
{ {
p.Score += 10; p.Score += 10;
} }
contained = doc.Any(d => p.FullName.ToLower().Contains(d)); contained = doc.Any(d => p.Name.ToLower().Contains(d));
if (contained) if (contained)
{ {
p.Score -= 10; p.Score -= 10;
} }
contained = uninstall.Any(u => p.FullName.ToLower().Contains(u)); contained = uninstall.Any(u => p.Name.ToLower().Contains(u));
if (contained) if (contained)
{ {
p.Score -= 20; p.Score -= 20;