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;
}
public Result ResultFromWin32(Win32 p)
public Result ResultFromWin32(Win32 program)
{
var result = new Result
{
Title = p.FullName,
SubTitle = p.FullPath,
IcoPath = p.IcoPath,
Score = p.Score,
ContextData = p,
SubTitle = program.FullPath,
IcoPath = program.IcoPath,
Score = program.Score,
ContextData = program,
Action = e =>
{
var info = new ProcessStartInfo
{
FileName = p.FullPath,
WorkingDirectory = p.ParentDirectory
FileName = program.FullPath,
WorkingDirectory = program.ParentDirectory
};
var hide = StartProcess(info);
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;
}
public Result ResultFromUWP(UWP.Application app)
{
var result = new Result
{
Title = app.DisplayName,
SubTitle = $"Windows Store app: {app.Description}",
SubTitle = $"{app.Location}",
Icon = app.Logo,
Score = app.Score,
ContextData = app,
@@ -95,16 +108,32 @@ namespace Wox.Plugin.Program
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;
}
private int Score(Win32 program, string query)
{
var score1 = StringMatcher.Score(program.FullName, query);
var score2 = StringMatcher.ScoreForPinyin(program.FullName, query);
var score3 = StringMatcher.Score(program.ExecutableName, query);
var score = new[] { score1, score2, score3 }.Max();
var score1 = StringMatcher.Score(program.Name, query);
var score2 = StringMatcher.ScoreForPinyin(program.Name, query);
var score3 = StringMatcher.Score(program.Description, query);
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;
return score;
}

View File

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

View File

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