mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Move ProgramSource definition
This commit is contained in:
parent
d646380f6e
commit
81d295498b
5 changed files with 108 additions and 29 deletions
|
|
@ -12,7 +12,7 @@ namespace Flow.Launcher.Plugin.Program
|
|||
public partial class AddProgramSource
|
||||
{
|
||||
private PluginInitContext _context;
|
||||
private Settings.ProgramSource _editing;
|
||||
private ProgramSource _editing;
|
||||
private Settings _settings;
|
||||
|
||||
public AddProgramSource(PluginInitContext context, Settings settings)
|
||||
|
|
@ -23,7 +23,7 @@ namespace Flow.Launcher.Plugin.Program
|
|||
Directory.Focus();
|
||||
}
|
||||
|
||||
public AddProgramSource(Settings.ProgramSource edit, Settings settings)
|
||||
public AddProgramSource(ProgramSource edit, Settings settings)
|
||||
{
|
||||
_editing = edit;
|
||||
_settings = settings;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Flow.Launcher.Plugin.Program.Views.Models;
|
||||
|
||||
namespace Flow.Launcher.Plugin.Program
|
||||
{
|
||||
|
|
@ -24,25 +25,5 @@ namespace Flow.Launcher.Plugin.Program
|
|||
internal const string Explorer = "explorer";
|
||||
|
||||
internal const string ExplorerArgs = "%s";
|
||||
|
||||
/// <summary>
|
||||
/// Contains user added folder location contents as well as all user disabled applications
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>Win32 class applications set UniqueIdentifier using their full file path</para>
|
||||
/// <para>UWP class applications set UniqueIdentifier using their Application User Model ID</para>
|
||||
/// <para>Custom user added program sources set UniqueIdentifier using their location</para>
|
||||
/// </remarks>
|
||||
public class ProgramSource
|
||||
{
|
||||
private string name;
|
||||
|
||||
public string Location { get; set; }
|
||||
public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }
|
||||
public bool Enabled { get; set; } = true;
|
||||
public string UniqueIdentifier { get; set; }
|
||||
}
|
||||
|
||||
public class DisabledProgramSource : ProgramSource { }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ namespace Flow.Launcher.Plugin.Program.Views.Commands
|
|||
{
|
||||
internal static class ProgramSettingDisplay
|
||||
{
|
||||
internal static List<ProgramSource> LoadProgramSources(this List<Settings.ProgramSource> programSources)
|
||||
internal static List<ProgramSource> LoadProgramSources(this List<ProgramSource> programSources)
|
||||
{
|
||||
var list = new List<ProgramSource>();
|
||||
|
||||
|
|
@ -108,7 +108,7 @@ namespace Flow.Launcher.Plugin.Program.Views.Commands
|
|||
.ToList()
|
||||
.ForEach(x => Main._settings.DisabledProgramSources
|
||||
.Add(
|
||||
new Settings.DisabledProgramSource
|
||||
new DisabledProgramSource
|
||||
{
|
||||
Name = x.Name,
|
||||
Location = x.Location,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,103 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Flow.Launcher.Plugin.Program.Programs;
|
||||
|
||||
namespace Flow.Launcher.Plugin.Program.Views.Models
|
||||
{
|
||||
public class ProgramSource : Settings.ProgramSource { }
|
||||
/// <summary>
|
||||
/// Contains user added folder location contents as well as all user disabled applications
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>Win32 class applications set UniqueIdentifier using their full file path</para>
|
||||
/// <para>UWP class applications set UniqueIdentifier using their Application User Model ID</para>
|
||||
/// <para>Custom user added program sources set UniqueIdentifier using their location</para>
|
||||
/// </remarks>
|
||||
public class ProgramSource
|
||||
{
|
||||
private string name;
|
||||
|
||||
public string Location;
|
||||
public string Name { get => name ?? new DirectoryInfo(Location).Name; set => name = value; }
|
||||
public bool Enabled { get; set; } = true;
|
||||
private string uid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Guranteed lowercase.
|
||||
/// </summary>
|
||||
public string UniqueIdentifier { get => uid; set => uid = value.ToLowerInvariant(); }
|
||||
|
||||
public ProgramSource()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom user added source.
|
||||
/// </summary>
|
||||
/// <param name="location"></param>
|
||||
/// <param name="enabled"></param>
|
||||
public ProgramSource(string location, bool enabled)
|
||||
{
|
||||
Location = location;
|
||||
Enabled = enabled;
|
||||
UniqueIdentifier = location;
|
||||
}
|
||||
|
||||
public ProgramSource(ProgramSource source)
|
||||
{
|
||||
Location = source.Location;
|
||||
Name = source.Name;
|
||||
Enabled = source.Enabled;
|
||||
UniqueIdentifier = source.UniqueIdentifier;
|
||||
}
|
||||
|
||||
public ProgramSource(IProgram source)
|
||||
{
|
||||
Location = source.Location;
|
||||
Name = source.Name;
|
||||
Enabled = source.Enabled;
|
||||
UniqueIdentifier = source.UniqueIdentifier;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is ProgramSource other && other.UniqueIdentifier == this.UniqueIdentifier;
|
||||
}
|
||||
|
||||
public bool Equals(IProgram program)
|
||||
{
|
||||
return program != null && program.UniqueIdentifier == this.UniqueIdentifier;
|
||||
}
|
||||
|
||||
public static bool operator ==(ProgramSource a, ProgramSource b)
|
||||
{
|
||||
return a is not null && a.Equals(b);
|
||||
}
|
||||
|
||||
public static bool operator !=(ProgramSource a, ProgramSource b)
|
||||
{
|
||||
return !(a == b);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(uid);
|
||||
}
|
||||
}
|
||||
|
||||
public class DisabledProgramSource : ProgramSource
|
||||
{
|
||||
public DisabledProgramSource() { }
|
||||
|
||||
public DisabledProgramSource(string location) : base(location, false) { }
|
||||
|
||||
public DisabledProgramSource(ProgramSource source) : base(source)
|
||||
{
|
||||
Enabled = false;
|
||||
}
|
||||
|
||||
public DisabledProgramSource(IProgram program) : base(program)
|
||||
{
|
||||
Enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -147,7 +147,7 @@ namespace Flow.Launcher.Plugin.Program.Views
|
|||
|
||||
private void btnEditProgramSource_OnClick(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var selectedProgramSource = programSourceView.SelectedItem as Settings.ProgramSource;
|
||||
var selectedProgramSource = programSourceView.SelectedItem as ProgramSource;
|
||||
if (selectedProgramSource != null)
|
||||
{
|
||||
var add = new AddProgramSource(selectedProgramSource, _settings);
|
||||
|
|
@ -360,4 +360,4 @@ namespace Flow.Launcher.Plugin.Program.Views
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue