Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ actions!(
SearchEverything,
CycleMode,
CloseTab,
CloseAllTabs,
ToggleSidebar,
ToggleResults,
ToggleRowPanel,
Expand Down
4 changes: 3 additions & 1 deletion src/keybindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use gpui_component::input::ShowCompletions;

use crate::{
actions::{
AcceptCompletion, AddFilter, ApplyEdits, CancelQuery, ClearFilter, CloseTab,
AcceptCompletion, AddFilter, ApplyEdits, CancelQuery, ClearFilter, CloseAllTabs, CloseTab,
CollapseAllSchemas, CommandPalette, ConfirmDialog, CopyCell, CopyDiagnostics, CopyPlan,
CopyResults, CopyRow, CopyRows, CopySelection, CycleMode, DeleteRow, DiagramFindNext,
DiagramFindPick, DiagramFindPrevious, DiagramFocusDown, DiagramFocusLeft,
Expand Down Expand Up @@ -165,6 +165,8 @@ registry! {
("new_connection", "New Connection", None, ["secondary-shift-n"], NewConnection),
("new_project", "New Project", None, [], NewProject),
("close_tab", "Close Tab", None, ["secondary-w"], CloseTab),
// Zed's chord for closing every item in a pane.
("close_all_tabs", "Close All Tabs", None, ["secondary-k w"], CloseAllTabs),
("refresh_relation", "Refresh Rows", None, ["secondary-r"], RefreshRelation),
("refresh_connection", "Refresh Schema", None, ["secondary-shift-r"], RefreshConnection),
("next_tab", "Next Tab", None, ["ctrl-tab"], NextTab),
Expand Down
11 changes: 6 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ use gpui_component::{
};

use actions::{
AddFilter, ApplyEdits, CancelQuery, ClearFilter, CloseTab, CollapseAllSchemas, CommandPalette,
CopyCell, CopyDiagnostics, CopyPlan, CopyResults, CopyRow, CopyRows, CopySelection,
CustomRowLimit, CycleMode, DeleteRow, DiscardEdits, Disconnect, EditCell, ExpandAllSchemas,
ExplainQuery, FollowForeignKey, FormatQuery, FuzzyOpen, GoToColumn, HideColumn,
ImportConnections, ImportRows, ImportRowsFromClipboard, LimitTarget,
AddFilter, ApplyEdits, CancelQuery, ClearFilter, CloseAllTabs, CloseTab, CollapseAllSchemas,
CommandPalette, CopyCell, CopyDiagnostics, CopyPlan, CopyResults, CopyRow, CopyRows,
CopySelection, CustomRowLimit, CycleMode, DeleteRow, DiscardEdits, Disconnect, EditCell,
ExpandAllSchemas, ExplainQuery, FollowForeignKey, FormatQuery, FuzzyOpen, GoToColumn,
HideColumn, ImportConnections, ImportRows, ImportRowsFromClipboard, LimitTarget,
MenuImportRowsFromClipboard, Minimize, MoveTabLeft, MoveTabRight, NewConnection, NewProject,
NewQuery, NewRow, NextEdit, NextPage, NextProfile, NextResult, NextTab, OpenLogsFolder,
OpenReference, OpenSettings, PreviousEdit, PreviousPage, PreviousProfile, PreviousResult,
Expand Down Expand Up @@ -396,6 +396,7 @@ pub(crate) fn app_menus(imports_rows: bool) -> Vec<Menu> {
MenuItem::action("Save Query", SaveQuery),
MenuItem::separator(),
MenuItem::action("Close Tab", CloseTab),
MenuItem::action("Close All Tabs", CloseAllTabs),
MenuItem::separator(),
MenuItem::action("Disconnect", Disconnect),
])
Expand Down
7 changes: 7 additions & 0 deletions src/palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ pub enum Command {
ImportRows,
ImportRowsFromClipboard,
CloseObject(u64),
CloseAllTabs,
/// Stage a `NULL`, the empty string or `DEFAULT` on the active cell. The
/// rows are how the gestures stop being folklore; the cell menu dispatches
/// the same actions.
Expand Down Expand Up @@ -4540,6 +4541,12 @@ fn command_items(workspace: &Workspace, profile: &Profile, cx: &App) -> Vec<Item
}
items.extend(appearance_items(overrides));
items.extend(workspace.update.iter().flat_map(update_items));
if !profile.session.strip_tabs().is_empty() {
items.push(bound(
command("Close all tabs", icon::CLOSE, Command::CloseAllTabs, TAB),
"close_all_tabs",
));
}
// One row rather than a Show/Hide pair: the palette is built from the
// session, which does not know whether the column is folded.
items.push(bound(
Expand Down
37 changes: 26 additions & 11 deletions src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1588,15 +1588,7 @@ impl Session {
pub(crate) fn grids(&self) -> impl Iterator<Item = &Entity<TableState<ResultGrid>>> {
self.queries
.iter()
.flat_map(|tab| {
std::iter::once(&tab.results)
.chain(tab.lent.iter().map(|(grid, _)| grid))
.chain(
tab.queue
.iter()
.flat_map(|queue| queue.done.iter().map(|finished| &finished.grid)),
)
})
.flat_map(QueryTab::grids)
.chain(self.objects.iter().filter_map(|tab| match &tab.body {
ObjectBody::Relation { results, .. } => Some(results),
ObjectBody::Routine(_)
Expand All @@ -1605,6 +1597,18 @@ impl Session {
}))
}

/// Every grid `tab` holds: a query tab's queue and lent results as well as
/// its own slot, any of which can carry staged edits.
pub(crate) fn grids_of(&self, tab: Tab) -> Vec<&Entity<TableState<ResultGrid>>> {
match tab {
Tab::Query(id) => self
.query_tab(id)
.map(|tab| tab.grids().collect())
.unwrap_or_default(),
Tab::Object(_) => self.results(tab).into_iter().collect(),
}
}

/// Where a run's state and rows belong. Returning both together is what
/// keeps a result from landing in one tab's grid with another tab's status.
pub(crate) fn slot(
Expand Down Expand Up @@ -1719,9 +1723,10 @@ pub(crate) enum PendingDelete {
}

/// A close held up by the unapplied-edits question, and the saved query to
/// delete once the tab goes, when deleting it is what closes the tab.
/// delete once the tab goes, when deleting it is what closes the tab. More
/// than one tab only when Close All Tabs found edits in several.
pub(crate) struct PendingDiscard {
pub(crate) tab: Tab,
pub(crate) tabs: Vec<Tab>,
pub(crate) deleting: Option<String>,
}

Expand Down Expand Up @@ -2728,6 +2733,16 @@ pub(crate) fn runs_at_once(engine: Engine, mode: Mode, statements: &[&str]) -> b
}

impl QueryTab {
fn grids(&self) -> impl Iterator<Item = &Entity<TableState<ResultGrid>>> {
std::iter::once(&self.results)
.chain(self.lent.iter().map(|(grid, _)| grid))
.chain(
self.queue
.iter()
.flat_map(|queue| queue.done.iter().map(|finished| &finished.grid)),
)
}

/// Whether the results pane offers Data and Plan to flip between.
pub(crate) fn flips_to_plan(&self) -> bool {
self.plan.as_ref().is_some_and(|plan| !plan.typed)
Expand Down
1 change: 1 addition & 0 deletions src/workspace/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,7 @@ impl Workspace {
self.import_rows_from_clipboard(&ImportRowsFromClipboard, window, cx)
}
Command::CloseObject(id) => self.ask_before_close(Tab::Object(id), window, cx),
Command::CloseAllTabs => self.close_all_tabs(&CloseAllTabs, window, cx),
Command::SetNull => self.set_null(&SetNull, window, cx),
Command::SetEmpty => self.set_empty(&SetEmpty, window, cx),
Command::SetDefault => self.set_default(&SetDefault, window, cx),
Expand Down
68 changes: 68 additions & 0 deletions src/workspace/e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,74 @@ fn the_move_tab_chords_reorder_the_strip(cx: &mut TestAppContext) {
});
}

#[gpui::test]
fn the_close_all_chord_empties_the_strip(cx: &mut TestAppContext) {
store::tests::with_home(|| {
let (workspace, cx) = launch_on_sqlite(cx);
let strip = |cx: &mut VisualTestContext| {
workspace.read_with(cx, |workspace, _| {
workspace
.profile()
.expect("a profile is open")
.session
.strip_tabs()
})
};
cx.simulate_keystrokes("secondary-t secondary-t");
settle(cx);
assert!(strip(cx).len() >= 3);

cx.simulate_keystrokes("secondary-k w");
settle(cx);
assert_eq!(strip(cx), Vec::new());

quit(workspace, cx);
});
}

#[gpui::test]
fn a_row_panel_draft_keeps_its_tab_open_for_the_discard_question(cx: &mut TestAppContext) {
store::tests::with_home(|| {
let (workspace, cx) = launch_on_sqlite_holding(
cx,
"create table fruit (id integer primary key, name text); \
insert into fruit values (1, 'apple');",
);
cx.simulate_input("select * from fruit");
cx.simulate_keystrokes("secondary-enter");
settle(cx);
cx.simulate_keystrokes("secondary-k r");
settle(cx);
press(cx, "right");
press(cx, "secondary-shift-e");
let input = workspace.read_with(cx, |workspace, _| {
let inputs = workspace.row_panel.inputs.as_ref().expect("Edit mode");
inputs.fields[1]
.as_ref()
.expect("an input on the name")
.input
.clone()
});
cx.update(|window, cx| {
input.update(cx, |input, cx| input.set_value("pear", window, cx));
});
settle(cx);

cx.simulate_keystrokes("secondary-k w");
settle(cx);
workspace.read_with(cx, |workspace, _| {
let session = &workspace.profile().expect("a connection in front").session;
let discard = session
.pending_discard
.as_ref()
.expect("the draft is asked about");
assert_eq!(discard.tabs, vec![session.active]);
assert_eq!(session.strip_tabs(), vec![session.active]);
});
quit(workspace, cx);
});
}

#[gpui::test]
fn the_command_palette_opens_on_the_welcome_surface(cx: &mut TestAppContext) {
// A `PG*` connection from the environment opens in place of the welcome
Expand Down
20 changes: 14 additions & 6 deletions src/workspace/forms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,7 @@ impl Workspace {

pub(crate) fn render_discard_confirmation(&self, cx: &mut Context<Self>) -> Option<AnyElement> {
let t = popup_theme(cx);
self.profile()?.session.pending_discard.as_ref()?;
let held = self.profile()?.session.pending_discard.as_ref()?.tabs.len();
let cancel_workspace = cx.entity().downgrade();
let discard_workspace = cancel_workspace.clone();

Expand All @@ -1727,18 +1727,26 @@ impl Workspace {
.justify_center()
.child(
dialog(t)
.child(section_label(t, "Close tab"))
.child(section_label(
t,
if held > 1 { "Close tabs" } else { "Close tab" },
))
.child(
div()
.text_size(px(layout::chrome(layout::TEXT_SM)))
.text_color(t.text_muted)
// The edits are held against the fetched rows
// and never written to them, so closing the
// tab is the moment they stop existing.
.child(
"This tab has cell edits that have not been applied. \
Closing it discards them.",
),
.child(match held {
1 => "This tab has cell edits that have not been applied. \
Closing it discards them."
.to_string(),
held => format!(
"{held} tabs have cell edits that have not been \
applied. Closing them discards them."
),
}),
)
.child(
div()
Expand Down
1 change: 1 addition & 0 deletions src/workspace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2664,6 +2664,7 @@ impl Render for Workspace {
.on_action(cx.listener(Self::new_row))
.on_action(cx.listener(Self::save_query))
.on_action(cx.listener(Self::close_tab))
.on_action(cx.listener(Self::close_all_tabs))
.on_action(cx.listener(Self::go_to_column))
.on_action(cx.listener(Self::toggle_results))
.on_action(cx.listener(Self::toggle_row_panel))
Expand Down
2 changes: 1 addition & 1 deletion src/workspace/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2028,7 +2028,7 @@ impl Workspace {
if let Some(tab) = holder.filter(|tab| self.has_unapplied_edits(*tab, cx)) {
if let Some(profile) = self.profile_mut() {
profile.session.pending_discard = Some(PendingDiscard {
tab,
tabs: vec![tab],
deleting: Some(name),
});
}
Expand Down
Loading
Loading