forked from 1b-agent/opencadstudio-upstream
feat(block-editor): add Save Block As
Create a new named definition from current session edits, restore the source checkpoint, and continue editing the copy with fresh local history. Add the name dialog and Save dropdown, clone supported owned metadata onto independent handles, and refuse unsupported relationships atomically.
This commit is contained in:
1 parent
da8e976a60
commit
78bdfa3c74
13 files changed
+1364
-8
No files matched your search
@@ -0,0 +1,52 @@
|
||||
use crate::app::Message;
|
||||
use crate::scene::WireModel;
|
||||
use iced::widget::{button, column, container, pick_list, row, text, text_input, Space};
|
||||
use iced::{Element, Fill};
|
||||
|
||||
pub(crate) struct State {
|
||||
pub document_id: u64,
|
||||
pub source: codec::Handle,
|
||||
pub name: String,
|
||||
pub existing_names: Vec<String>,
|
||||
pub preview: Vec<WireModel>,
|
||||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
pub(crate) fn view(state: &State, sizing: crate::ui::modal::ModalSizing) -> Element<'_, Message> {
|
||||
let field = text_input(crate::t!("Block name").as_ref(), &state.name)
|
||||
.on_input(Message::BlockSaveAsName)
|
||||
.on_submit_maybe(state.error.is_none().then_some(Message::BlockSaveAsApply))
|
||||
.style(crate::ui::style::form::field_style);
|
||||
let names = pick_list(
|
||||
None::<String>,
|
||||
state.existing_names.as_slice(),
|
||||
|name: &String| name.clone(),
|
||||
)
|
||||
.on_select(Message::BlockSaveAsName)
|
||||
.placeholder(crate::t!("Existing blocks").into_owned())
|
||||
.width(Fill);
|
||||
container(
|
||||
column![
|
||||
text(crate::t!("Block name").into_owned()).size(13),
|
||||
field,
|
||||
names,
|
||||
super::block_palette::preview_canvas(&state.preview, 160.0),
|
||||
text(state.error.clone().unwrap_or_default())
|
||||
.size(12)
|
||||
.style(text::danger),
|
||||
row![
|
||||
Space::new().width(Fill),
|
||||
button(text(crate::t!("OK").into_owned()))
|
||||
.on_press_maybe(state.error.is_none().then_some(Message::BlockSaveAsApply))
|
||||
.style(button::primary),
|
||||
button(text(crate::t!("Cancel").into_owned())).on_press(Message::CloseModal),
|
||||
]
|
||||
.spacing(8),
|
||||
]
|
||||
.spacing(10),
|
||||
)
|
||||
.padding(16)
|
||||
.width(sizing.width)
|
||||
.height(sizing.height)
|
||||
.into()
|
||||
}
|
||||
@@ -5,6 +5,7 @@ pub mod attdef_dialog;
|
||||
pub mod attribute_editor;
|
||||
pub mod auto_constrain_settings;
|
||||
pub mod block_definition;
|
||||
pub mod block_save_as;
|
||||
pub mod block_palette;
|
||||
pub mod browser;
|
||||
pub mod count_palette;
|
||||
|
||||
Reference in new issue
Block a user