Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add favorite by regex #160

Merged
merged 3 commits into from
Aug 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Common/Favorites.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using BorderlessGaming.Utilities;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text.RegularExpressions;

namespace BorderlessGaming.Common
{
Expand Down Expand Up @@ -105,6 +106,7 @@ public enum FavoriteKinds : int
{
ByBinaryName = 0,
ByTitleText = 1,
ByRegexString = 2,
}

public SizeModes SizeMode = SizeModes.FullScreen;
Expand Down Expand Up @@ -145,6 +147,8 @@ public override string ToString() // so that the ListView control knows how to d
extra_details += " [Process]";
else if (this.Kind != FavoriteKinds.ByTitleText)
extra_details += " [?]";
else if (this.Kind != FavoriteKinds.ByRegexString)
extra_details += " [Regex]";

extra_details += ((this.ShouldMaximize) ? " [Max]" : "");
extra_details += ((this.SizeMode == SizeModes.NoChange) ? " [NoSize]" : "");
Expand All @@ -170,8 +174,9 @@ public override string ToString() // so that the ListView control knows how to d

public bool Matches(ProcessDetails pd)
{
return (((Kind == FavoriteKinds.ByBinaryName) && (pd.BinaryName == SearchText)) ||
((Kind == FavoriteKinds.ByTitleText) && (pd.WindowTitle == SearchText)));
return (((Kind == FavoriteKinds.ByBinaryName) && (pd.BinaryName == SearchText)) ||
((Kind == FavoriteKinds.ByTitleText) && (pd.WindowTitle == SearchText)) ||
((Kind == FavoriteKinds.ByRegexString) && (Regex.IsMatch(pd.WindowTitle, SearchText))));
}
}
}
Expand Down
34 changes: 26 additions & 8 deletions Forms/MainWindow.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions Forms/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ private void toolStripSupportUs_Click(object sender, EventArgs e)
Tools.GotoSite("http://store.steampowered.com/app/388080");
}

private void toolStripRegexReference_Click(object sender, EventArgs e)
{
Tools.GotoSite("http://store.steampowered.com/app/388080");
}

private void toolStripAbout_Click(object sender, EventArgs e)
{
new AboutForm().ShowDialog();
Expand Down Expand Up @@ -403,6 +408,37 @@ private void byTheProcessBinaryNameToolStripMenuItem_Click(object sender, EventA
controller.Favorites.Add(fav);
}
}

/// <summary>
/// adds the currently selected process to the favorites (by window title text)
/// </summary>
private void byTheWindowTitleTextregexToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.lstProcesses.SelectedItem == null) return;

ProcessDetails pd = ((ProcessDetails)this.lstProcesses.SelectedItem);

if (!pd.Manageable)
return;

//TODO move to controller
if (controller.Favorites.CanAdd(pd.WindowTitle))
{
InputText it = new InputText();
it.Text = "Add to favorites by regex string";
it.Input = pd.WindowTitle;
it.Instructions = "Regex string (reference is in the Help menu)";

it.ShowDialog();
if (it.DialogResult != DialogResult.OK)
return;

Favorites.Favorite fav = new Favorites.Favorite();
fav.Kind = Favorites.Favorite.FavoriteKinds.ByTitleText;
fav.SearchText = pd.WindowTitle;
controller.Favorites.Add(fav);
}
}

private void addSelectedItem_Click(object sender, EventArgs e)
{
Expand Down
24 changes: 24 additions & 0 deletions Forms/MainWindow.resx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@
<data name="byTheProcessBinaryNameToolStripMenuItem.Text" xml:space="preserve">
<value>... by the process binary name</value>
</data>
<data name="byTheWindowTitleTextregexToolStripMenuItem.Size" type="System.Drawing.Size, System.Drawing">
<value>253, 22</value>
</data>
<data name="byTheWindowTitleTextregexToolStripMenuItem.Text" xml:space="preserve">
<value>... by the window title text (regex)</value>
</data>
<data name="toolStripMenuItem1.Size" type="System.Drawing.Size, System.Drawing">
<value>201, 6</value>
</data>
Expand Down Expand Up @@ -721,6 +727,12 @@
<data name="toolStripSupportUs.Text" xml:space="preserve">
<value>Support Us</value>
</data>
<data name="toolStripRegexReference.Size" type="System.Drawing.Size, System.Drawing">
<value>152, 22</value>
</data>
<data name="toolStripRegexReference.Text" xml:space="preserve">
<value>Regex Reference</value>
</data>
<data name="toolStripMenuItem2.Size" type="System.Drawing.Size, System.Drawing">
<value>149, 6</value>
</data>
Expand Down Expand Up @@ -989,6 +1001,12 @@
<data name="&gt;&gt;byTheProcessBinaryNameToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;byTheWindowTitleTextregexToolStripMenuItem.Name" xml:space="preserve">
<value>byTheWindowTitleTextregexToolStripMenuItem</value>
</data>
<data name="&gt;&gt;byTheWindowTitleTextregexToolStripMenuItem.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;toolStripMenuItem1.Name" xml:space="preserve">
<value>toolStripMenuItem1</value>
</data>
Expand Down Expand Up @@ -1277,6 +1295,12 @@
<data name="&gt;&gt;toolStripSupportUs.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;toolStripRegexReference.Name" xml:space="preserve">
<value>toolStripRegexReference</value>
</data>
<data name="&gt;&gt;toolStripRegexReference.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;toolStripMenuItem2.Name" xml:space="preserve">
<value>toolStripMenuItem2</value>
</data>
Expand Down