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(editor): Duplicate Row button next to +Row

DangHuynh2d86c35f9a78
diff --git a/windows/Gridex/WorkspacePage.cpp b/windows/Gridex/WorkspacePage.cpp
index f167042..47f875b 100644
--- a/windows/Gridex/WorkspacePage.cpp
+++ b/windows/Gridex/WorkspacePage.cpp
@@ -168,12 +168,18 @@ namespace winrt::Gridex::implementation
// DataGrid callbacks
DataGrid().as<DataGridView>()->OnRowSelected = [this](int rowIndex)
{
- if (rowIndex >= 0 && rowIndex < static_cast<int>(state_.currentData.rows.size()))
+ const bool valid = rowIndex >= 0
+ && rowIndex < static_cast<int>(state_.currentData.rows.size());
+ if (valid)
{
Details().as<DetailsPanel>()->ShowRow(
state_.currentData.columnNames,
state_.currentData.rows[rowIndex]);
}
+ // Duplicate only makes sense when a row is selected; toggling
+ // the button here keeps the enable state in sync with grid
+ // selection without a separate subscription.
+ DuplicateRowBtn().IsEnabled(valid);
};
// Delete key on grid → same as Delete toolbar button (mark row
@@ -1043,6 +1049,9 @@ namespace winrt::Gridex::implementation
AddRowBtn().Click([this](winrt::Windows::Foundation::IInspectable const&, mux::RoutedEventArgs const&)
{ AddNewRow(); });
+ DuplicateRowBtn().Click([this](winrt::Windows::Foundation::IInspectable const&, mux::RoutedEventArgs const&)
+ { DuplicateSelectedRow(); });
+
PrevPageBtn().Click([this](winrt::Windows::Foundation::IInspectable const&, mux::RoutedEventArgs const&)
{ PrevPage(); });
@@ -2091,6 +2100,52 @@ namespace winrt::Gridex::implementation
UpdatePendingUI();
}
+ // Clone the currently-selected grid row as a pending INSERT so the
+ // user can tweak a couple fields (e.g. unique name) before commit.
+ // Mirrors AddNewRow for skipped columns — IDENTITY, SQL-expression
+ // PK defaults, and expression defaults like now()/nextval() stay
+ // server-generated so the copy doesn't collide with the source.
+ void WorkspacePage::DuplicateSelectedRow()
+ {
+ if (state_.currentColumns.empty()) return;
+ auto* sel = DataGrid().as<DataGridView>()->GetSelectedRow();
+ if (!sel) return;
+
+ DBModels::TableRow newRow;
+ for (auto& col : state_.currentColumns)
+ {
+ if (col.comment == L"IDENTITY") continue;
+ if (col.isPrimaryKey && IsSqlExpression(col.defaultValue)) continue;
+ if (IsSqlExpression(col.defaultValue)) continue;
+
+ auto it = sel->find(col.name);
+ if (it != sel->end())
+ newRow[col.name] = it->second; // copy source value as-is (incl. NULL sentinel)
+ else if (!col.defaultValue.empty() && col.defaultValue != L"NULL")
+ newRow[col.name] = col.defaultValue;
+ else if (col.nullable)
+ newRow[col.name] = L"NULL";
+ else
+ newRow[col.name] = L"";
+ }
+
+ // Display row carries the auto-gen placeholders (e.g.
+ // "gen_random_uuid()") for skipped columns so the new grid row
+ // visually matches a fresh insert.
+ DBModels::TableRow displayRow = newRow;
+ for (auto& col : state_.currentColumns)
+ {
+ if (displayRow.find(col.name) == displayRow.end())
+ displayRow[col.name] = col.defaultValue;
+ }
+
+ state_.currentData.rows.push_back(displayRow);
+ int newRowIndex = static_cast<int>(state_.currentData.rows.size()) - 1;
+ changeTracker_.trackInsert(newRow, newRowIndex);
+ DataGrid().as<DataGridView>()->SetData(state_.currentData);
+ UpdatePendingUI();
+ }
+
void WorkspacePage::CommitChanges()
{
// Flush any in-flight inline cell edit before reading the
diff --git a/windows/Gridex/WorkspacePage.h b/windows/Gridex/WorkspacePage.h
index e72dfee..567f056 100644
--- a/windows/Gridex/WorkspacePage.h
+++ b/windows/Gridex/WorkspacePage.h
@@ -116,6 +116,7 @@ namespace winrt::Gridex::implementation
// ── CRUD Operations ─────────────────────────
void DeleteSelectedRow();
void AddNewRow();
+ void DuplicateSelectedRow();
void CommitChanges();
void DiscardChanges();
DBModels::TableRow ExtractPrimaryKey(int rowIndex);
diff --git a/windows/Gridex/WorkspacePage.xaml b/windows/Gridex/WorkspacePage.xaml
index e17a586..93f77c4 100644
--- a/windows/Gridex/WorkspacePage.xaml
+++ b/windows/Gridex/WorkspacePage.xaml
@@ -333,16 +333,29 @@
Padding="10,4" />
</StackPanel>
- <!-- + Row Button -->
- <Button x:Name="AddRowBtn" Grid.Column="1" Margin="8,0,0,0"
- Padding="6,4"
- Background="Transparent" BorderThickness="0"
- ToolTipService.ToolTip="Add Row">
- <StackPanel Orientation="Horizontal" Spacing="4">
- <FontIcon Glyph="&#xE710;" FontSize="10" />
- <TextBlock Text="Row" FontSize="11" />
- </StackPanel>
- </Button>
+ <!-- + Row / Duplicate Row Buttons -->
+ <StackPanel Grid.Column="1" Orientation="Horizontal"
+ Spacing="2" Margin="8,0,0,0">
+ <Button x:Name="AddRowBtn"
+ Padding="6,4"
+ Background="Transparent" BorderThickness="0"
+ ToolTipService.ToolTip="Add Row">
+ <StackPanel Orientation="Horizontal" Spacing="4">
+ <FontIcon Glyph="&#xE710;" FontSize="10" />
+ <TextBlock Text="Row" FontSize="11" />
+ </StackPanel>
+ </Button>
+ <Button x:Name="DuplicateRowBtn"
+ Padding="6,4"
+ Background="Transparent" BorderThickness="0"
+ IsEnabled="False"
+ ToolTipService.ToolTip="Duplicate selected row (pending — edit before commit)">
+ <StackPanel Orientation="Horizontal" Spacing="4">
+ <FontIcon Glyph="&#xE8C8;" FontSize="10" />
+ <TextBlock Text="Duplicate" FontSize="11" />
+ </StackPanel>
+ </Button>
+ </StackPanel>
<!-- Pagination -->
<StackPanel Grid.Column="3" Orientation="Horizontal" Spacing="4"