Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to close a recording #2972

Merged
merged 3 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions crates/re_data_store/src/store_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,4 +374,10 @@ impl StoreDb {

entity_db.purge(&cutoff_times, &drop_row_ids);
}

/// Key used for sorting recordings in the UI.
pub fn sort_key(&self) -> impl Ord + '_ {
self.store_info()
.map(|info| (info.application_id.0.as_str(), info.started))
}
}
4 changes: 4 additions & 0 deletions crates/re_ui/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum UICommand {
Save,
#[cfg(not(target_arch = "wasm32"))]
SaveSelection,
CloseCurrentRecording,
#[cfg(not(target_arch = "wasm32"))]
Quit,

Expand Down Expand Up @@ -86,6 +87,8 @@ impl UICommand {
#[cfg(not(target_arch = "wasm32"))]
UICommand::Open => ("Open…", "Open a Rerun Data File (.rrd)"),

UICommand::CloseCurrentRecording => ("Close recording", "Close the current Recording"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the tooltip should mention that all data will be lost unrecoverably unless saved?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also consider adding the actual name of the recording to the tooltip for added clarity.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also consider using the label "Close current recording" to be more specific. If it doesn't take too much space I think that specificity would make things clearer

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nikolausWest "dynamic" tooltips would require a significant refactor of that area of code I believe. I'd rather avoid that can of worm in this PR so I'll open an issue. Also, this might be a little-used feature anyways once I add the "delete" button in the recording list.


#[cfg(not(target_arch = "wasm32"))]
UICommand::Quit => ("Quit", "Close the Rerun Viewer"),

Expand Down Expand Up @@ -186,6 +189,7 @@ impl UICommand {
UICommand::SaveSelection => Some(cmd_alt(Key::S)),
#[cfg(not(target_arch = "wasm32"))]
UICommand::Open => Some(cmd(Key::O)),
UICommand::CloseCurrentRecording => None,

#[cfg(all(not(target_arch = "wasm32"), target_os = "windows"))]
UICommand::Quit => Some(KeyboardShortcut::new(Modifiers::ALT, Key::F4)),
Expand Down
12 changes: 12 additions & 0 deletions crates/re_viewer/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ impl App {
SystemCommand::SetRecordingId(recording_id) => {
store_hub.set_recording_id(recording_id);
}
SystemCommand::CloseRecordingId(recording_id) => {
store_hub.remove_recording_id(&recording_id);
}
#[cfg(not(target_arch = "wasm32"))]
SystemCommand::LoadRrd(path) => {
let with_notification = true;
Expand Down Expand Up @@ -343,6 +346,15 @@ impl App {
.send_system(SystemCommand::LoadRrd(rrd_file));
}
}
UICommand::CloseCurrentRecording => {
let cur_rec = store_context
.and_then(|ctx| ctx.recording)
.map(|rec| rec.store_id());
if let Some(cur_rec) = cur_rec {
self.command_sender
.send_system(SystemCommand::CloseRecordingId(cur_rec.clone()));
}
}
#[cfg(not(target_arch = "wasm32"))]
UICommand::Quit => {
_frame.close();
Expand Down
35 changes: 35 additions & 0 deletions crates/re_viewer/src/store_hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,17 @@ impl StoreHub {
self.selected_rec_id = Some(recording_id);
}

pub fn remove_recording_id(&mut self, recording_id: &StoreId) {
if let Some(new_selection) = self.store_dbs.find_closest_recording(recording_id) {
self.set_recording_id(new_selection.clone());
} else {
self.application_id = None;
self.selected_rec_id = None;
}

self.store_dbs.remove(recording_id);
}

/// Change the selected [`ApplicationId`]
pub fn set_app_id(&mut self, app_id: ApplicationId) {
// If we don't know of a blueprint for this `ApplicationId` yet,
Expand Down Expand Up @@ -326,6 +337,30 @@ impl StoreBundle {
self.store_dbs.remove(id);
}

/// Returns the closest "neighbor" recording to the given id.
///
/// The closest neighbor is the next recording when sorted by (app ID, time), if any, or the
/// previous one otherwise. This is used to update the selected recording when the current one
/// is deleted.
pub fn find_closest_recording(&self, id: &StoreId) -> Option<&StoreId> {
let mut recs = self.recordings().collect_vec();
recs.sort_by_key(|store_db| store_db.sort_key());

let cur_pos = recs.iter().position(|rec| rec.store_id() == id);

if let Some(cur_pos) = cur_pos {
if recs.len() > cur_pos + 1 {
Some(recs[cur_pos + 1].store_id())
} else if cur_pos > 0 {
Some(recs[cur_pos - 1].store_id())
} else {
None
}
} else {
None
}
}

// --

pub fn contains_recording(&self, id: &StoreId) -> bool {
Expand Down
9 changes: 1 addition & 8 deletions crates/re_viewer/src/ui/recordings_panel.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use re_data_store::StoreDb;
use re_viewer_context::{SystemCommand, SystemCommandSender, ViewerContext};
use time::macros::format_description;

Expand Down Expand Up @@ -39,13 +38,7 @@ fn recording_list_ui(ctx: &mut ViewerContext<'_>, ui: &mut egui::Ui) {
return;
}

fn store_db_key(store_db: &StoreDb) -> impl Ord + '_ {
store_db
.store_info()
.map(|info| (info.application_id.0.as_str(), info.started))
}

store_dbs.sort_by_key(|store_db| store_db_key(store_db));
store_dbs.sort_by_key(|store_db| store_db.sort_key());

let active_recording = store_context.recording.map(|rec| rec.store_id());

Expand Down
2 changes: 2 additions & 0 deletions crates/re_viewer/src/ui/rerun_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ impl App {

self.save_buttons_ui(ui, _store_context);

UICommand::CloseCurrentRecording.menu_button_ui(ui, &self.command_sender);

ui.add_space(spacing);

// On the web the browser controls the zoom
Expand Down
3 changes: 3 additions & 0 deletions crates/re_viewer_context/src/command_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pub enum SystemCommand {
/// Change the active recording-id in the `StoreHub`
SetRecordingId(StoreId),

/// Close a recording
CloseRecordingId(StoreId),

/// Update the blueprint with additional data
///
/// The [`StoreId`] should generally be the currently selected blueprint
Expand Down