forked from 1b-agent/opencadstudio-upstream
refactor(tabs): use context menu widget
This commit is contained in:
1 parent
ce1091cea5
commit
73545520c8
8 files changed
+194
-403
No files matched your search
@@ -561,7 +561,7 @@ pub(super) fn on_tab_close(&mut self, idx: usize) -> Task<Message> {
|
||||
self.refresh_properties();
|
||||
return Task::none();
|
||||
}
|
||||
// Cancel layout rename / context menus first, then fall through.
|
||||
// Cancel layout rename first, then fall through.
|
||||
let i_e = self.active_tab;
|
||||
if self.qselect.take().is_some() {
|
||||
return Task::none();
|
||||
@@ -573,10 +573,7 @@ pub(super) fn on_tab_close(&mut self, idx: usize) -> Task<Message> {
|
||||
return Task::none();
|
||||
}
|
||||
}
|
||||
if self.layout_rename_state.take().is_some()
|
||||
|| self.layout_context_menu.take().is_some()
|
||||
|| self.doc_tab_context_menu.take().is_some()
|
||||
{
|
||||
if self.layout_rename_state.take().is_some() {
|
||||
return Task::none();
|
||||
}
|
||||
// Typed text on the command line cancels first — one
|
||||
|
||||
+2
-51
@@ -930,9 +930,7 @@ impl OpenCADStudio {
|
||||
}
|
||||
|
||||
Message::TabSwitch(idx) => {
|
||||
self.doc_tab_context_menu = None;
|
||||
self.layout_list_open = false;
|
||||
self.layout_context_menu = None;
|
||||
self.layout_rename_state = None;
|
||||
if idx < self.tabs.len() {
|
||||
if idx != self.active_tab {
|
||||
@@ -991,35 +989,14 @@ impl OpenCADStudio {
|
||||
if let Some(index) = self.tabs.iter().position(|tab| tab.id == active_id) {
|
||||
self.active_tab = index;
|
||||
}
|
||||
self.doc_tab_context_menu = None;
|
||||
Task::none()
|
||||
}
|
||||
|
||||
Message::TabClose(idx) => {
|
||||
self.doc_tab_context_menu = None;
|
||||
self.on_tab_close(idx)
|
||||
}
|
||||
Message::TabClose(idx) => self.on_tab_close(idx),
|
||||
|
||||
Message::DocTabContextMenu(idx) => {
|
||||
if self.tabs.get(idx).is_some_and(|tab| !tab.is_start) {
|
||||
self.layout_context_menu = None;
|
||||
self.doc_tab_context_menu = Some(idx);
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
Message::DocTabContextMenuClose => {
|
||||
self.doc_tab_context_menu = None;
|
||||
Task::none()
|
||||
}
|
||||
|
||||
Message::DocTabSaveAll => {
|
||||
self.doc_tab_context_menu = None;
|
||||
self.dispatch_command("SAVEALL")
|
||||
}
|
||||
Message::DocTabSaveAll => self.dispatch_command("SAVEALL"),
|
||||
|
||||
Message::DocTabCloseAll => {
|
||||
self.doc_tab_context_menu = None;
|
||||
let ids = self
|
||||
.tabs
|
||||
.iter()
|
||||
@@ -1030,7 +1007,6 @@ impl OpenCADStudio {
|
||||
}
|
||||
|
||||
Message::DocTabCloseOthers(idx) => {
|
||||
self.doc_tab_context_menu = None;
|
||||
let Some(keep_id) = self.tabs.get(idx).filter(|tab| !tab.is_start).map(|t| t.id)
|
||||
else {
|
||||
return Task::none();
|
||||
@@ -1046,7 +1022,6 @@ impl OpenCADStudio {
|
||||
}
|
||||
|
||||
Message::DocTabCopyFullPath(idx) => {
|
||||
self.doc_tab_context_menu = None;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
let Some(path) = self.tabs.get(idx).and_then(|tab| tab.current_path.clone())
|
||||
@@ -1078,7 +1053,6 @@ impl OpenCADStudio {
|
||||
}
|
||||
|
||||
Message::DocTabOpenFileLocation(idx) => {
|
||||
self.doc_tab_context_menu = None;
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
{
|
||||
let Some(path) = self.tabs.get(idx).and_then(|tab| tab.current_path.clone())
|
||||
@@ -3383,7 +3357,6 @@ impl OpenCADStudio {
|
||||
self.push_undo_snapshot(i, "LAYOUT REORDER");
|
||||
self.tabs[i].scene.set_layout_tab_order(&paper);
|
||||
self.tabs[i].dirty = true;
|
||||
self.layout_context_menu = None;
|
||||
Task::none()
|
||||
}
|
||||
|
||||
@@ -3393,7 +3366,6 @@ impl OpenCADStudio {
|
||||
let i = self.active_tab;
|
||||
self.push_undo_snapshot(i, "LAYOUT DEL");
|
||||
if self.tabs[i].scene.delete_layout(&name) {
|
||||
self.layout_context_menu = None;
|
||||
self.layout_rename_state = None;
|
||||
self.command_line
|
||||
.push_output(&format!("Layout \"{name}\" silindi"));
|
||||
@@ -3405,7 +3377,6 @@ impl OpenCADStudio {
|
||||
Message::LayoutRenameStart(name) => {
|
||||
if name != "Model" {
|
||||
self.layout_rename_state = Some((name.clone(), name));
|
||||
self.layout_context_menu = None;
|
||||
// Focus the inline field so the user types into it
|
||||
// directly instead of the command line (issue #86).
|
||||
return iced::widget::operation::focus(iced::widget::Id::new(
|
||||
@@ -3430,26 +3401,6 @@ impl OpenCADStudio {
|
||||
Task::none()
|
||||
}
|
||||
|
||||
Message::LayoutContextMenu(name) => {
|
||||
// No menu on the transient BEDIT block tab: Rename/Delete are
|
||||
// layout operations and don't apply to it.
|
||||
let is_block_tab = self.tabs[self.active_tab]
|
||||
.block_edit
|
||||
.as_ref()
|
||||
.map(|be| be.block_name == name)
|
||||
.unwrap_or(false);
|
||||
if name != "Model" && !is_block_tab {
|
||||
self.doc_tab_context_menu = None;
|
||||
self.layout_context_menu = Some(name);
|
||||
}
|
||||
Task::none()
|
||||
}
|
||||
|
||||
Message::LayoutContextMenuClose => {
|
||||
self.layout_context_menu = None;
|
||||
Task::none()
|
||||
}
|
||||
|
||||
// ── Layout Manager Panel ──────────────────────────────────────────
|
||||
Message::LayoutManagerOpen => {
|
||||
let i = self.active_tab;
|
||||
|
||||
@@ -3702,9 +3702,8 @@ impl OpenCADStudio {
|
||||
self.tabs[i].scene.sync_camera_to_document();
|
||||
self.tabs[i].last_synced_camera_gen = self.tabs[i].scene.camera_generation;
|
||||
let sync_ms = perf_phase.elapsed().as_secs_f64() * 1000.0;
|
||||
// Cancel any pending rename/context-menu and active viewport when switching.
|
||||
// Cancel any pending rename and active viewport when switching.
|
||||
self.layout_rename_state = None;
|
||||
self.layout_context_menu = None;
|
||||
self.tabs[i].scene.active_viewport = None;
|
||||
let perf_phase = Instant::now();
|
||||
self.tabs[i].scene.set_current_layout(name.clone());
|
||||
|
||||
Reference in new issue
Block a user