On macOS, add a way to query amount of tabbed windows

This should provide a way to iterate all the tabs and select the last
tab. The tab indicies are now zero based as any other sane index.

Follow-up-to: c5941d105f (add tabbing API)
This commit is contained in:
Kirill Chibisov 2023-07-14 08:01:40 +00:00 committed by GitHub
parent 06fb089633
commit 97434d8d80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 7 deletions

View file

@ -2,7 +2,6 @@
use std::collections::VecDeque;
use std::f64;
use std::num::NonZeroUsize;
use std::ops;
use std::os::raw::c_void;
use std::ptr::NonNull;
@ -1423,15 +1422,20 @@ impl WindowExtMacOS for WinitWindow {
}
#[inline]
fn select_tab_at_index(&self, index: NonZeroUsize) {
fn select_tab_at_index(&self, index: usize) {
let tab_group = self.tabGroup();
let windows = tab_group.tabbedWindows();
let index = index.get() - 1;
if index < windows.len() {
tab_group.setSelectedWindow(&windows[index]);
}
}
#[inline]
fn num_tabs(&self) -> usize {
let tab_group = self.tabGroup();
tab_group.tabbedWindows().len()
}
fn is_document_edited(&self) -> bool {
self.isDocumentEdited()
}