Skip to content

Commit

Permalink
Use Listener for commands (lapce#2441)
Browse files Browse the repository at this point in the history
  • Loading branch information
MinusGix authored Jun 9, 2023
1 parent aa20622 commit 2f9432b
Show file tree
Hide file tree
Showing 17 changed files with 300 additions and 261 deletions.
21 changes: 9 additions & 12 deletions lapce-app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,12 @@ fn editor_tab_header(
move || {
let editor_tab_id =
editor_tab.with_untracked(|t| t.editor_tab_id);
internal_command.set(Some(
internal_command.send(
InternalCommand::EditorTabChildClose {
editor_tab_id,
child: child_for_close.clone(),
},
));
);
},
|| false,
|| false,
Expand Down Expand Up @@ -393,10 +393,10 @@ fn editor_tab_header(
move || {
let editor_tab_id =
editor_tab.with_untracked(|t| t.editor_tab_id);
internal_command.set(Some(InternalCommand::Split {
internal_command.send(InternalCommand::Split {
direction: SplitDirection::Vertical,
editor_tab_id,
}));
});
},
|| false,
|| false,
Expand All @@ -408,9 +408,8 @@ fn editor_tab_header(
move || {
let editor_tab_id =
editor_tab.with_untracked(|t| t.editor_tab_id);
internal_command.set(Some(InternalCommand::EditorTabClose {
editor_tab_id,
}));
internal_command
.send(InternalCommand::EditorTabClose { editor_tab_id });
},
|| false,
|| false,
Expand Down Expand Up @@ -530,8 +529,7 @@ fn editor_tab(
focus.set(Focus::Workbench);
}
let editor_tab_id = editor_tab.with_untracked(|t| t.editor_tab_id);
internal_command
.set(Some(InternalCommand::FocusEditorTab { editor_tab_id }));
internal_command.send(InternalCommand::FocusEditorTab { editor_tab_id });
false
})
.style(|| Style::BASE.flex_col().size_pct(100.0, 100.0))
Expand Down Expand Up @@ -2010,8 +2008,7 @@ fn window_tab(window_tab_data: Arc<WindowTabData>) -> impl View {
let update_in_progress = window_tab_data.update_in_progress;
let config = window_tab_data.common.config;
let workspace = window_tab_data.workspace.clone();
let set_workbench_command =
window_tab_data.common.workbench_command.write_only();
let workbench_command = window_tab_data.common.workbench_command;
let main_split = window_tab_data.main_split.clone();

let view = stack(|| {
Expand All @@ -2022,7 +2019,7 @@ fn window_tab(window_tab_data: Arc<WindowTabData>) -> impl View {
workspace,
main_split,
source_control,
set_workbench_command,
workbench_command,
latest_release,
update_in_progress,
config,
Expand Down
4 changes: 2 additions & 2 deletions lapce-app/src/code_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ impl CodeActionData {
if let Some(item) = self.filtered_items.get(self.active.get_untracked()) {
self.common
.internal_command
.set(Some(InternalCommand::RunCodeAction {
.send(InternalCommand::RunCodeAction {
plugin_id: item.plugin_id,
action: item.item.clone(),
}));
});
}
self.cancel();
}
Expand Down
104 changes: 49 additions & 55 deletions lapce-app/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,13 @@ impl EditorData {
if let Some(path) = path {
let offset = self.cursor.with_untracked(|c| c.offset());
let scroll_offset = self.viewport.get_untracked().origin().to_vec2();
self.common.internal_command.set(Some(
self.common.internal_command.send(
InternalCommand::SaveJumpLocation {
path,
offset,
scroll_offset,
},
));
);
}
}
self.last_movement.set(movement.clone());
Expand Down Expand Up @@ -412,79 +412,75 @@ impl EditorData {
match cmd {
FocusCommand::SplitVertical => {
if let Some(editor_tab_id) = self.editor_tab_id {
self.common
.internal_command
.set(Some(InternalCommand::Split {
direction: SplitDirection::Vertical,
editor_tab_id,
}));
self.common.internal_command.send(InternalCommand::Split {
direction: SplitDirection::Vertical,
editor_tab_id,
});
}
}
FocusCommand::SplitHorizontal => {
if let Some(editor_tab_id) = self.editor_tab_id {
self.common
.internal_command
.set(Some(InternalCommand::Split {
direction: SplitDirection::Horizontal,
editor_tab_id,
}));
self.common.internal_command.send(InternalCommand::Split {
direction: SplitDirection::Horizontal,
editor_tab_id,
});
}
}
FocusCommand::SplitRight => {
if let Some(editor_tab_id) = self.editor_tab_id {
self.common.internal_command.set(Some(
InternalCommand::SplitMove {
self.common
.internal_command
.send(InternalCommand::SplitMove {
direction: SplitMoveDirection::Right,
editor_tab_id,
},
));
});
}
}
FocusCommand::SplitLeft => {
if let Some(editor_tab_id) = self.editor_tab_id {
self.common.internal_command.set(Some(
InternalCommand::SplitMove {
self.common
.internal_command
.send(InternalCommand::SplitMove {
direction: SplitMoveDirection::Left,
editor_tab_id,
},
));
});
}
}
FocusCommand::SplitUp => {
if let Some(editor_tab_id) = self.editor_tab_id {
self.common.internal_command.set(Some(
InternalCommand::SplitMove {
self.common
.internal_command
.send(InternalCommand::SplitMove {
direction: SplitMoveDirection::Up,
editor_tab_id,
},
));
});
}
}
FocusCommand::SplitDown => {
if let Some(editor_tab_id) = self.editor_tab_id {
self.common.internal_command.set(Some(
InternalCommand::SplitMove {
self.common
.internal_command
.send(InternalCommand::SplitMove {
direction: SplitMoveDirection::Down,
editor_tab_id,
},
));
});
}
}
FocusCommand::SplitExchange => {
if let Some(editor_tab_id) = self.editor_tab_id {
self.common
.internal_command
.set(Some(InternalCommand::SplitExchange { editor_tab_id }));
.send(InternalCommand::SplitExchange { editor_tab_id });
}
}
FocusCommand::SplitClose => {
if let Some(editor_tab_id) = self.editor_tab_id {
self.common.internal_command.set(Some(
self.common.internal_command.send(
InternalCommand::EditorTabChildClose {
editor_tab_id,
child: EditorTabChild::Editor(self.editor_id),
},
));
);
}
}
FocusCommand::PageUp => {
Expand Down Expand Up @@ -730,10 +726,10 @@ impl EditorData {
match d {
DefinitionOrReferece::Location(location) => {
internal_command
.set(Some(InternalCommand::JumpToLocation { location }));
.send(InternalCommand::JumpToLocation { location });
}
DefinitionOrReferece::References(locations) => {
internal_command.set(Some(InternalCommand::PaletteReferences {
internal_command.send(InternalCommand::PaletteReferences {
references: locations
.into_iter()
.map(|l| EditorLocation {
Expand All @@ -746,7 +742,7 @@ impl EditorData {
same_editor_tab: false,
})
.collect(),
}));
});
}
}
});
Expand Down Expand Up @@ -1491,13 +1487,13 @@ impl EditorData {
.with_untracked(|doc| doc.code_actions.get(&offset).cloned());
if let Some(code_actions) = code_actions {
if !code_actions.1.is_empty() {
self.common.internal_command.set(Some(
self.common.internal_command.send(
InternalCommand::ShowCodeActions {
offset,
mouse_click,
code_actions,
},
));
);
}
}
}
Expand Down Expand Up @@ -1578,11 +1574,9 @@ impl EditorData {
)
});
self.common.find.whole_words.set(true);
self.common
.internal_command
.set(Some(InternalCommand::Search {
pattern: Some(word),
}));
self.common.internal_command.send(InternalCommand::Search {
pattern: Some(word),
});
let next = self.common.find.next(buffer.text(), offset, false, true);

if let Some((start, _end)) = next {
Expand Down Expand Up @@ -1713,12 +1707,12 @@ impl EditorData {
doc.buffer().slice_to_cow(start..end).to_string()
})
});
internal_command.set(Some(InternalCommand::StartRename {
internal_command.send(InternalCommand::StartRename {
path: local_path.clone(),
placeholder,
start,
position,
}));
});
}
});
self.common
Expand Down Expand Up @@ -1783,7 +1777,7 @@ impl EditorData {

self.common
.internal_command
.set(Some(InternalCommand::Search { pattern }));
.send(InternalCommand::Search { pattern });
self.common.find.visual.set(true);
self.find_focus.set(true);
self.common.find.replace_focus.set(false);
Expand All @@ -1793,7 +1787,7 @@ impl EditorData {
if let Some(editor_tab_id) = self.editor_tab_id {
self.common
.internal_command
.set(Some(InternalCommand::FocusEditorTab { editor_tab_id }));
.send(InternalCommand::FocusEditorTab { editor_tab_id });
}
self.common.focus.set(Focus::Workbench);
self.find_focus.set(false);
Expand Down Expand Up @@ -1941,21 +1935,21 @@ impl KeyPressFocus for EditorData {
| CommandKind::Move(_)
| CommandKind::MultiSelection(_) => {
if self.common.find.replace_focus.get_untracked() {
self.common.internal_command.set(Some(
self.common.internal_command.send(
InternalCommand::ReplaceEditorCommand {
command: command.clone(),
count,
mods,
},
));
);
} else {
self.common.internal_command.set(Some(
self.common.internal_command.send(
InternalCommand::FindEditorCommand {
command: command.clone(),
count,
mods,
},
));
);
}
return CommandExecuted::Yes;
}
Expand Down Expand Up @@ -1999,13 +1993,13 @@ impl KeyPressFocus for EditorData {
{
// find/relace editor receive char
if self.common.find.replace_focus.get_untracked() {
self.common.internal_command.set(Some(
self.common.internal_command.send(
InternalCommand::ReplaceEditorReceiveChar { s: c.to_string() },
));
);
} else {
self.common.internal_command.set(Some(
self.common.internal_command.send(
InternalCommand::FindEditorReceiveChar { s: c.to_string() },
));
);
}
} else {
// normal editor receive char
Expand Down
2 changes: 1 addition & 1 deletion lapce-app/src/editor/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1656,7 +1656,7 @@ fn find_view(
editor
.common
.internal_command
.set(Some(InternalCommand::FocusEditorTab { editor_tab_id }));
.send(InternalCommand::FocusEditorTab { editor_tab_id });
}
true
})
Expand Down
8 changes: 4 additions & 4 deletions lapce-app/src/file_explorer/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use floem::{
use indexmap::IndexMap;
use lapce_rpc::proxy::{ProxyResponse, ProxyRpcHandler};

use crate::command::InternalCommand;
use crate::{command::InternalCommand, listener::Listener};

#[derive(Clone)]
pub struct FileNode {
Expand All @@ -24,7 +24,7 @@ pub struct FileNode {
pub children_open_count: RwSignal<usize>,
pub all_files: RwSignal<im::HashMap<PathBuf, FileNode>>,
pub line_height: Memo<f64>,
pub internal_command: RwSignal<Option<InternalCommand>>,
pub internal_command: Listener<InternalCommand>,
}

impl VirtualListVector<(PathBuf, FileNode)> for FileNode {
Expand Down Expand Up @@ -60,9 +60,9 @@ impl FileNode {
if self.is_dir {
self.toggle_expand(proxy)
} else {
self.internal_command.set(Some(InternalCommand::OpenFile {
self.internal_command.send(InternalCommand::OpenFile {
path: self.path.clone(),
}))
})
}
}

Expand Down
Loading

0 comments on commit 2f9432b

Please sign in to comment.