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

Several improvements #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Archive data grid: right click to select the cell;
Added archive data grid's context menu;
Archive delete confirmation dialog added;
  • Loading branch information
PavelKn committed Apr 12, 2019
commit c67116ba4c4d0fc33fc548548d3bbe3ffe78d7c6
107 changes: 72 additions & 35 deletions src/MainForm.Designer.cs

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

61 changes: 60 additions & 1 deletion src/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
// with HostsFileEditor. If not, see http:https://www.gnu.org/licenses/.
// </copyright>

using System.Drawing;

namespace HostsFileEditor
{
using System;
Expand Down Expand Up @@ -878,12 +880,31 @@ private void OnRedoClick(object sender, EventArgs e)
/// <param name="e">The <see cref="System.EventArgs"/> instance
/// containing the event data.</param>
private void OnArchiveDeleteClick(object sender, EventArgs e)
{
SelectedArchiveDelete();
}

/// <summary>
/// Delete the selected archive
/// </summary>
private void SelectedArchiveDelete()
{
HostsArchive archive = this.dataGridViewArchive.CurrentHostsArchive;

if (archive != null)
{
HostsArchiveList.Instance.Delete(archive);
DialogResult result = MessageBox.Show(
this,
string.Format(Resources.ArchiveDeleteQuestion, archive.FileName),
Resources.ArchiveDeleteDialogCaption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1);

if (result == DialogResult.Yes)
{
HostsArchiveList.Instance.Delete(archive);
}
}
}

Expand All @@ -894,6 +915,14 @@ private void OnArchiveDeleteClick(object sender, EventArgs e)
/// <param name="e">The <see cref="System.EventArgs"/> instance
/// containing the event data.</param>
private void OnArchiveLoadClick(object sender, EventArgs e)
{
SelectedArchiveLoad();
}

/// <summary>
/// Load the selected archive
/// </summary>
private void SelectedArchiveLoad()
{
HostsArchive archive = this.dataGridViewArchive.CurrentHostsArchive;

Expand Down Expand Up @@ -1085,5 +1114,35 @@ private void OnOpenTextEditorClick(object sender, EventArgs e)
}

#endregion

private void dataGridViewArchive_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
dataGridViewArchive.CurrentCell = dataGridViewArchive.Rows[e.RowIndex].Cells[e.ColumnIndex];
// Can leave these here - doesn't hurt
dataGridViewArchive.Rows[e.RowIndex].Selected = true;
dataGridViewArchive.Focus();
}
}

private void dataGridViewArchive_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
var relativeMousePosition = dataGridViewArchive.PointToClient(Cursor.Position);
contextMenuArchive.Show(dataGridViewArchive, relativeMousePosition);
}
}

private void toolStripMenuArchiveLoad_Click(object sender, EventArgs e)
{
SelectedArchiveLoad();
}

private void toolStripMenuArchiveDelete_Click(object sender, EventArgs e)
{
SelectedArchiveDelete();
}
}
}
Loading