Skip to content

Commit

Permalink
add problem panel
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhou121 committed Jan 12, 2022
1 parent a224a4c commit a502a2e
Show file tree
Hide file tree
Showing 11 changed files with 379 additions and 40 deletions.
15 changes: 1 addition & 14 deletions core/src/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,7 @@ impl Widget<LapceTabData> for ActivityBar {
.clone();
if let Some(panel) = data.panels.get(&PanelPosition::LeftTop) {
for (widget_id, kind) in panel.widgets.iter() {
let svg = match kind {
crate::data::PanelKind::FileExplorer => {
get_svg("file-explorer.svg").unwrap()
}
crate::data::PanelKind::SourceControl => {
get_svg("git-icon.svg").unwrap()
}
crate::data::PanelKind::Plugin => {
get_svg("plugin-icon.svg").unwrap()
}
crate::data::PanelKind::Terminal => {
get_svg("terminal.svg").unwrap()
}
};
let svg = kind.svg();
if &panel.active == widget_id {
ctx.fill(
Size::new(size, size)
Expand Down
12 changes: 12 additions & 0 deletions core/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ pub enum LapceWorkbenchCommand {
#[strum(serialize = "toggle_maximized_panel")]
ToggleMaximizedPanel,

#[strum(serialize = "toggle_source_control")]
ToggleSourceControl,

#[strum(serialize = "toggle_plugin")]
TogglePlugin,

#[strum(serialize = "toggle_file_explorer")]
ToggleFileExplorer,

#[strum(serialize = "toggle_problem")]
ToggleProblem,

#[strum(serialize = "focus_editor")]
FocusEditor,

Expand Down
95 changes: 89 additions & 6 deletions core/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crossbeam_channel::{bounded, unbounded, Receiver, Sender, TryRecvError};
use crossbeam_utils::sync::WaitGroup;
use directories::{ProjectDirs, UserDirs};
use druid::{
piet::{PietText, Text},
piet::{PietText, Svg, Text},
theme,
widget::{Label, LabelText},
Application, Color, Command, Data, Env, EventCtx, ExtEventSink, FontDescriptor,
Expand Down Expand Up @@ -71,9 +71,11 @@ use crate::{
palette::{PaletteData, PaletteType, PaletteViewData},
panel::PanelPosition,
plugin::PluginData,
problem::ProblemData,
proxy::{LapceProxy, ProxyHandlerNew, TermEvent},
source_control::{SourceControlData, SOURCE_CONTROL_BUFFER},
state::{LapceWorkspace, LapceWorkspaceType, Mode, VisualMode},
svg::get_svg,
terminal::TerminalSplitData,
};

Expand Down Expand Up @@ -208,12 +210,29 @@ pub struct EditorDiagnostic {
pub diagnositc: Diagnostic,
}

#[derive(Clone)]
#[derive(Clone, PartialEq, Data)]
pub enum PanelKind {
FileExplorer,
SourceControl,
Plugin,
Terminal,
Problem,
}

impl PanelKind {
pub fn svg_name(&self) -> String {
match &self {
PanelKind::FileExplorer => "file-explorer.svg".to_string(),
PanelKind::SourceControl => "git-icon.svg".to_string(),
PanelKind::Plugin => "plugin-icon.svg".to_string(),
PanelKind::Terminal => "terminal.svg".to_string(),
PanelKind::Problem => "error.svg".to_string(),
}
}

pub fn svg(&self) -> Svg {
get_svg(&self.svg_name()).unwrap()
}
}

#[derive(Clone)]
Expand Down Expand Up @@ -284,9 +303,8 @@ pub struct WorkProgress {
#[derive(Clone, PartialEq, Data)]
pub enum FocusArea {
Palette,
SourceControl,
Editor,
Terminal,
Panel(PanelKind),
}

#[derive(Clone, Lens)]
Expand All @@ -299,6 +317,7 @@ pub struct LapceTabData {
pub palette: Arc<PaletteData>,
pub find: Arc<Find>,
pub source_control: Arc<SourceControlData>,
pub problem: Arc<ProblemData>,
pub plugin: Arc<PluginData>,
pub plugins: Arc<Vec<PluginDescription>>,
pub installed_plugins: Arc<HashMap<String, PluginDescription>>,
Expand Down Expand Up @@ -339,6 +358,7 @@ impl Data for LapceTabData {
&& self.progresses.ptr_eq(&other.progresses)
&& self.file_explorer.same(&other.file_explorer)
&& self.plugin.same(&other.plugin)
&& self.problem.same(&other.problem)
&& self.installed_plugins.same(&other.installed_plugins)
}
}
Expand Down Expand Up @@ -393,6 +413,7 @@ impl LapceTabData {
);

let terminal = Arc::new(TerminalSplitData::new(proxy.clone()));
let problem = Arc::new(ProblemData::new());

let mut panels = im::HashMap::new();
panels.insert(
Expand All @@ -412,7 +433,10 @@ impl LapceTabData {
PanelPosition::BottomLeft,
Arc::new(PanelData {
active: terminal.widget_id,
widgets: vec![(terminal.widget_id, PanelKind::Terminal)],
widgets: vec![
(terminal.widget_id, PanelKind::Terminal),
(problem.widget_id, PanelKind::Problem),
],
shown: true,
maximized: false,
}),
Expand All @@ -425,6 +449,7 @@ impl LapceTabData {
completion,
terminal,
plugin,
problem,
plugins: Arc::new(Vec::new()),
installed_plugins: Arc::new(HashMap::new()),
find: Arc::new(Find::new(0)),
Expand Down Expand Up @@ -845,7 +870,7 @@ impl LapceTabData {
));
}
LapceWorkbenchCommand::ToggleTerminal => {
if self.focus_area == FocusArea::Terminal {
if self.focus_area == FocusArea::Panel(PanelKind::Terminal) {
for (_, panel) in self.panels.iter_mut() {
if panel
.widgets
Expand Down Expand Up @@ -911,6 +936,18 @@ impl LapceTabData {
Target::Widget(self.terminal.active),
));
}
LapceWorkbenchCommand::ToggleSourceControl => {
self.toggle_panel(
ctx,
self.source_control.widget_id,
PanelKind::SourceControl,
);
}
LapceWorkbenchCommand::TogglePlugin => {}
LapceWorkbenchCommand::ToggleFileExplorer => {}
LapceWorkbenchCommand::ToggleProblem => {
self.toggle_panel(ctx, self.problem.widget_id, PanelKind::Problem);
}
}
}

Expand Down Expand Up @@ -991,6 +1028,52 @@ impl LapceTabData {
}
}

fn toggle_panel(
&mut self,
ctx: &mut EventCtx,
widget_id: WidgetId,
kind: PanelKind,
) {
if self.focus_area == FocusArea::Panel(kind) {
for (_, panel) in self.panels.iter_mut() {
if panel
.widgets
.iter()
.map(|(id, kind)| *id)
.contains(&widget_id)
{
let panel = Arc::make_mut(panel);
panel.shown = false;
break;
}
}
ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
LapceUICommand::Focus,
Target::Widget(*self.main_split.active),
));
} else {
for (_, panel) in self.panels.iter_mut() {
if panel
.widgets
.iter()
.map(|(id, kind)| *id)
.contains(&widget_id)
{
let panel = Arc::make_mut(panel);
panel.shown = true;
panel.active = widget_id;
ctx.submit_command(Command::new(
LAPCE_UI_COMMAND,
LapceUICommand::Focus,
Target::Widget(widget_id),
));
break;
}
}
}
}

pub fn buffer_update_process(
tab_id: WidgetId,
receiver: Receiver<UpdateEvent>,
Expand Down
1 change: 1 addition & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod outline;
pub mod palette;
pub mod panel;
pub mod plugin;
pub mod problem;
pub mod proxy;
pub mod scroll;
pub mod signature;
Expand Down
4 changes: 2 additions & 2 deletions core/src/palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use crate::{
config::{Config, LapceTheme},
data::{
EditorContent, EditorKind, FocusArea, LapceEditorData, LapceEditorViewData,
LapceMainSplitData, LapceTabData,
LapceMainSplitData, LapceTabData, PanelKind,
},
editor::{EditorLocationNew, LapceEditorContainer, LapceEditorView},
find::Find,
Expand Down Expand Up @@ -859,7 +859,7 @@ impl PaletteViewData {
}

fn get_lines(&mut self, ctx: &mut EventCtx) {
if self.focus_area == FocusArea::Terminal {
if self.focus_area == FocusArea::Panel(PanelKind::Terminal) {
if let Some(terminal) =
self.terminal.terminals.get(&self.terminal.active_term_id)
{
Expand Down
107 changes: 107 additions & 0 deletions core/src/problem.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
use std::sync::Arc;

use druid::{
piet::{Text, TextAttribute, TextLayout as PietTextLayout, TextLayoutBuilder},
theme,
widget::{CrossAxisAlignment, Flex, FlexParams, Label, Scroll, SvgData},
Affine, BoxConstraints, Color, Command, Cursor, Data, Env, Event, EventCtx,
FontFamily, FontWeight, LayoutCtx, LifeCycle, LifeCycleCtx, MouseEvent,
PaintCtx, Point, Rect, RenderContext, Size, Target, TextLayout, UpdateCtx, Vec2,
Widget, WidgetExt, WidgetId, WidgetPod, WindowId,
};

use crate::{
command::{LapceUICommand, LAPCE_UI_COMMAND},
data::{FocusArea, LapceTabData, PanelKind},
};

pub struct ProblemData {
pub widget_id: WidgetId,
}

impl ProblemData {
pub fn new() -> Self {
Self {
widget_id: WidgetId::next(),
}
}
}

pub struct Problem {
pub widget_id: WidgetId,
}

impl Problem {
pub fn new(data: &LapceTabData) -> Self {
Self {
widget_id: data.problem.widget_id,
}
}

pub fn request_focus(&self, ctx: &mut EventCtx, data: &mut LapceTabData) {
ctx.request_focus();
data.focus = self.widget_id;
data.focus_area = FocusArea::Panel(PanelKind::Problem);
}
}

impl Widget<LapceTabData> for Problem {
fn id(&self) -> Option<WidgetId> {
Some(self.widget_id)
}

fn event(
&mut self,
ctx: &mut EventCtx,
event: &Event,
data: &mut LapceTabData,
env: &Env,
) {
match event {
Event::MouseDown(mouse_event) => {
self.request_focus(ctx, data);
}
Event::Command(cmd) if cmd.is(LAPCE_UI_COMMAND) => {
let command = cmd.get_unchecked(LAPCE_UI_COMMAND);
match command {
LapceUICommand::Focus => {
self.request_focus(ctx, data);
ctx.set_handled();
}
_ => (),
}
}
_ => (),
}
}

fn lifecycle(
&mut self,
ctx: &mut LifeCycleCtx,
event: &LifeCycle,
data: &LapceTabData,
env: &Env,
) {
}

fn update(
&mut self,
ctx: &mut UpdateCtx,
old_data: &LapceTabData,
data: &LapceTabData,
env: &Env,
) {
}

fn layout(
&mut self,
ctx: &mut LayoutCtx,
bc: &BoxConstraints,
data: &LapceTabData,
env: &Env,
) -> Size {
bc.max()
}

fn paint(&mut self, ctx: &mut PaintCtx, data: &LapceTabData, env: &Env) {}
}
7 changes: 4 additions & 3 deletions core/src/source_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use druid::{
use crate::{
command::{CommandTarget, LapceCommand, LapceUICommand, LAPCE_UI_COMMAND},
config::LapceTheme,
data::{FocusArea, LapceTabData},
data::{FocusArea, LapceTabData, PanelKind},
editor::{LapceEditorContainer, LapceEditorView},
keypress::KeyPressFocus,
movement::Movement,
Expand Down Expand Up @@ -330,7 +330,7 @@ impl Widget<LapceTabData> for SourceControlFileList {
}
ctx.request_focus();
source_control.active = self.widget_id;
data.focus_area = FocusArea::SourceControl;
data.focus_area = FocusArea::Panel(PanelKind::SourceControl);
ctx.set_handled();
}
Event::KeyDown(key_event) => {
Expand All @@ -355,7 +355,8 @@ impl Widget<LapceTabData> for SourceControlFileList {
let source_control =
Arc::make_mut(&mut data.source_control);
source_control.active = self.widget_id;
data.focus_area = FocusArea::SourceControl;
data.focus_area =
FocusArea::Panel(PanelKind::SourceControl);
ctx.request_focus();
}
ctx.set_handled();
Expand Down
Loading

0 comments on commit a502a2e

Please sign in to comment.