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

Search dropdown #3175

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 16 additions & 1 deletion GUI/CKAN-GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@
<Compile Include="Controls\EditModSearch.Designer.cs">
<DependentUpon>EditModSearch.cs</DependentUpon>
</Compile>
<Compile Include="Controls\EditModSearchDetails.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Controls\EditModSearchDetails.Designer.cs">
<DependentUpon>EditModSearchDetails.cs</DependentUpon>
</Compile>
<Compile Include="Controls\ManageMods.cs">
<SubType>UserControl</SubType>
</Compile>
Expand Down Expand Up @@ -482,6 +488,15 @@
<EmbeddedResource Include="Localization\zh-CN\EditModSearch.zh-CN.resx">
<DependentUpon>..\..\Controls\EditModSearch.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Controls\EditModSearchDetails.resx">
<DependentUpon>EditModSearchDetails.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Localization\de-DE\EditModSearchDetails.de-DE.resx">
<DependentUpon>..\..\Controls\EditModSearchDetails.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Localization\zh-CN\EditModSearchDetails.zh-CN.resx">
<DependentUpon>..\..\Controls\EditModSearchDetails.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Localization\de-DE\ModInfo.de-DE.resx">
<DependentUpon>..\..\Controls\ModInfo.cs</DependentUpon>
</EmbeddedResource>
Expand Down Expand Up @@ -614,4 +629,4 @@
<Exec Command="powershell ../build.ps1 Generate-GlobalAssemblyVersionInfo" Condition="!Exists('../_build/meta/GlobalAssemblyVersionInfo.cs') And '$(OS)' == 'Windows_NT'" />
<Exec Command="sh ../build Generate-GlobalAssemblyVersionInfo" Condition="!Exists('../_build/meta/GlobalAssemblyVersionInfo.cs') And '$(OS)' == 'Unix'" />
</Target>
</Project>
</Project>
275 changes: 25 additions & 250 deletions GUI/Controls/EditModSearch.Designer.cs

Large diffs are not rendered by default.

148 changes: 65 additions & 83 deletions GUI/Controls/EditModSearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,10 @@ public EditModSearch()

this.ToolTip.SetToolTip(ExpandButton, Properties.Resources.EditModSearchTooltipExpandButton);

labels = new Label[]
{
FilterByNameLabel,
FilterByAuthorLabel,
FilterByDescriptionLabel,
FilterByLanguageLabel,
FilterByDependsLabel,
FilterByRecommendsLabel,
FilterBySuggestsLabel,
FilterByConflictsLabel,
FilterCombinedLabel,
};
textboxes = new TextBox[]
{
FilterByNameTextBox,
FilterByAuthorTextBox,
FilterByDescriptionTextBox,
FilterByLanguageTextBox,
FilterByDependsTextBox,
FilterByRecommendsTextBox,
FilterBySuggestsTextBox,
FilterByConflictsTextBox,
FilterCombinedTextBox,
};
rowCount = labels.Length;
maxLabelWidth = labels.Select(l => l.Width).Max();
DoLayout(ExpandButton.Checked);
// TextBox resizes unpredictably at runtime, so we need special logic
// to line up the button with it
ExpandButton.Top = FilterCombinedTextBox.Top;
ExpandButton.Height = ExpandButton.Width = FilterCombinedTextBox.Height;
}

/// <summary>
Expand Down Expand Up @@ -79,61 +56,46 @@ public void ExpandCollapse()
public event Action SurrenderFocus;

private static readonly ILog log = LogManager.GetLogger(typeof(EditModSearch));
private Label[] labels;
private TextBox[] textboxes;
private readonly int rowCount;
private const int rowHeight = 26;
private const int padding = 4;
private readonly int maxLabelWidth;
private Timer filterTimer;
private bool suppressSearch = false;
private ModSearch currentSearch = null;

private void ExpandButton_CheckedChanged(object sender, EventArgs e)
{
ExpandButton.Text = ExpandButton.Checked ? "" : "";
ExpandButton.Text = ExpandButton.Checked ? "" : "";
DoLayout(ExpandButton.Checked);
}

private void DoLayout(bool expanded)
{
if (expanded)
FormGeometryChanged(null, null);
SearchDetails.Visible = expanded;
if (SearchDetails.Visible)
{
for (int row = 0; row < rowCount; ++row)
SearchDetails.FilterByNameTextBox.Focus();
if (Main.Instance != null)
{
labels[row].Visible = true;
labels[row].Left = padding;
labels[row].Top = padding + row * (rowHeight + padding);
textboxes[row].Visible = true;
textboxes[row].Left = maxLabelWidth + 2 * padding;
textboxes[row].Top = padding + row * (rowHeight + padding);
Main.Instance.Move += FormGeometryChanged;
Resize += FormGeometryChanged;
}
Height = rowCount * (rowHeight + padding);
}
else
else if (Main.Instance != null)
{
Height = rowHeight + padding;
for (int row = 0; row < labels.Length; ++row)
{
if (row < labels.Length - 1)
{
labels[row].Visible = false;
textboxes[row].Visible = false;
}
else
{
labels[row].Top = padding;
labels[row].Left = padding;
textboxes[row].Top = padding;
textboxes[row].Left = maxLabelWidth + 2 * padding;
}
}
Main.Instance.Move -= FormGeometryChanged;
Resize -= FormGeometryChanged;
}
var botTB = textboxes[rowCount - 1];
ExpandButton.Left = botTB.Left + botTB.Width;
ExpandButton.Top = botTB.Top;
ExpandButton.Height = botTB.Height;
ExpandButton.Width = botTB.Height;
}

