Skip to content

Commit

Permalink
better references
Browse files Browse the repository at this point in the history
  • Loading branch information
factubsio committed Mar 18, 2023
1 parent 5750e5a commit 326c27f
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions BlueprintExplorer/BlueprintViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,29 @@ public BlueprintViewer()
{
references = new();
references.Columns.Add("ref", "References");
references.Columns.Add("typ", "Type");
references.Columns.Add("guid", "Guid");

references.Columns[0].Width = 800;
references.Columns[0].DataPropertyName = "References";
references.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

references.Columns[1].Width = 800;
references.Columns[1].DataPropertyName = "RefType";
references.Columns[1].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;

references.Columns[2].Width = 0;
references.Columns[2].DataPropertyName = "Guid";
references.Columns[2].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;


references.ReadOnly = true;
references.Cursor = Cursors.Arrow;

references.AutoGenerateColumns = false;

references.RowHeadersVisible = false;
references.ColumnHeadersVisible = false;
references.ColumnHeadersVisible = true;
references.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
references.MultiSelect = false;
references.AllowUserToResizeRows = false;
Expand All @@ -100,7 +111,7 @@ public BlueprintViewer()
kryptonSplitContainer1.Panel2Collapsed = !toggleReferencesVisible.Checked;
if (refShownFirstTime)
{
kryptonSplitContainer1.SplitterDistance = this.Width - 300;
kryptonSplitContainer1.SplitterDistance = this.Width - 500;
refShownFirstTime = false;

}
Expand Down Expand Up @@ -173,7 +184,7 @@ public BlueprintViewer()
BubbleTheme.DarkenStyles(references.DefaultCellStyle, references.ColumnHeadersDefaultCellStyle);
}

references.CellMouseClick += (sender, e) => ShowReferenceSelected(e.Button);
references.CellMouseClick += (sender, e) => ShowReferenceSelected(e.RowIndex, e.Button);
references.Cursor = Cursors.Arrow;

openExternal.Click += (sender, e) => OnOpenExternally?.Invoke(View.Blueprint as BlueprintHandle);
Expand Down Expand Up @@ -221,7 +232,11 @@ public void ShowBlueprint(BlueprintHandle handle, ShowFlags flags)
var me = Guid.Parse(handle.GuidText);
foreach (var reference in handle.BackReferences)
{
references.Rows.Add(BlueprintDB.Instance.Blueprints[reference].Name);
var bp = BlueprintDB.Instance.Blueprints[reference];
references.Rows.Add(bp.Name, bp.TypeName, bp.GuidText);
}
if (references.SortedColumn is not null) {
references.Sort(references.SortedColumn, ListSortDirection.Ascending);
}

if (flags.ClearHistory())
Expand Down Expand Up @@ -285,19 +300,20 @@ private void InvalidateHistory()
}
}

private void ShowReferenceSelected(MouseButtons button = MouseButtons.Left)
private void ShowReferenceSelected(int row, MouseButtons button = MouseButtons.Left)
{
var handle = View.Blueprint as BlueprintHandle;
if (handle == null) return;
if (View.Blueprint is not BlueprintHandle handle) return;
if (handle.BackReferences.Count != references.RowCount) return;
int row = references.SelectedRow();
Console.WriteLine(row);

if (row >= 0 && row < handle.BackReferences.Count)
{
var obj = references.Rows[row];
var guid = obj.Cells[2].Value as string;
bool tabbed = ModifierKeys.HasFlag(Keys.Control) || button == MouseButtons.Middle;
if (handle.BackReferences[row] != Guid.Parse(handle.GuidText))
if (guid != handle.GuidText)
{
BlueprintHandle bp = BlueprintDB.Instance.Blueprints[handle.BackReferences[row]];
BlueprintHandle bp = BlueprintDB.Instance.Blueprints[Guid.Parse(guid)];
if (tabbed)
{
OnLinkOpenNewTab?.Invoke(bp);
Expand Down

0 comments on commit 326c27f

Please sign in to comment.