commit fc9688dfc9075956df2a1070c390355f0c333c07
parent 7229b607954e78832f51b81b07a8b641bf203562
Author: deurzen <m.deurzen@tum.de>
Date: Tue, 16 Mar 2021 13:59:58 +0100
implements layout persistent data copy setting
Diffstat:
2 files changed, 46 insertions(+), 13 deletions(-)
diff --git a/src/core/model.rs b/src/core/model.rs
@@ -1701,15 +1701,12 @@ impl<'a> Model<'a> {
let workspace = self.workspace_mut(workspace_index);
if let Some(id) = workspace.active_zone() {
- let cycle = self.zone_manager.nearest_cycle(id);
- let cycle = self.zone_manager.zone_mut(cycle);
-
info!(
"activating layout {:?} on workspace {}",
kind, workspace_index
);
- cycle.set_kind(kind);
+ self.zone_manager.set_kind(id, kind);
self.apply_layout(workspace_index, true);
}
}
@@ -1719,16 +1716,13 @@ impl<'a> Model<'a> {
let workspace = self.workspace_mut(workspace_index);
if let Some(id) = workspace.active_zone() {
- let cycle = self.zone_manager.nearest_cycle(id);
- let cycle = self.zone_manager.zone_mut(cycle);
- let prev_kind = cycle.get_prev_kind();
+ let prev_kind = self.zone_manager.set_prev_kind(id);
info!(
"activating layout {:?} on workspace {}",
prev_kind, workspace_index
);
- cycle.set_kind(prev_kind);
self.apply_layout(workspace_index, true);
}
}
diff --git a/src/core/zone.rs b/src/core/zone.rs
@@ -843,27 +843,26 @@ impl Zone {
self.content = content;
}
- pub fn set_kind(
+ fn set_kind(
&mut self,
kind: LayoutKind,
) {
match self.content {
ZoneContent::Layout(ref mut layout, _) => {
- layout.prev_kind = layout.kind;
- layout.kind = kind;
+ layout.set_kind(kind);
},
_ => {},
}
}
- pub fn get_prev_kind(&self) -> LayoutKind {
+ pub fn prev_kind(&self) -> LayoutKind {
match &self.content {
ZoneContent::Layout(layout, _) => layout.prev_kind,
_ => panic!("attempting to obtain layout kind from non-layout"),
}
}
- pub fn get_kind(&self) -> LayoutKind {
+ pub fn kind(&self) -> LayoutKind {
match &self.content {
ZoneContent::Layout(layout, _) => layout.kind,
_ => panic!("attempting to obtain layout kind from non-layout"),
@@ -933,12 +932,14 @@ enum ZoneChange {
pub struct ZoneManager {
zone_map: HashMap<ZoneId, Zone>,
+ persistent_data_copy: bool,
}
impl ZoneManager {
pub fn new() -> Self {
Self {
zone_map: HashMap::new(),
+ persistent_data_copy: true,
}
}
@@ -980,6 +981,44 @@ impl ZoneManager {
}
}
+ pub fn set_kind(
+ &mut self,
+ id: ZoneId,
+ kind: LayoutKind,
+ ) {
+ let persistent_data_copy = self.persistent_data_copy;
+ let cycle = self.nearest_cycle(id);
+ let cycle = self.zone_mut(cycle);
+
+ cycle.set_kind(kind);
+
+ if persistent_data_copy {
+ let prev_data = *cycle.prev_data().unwrap();
+ let data = cycle.data_mut().unwrap();
+ *data = prev_data;
+ }
+ }
+
+ pub fn set_prev_kind(
+ &mut self,
+ id: ZoneId,
+ ) -> LayoutKind {
+ let persistent_data_copy = self.persistent_data_copy;
+ let cycle = self.nearest_cycle(id);
+ let cycle = self.zone_mut(cycle);
+ let prev_kind = cycle.prev_kind();
+
+ cycle.set_kind(prev_kind);
+
+ if persistent_data_copy {
+ let prev_data = *cycle.prev_data().unwrap();
+ let data = cycle.data_mut().unwrap();
+ *data = prev_data;
+ }
+
+ prev_kind
+ }
+
pub fn active_default_data(
&mut self,
id: ZoneId,