-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract search commands into a pluggable container (in core)
- Loading branch information
Christian Rondeau
committed
Sep 1, 2014
1 parent
49bcd42
commit 8533212
Showing
15 changed files
with
258 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<UserControl x:Class="GoToWindow.Extensibility.Controls.BasicCommandEntry" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
mc:Ignorable="d" | ||
d:DesignHeight="48" d:DesignWidth="512" | ||
d:DataContext="{d:DesignData basicViewModel:DesignTimeCommandResult, IsDesignTimeCreatable=True}"> | ||
<Grid> | ||
<StackPanel Orientation="Horizontal" Height="Auto"> | ||
<TextBlock Margin="16, 16, 0, 16" VerticalAlignment="Center" Foreground="Gray" Text="{Binding BeforeText}"></TextBlock> | ||
<TextBlock Margin="0, 16, 0, 16" VerticalAlignment="Center" Foreground="Black" FontWeight="Bold" Text="{Binding Text, UpdateSourceTrigger=PropertyChanged}" /> | ||
<TextBlock Margin="0, 16, 0, 16" VerticalAlignment="Center" Foreground="Gray" Text="{Binding AfterText}"></TextBlock> | ||
</StackPanel> | ||
</Grid> | ||
</UserControl> |
12 changes: 12 additions & 0 deletions
12
GoToWindow.Extensibility/Controls/BasicCommandEntry.xaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Windows.Controls; | ||
|
||
namespace GoToWindow.Extensibility.Controls | ||
{ | ||
public partial class BasicCommandEntry : UserControl | ||
{ | ||
public BasicCommandEntry() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
GoToWindow.Extensibility/ViewModel/DesignTimeCommandResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System.Windows.Controls; | ||
|
||
namespace GoToWindow.Extensibility.ViewModel | ||
{ | ||
public class DesignTimeCommandResult : IBasicCommandResult | ||
{ | ||
public UserControl View { get; private set; } | ||
public string BeforeText { get; private set; } | ||
public string Text { get; private set; } | ||
public string AfterText { get; private set; } | ||
|
||
public DesignTimeCommandResult() | ||
{ | ||
BeforeText = "Execute command '"; | ||
Text = "Input Text"; | ||
AfterText = "' with something"; | ||
} | ||
|
||
public void Select() | ||
{ | ||
} | ||
|
||
public bool IsShown(string searchQuery) | ||
{ | ||
return true; | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
GoToWindow.Extensibility/ViewModel/DesignTimeSearchResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System.Windows.Controls; | ||
using System.Windows.Media.Imaging; | ||
using GoToWindow.Extensibility.Controls; | ||
|
||
namespace GoToWindow.Extensibility.ViewModel | ||
{ | ||
public class DesignTimeSearchResult : IBasicSearchResult | ||
{ | ||
public UserControl View { get; private set; } | ||
|
||
public BitmapFrame Icon { get; private set; } | ||
public string Title { get; private set; } | ||
public string ProcessName { get; private set; } | ||
|
||
public DesignTimeSearchResult() | ||
: this(null, "process", "Window Title") | ||
{ | ||
} | ||
|
||
public DesignTimeSearchResult(BitmapFrame icon, string processName, string title) | ||
{ | ||
View = new BasicListEntry(); | ||
Icon = icon; | ||
ProcessName = processName; | ||
Title = title; | ||
} | ||
|
||
public void Select() | ||
{ | ||
} | ||
|
||
public bool IsShown(string searchQuery) | ||
{ | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace GoToWindow.Extensibility.ViewModel | ||
{ | ||
public interface IBasicCommandResult : ISearchResult | ||
{ | ||
string BeforeText { get; } | ||
string Text { get; } | ||
string AfterText { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
GoToWindow.Plugins.Core/ViewModel/WindowSearchCommandResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using System.ComponentModel; | ||
using GoToWindow.Api; | ||
using GoToWindow.Extensibility.Controls; | ||
using GoToWindow.Extensibility.ViewModel; | ||
using log4net; | ||
|
||
namespace GoToWindow.Plugins.Core.ViewModel | ||
{ | ||
public class WindowSearchCommandResult : SearchResultBase, IBasicCommandResult, INotifyPropertyChanged | ||
{ | ||
private static readonly ILog Log = LogManager.GetLogger(typeof(WindowSearchCommandResult).Assembly, "GoToWindow"); | ||
|
||
private string _text; | ||
private string _query; | ||
|
||
public event PropertyChangedEventHandler PropertyChanged; | ||
|
||
public string BeforeText { get { return "Search for '"; } } | ||
public string AfterText { get { return "' using Windows Search"; } } | ||
|
||
public string Text | ||
{ | ||
get { return _text; } | ||
set | ||
{ | ||
_text = value; | ||
OnPropertyChanged("Text"); | ||
} | ||
} | ||
|
||
public WindowSearchCommandResult() | ||
: base(() => new BasicCommandEntry()) | ||
{ | ||
|
||
} | ||
|
||
protected void OnPropertyChanged(string name) | ||
{ | ||
if (PropertyChanged != null) | ||
PropertyChanged(this, new PropertyChangedEventArgs(name)); | ||
} | ||
|
||
public void Select() | ||
{ | ||
Log.DebugFormat("Launching Windows Search with '{0}'.", _query); | ||
WindowsSearch.Launch(_query); | ||
} | ||
|
||
public bool IsShown(string searchQuery) | ||
{ | ||
_query = searchQuery; | ||
Text = _query; | ||
return !String.IsNullOrWhiteSpace(searchQuery); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,46 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Windows.Controls; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.IO; | ||
using System.Windows.Data; | ||
using System.Windows.Media.Imaging; | ||
using GoToWindow.Extensibility; | ||
using GoToWindow.Extensibility.Controls; | ||
using GoToWindow.Extensibility.ViewModel; | ||
|
||
namespace GoToWindow.ViewModels | ||
{ | ||
public class DesignTimeMainViewModel : MainViewModel | ||
{ | ||
private class DesignTimeSearchResult : ISearchResult, IBasicSearchResult | ||
{ | ||
public UserControl View { get; private set; } | ||
|
||
public BitmapFrame Icon { get; private set; } | ||
public string Title { get; private set; } | ||
public string ProcessName { get; private set; } | ||
|
||
public DesignTimeSearchResult(string processName, string title) | ||
{ | ||
View = new BasicListEntry(); | ||
ProcessName = processName; | ||
Title = title; | ||
} | ||
|
||
public void Select() | ||
{ | ||
} | ||
|
||
public bool IsShown(string searchQuery) | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
public DesignTimeMainViewModel() | ||
{ | ||
IsEmpty = false; | ||
AvailableWindowWidth = 640; | ||
AvailableWindowHeight = 320; | ||
//SearchText = "User Query..."; | ||
AvailableWindowHeight = 240; | ||
SearchText = "User Query..."; | ||
var icon = ConvertFromIcon(Properties.Resources.AppIcon); | ||
Windows = new CollectionViewSource | ||
{ | ||
Source = new List<ISearchResult> | ||
{ | ||
new DesignTimeSearchResult("process", "Window Title"), | ||
new DesignTimeSearchResult("very long process name", "Very very long window title that should end up with ellipsis because it is so very long"), | ||
new DesignTimeSearchResult("filler", "Some Window Title"), | ||
new DesignTimeSearchResult("filler", "Some Window Title"), | ||
new DesignTimeSearchResult("filler", "Some Window Title"), | ||
new DesignTimeSearchResult("filler", "Some Window Title"), | ||
new DesignTimeSearchResult("filler", "Some Window Title"), | ||
new DesignTimeSearchResult("filler", "Some Window Title"), | ||
new DesignTimeSearchResult("filler", "Some Window Title"), | ||
new DesignTimeSearchResult("filler", "Some Window Title") | ||
new DesignTimeSearchResult(icon, "process", "Window Title"), | ||
new DesignTimeSearchResult(icon, "very long process name", "Very very long window title that should end up with ellipsis because it is so very long"), | ||
new DesignTimeSearchResult(icon, "filler", "Some Window Title"), | ||
new DesignTimeSearchResult(icon, "filler", "Some Window Title"), | ||
new DesignTimeSearchResult(icon, "filler", "Some Window Title"), | ||
new DesignTimeSearchResult(icon, "filler", "Some Window Title"), | ||
new DesignTimeSearchResult(icon, "filler", "Some Window Title"), | ||
new DesignTimeSearchResult(icon, "filler", "Some Window Title"), | ||
new DesignTimeSearchResult(icon, "filler", "Some Window Title"), | ||
new DesignTimeSearchResult(icon, "filler", "Some Window Title") | ||
} | ||
}; | ||
} | ||
|
||
private static BitmapFrame ConvertFromIcon(Icon icon) | ||
{ | ||
var memoryStream = new MemoryStream(); | ||
icon.Save(memoryStream); | ||
memoryStream.Seek(0, SeekOrigin.Begin); | ||
return BitmapFrame.Create(memoryStream); | ||
} | ||
} | ||
} |
Oops, something went wrong.