From 6c4670287d7bc4c671d81b19b5c88a9e8346a17a Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 22 Dec 2023 10:45:51 +0200 Subject: [PATCH] Highlight termina on external files drag and drop --- crates/terminal_view2/src/terminal_element.rs | 21 +++++++------------ crates/terminal_view2/src/terminal_panel.rs | 14 +++++-------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/crates/terminal_view2/src/terminal_element.rs b/crates/terminal_view2/src/terminal_element.rs index ec1e1736c31a3ab24911c83f46d2edf734a2b2eb..eb7348b9357cfe2c2c44c3405ceb2665318a7a7a 100644 --- a/crates/terminal_view2/src/terminal_element.rs +++ b/crates/terminal_view2/src/terminal_element.rs @@ -4,8 +4,9 @@ use gpui::{ BorrowWindow, Bounds, DispatchPhase, Element, ElementId, ExternalPaths, FocusHandle, Font, FontStyle, FontWeight, HighlightStyle, Hsla, InteractiveElement, InteractiveElementState, Interactivity, IntoElement, LayoutId, Model, ModelContext, ModifiersChangedEvent, MouseButton, - Pixels, PlatformInputHandler, Point, Rgba, ShapedLine, StatefulInteractiveElement, Styled, - TextRun, TextStyle, TextSystem, UnderlineStyle, WhiteSpace, WindowContext, + Pixels, PlatformInputHandler, Point, Rgba, ShapedLine, StatefulInteractiveElement, + StyleRefinement, Styled, TextRun, TextStyle, TextSystem, UnderlineStyle, WhiteSpace, + WindowContext, }; use itertools::Itertools; use language::CursorShape; @@ -24,7 +25,7 @@ use terminal::{ use theme::{ActiveTheme, Theme, ThemeSettings}; use ui::Tooltip; -use std::mem; +use std::{any::TypeId, mem}; use std::{fmt::Debug, ops::RangeInclusive}; ///The information generated during layout that is necessary for painting @@ -689,6 +690,10 @@ impl TerminalElement { } }); + self.interactivity.drag_over_styles.push(( + TypeId::of::(), + StyleRefinement::default().bg(cx.theme().colors().drop_target_background), + )); self.interactivity.on_drop::({ let focus = focus.clone(); let terminal = terminal.clone(); @@ -787,8 +792,6 @@ impl Element for TerminalElement { ) { let mut layout = self.compute_layout(bounds, cx); - let theme = cx.theme(); - cx.paint_quad(fill(bounds, layout.background_color)); let origin = bounds.origin + Point::new(layout.gutter, px(0.)); @@ -801,16 +804,8 @@ impl Element for TerminalElement { .map(|cursor| cursor.bounding_rect(origin)), }; - let terminal_focus_handle = self.focus.clone(); - let terminal_handle = self.terminal.clone(); self.register_mouse_listeners(origin, layout.mode, bounds, cx); - // todo!(change this to work in terms of on_drag_move or some such) - // .drag_over::(|style| { - // // todo!() why does not it work? z-index of elements? - // style.bg(cx.theme().colors().ghost_element_hover) - // }) - let mut interactivity = mem::take(&mut self.interactivity); interactivity.paint(bounds, bounds.size, state, cx, |_, _, cx| { cx.handle_input(&self.focus, terminal_input_handler); diff --git a/crates/terminal_view2/src/terminal_panel.rs b/crates/terminal_view2/src/terminal_panel.rs index 245add3eeb9b3cad48f38a3c443597330ffc8328..3c7b2a2e0e9d1e1d8f7a37311e4923c996da5e8b 100644 --- a/crates/terminal_view2/src/terminal_panel.rs +++ b/crates/terminal_view2/src/terminal_panel.rs @@ -4,8 +4,8 @@ use crate::TerminalView; use db::kvp::KEY_VALUE_STORE; use gpui::{ actions, div, serde_json, AppContext, AsyncWindowContext, Div, Entity, EventEmitter, - FocusHandle, FocusableView, ParentElement, Render, Styled, Subscription, Task, View, - ViewContext, VisualContext, WeakView, WindowContext, + ExternalPaths, FocusHandle, FocusableView, ParentElement, Render, Styled, Subscription, Task, + View, ViewContext, VisualContext, WeakView, WindowContext, }; use project::Fs; use serde::{Deserialize, Serialize}; @@ -64,6 +64,9 @@ impl TerminalPanel { return item.downcast::().is_some(); } } + if a.downcast_ref::().is_some() { + return true; + } false })), @@ -72,13 +75,6 @@ impl TerminalPanel { pane.set_can_split(false, cx); pane.set_can_navigate(false, cx); // todo!() - // pane.on_can_drop(move |drag_and_drop, cx| { - // drag_and_drop - // .currently_dragged::(window) - // .map_or(false, |(_, item)| { - // item.handle.act_as::(cx).is_some() - // }) - // }); // pane.set_render_tab_bar_buttons(cx, move |pane, cx| { // let this = weak_self.clone(); // Flex::row()