private void FormGeometryChanged(object sender, EventArgs e)
{
SearchDetails.Location = PointToScreen(new Point(
FilterCombinedTextBox.Left,
FilterCombinedTextBox.Top + FilterCombinedTextBox.Height - 1
));
// Fit dropdown from left edge of text box to right edge of button
SearchDetails.Width = Math.Max(200,
ExpandButton.Left + ExpandButton.Width
- FilterCombinedTextBox.Left);
}

private void FilterCombinedTextBox_TextChanged(object sender, EventArgs e)
Expand All @@ -145,14 +107,14 @@ private void FilterCombinedTextBox_TextChanged(object sender, EventArgs e)
{
currentSearch = ModSearch.Parse(FilterCombinedTextBox.Text);
suppressSearch = true;
FilterByNameTextBox.Text = currentSearch?.Name ?? "";
FilterByAuthorTextBox.Text = currentSearch?.Author ?? "";
FilterByDescriptionTextBox.Text = currentSearch?.Description ?? "";
FilterByLanguageTextBox.Text = currentSearch?.Localization ?? "";
FilterByDependsTextBox.Text = currentSearch?.DependsOn ?? "";
FilterByRecommendsTextBox.Text = currentSearch?.Recommends ?? "";
FilterBySuggestsTextBox.Text = currentSearch?.Suggests ?? "";
FilterByConflictsTextBox.Text = currentSearch?.ConflictsWith ?? "";
SearchDetails.FilterByNameTextBox.Text = currentSearch?.Name ?? "";
SearchDetails.FilterByAuthorTextBox.Text = currentSearch?.Author ?? "";
SearchDetails.FilterByDescriptionTextBox.Text = currentSearch?.Description ?? "";
SearchDetails.FilterByLanguageTextBox.Text = currentSearch?.Localization ?? "";
SearchDetails.FilterByDependsTextBox.Text = currentSearch?.DependsOn ?? "";
SearchDetails.FilterByRecommendsTextBox.Text = currentSearch?.Recommends ?? "";
SearchDetails.FilterByConflictsTextBox.Text = currentSearch?.ConflictsWith ?? "";
SearchDetails.FilterBySuggestsTextBox.Text = currentSearch?.Suggests ?? "";
suppressSearch = false;
TriggerSearchOrTimer();
}
Expand All @@ -162,25 +124,45 @@ private void FilterCombinedTextBox_TextChanged(object sender, EventArgs e)
}
}

private void FilterTextBox_TextChanged(object sender, EventArgs e)
private void SearchDetails_ApplySearch(bool immediately)
{
if (suppressSearch)
return;

currentSearch = new ModSearch(
FilterByNameTextBox.Text,
FilterByAuthorTextBox.Text,
FilterByDescriptionTextBox.Text,
FilterByLanguageTextBox.Text,
FilterByDependsTextBox.Text,
FilterByRecommendsTextBox.Text,
FilterBySuggestsTextBox.Text,
FilterByConflictsTextBox.Text
SearchDetails.FilterByNameTextBox.Text,
SearchDetails.FilterByAuthorTextBox.Text,
SearchDetails.FilterByDescriptionTextBox.Text,
SearchDetails.FilterByLanguageTextBox.Text,
SearchDetails.FilterByDependsTextBox.Text,
SearchDetails.FilterByRecommendsTextBox.Text,
SearchDetails.FilterBySuggestsTextBox.Text,
SearchDetails.FilterByConflictsTextBox.Text
);
suppressSearch = true;
FilterCombinedTextBox.Text = currentSearch?.Combined ?? "";
suppressSearch = false;
TriggerSearchOrTimer();
if (immediately)
{
TriggerSearch();
}
else
{
TriggerSearchOrTimer();
}
}

private void SearchDetails_SurrenderFocus()
{
if (SurrenderFocus != null)
{
SurrenderFocus();
}
}

protected override void OnLeave(EventArgs e)
{
ExpandButton.Checked = false;
}

private void FilterTextBox_KeyDown(object sender, KeyEventArgs e)
Expand Down
8 changes: 0 additions & 8 deletions GUI/Controls/EditModSearch.resx
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,4 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="FilterCombinedLabel.Text" xml:space="preserve"><value>Search:</value></data>
<data name="FilterByNameLabel.Text" xml:space="preserve"><value>Name:</value></data>
<data name="FilterByAuthorLabel.Text" xml:space="preserve"><value>Author:</value></data>
<data name="FilterByDescriptionLabel.Text" xml:space="preserve"><value>Description:</value></data>
<data name="FilterByLanguageLabel.Text" xml:space="preserve"><value>Language:</value></data>
<data name="FilterByDependsLabel.Text" xml:space="preserve"><value>Depends on:</value></data>
<data name="FilterByRecommendsLabel.Text" xml:space="preserve"><value>Recommends:</value></data>
<data name="FilterBySuggestsLabel.Text" xml:space="preserve"><value>Suggests:</value></data>
<data name="FilterByConflictsLabel.Text" xml:space="preserve"><value>Conflicts with:</value></data>
</root>
Loading