Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the drag-and-drop to open file feature. #125

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions lapce-app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub struct AppInfo {
#[derive(Clone)]
pub enum AppCommand {
SaveApp,
NewWindow,
NewWindow { folder: Option<PathBuf> },
CloseWindow(WindowId),
WindowGotFocus(WindowId),
WindowClosed(WindowId),
Expand Down Expand Up @@ -202,7 +202,7 @@ impl AppData {
.title("Lapce")
}

pub fn new_window(&self) {
pub fn new_window(&self, folder: Option<PathBuf>) {
let config = self
.active_window()
.map(|window| {
Expand All @@ -228,6 +228,8 @@ impl AppData {
} else {
config
};
let mut workspace = LapceWorkspace::default();
workspace.path = folder;
let app_data = self.clone();
floem::new_window(
move |window_id| {
Expand All @@ -239,7 +241,7 @@ impl AppData {
maximised: false,
tabs: TabsInfo {
active_tab: 0,
workspaces: vec![LapceWorkspace::default()],
workspaces: vec![workspace],
},
},
)
Expand Down Expand Up @@ -274,8 +276,8 @@ impl AppData {
AppCommand::CloseWindow(window_id) => {
floem::close_window(window_id);
}
AppCommand::NewWindow => {
self.new_window();
AppCommand::NewWindow { folder } => {
self.new_window(folder);
}
AppCommand::WindowGotFocus(window_id) => {
self.active_window.set(window_id);
Expand Down Expand Up @@ -566,12 +568,15 @@ impl AppData {
EventPropagation::Continue
}
})
.on_event(EventListener::PointerDown, move |event| {
if let Event::PointerDown(pointer_event) = event {
window_data.key_down(pointer_event);
EventPropagation::Stop
} else {
EventPropagation::Continue
.on_event(EventListener::PointerDown, {
let window_data = window_data.clone();
move |event| {
if let Event::PointerDown(pointer_event) = event {
window_data.key_down(pointer_event);
EventPropagation::Stop
} else {
EventPropagation::Continue
}
}
})
.on_event_stop(EventListener::WindowResized, move |event| {
Expand All @@ -590,6 +595,29 @@ impl AppData {
.on_event_stop(EventListener::WindowClosed, move |_| {
app_command.send(AppCommand::WindowClosed(window_id));
})
.on_event_stop(EventListener::DroppedFile, move |event: &Event| {
if let Event::DroppedFile(file) = event {
if file.path.is_dir() {
app_command.send(AppCommand::NewWindow {
folder: Some(file.path.clone()),
});
} else {
if let Some(win_tab_data) = window_data.active_window_tab() {
win_tab_data.common.internal_command.send(
InternalCommand::GoToLocation {
location: EditorLocation {
path: file.path.clone(),
position: None,
scroll_offset: None,
ignore_unconfirmed: false,
same_editor_tab: false,
},
},
)
}
}
}
})
.debug_name("App View")
}
}
Expand Down Expand Up @@ -3824,7 +3852,7 @@ pub fn launch() {
has_visible_windows,
} => {
if !has_visible_windows {
app_data.new_window();
app_data.new_window(None);
}
}
})
Expand Down
3 changes: 2 additions & 1 deletion lapce-app/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ impl WindowData {
}
}
WindowCommand::NewWindow => {
self.app_command.send(AppCommand::NewWindow);
self.app_command
.send(AppCommand::NewWindow { folder: None });
}
WindowCommand::CloseWindow => {
self.app_command
Expand Down
Loading