A native macOS / windows / Linux database IDE built with Swift and AppKit. Connect to PostgreSQL, MySQL, SQLite, and Redis from a single app with a fast, keyboard-driven interface.
C++
feat(windows): column header metadata — PK/FK icons, tooltip, nullable italic
DangHuynhc99083371401
diff --git a/windows/Gridex/DataGridView.cpp b/windows/Gridex/DataGridView.cppindex ba2ccd0..d17112d 100644--- a/windows/Gridex/DataGridView.cpp+++ b/windows/Gridex/DataGridView.cpp@@ -139,6 +139,15 @@ namespace winrt::Gridex::implementation});}+ void DataGridView::SetColumnMetadata(const std::vector<DBModels::ColumnInfo>& meta)+ {+ columnMetadata_ = meta;+ // Re-render headers only if we already have data laid out;+ // otherwise the next SetData call will pick up the metadata.+ if (!data_.columnNames.empty())+ BuildHeaders();+ }+void DataGridView::SetData(const DBModels::QueryResult& result){data_ = result;@@ -264,43 +273,96 @@ namespace winrt::Gridex::implementationheaderBtn.BorderThickness(mux::Thickness{ 0, 0, 0, 0 });muxc::Grid::SetColumn(headerBtn, 0);- // Header content layout: Grid with [auto icon] [* label] [auto sort].- // Star column on the label means it auto-stretches to whatever- // space is left after the icons — when the user resizes the- // outer cellGrid, the label's available width tracks live via- // layout pass, no manual MaxWidth bookkeeping needed.+ // Look up optional metadata (PK / FK / nullable / full type+ // string) by column name. Header falls back gracefully if+ // SetColumnMetadata was never called (e.g., ad-hoc query view).+ const DBModels::ColumnInfo* meta = nullptr;+ for (const auto& m : columnMetadata_)+ {+ if (m.name == colName) { meta = &m; break; }+ }++ // Resolve type string: prefer metadata (has length info like+ // varchar(255)), else QueryResult.columnTypes.+ std::wstring colType;+ if (meta && !meta->dataType.empty()) colType = meta->dataType;+ else if (ci < data_.columnTypes.size()) colType = data_.columnTypes[ci];++ // Header content layout: Grid with [auto PK] [auto FK] [* label]+ // [auto sort]. Star column on the label lets it auto-stretch to+ // whatever space is left after the icons — when the user resizes+ // the outer cellGrid, the label's available width tracks live+ // via layout pass, no manual MaxWidth bookkeeping needed.muxc::Grid headerContent;{- muxc::ColumnDefinition iconCol, labelCol, sortCol;- iconCol.Width(mux::GridLength{ 0.0, mux::GridUnitType::Auto });+ muxc::ColumnDefinition pkCol, fkCol, labelCol, sortCol;+ pkCol.Width(mux::GridLength{ 0.0, mux::GridUnitType::Auto });+ fkCol.Width(mux::GridLength{ 0.0, mux::GridUnitType::Auto });labelCol.Width(mux::GridLength{ 1.0, mux::GridUnitType::Star });sortCol.Width(mux::GridLength{ 0.0, mux::GridUnitType::Auto });- headerContent.ColumnDefinitions().Append(iconCol);+ headerContent.ColumnDefinitions().Append(pkCol);+ headerContent.ColumnDefinitions().Append(fkCol);headerContent.ColumnDefinitions().Append(labelCol);headerContent.ColumnDefinitions().Append(sortCol);}- // Column type icon at column 0- std::wstring colType;- if (ci < data_.columnTypes.size()) colType = data_.columnTypes[ci];- muxc::FontIcon typeIcon;- typeIcon.FontSize(10.0);- typeIcon.Opacity(0.4);- typeIcon.Margin(mux::Thickness{ 0.0, 0.0, 4.0, 0.0 });- if (colType.find(L"int") != std::wstring::npos || colType.find(L"numeric") != std::wstring::npos)- typeIcon.Glyph(L"\xE8EF");- else if (colType.find(L"bool") != std::wstring::npos)- typeIcon.Glyph(L"\xE73E");- else if (colType.find(L"time") != std::wstring::npos || colType.find(L"date") != std::wstring::npos)- typeIcon.Glyph(L"\xE787");- else- typeIcon.Glyph(L"\xE8C1");- muxc::Grid::SetColumn(typeIcon, 0);- headerContent.Children().Append(typeIcon);+ // PK icon (key glyph) — gold-ish tint so it reads as a badge.+ if (meta && meta->isPrimaryKey)+ {+ muxc::FontIcon pkIcon;+ pkIcon.Glyph(L"\xE192");+ pkIcon.FontSize(10.0);+ pkIcon.Margin(mux::Thickness{ 0.0, 0.0, 4.0, 0.0 });+ pkIcon.Foreground(muxm::SolidColorBrush(+ winrt::Windows::UI::ColorHelper::FromArgb(255, 220, 170, 40)));+ muxc::ToolTip pkTip;+ pkTip.Content(winrt::box_value(winrt::hstring(L"Primary Key")));+ muxc::ToolTipService::SetToolTip(pkIcon, pkTip);+ muxc::Grid::SetColumn(pkIcon, 0);+ headerContent.Children().Append(pkIcon);+ }- // Label at column 1 — fills the star column. NO MaxWidth — the+ // FK icon (link glyph). Wrap in a button so the click jumps+ // to the referenced table — separate from header sort click.+ if (meta && meta->isForeignKey)+ {+ muxc::Button fkBtn;+ fkBtn.Padding(mux::Thickness{ 2.0, 0.0, 2.0, 0.0 });+ fkBtn.Margin(mux::Thickness{ 0.0, 0.0, 4.0, 0.0 });+ fkBtn.Background(muxm::SolidColorBrush(winrt::Windows::UI::Colors::Transparent()));+ fkBtn.BorderThickness(mux::Thickness{ 0, 0, 0, 0 });+ fkBtn.MinWidth(0.0);+ fkBtn.MinHeight(0.0);+ muxc::FontIcon fkIcon;+ fkIcon.Glyph(L"\xE71B");+ fkIcon.FontSize(10.0);+ fkIcon.Foreground(muxm::SolidColorBrush(+ winrt::Windows::UI::ColorHelper::FromArgb(255, 88, 166, 255)));+ fkBtn.Content(fkIcon);++ std::wstring refTable = meta->fkReferencedTable;+ std::wstring refColumn = meta->fkReferencedColumn;+ std::wstring fkTipText = L"Foreign Key → " + refTable;+ if (!refColumn.empty()) fkTipText += L"." + refColumn;+ fkTipText += L"\n(click to open referenced table)";+ muxc::ToolTip fkTip;+ fkTip.Content(winrt::box_value(winrt::hstring(fkTipText)));+ muxc::ToolTipService::SetToolTip(fkBtn, fkTip);++ fkBtn.Click([this, refTable](auto&&, auto&&)+ {+ if (OnForeignKeyClicked && !refTable.empty())+ OnForeignKeyClicked(refTable, L"");+ });+ muxc::Grid::SetColumn(fkBtn, 1);+ headerContent.Children().Append(fkBtn);+ }++ // Label at column 2 — fills the star column. NO MaxWidth — the// grid layout constrains it; trimming kicks in only when the- // column is actually narrower than the text.+ // column is actually narrower than the text. Nullable columns+ // render in italics so the distinction is obvious at a glance+ // without stealing extra header space for a separate indicator.muxc::TextBlock lbl;lbl.Text(winrt::hstring(colName));lbl.FontSize(11.0);@@ -308,10 +370,40 @@ namespace winrt::Gridex::implementationlbl.VerticalAlignment(mux::VerticalAlignment::Center);lbl.TextTrimming(mux::TextTrimming::CharacterEllipsis);lbl.TextWrapping(mux::TextWrapping::NoWrap);- muxc::Grid::SetColumn(lbl, 1);+ if (meta && meta->nullable)+ lbl.FontStyle(winrt::Windows::UI::Text::FontStyle::Italic);+ muxc::Grid::SetColumn(lbl, 2);headerContent.Children().Append(lbl);- // Sort indicator at column 2 (only if this column is the sort key)+ // Tooltip on the whole header button summarising every piece+ // of metadata we have — the spot users reach for when the+ // column's declared type or constraints are not obvious.+ {+ std::wstring tipText;+ if (!colType.empty()) tipText = colType;+ if (meta)+ {+ tipText += tipText.empty() ? L"" : L"\n";+ tipText += meta->nullable ? L"NULL" : L"NOT NULL";+ if (meta->isPrimaryKey) tipText += L"\nPRIMARY KEY";+ if (meta->isForeignKey)+ {+ tipText += L"\nFK → " + meta->fkReferencedTable;+ if (!meta->fkReferencedColumn.empty())+ tipText += L"." + meta->fkReferencedColumn;+ }+ if (!meta->defaultValue.empty())+ tipText += L"\nDEFAULT " + meta->defaultValue;+ }+ if (!tipText.empty())+ {+ muxc::ToolTip headerTip;+ headerTip.Content(winrt::box_value(winrt::hstring(tipText)));+ muxc::ToolTipService::SetToolTip(headerBtn, headerTip);+ }+ }++ // Sort indicator at column 3 (only if this column is the sort key)if (sortColumn_ == colName){muxc::FontIcon sortIcon;@@ -319,7 +411,7 @@ namespace winrt::Gridex::implementationsortIcon.Glyph(sortAscending_ ? L"\xE70E" : L"\xE70D");sortIcon.Opacity(0.7);sortIcon.Margin(mux::Thickness{ 4.0, 0.0, 0.0, 0.0 });- muxc::Grid::SetColumn(sortIcon, 2);+ muxc::Grid::SetColumn(sortIcon, 3);headerContent.Children().Append(sortIcon);}diff --git a/windows/Gridex/DataGridView.h b/windows/Gridex/DataGridView.hindex 4f26a4a..056f04e 100644--- a/windows/Gridex/DataGridView.h+++ b/windows/Gridex/DataGridView.h@@ -2,6 +2,7 @@#include "DataGridView.g.h"#include "Models/QueryResult.h"+#include "Models/ColumnInfo.h"#include <functional>namespace winrt::Gridex::implementation@@ -12,6 +13,13 @@ namespace winrt::Gridex::implementationvoid SetData(const DBModels::QueryResult& result);+ // Optional: feed full column metadata (PK / FK / nullable / full+ // dataType string) so the header can render PK / FK icons, a+ // tooltip with the declared type, and italicize nullable columns.+ // Safe to omit — SetData alone still works with types from+ // QueryResult.columnTypes but without PK/FK/nullable decoration.+ void SetColumnMetadata(const std::vector<DBModels::ColumnInfo>& meta);+// Put the grid in read-only mode (disables inline cell editing).// Used for adapters like Redis where the "table" is a key/value// projection and inline SQL-style edit does not map to a single@@ -37,6 +45,12 @@ namespace winrt::Gridex::implementation// host re-runs the current tab's query to pull fresh rows.std::function<void()> OnRefreshRequested;+ // Callback when user clicks an FK icon in a column header — host+ // navigates to the referenced table/schema. Arg schema may be+ // empty; host falls back to the current connection's default.+ std::function<void(const std::wstring& refTable,+ const std::wstring& refSchema)> OnForeignKeyClicked;+// Get selected row data for copyconst DBModels::TableRow* GetSelectedRow() const;@@ -59,6 +73,7 @@ namespace winrt::Gridex::implementationprivate:DBModels::QueryResult data_;+ std::vector<DBModels::ColumnInfo> columnMetadata_;int selectedRow_ = -1;std::wstring sortColumn_;bool sortAscending_ = true;diff --git a/windows/Gridex/WorkspacePage.cpp b/windows/Gridex/WorkspacePage.cppindex db8696a..9423883 100644--- a/windows/Gridex/WorkspacePage.cpp+++ b/windows/Gridex/WorkspacePage.cpp@@ -179,6 +179,16 @@ namespace winrt::Gridex::implementationReloadCurrentTable();};+ // FK icon click in a header → open the referenced table. Schema+ // arg is empty; reuse the current schema so cross-schema FKs in+ // pg still resolve against the active search path.+ DataGrid().as<DataGridView>()->OnForeignKeyClicked =+ [this](const std::wstring& refTable, const std::wstring&)+ {+ if (!refTable.empty())+ OnTableSelected(refTable, currentSchema_);+ };+// Wire structure view ALTER applyStructure().as<StructureView>()->OnApplyAlter = [this](const std::vector<std::wstring>& sqls){@@ -1489,6 +1499,8 @@ namespace winrt::Gridex::implementation// layer instead of lumped under a single number.auto renderStart = std::chrono::steady_clock::now();self->DataGrid().as<DataGridView>()->SetData(self->state_.currentData);+ self->DataGrid().as<DataGridView>()->SetColumnMetadata(+ self->state_.currentColumns);auto renderEnd = std::chrono::steady_clock::now();self->state_.statusRenderTimeMs =std::chrono::duration<double, std::milli>(renderEnd - renderStart).count();