add checkbox to skip marked

This commit is contained in:
2022-02-18 10:22:58 +01:00
parent ee3f8fa6f4
commit fe8ee5b5cb
3 changed files with 37 additions and 5 deletions

View File

@@ -91,6 +91,14 @@ fn build_ui(app: &Application) {
action_toggle_neighbour action_toggle_neighbour
.connect_activate(move |_, _| _sender.send(Message::UI(UIMessage::ToggleGrid)).unwrap()); .connect_activate(move |_, _| _sender.send(Message::UI(UIMessage::ToggleGrid)).unwrap());
let _sender = sender.clone();
image_ui
.skip_marked_checkbox
.connect_toggled(move |check_button| {
let value = check_button.is_active();
_sender.send(Message::SkipMarkedToogled(value)).unwrap();
});
let _sender = sender.clone(); let _sender = sender.clone();
let action_focus_scale_increment = SimpleAction::new("increment_focus_scale", None); let action_focus_scale_increment = SimpleAction::new("increment_focus_scale", None);
action_focus_scale_increment.connect_activate(move |_, _| { action_focus_scale_increment.connect_activate(move |_, _| {

View File

@@ -17,6 +17,7 @@ pub enum Message {
PreviousImage, PreviousImage,
UI(UIMessage), UI(UIMessage),
OpenFile(File), OpenFile(File),
SkipMarkedToogled(bool),
Quit, Quit,
} }
@@ -39,6 +40,7 @@ pub struct State {
file_name: Option<String>, file_name: Option<String>,
annotation_cache: Vec<LightAnnotation>, annotation_cache: Vec<LightAnnotation>,
pub root_path: Option<String>, pub root_path: Option<String>,
skip_marked: bool,
} }
#[derive(Debug, Clone, Serialize, Deserialize)] #[derive(Debug, Clone, Serialize, Deserialize)]
pub struct LightAnnotation { pub struct LightAnnotation {
@@ -64,6 +66,7 @@ impl State {
file_name: None, file_name: None,
annotation_cache: Vec::new(), annotation_cache: Vec::new(),
root_path: None, root_path: None,
skip_marked: true,
} }
} }
@@ -101,6 +104,9 @@ impl State {
Message::FocusLevelChange(lvl) => { Message::FocusLevelChange(lvl) => {
self.set_focus_image_index(Some(*lvl)); self.set_focus_image_index(Some(*lvl));
} }
Message::SkipMarkedToogled(value) => {
self.skip_marked = value.clone();
}
Message::UI(_) => {} Message::UI(_) => {}
} }
} }
@@ -159,8 +165,18 @@ impl State {
let len = self.stacks.len(); let len = self.stacks.len();
if len == 0 { if len == 0 {
self.stack_index = None; self.stack_index = None;
} else if self.stack_index.map_or_else(|| false, |x| x + 1 < len) { } else {
loop {
if self.stack_index.map_or_else(|| false, |x| x + 1 < len) {
self.stack_index = self.stack_index.map(|x| x + 1) self.stack_index = self.stack_index.map(|x| x + 1)
} else {
break;
}
if !self.skip_marked || self.get_current_foucs_stack_best_index() == None {
break;
}
}
} }
eprintln!("{:?}", self.stack_index) eprintln!("{:?}", self.stack_index)

View File

@@ -7,8 +7,9 @@ use gtk::{
BoxExt, ButtonExt, DialogExt, FileChooserExt, GridExt, GtkApplicationExt, GtkWindowExt, BoxExt, ButtonExt, DialogExt, FileChooserExt, GridExt, GtkApplicationExt, GtkWindowExt,
RangeExt, ScaleExt, ToggleButtonExt, WidgetExt, RangeExt, ScaleExt, ToggleButtonExt, WidgetExt,
}, },
ActionBar, AspectFrame, Box, Button, FileChooserAction, FileChooserDialog, FileFilter, Grid, ActionBar, AspectFrame, Box, Button, CheckButton, FileChooserAction, FileChooserDialog,
Image, Orientation, PositionType, ResponseType, Scale, Separator, ToggleButton, FileFilter, Grid, Image, Orientation, PositionType, ResponseType, Scale, Separator,
ToggleButton,
}; };
use crate::{ use crate::{
@@ -32,6 +33,7 @@ pub struct ImageUI {
pub focus_neighbours_aspect_frame: Arc<AspectFrame>, pub focus_neighbours_aspect_frame: Arc<AspectFrame>,
pub neighbour_toggle_button: ToggleButton, pub neighbour_toggle_button: ToggleButton,
pub skip_marked_checkbox: CheckButton,
pub open_button: Arc<SplitButton>, pub open_button: Arc<SplitButton>,
pub back_button: Arc<Button>, pub back_button: Arc<Button>,
pub skip_button: Arc<Button>, pub skip_button: Arc<Button>,
@@ -178,6 +180,9 @@ impl ImageUI {
.width_request(158) .width_request(158)
.build(); .build();
let skip_marked_checkbox = CheckButton::builder().label("skip marked").build();
skip_marked_checkbox.activate();
let focus_skip_link_widget = Box::builder() let focus_skip_link_widget = Box::builder()
.css_classes(vec!["linked".to_string()]) .css_classes(vec!["linked".to_string()])
.build(); .build();
@@ -186,12 +191,15 @@ impl ImageUI {
focus_skip_link_widget.append(focus_button.as_ref()); focus_skip_link_widget.append(focus_button.as_ref());
bottom_toolbar.pack_start(&neighbour_toggle_button); bottom_toolbar.pack_start(&neighbour_toggle_button);
bottom_toolbar.pack_end(&focus_skip_link_widget); bottom_toolbar.pack_end(&focus_skip_link_widget);
bottom_toolbar.pack_end(&skip_marked_checkbox);
application_vertical_widget.append(&bottom_toolbar); application_vertical_widget.append(&bottom_toolbar);
builder builder
.neighbour_toggle_button(neighbour_toggle_button) .neighbour_toggle_button(neighbour_toggle_button)
.skip_marked_checkbox(skip_marked_checkbox)
.back_button(back_button) .back_button(back_button)
.skip_button(skip_button) .skip_button(skip_button)
.focus_button(focus_button); .focus_button(focus_button);
@@ -275,7 +283,7 @@ impl ImageUI {
} }
self.update_focus_scale(&state); self.update_focus_scale(&state);
} }
Message::Quit => {} Message::Quit | Message::SkipMarkedToogled(_) => {}
} }
} }
fn update_image(&self, annotation_image: &AnnotationImage, base_path: String) { fn update_image(&self, annotation_image: &AnnotationImage, base_path: String) {