Skip to content

Commit

Permalink
Added option to copy URL to record
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkMpn committed Nov 22, 2023
1 parent 8077808 commit 79462c3
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
13 changes: 12 additions & 1 deletion MarkMpn.Sql4Cds.XTB/SqlQueryControl.Designer.cs

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

33 changes: 30 additions & 3 deletions MarkMpn.Sql4Cds.XTB/SqlQueryControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1378,13 +1378,25 @@ private int BorderThickness(DataGridViewAdvancedCellBorderStyle style)
}
}

private string GetRecordUrl(SqlEntityReference entityReference, out XtbDataSource dataSource)
{
dataSource = null;

if (!DataSources.TryGetValue(entityReference.DataSource, out var ds))
return null;

dataSource = (XtbDataSource)ds;
return dataSource.ConnectionDetail.GetEntityReferenceUrl(entityReference);
}

private void OpenRecord(SqlEntityReference entityReference)
{
if (!DataSources.TryGetValue(entityReference.DataSource, out var dataSource))
var url = GetRecordUrl(entityReference, out var dataSource);

if (url == null)
return;

var url = ((XtbDataSource) dataSource).ConnectionDetail.GetEntityReferenceUrl(entityReference);
((XtbDataSource)dataSource).ConnectionDetail.OpenUrlWithBrowserProfile(new Uri(url));
dataSource.ConnectionDetail.OpenUrlWithBrowserProfile(new Uri(url));
}

private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
Expand Down Expand Up @@ -1514,11 +1526,13 @@ private void gridContextMenuStrip_Opening(object sender, CancelEventArgs e)
var grid = (DataGridView)gridContextMenuStrip.SourceControl;

openRecordToolStripMenuItem.Enabled = false;
copyRecordUrlToolStripMenuItem.Enabled = false;
createSELECTStatementToolStripMenuItem.Enabled = false;

if (grid.CurrentCell?.Value is SqlEntityReference er && !er.IsNull)
{
openRecordToolStripMenuItem.Enabled = true;
copyRecordUrlToolStripMenuItem.Enabled = true;
createSELECTStatementToolStripMenuItem.Enabled = true;
}

Expand All @@ -1533,6 +1547,19 @@ private void openRecordToolStripMenuItem_Click(object sender, EventArgs e)
OpenRecord(er);
}

private void copyRecordUrlToolStripMenuItem_Click(object sender, EventArgs e)
{
var grid = (DataGridView)gridContextMenuStrip.SourceControl;

if (grid.CurrentCell?.Value is SqlEntityReference er && !er.IsNull)
{
var url = GetRecordUrl(er, out _);

if (url != null)
Clipboard.SetText(url);
}
}

private void createSELECTStatementToolStripMenuItem_Click(object sender, EventArgs e)
{
var grid = (DataGridView)gridContextMenuStrip.SourceControl;
Expand Down
2 changes: 1 addition & 1 deletion MarkMpn.Sql4Cds.XTB/SqlQueryControl.resx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAACM
CQAAAk1TRnQBSQFMAgEBAwEAAXABAAFwAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
CQAAAk1TRnQBSQFMAgEBAwEAAYABAAGAAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
Expand Down

0 comments on commit 79462c3

Please sign in to comment.