Skip to content

Commit

Permalink
#24 : Allow removing separators in Settings UI
Browse files Browse the repository at this point in the history
  • Loading branch information
clechasseur committed Jan 3, 2018
1 parent 4f76038 commit 393de88
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 31 deletions.
26 changes: 13 additions & 13 deletions PathCopyCopySettings/UI/Forms/MainForm.Designer.cs

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

64 changes: 49 additions & 15 deletions PathCopyCopySettings/UI/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,28 @@ private bool AreOnlyPipelinePluginsSelected()
return onlyPipeline;
}

/// <summary>
/// Determines if the selected plugins in the data grid are pipeline
/// or separator plugins.
/// </summary>
/// <returns><c>true</c> if all selected plugins are pipeline or
/// separator plugins.</returns>
/// <remarks>
/// If no plugin is selected, this method returns <c>true</c>.
/// </remarks>
private bool AreOnlyPipelineOrSeparatorPluginsSelected()
{
bool onlyPipelineOrSeparator = true;

for (int i = 0; onlyPipelineOrSeparator && i < PluginsDataGrid.SelectedRows.Count; ++i) {
DataGridViewRow row = PluginsDataGrid.SelectedRows[i];
Plugin rowPlugin = ((PluginDisplayInfo) row.DataBoundItem).Plugin;
onlyPipelineOrSeparator = (rowPlugin is PipelinePlugin) || (rowPlugin is SeparatorPlugin);
}

return onlyPipelineOrSeparator;
}

/// <summary>
/// Updates the state of buttons on the Commands page.
/// Call this when selection changes somewhere.
Expand All @@ -485,7 +507,7 @@ private void UpdatePluginButtons()
AddPipelinePluginBtn.Enabled = true;
AddSeparatorBtn.Enabled = true;
EditPipelinePluginBtn.Enabled = PluginsDataGrid.SelectedRows.Count == 1 && AreOnlyPipelinePluginsSelected();
RemovePipelinePluginBtn.Enabled = PluginsDataGrid.SelectedRows.Count == 1 && AreOnlyPipelinePluginsSelected();
RemovePluginBtn.Enabled = PluginsDataGrid.SelectedRows.Count == 1 && AreOnlyPipelineOrSeparatorPluginsSelected();

ExportPipelinePluginsBtn.Enabled = PluginsDataGrid.SelectedRows.Count > 0 && AreOnlyPipelinePluginsSelected();
ImportPipelinePluginsBtn.Enabled = true;
Expand Down Expand Up @@ -1048,25 +1070,37 @@ private void EditPipelinePluginBtn_Click(object sender, EventArgs e)

/// <summary>
/// Called when the Remove button is pressed. We remove
/// selected pipeline plugins.
/// selected plugins.
/// </summary>
/// <param name="sender">Event sender.</param>
/// <param name="e">Event arguments.</param>
private void RemovePipelinePluginBtn_Click(object sender, EventArgs e)
private void RemovePluginBtn_Click(object sender, EventArgs e)
{
Debug.Assert(PluginsDataGrid.SelectedRows.Count == 1);
Debug.Assert(PluginsDataGrid.SelectedRows.Count == 1);

// Check type of selected plugin.
DataGridViewRow row = PluginsDataGrid.SelectedRows[0];
int rowIndex = row.Index;
PluginDisplayInfo displayInfo = (PluginDisplayInfo) row.DataBoundItem;

if (displayInfo.Plugin is PipelinePlugin) {
// First confirm since this is an "irreversible" action. We have a string
// in resources for this message and it includes a format placeholder
// for the plugin description.
PipelinePluginInfo pluginInfo = ((PipelinePlugin) displayInfo.Plugin).Info;
DialogResult res = MessageBox.Show(this, String.Format(Resources.REMOVE_PIPELINE_PLUGIN_MESSAGE, pluginInfo.Description),
Resources.REMOVE_PIPELINE_PLUGIN_TITLE, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (res == DialogResult.OK) {
// Remove plugin from data grid.
pluginDisplayInfos.RemoveAt(rowIndex);

// All this will enable the "Apply" button.
ApplyBtn.Enabled = true;
}
} else {
Debug.Assert(displayInfo.Plugin is SeparatorPlugin);

// First confirm since this is an "irreversible" action. We have a string
// in resources for this message and it includes a format placeholder
// for the plugin description.
DataGridViewRow row = PluginsDataGrid.SelectedRows[0];
int rowIndex = row.Index;
PluginDisplayInfo displayInfo = (PluginDisplayInfo) row.DataBoundItem;
PipelinePluginInfo pluginInfo = ((PipelinePlugin) displayInfo.Plugin).Info;
DialogResult res = MessageBox.Show(this, String.Format(Resources.REMOVE_PIPELINE_PLUGIN_MESSAGE, pluginInfo.Description),
Resources.REMOVE_PIPELINE_PLUGIN_TITLE, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (res == DialogResult.OK) {
// Remove plugin from data grid.
// No need to confirm removing separator plugins, since it's reversible.
pluginDisplayInfos.RemoveAt(rowIndex);

// All this will enable the "Apply" button.
Expand Down
6 changes: 3 additions & 3 deletions PathCopyCopySettings/UI/Forms/MainForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@
<metadata name="MainToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>769, 18</value>
</metadata>
<metadata name="MainToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>769, 18</value>
</metadata>
<metadata name="IconCol.UserAddedColumn" type="System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
Expand Down Expand Up @@ -156,7 +159,4 @@
<metadata name="ExportUserSettingsSaveDlg.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>583, 18</value>
</metadata>
<metadata name="MainToolTip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>769, 18</value>
</metadata>
</root>

0 comments on commit 393de88

Please sign in to comment.