completion color

This commit is contained in:
Dongdong Zhou 2021-09-28 12:36:39 +01:00
parent 12785c2fae
commit 8886b8053b
7 changed files with 100 additions and 11 deletions

17
Cargo.lock generated
View File

@ -1025,7 +1025,7 @@ checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]]
name = "druid"
version = "0.7.0"
source = "git+https://github.com/lapce/druid#e121a48816c6b9b742d6fb941a8da0abf10123e3"
source = "git+https://github.com/lapce/druid#fa80c9289a64857d492d619a40158cb116cfb9f3"
dependencies = [
"console_error_panic_hook",
"druid-derive",
@ -1049,7 +1049,7 @@ dependencies = [
[[package]]
name = "druid-derive"
version = "0.4.0"
source = "git+https://github.com/lapce/druid#e121a48816c6b9b742d6fb941a8da0abf10123e3"
source = "git+https://github.com/lapce/druid#fa80c9289a64857d492d619a40158cb116cfb9f3"
dependencies = [
"proc-macro2 1.0.29",
"quote 1.0.9",
@ -1059,7 +1059,7 @@ dependencies = [
[[package]]
name = "druid-shell"
version = "0.7.0"
source = "git+https://github.com/lapce/druid#e121a48816c6b9b742d6fb941a8da0abf10123e3"
source = "git+https://github.com/lapce/druid#fa80c9289a64857d492d619a40158cb116cfb9f3"
dependencies = [
"anyhow",
"bitflags",
@ -2149,6 +2149,7 @@ dependencies = [
"serde_json",
"strum 0.19.5",
"strum_macros 0.19.4",
"tinyfiledialogs",
"toml 0.5.8 (git+https://github.com/lapce/toml-rs)",
"tree-sitter",
"tree-sitter-highlight",
@ -4233,6 +4234,16 @@ dependencies = [
"syn 1.0.75",
]
[[package]]
name = "tinyfiledialogs"
version = "3.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9545b2375cbcb7a7d70cca5e92fbaa096fd89bebd2fbc54a3da7f37d15a54e6b"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "tinystr"
version = "0.3.4"

View File

@ -5,6 +5,7 @@ authors = ["Dongdong Zhou <dzhou121@gmail.com>"]
edition = "2018"
[dependencies]
tinyfiledialogs = "3.8.3"
itertools = "0.10.1"
unicode-width = "0.1.8"
unicode-segmentation = "1.7.1"

View File

@ -259,9 +259,13 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) {
}
let rect = ctx.size().to_rect();
let blur_color = Color::grey8(180);
let shadow_width = 5.0;
ctx.blurred_rect(rect, shadow_width, &blur_color);
ctx.blurred_rect(
rect,
shadow_width,
data.config
.get_color_unchecked(LapceTheme::LAPCE_DROPDOWN_SHADOW),
);
ctx.fill(
rect,
data.config

View File

@ -700,8 +700,7 @@ fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) {
let y = line_height * line as f64 + 5.0;
if let Some((svg, color)) =
completion_svg(item.item.kind, data.theme.clone())
if let Some((svg, color)) = completion_svg(item.item.kind, &data.config)
{
let color = color.unwrap_or(
data.config

View File

@ -79,7 +79,9 @@ fn string(&self) -> String {
fn has_preview(&self) -> bool {
match &self {
PaletteType::File | PaletteType::Workspace => false,
PaletteType::File | PaletteType::Workspace | PaletteType::Command => {
false
}
_ => true,
}
}
@ -111,6 +113,7 @@ pub enum PaletteItemContent {
},
ReferenceLocation(PathBuf, EditorLocationNew),
Workspace(LapceWorkspace),
Command(LapceCommand),
}
impl PaletteItemContent {
@ -175,6 +178,35 @@ fn select(&self, ctx: &mut EventCtx, preview: bool) {
));
}
}
PaletteItemContent::Command(command) => {
if !preview {
match command {
LapceCommand::OpenFolder => {
let event_sink = ctx.get_external_handle();
thread::spawn(move || {
if let Some(folder) =
tinyfiledialogs::select_folder_dialog(
"Open folder",
"./",
)
{
event_sink.submit_command(
LAPCE_UI_COMMAND,
LapceUICommand::SetWorkspace(
LapceWorkspace {
kind: LapceWorkspaceType::Local,
path: PathBuf::from(folder),
},
),
Target::Auto,
);
}
});
}
_ => (),
}
}
}
}
}
@ -236,6 +268,13 @@ fn paint(
};
(None, text, indices.to_vec(), "".to_string(), vec![])
}
PaletteItemContent::Command(command) => (
None,
command.to_string(),
indices.to_vec(),
"".to_string(),
vec![],
),
};
if let Some(svg) = svg.as_ref() {
@ -564,6 +603,9 @@ pub fn run(&mut self, ctx: &mut EventCtx, palette_type: Option<PaletteType>) {
self.get_workspaces(ctx);
}
&PaletteType::Reference => {}
&PaletteType::Command => {
self.get_commands(ctx);
}
_ => self.get_files(ctx),
}
}
@ -774,6 +816,16 @@ fn get_workspaces(&mut self, ctx: &mut EventCtx) {
.collect();
}
fn get_commands(&mut self, ctx: &mut EventCtx) {
let palette = Arc::make_mut(&mut self.palette);
palette.items = vec![NewPaletteItem {
content: PaletteItemContent::Command(LapceCommand::OpenFolder),
filter_text: "Open Folder".to_string(),
score: 0,
indices: vec![],
}];
}
fn get_lines(&mut self, ctx: &mut EventCtx) {
let editor = self.main_split.active_editor();
let buffer = self.main_split.open_files.get(&editor.buffer).unwrap();

View File

@ -13,6 +13,8 @@
use parking_lot::Mutex;
use usvg;
use crate::config::Config;
pub const ICONS_DIR: Dir = include_dir!("../icons");
lazy_static! {
static ref SVG_STORE: SvgStore = SvgStore::new();
@ -85,7 +87,7 @@ pub fn symbol_svg_new(kind: &SymbolKind) -> Option<Svg> {
pub fn completion_svg(
kind: Option<CompletionItemKind>,
theme: Arc<HashMap<String, Color>>,
config: &Config,
) -> Option<(Svg, Option<Color>)> {
let kind = kind?;
let kind_str = match kind {
@ -113,6 +115,8 @@ pub fn completion_svg(
Some((
get_svg(&format!("symbol-{}.svg", kind_str))?,
theme.get(theme_str).map(|c| c.clone()),
config
.get_color(&("style.".to_string() + theme_str))
.map(|c| c.clone()),
))
}

View File

@ -3,7 +3,7 @@
use druid::{
theme, BoxConstraints, Color, Command, Cursor, Data, Env, Event, EventCtx,
Insets, LayoutCtx, LifeCycle, LifeCycleCtx, PaintCtx, Point, RenderContext,
Size, Target, Widget, WidgetExt, WidgetId, WidgetPod,
Size, Target, Widget, WidgetExt, WidgetId, WidgetPod, WindowConfig,
};
use lsp_types::{CallHierarchyOptions, DiagnosticSeverity};
@ -389,6 +389,24 @@ fn event(
| LapceUICommand::CancelCodeActions => {
self.code_action.event(ctx, event, data, env);
}
LapceUICommand::FocusTab => {
let dir = data
.workspace
.as_ref()
.map(|w| {
let dir =
w.path.file_name().unwrap().to_str().unwrap();
let dir = match &w.kind {
LapceWorkspaceType::Local => dir.to_string(),
LapceWorkspaceType::RemoteSSH(user, host) => {
format!("{} [{}@{}]", dir, user, host)
}
};
dir
})
.unwrap_or("Lapce".to_string());
ctx.configure_window(WindowConfig::default().set_title(dir));
}
LapceUICommand::UpdateStyle {
id,
path,