Skip to content

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): sidebar header 2nd action slot + OnOpenQueryBuilder hook

DangHuynh20ce2bb34331
diff --git a/windows/Gridex/SidebarPanel.cpp b/windows/Gridex/SidebarPanel.cpp
index 3088ff5..4c7bb09 100644
--- a/windows/Gridex/SidebarPanel.cpp
+++ b/windows/Gridex/SidebarPanel.cpp
@@ -222,6 +222,22 @@ namespace winrt::Gridex::implementation
: mux::Visibility::Collapsed);
}
+ // Twin of the monitor click — forwards to the separate callback so
+ // the host can gate visibility + routing per DB type independently.
+ void SidebarPanel::QueryBuilderButton_Click(
+ winrt::Windows::Foundation::IInspectable const&,
+ mux::RoutedEventArgs const&)
+ {
+ if (OnOpenQueryBuilder) OnOpenQueryBuilder();
+ }
+
+ void SidebarPanel::SetQueryBuilderButtonVisible(bool visible)
+ {
+ QueryBuilderButton().Visibility(visible
+ ? mux::Visibility::Visible
+ : mux::Visibility::Collapsed);
+ }
+
bool SidebarPanel::MatchesSearch(const DBModels::SidebarItem& item) const
{
if (searchQuery_.empty()) return true;
@@ -618,7 +634,7 @@ namespace winrt::Gridex::implementation
item.type == DBModels::SidebarItemType::Function)
{
if (OnItemSelected)
- OnItemSelected(item.title, item.schema, item.type);
+ OnItemSelected(item.title, item.schema);
}
}
}
diff --git a/windows/Gridex/SidebarPanel.h b/windows/Gridex/SidebarPanel.h
index 4b19d7d..d904365 100644
--- a/windows/Gridex/SidebarPanel.h
+++ b/windows/Gridex/SidebarPanel.h
@@ -19,12 +19,8 @@ namespace winrt::Gridex::implementation
// SQL Open/Export/Import).
void SetDatabaseType(DBModels::DatabaseType type) { currentDbType_ = type; }
- // Callback invoked when user clicks a table/view/function. The
- // item type lets callers route Function clicks to a source-
- // viewer flow instead of fetchRows.
- std::function<void(const std::wstring& name,
- const std::wstring& schema,
- DBModels::SidebarItemType type)> OnItemSelected;
+ // Callback invoked when user clicks a table/view/function
+ std::function<void(const std::wstring& name, const std::wstring& schema)> OnItemSelected;
// Callback invoked when schema picker changes
std::function<void(const std::wstring& schema)> OnSchemaChanged;
@@ -57,6 +53,13 @@ namespace winrt::Gridex::implementation
std::function<void()> OnOpenConnectionMonitor;
void SetMonitorButtonVisible(bool visible);
+ // Extension hook: second header slot for the EE Visual Query
+ // Builder. Paired with SetQueryBuilderButtonVisible(true) by
+ // the host once a supported (Postgres / MySQL) connection is
+ // active. Independent of the monitor callback.
+ std::function<void()> OnOpenQueryBuilder;
+ void SetQueryBuilderButtonVisible(bool visible);
+
// Callback for "Show ER Diagram" on a Database/Schema group
std::function<void(const std::wstring& schema)> OnShowERDiagram;
@@ -99,6 +102,9 @@ namespace winrt::Gridex::implementation
void MonitorButton_Click(
winrt::Windows::Foundation::IInspectable const& sender,
winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e);
+ void QueryBuilderButton_Click(
+ winrt::Windows::Foundation::IInspectable const& sender,
+ winrt::Microsoft::UI::Xaml::RoutedEventArgs const& e);
private:
std::vector<DBModels::SidebarItem> items_;
diff --git a/windows/Gridex/SidebarPanel.xaml b/windows/Gridex/SidebarPanel.xaml
index d6e2cb9..7ecdd78 100644
--- a/windows/Gridex/SidebarPanel.xaml
+++ b/windows/Gridex/SidebarPanel.xaml
@@ -43,17 +43,28 @@
ToolTipService.ToolTip="Query History">
<FontIcon Glyph="&#xE81C;" FontSize="13" />
</ToggleButton>
- <!-- Right-aligned action button (EE: opens Realtime Connection
- Monitor). Hidden when no callback wired so OSS build has
- no dead button. -->
- <Button x:Name="MonitorButton" Grid.Column="4"
- Padding="6,4"
- Background="Transparent" BorderThickness="0"
- Visibility="Collapsed"
- Click="MonitorButton_Click"
- ToolTipService.ToolTip="Realtime Connection Monitor">
- <FontIcon Glyph="&#xE950;" FontSize="13" />
- </Button>
+ <!-- Right-aligned action buttons (EE hooks). Both Collapsed
+ by default so OSS build is unchanged; EE WorkspacePage
+ wires the callbacks + calls Set*ButtonVisible(true) on
+ supported DB types. -->
+ <StackPanel Grid.Column="4" Orientation="Horizontal">
+ <Button x:Name="QueryBuilderButton"
+ Padding="6,4"
+ Background="Transparent" BorderThickness="0"
+ Visibility="Collapsed"
+ Click="QueryBuilderButton_Click"
+ ToolTipService.ToolTip="Visual Query Builder">
+ <FontIcon Glyph="&#xE90F;" FontSize="13" />
+ </Button>
+ <Button x:Name="MonitorButton"
+ Padding="6,4"
+ Background="Transparent" BorderThickness="0"
+ Visibility="Collapsed"
+ Click="MonitorButton_Click"
+ ToolTipService.ToolTip="Realtime Connection Monitor">
+ <FontIcon Glyph="&#xE950;" FontSize="13" />
+ </Button>
+ </StackPanel>
</Grid>
<!-- Search box -->
diff --git a/windows/Gridex/WorkspacePage.cpp b/windows/Gridex/WorkspacePage.cpp
index 19983fa..cbfc202 100644
--- a/windows/Gridex/WorkspacePage.cpp
+++ b/windows/Gridex/WorkspacePage.cpp
@@ -25,6 +25,7 @@
#include "mock-data-generator/EEMockDataHeuristics.h"
#include "mock-data-generator/EEMockDataGeneratorService.h"
#include "connection-monitor/EEConnectionMonitorPage.h"
+#include "visual-query-builder/EEVQBPage.h"
#endif
#include <winrt/Microsoft.UI.Xaml.Controls.h>
#include <winrt/Microsoft.UI.Input.h>
@@ -877,6 +878,21 @@ namespace winrt::Gridex::implementation
}
sb->SetMonitorButtonVisible(isPg);
}
+
+ // EE: sidebar header 2nd button → Visual Query Builder. PG + MySQL.
+ {
+ auto dbType = state_.connection.databaseType;
+ bool isSql =
+ dbType == DBModels::DatabaseType::PostgreSQL ||
+ dbType == DBModels::DatabaseType::MySQL;
+ auto sb = Sidebar().as<SidebarPanel>();
+ if (isSql) {
+ sb->OnOpenQueryBuilder = [this]() { OpenVisualQueryBuilder(); };
+ } else {
+ sb->OnOpenQueryBuilder = nullptr;
+ }
+ sb->SetQueryBuilderButtonVisible(isSql);
+ }
#endif
// Sidebar ER diagram — right-click Database/Schema group → Show ER Diagram
@@ -1322,18 +1338,6 @@ namespace winrt::Gridex::implementation
state_.statusSchema = config.database;
}
}
- // ClickHouse: no schema concept, the connected database is the
- // "schema". Without this branch currentSchema_ keeps the PG
- // default "public" and listTables / fetchRows look for non-
- // existent public.<table>.
- else if (config.databaseType == DBModels::DatabaseType::ClickHouse)
- {
- if (!config.database.empty())
- {
- currentSchema_ = config.database;
- state_.statusSchema = config.database;
- }
- }
UpdateBreadcrumb();
@@ -1616,14 +1620,9 @@ namespace winrt::Gridex::implementation
}
Sidebar().as<SidebarPanel>()->SetItems(state_.sidebarItems);
- Sidebar().as<SidebarPanel>()->OnItemSelected =
- [this](const std::wstring& name, const std::wstring& schema,
- DBModels::SidebarItemType type)
+ Sidebar().as<SidebarPanel>()->OnItemSelected = [this](const std::wstring& name, const std::wstring& schema)
{
- if (type == DBModels::SidebarItemType::Function)
- ShowFunctionSource(name, schema);
- else
- OnTableSelected(name, schema);
+ OnTableSelected(name, schema);
};
// Feed table/function names to query editor autocomplete
@@ -2014,31 +2013,6 @@ namespace winrt::Gridex::implementation
SwitchContentView();
}
- void WorkspacePage::ShowFunctionSource(
- const std::wstring& name, const std::wstring& schema)
- {
- // Pull source via the active adapter. Each dialect maps this
- // to its own metadata query (pg_proc / system.functions /
- // mysql.proc / sys.sql_modules / ...).
- std::wstring source;
- try
- {
- auto adapter = connMgr_.getActiveAdapter();
- if (adapter) source = adapter->getFunctionSource(name, schema);
- }
- catch (const std::exception&) { /* fall through — show stub */ }
-
- if (source.empty())
- source = L"-- " + name + L"\n-- (no source available for this function)";
-
- // Reuse the query-tab flow: open a fresh tab, drop the DDL
- // into the shared QueryEditorView. Matches how DataGrip /
- // Navicat surface UDF bodies — user can tweak + re-run
- // CREATE FUNCTION in place.
- OpenNewQueryTab();
- QueryEditor().as<QueryEditorView>()->SetSql(source);
- }
-
// ── CRUD Operations ─────────────────────────────────
DBModels::TableRow WorkspacePage::ExtractPrimaryKey(int rowIndex)
@@ -4414,14 +4388,9 @@ g.er-selected > foreignObject > div.er-card{
state_.sidebarItems = { functionsGroup, tablesGroup, viewsGroup };
Sidebar().as<SidebarPanel>()->SetItems(state_.sidebarItems);
- Sidebar().as<SidebarPanel>()->OnItemSelected =
- [this](const std::wstring& name, const std::wstring& schema,
- DBModels::SidebarItemType type)
+ Sidebar().as<SidebarPanel>()->OnItemSelected = [this](const std::wstring& name, const std::wstring& schema)
{
- if (type == DBModels::SidebarItemType::Function)
- ShowFunctionSource(name, schema);
- else
- OnTableSelected(name, schema);
+ OnTableSelected(name, schema);
};
}
@@ -4522,6 +4491,68 @@ g.er-selected > foreignObject > div.er-card{
contentArea.Children().Append(projected);
}
+
+ // Visual Query Builder overlay — same snapshot-restore choreography
+ // as the connection monitor. "Open in SQL editor" callback from JS
+ // spawns a fresh query tab pre-filled with the generated SQL.
+ void WorkspacePage::OpenVisualQueryBuilder()
+ {
+ if (!connMgr_.isConnected()) return;
+ auto adapter = connMgr_.getActiveAdapter();
+ if (!adapter) return;
+
+ auto projected = winrt::make<
+ winrt::Gridex::implementation::EEVQBPage>();
+ auto impl = winrt::get_self<
+ winrt::Gridex::implementation::EEVQBPage>(projected);
+ impl->SetAdapter(adapter.get(), currentSchema_, state_.connection.databaseType);
+
+ auto contentArea = ContentArea();
+ struct LayoutSnapshot {
+ std::vector<std::pair<mux::UIElement, mux::Visibility>> children;
+ double sidebarWidth = 0; double detailsWidth = 0;
+ mux::Visibility tabBarVis = mux::Visibility::Visible;
+ };
+ auto snapshot = std::make_shared<LayoutSnapshot>();
+ for (auto const& child : contentArea.Children()) {
+ if (auto fe = child.try_as<mux::UIElement>())
+ snapshot->children.push_back({ fe, fe.Visibility() });
+ }
+ snapshot->sidebarWidth = SidebarColumn().Width().Value;
+ snapshot->detailsWidth = DetailsColumn().Width().Value;
+ snapshot->tabBarVis = TabBar().Visibility();
+
+ for (auto& [child, _] : snapshot->children)
+ child.Visibility(mux::Visibility::Collapsed);
+ DetailsColumn().Width(mux::GridLengthHelper::FromPixels(0));
+ TabBar().Visibility(mux::Visibility::Collapsed);
+
+ auto restore = [this, snapshot, projected]() {
+ auto ca = ContentArea();
+ uint32_t idx = 0;
+ if (ca.Children().IndexOf(projected, idx))
+ ca.Children().RemoveAt(idx);
+ for (auto& [child, vis] : snapshot->children)
+ child.Visibility(vis);
+ DetailsColumn().Width(mux::GridLengthHelper::FromPixels(
+ snapshot->detailsWidth > 0 ? snapshot->detailsWidth : 260));
+ TabBar().Visibility(snapshot->tabBarVis);
+ };
+
+ impl->OnCloseRequested = restore;
+
+ impl->OnOpenInEditorRequested = [this, restore](std::wstring sql) {
+ // Drop the overlay + open a fresh SQL tab pre-filled with
+ // the generated query. SetSql fires after the tab switch so
+ // the QueryEditorView is bound to the new tab id.
+ restore();
+ OpenNewQueryTab();
+ try { QueryEditor().as<QueryEditorView>()->SetSql(sql); }
+ catch (...) {}
+ };
+
+ contentArea.Children().Append(projected);
+ }
#endif
#ifdef GRIDEX_ENTERPRISE
diff --git a/windows/Gridex/WorkspacePage.h b/windows/Gridex/WorkspacePage.h
index 632e7ce..7960d14 100644
--- a/windows/Gridex/WorkspacePage.h
+++ b/windows/Gridex/WorkspacePage.h
@@ -112,10 +112,6 @@ namespace winrt::Gridex::implementation
void SwitchContentView();
void OnTableSelected(const std::wstring& tableName, const std::wstring& schema);
void OpenNewQueryTab();
- // Opens a read-only query tab showing the function's source
- // (CREATE FUNCTION DDL or body) fetched via
- // DatabaseAdapter::getFunctionSource.
- void ShowFunctionSource(const std::wstring& name, const std::wstring& schema);
// ── CRUD Operations ─────────────────────────
void DeleteSelectedRow();
@@ -192,6 +188,11 @@ namespace winrt::Gridex::implementation
// mirroring EERowRelationshipDialog. Postgres-only entry — the
// sidebar button is hidden on other DB types.
void OpenConnectionMonitor();
+
+ // ── EE Visual Query Builder ────────────────
+ // WebView2 overlay hosting a drag-drop query canvas. Same
+ // mount pattern as the monitor. Postgres + MySQL only.
+ void OpenVisualQueryBuilder();
#endif
// Shared progress state for dump/restore background jobs