Skip to content

Commit

Permalink
Added a cancel button to the search box (an icon would be better). It…
Browse files Browse the repository at this point in the history
…s better but still open issues... 1: searchpanel gets too tall somehow? 2: file count in status bar persists after closing panel.
  • Loading branch information
activescott committed Sep 11, 2014
1 parent 396c03a commit d9b551f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 51 deletions.
45 changes: 5 additions & 40 deletions src/LessMsi.Gui/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ public void AutoSizeFileGridColumns()
}

private ToolStripMenuItem searchFileToolStripMenuItem;
private Button btRemoveFilter;

public FileInfo SelectedMsiFile
{
Expand Down Expand Up @@ -261,7 +260,6 @@ private void InitializeComponent()
this.tabExtractFiles = new System.Windows.Forms.TabPage();
this.fileGrid = new System.Windows.Forms.DataGridView();
this.panel2 = new System.Windows.Forms.Panel();
this.btRemoveFilter = new System.Windows.Forms.Button();
this.btnSelectAll = new System.Windows.Forms.Button();
this.btnUnselectAll = new System.Windows.Forms.Button();
this.btnExtract = new System.Windows.Forms.Button();
Expand Down Expand Up @@ -384,7 +382,6 @@ private void InitializeComponent()
//
// panel2
//
this.panel2.Controls.Add(this.btRemoveFilter);
this.panel2.Controls.Add(this.btnSelectAll);
this.panel2.Controls.Add(this.btnUnselectAll);
this.panel2.Controls.Add(this.btnExtract);
Expand All @@ -394,17 +391,6 @@ private void InitializeComponent()
this.panel2.Size = new System.Drawing.Size(446, 37);
this.panel2.TabIndex = 4;
//
// btRemoveFilter
//
this.btRemoveFilter.Location = new System.Drawing.Point(212, 9);
this.btRemoveFilter.Name = "btRemoveFilter";
this.btRemoveFilter.Size = new System.Drawing.Size(91, 27);
this.btRemoveFilter.TabIndex = 4;
this.btRemoveFilter.Text = "Remove fillter";
this.btRemoveFilter.UseVisualStyleBackColor = true;
this.btRemoveFilter.Visible = false;
this.btRemoveFilter.Click += new System.EventHandler(this.btRemoveFilter_Click);
//
// btnSelectAll
//
this.btnSelectAll.FlatStyle = System.Windows.Forms.FlatStyle.System;
Expand Down Expand Up @@ -920,14 +906,15 @@ private static IEnumerable<FileInfo> GetDraggedFiles(DragEventArgs e)
private void searchFileToolStripMenuItem_Click(object sender, EventArgs e) {
if (searchPanel == null) {
searchPanel = new SearchPanel();
searchPanel.StartPosition = FormStartPosition.Manual;
var screenPos = GetScreenPosition(this.fileGrid);
searchPanel.Left = screenPos.X;
searchPanel.Top = screenPos.Y;
searchPanel.Width = fileGrid.Width;
searchPanel.SearchTermChanged += SearchPanelSearchTermChanged;

searchPanel.ShowDialog(this);

searchPanel.SearchTermChanged += (o, args) => Presenter.BeginSearching(args.SearchString);
searchPanel.SearchCanceled += (o, args) => Presenter.CancelSearching();
searchPanel.Show(this);
searchPanel.Height = 26;
}
else {
searchPanel.Close();
Expand All @@ -947,28 +934,6 @@ private Point GetScreenPosition(Control ctl)
return this.PointToScreen(p);
}

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void SearchPanelSearchTermChanged(object sender, EnterEventArgs e) {
if (!string.IsNullOrEmpty(e.SearchString)) {
btRemoveFilter.Visible = true;
}
Presenter.PerformSearching(e.SearchString);
}

/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btRemoveFilter_Click(object sender, EventArgs e) {
btRemoveFilter.Visible = false;
Presenter.RemoveFilter();
}

/// <summary>
/// Closes search panel when main window change its size.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/LessMsi.Gui/MainFormPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ public void LoadCurrentFile()
/// Executes searching on gridtable and shows only filtered values
/// </summary>
/// <param name="p"></param>
internal void PerformSearching(string p) {
internal void BeginSearching(string p) {
var dataSource = this.fileDataSource.Where(x=>x.Component.Contains(p) || x.Directory.Contains(p) || x.Name.Contains(p) || x.Version.Contains(p)).ToList();
View.fileGrid.DataSource = dataSource;
Status(string.Format("Items count: {0}", dataSource.Count));
Expand All @@ -421,7 +421,7 @@ internal void PerformSearching(string p) {
/// <summary>
/// Removes file gridview filter
/// </summary>
internal void RemoveFilter() {
internal void CancelSearching() {
View.fileGrid.DataSource = this.fileDataSource;
}
}
Expand Down
19 changes: 17 additions & 2 deletions src/LessMsi.Gui/Windows.Forms/SearchPanel.Designer.cs

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

26 changes: 19 additions & 7 deletions src/LessMsi.Gui/Windows.Forms/SearchPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
namespace LessMsi.Gui.Windows.Forms {
public partial class SearchPanel : Form {
public event EventHandler<EnterEventArgs> SearchTermChanged;
/// <summary>
/// Raised when the search term box is canceled. Any filtering done based on the search can be cleared at this point.
/// </summary>
public event EventHandler<EventArgs> SearchCanceled;

public SearchPanel() {
InitializeComponent();
Expand All @@ -22,16 +26,24 @@ private void tbSearchText_TextChanged(object sender, EventArgs e) {
}
}

private void tbSearchText_Leave(object sender, EventArgs e) {
this.Close();
}

private void tbSearchText_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape) {
this.Close();
}
if (e.KeyCode == Keys.Escape)
CancelSearch();
}

private void CancelSearch()
{
this.Hide();
if (SearchCanceled != null)
SearchCanceled(this, EventArgs.Empty);
this.Close();
}

private void btnCancel_Click(object sender, EventArgs e)
{
CancelSearch();
}
}

public class EnterEventArgs : EventArgs{
Expand Down

0 comments on commit d9b551f

Please sign in to comment.