mirror of https://github.com/lapce/lapce.git
settings and key bindings
This commit is contained in:
parent
4d0ef4adc0
commit
6cab68ab36
|
@ -1029,14 +1029,7 @@ pub fn run_workbench_command(
|
|||
}
|
||||
}
|
||||
LapceWorkbenchCommand::OpenSettings => {
|
||||
self.main_split.open_settings(ctx);
|
||||
// let settings = Arc::make_mut(&mut self.settings);
|
||||
// settings.shown = true;
|
||||
// ctx.submit_command(Command::new(
|
||||
// LAPCE_UI_COMMAND,
|
||||
// LapceUICommand::ShowSettings,
|
||||
// Target::Widget(self.settings.panel_widget_id),
|
||||
// ));
|
||||
self.main_split.open_settings(ctx, false);
|
||||
}
|
||||
LapceWorkbenchCommand::OpenSettingsFile => {
|
||||
if let Some(path) = Config::settings_file() {
|
||||
|
@ -1054,11 +1047,7 @@ pub fn run_workbench_command(
|
|||
}
|
||||
}
|
||||
LapceWorkbenchCommand::OpenKeyboardShortcuts => {
|
||||
ctx.submit_command(Command::new(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::ShowKeybindings,
|
||||
Target::Widget(self.settings.panel_widget_id),
|
||||
));
|
||||
self.main_split.open_settings(ctx, true);
|
||||
}
|
||||
LapceWorkbenchCommand::OpenKeyboardShortcutsFile => {
|
||||
if let Some(path) = KeyPressData::file() {
|
||||
|
@ -2011,11 +2000,12 @@ fn editor_tab_new_settings(
|
|||
&mut self,
|
||||
_ctx: &mut EventCtx,
|
||||
editor_tab_id: WidgetId,
|
||||
) {
|
||||
) -> WidgetId {
|
||||
let editor_tab = self.editor_tabs.get_mut(&editor_tab_id).unwrap();
|
||||
let editor_tab = Arc::make_mut(editor_tab);
|
||||
let child = EditorTabChild::Settings(WidgetId::next(), editor_tab_id);
|
||||
editor_tab.children.push(child.clone());
|
||||
child.widget_id()
|
||||
}
|
||||
|
||||
fn editor_tab_new_editor(
|
||||
|
@ -2164,45 +2154,63 @@ pub fn jump_to_position(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn open_settings(&mut self, ctx: &mut EventCtx) {
|
||||
match *self.active_tab {
|
||||
pub fn open_settings(&mut self, ctx: &mut EventCtx, show_key_bindings: bool) {
|
||||
let widget_id = match *self.active_tab {
|
||||
Some(active) => {
|
||||
let editor_tab =
|
||||
Arc::make_mut(self.editor_tabs.get_mut(&active).unwrap());
|
||||
let mut existing: Option<WidgetId> = None;
|
||||
for (i, child) in editor_tab.children.iter().enumerate() {
|
||||
if let EditorTabChild::Settings(_, _) = child {
|
||||
ctx.submit_command(Command::new(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::Focus,
|
||||
Target::Widget(active),
|
||||
));
|
||||
editor_tab.active = i;
|
||||
return;
|
||||
existing = Some(child.widget_id());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let child =
|
||||
EditorTabChild::Settings(WidgetId::next(), editor_tab.widget_id);
|
||||
editor_tab
|
||||
.children
|
||||
.insert(editor_tab.active + 1, child.clone());
|
||||
ctx.submit_command(Command::new(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::EditorTabAdd(editor_tab.active + 1, child),
|
||||
Target::Widget(editor_tab.widget_id),
|
||||
));
|
||||
editor_tab.active += 1;
|
||||
if let Some(widget_id) = existing {
|
||||
widget_id
|
||||
} else {
|
||||
let child = EditorTabChild::Settings(
|
||||
WidgetId::next(),
|
||||
editor_tab.widget_id,
|
||||
);
|
||||
editor_tab
|
||||
.children
|
||||
.insert(editor_tab.active + 1, child.clone());
|
||||
ctx.submit_command(Command::new(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::EditorTabAdd(
|
||||
editor_tab.active + 1,
|
||||
child.clone(),
|
||||
),
|
||||
Target::Widget(editor_tab.widget_id),
|
||||
));
|
||||
editor_tab.active += 1;
|
||||
child.widget_id()
|
||||
}
|
||||
}
|
||||
None => {
|
||||
let editor_tab_id = self.new_editor_tab(ctx, *self.split_id);
|
||||
self.editor_tab_new_settings(ctx, editor_tab_id);
|
||||
self.editor_tab_new_settings(ctx, editor_tab_id)
|
||||
}
|
||||
}
|
||||
if let Some(active) = *self.active_tab {
|
||||
};
|
||||
ctx.submit_command(Command::new(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::Focus,
|
||||
Target::Widget(widget_id),
|
||||
));
|
||||
if show_key_bindings {
|
||||
ctx.submit_command(Command::new(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::Focus,
|
||||
Target::Widget(active),
|
||||
LapceUICommand::ShowKeybindings,
|
||||
Target::Widget(widget_id),
|
||||
));
|
||||
} else {
|
||||
ctx.submit_command(Command::new(
|
||||
LAPCE_UI_COMMAND,
|
||||
LapceUICommand::ShowSettings,
|
||||
Target::Widget(widget_id),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
data::{DragContent, EditorTabChild, LapceTabData},
|
||||
document::BufferContent,
|
||||
editor::TabRect,
|
||||
proxy::VERSION,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
@ -368,7 +369,7 @@ fn layout(
|
|||
}
|
||||
}
|
||||
EditorTabChild::Settings(_, _) => {
|
||||
text = "Settings".to_string();
|
||||
text = format!("Settings v{}", VERSION);
|
||||
}
|
||||
}
|
||||
let text_layout = ctx
|
||||
|
|
|
@ -86,7 +86,7 @@ fn mouse_down(
|
|||
&mut self,
|
||||
ctx: &mut EventCtx,
|
||||
mouse_event: &MouseEvent,
|
||||
_data: &mut LapceTabData,
|
||||
data: &mut LapceTabData,
|
||||
) {
|
||||
if self.switcher_rect.contains(mouse_event.pos) {
|
||||
let index = ((mouse_event.pos.y - self.switcher_rect.y0)
|
||||
|
@ -97,9 +97,14 @@ fn mouse_down(
|
|||
ctx.request_layout();
|
||||
}
|
||||
ctx.set_handled();
|
||||
ctx.request_focus();
|
||||
self.request_focus(ctx, data);
|
||||
}
|
||||
}
|
||||
|
||||
fn request_focus(&self, ctx: &mut EventCtx, data: &mut LapceTabData) {
|
||||
data.main_split.active_tab = Arc::new(Some(self.editor_tab_id));
|
||||
ctx.request_focus();
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget<LapceTabData> for LapceSettingsPanel {
|
||||
|
@ -154,10 +159,8 @@ fn event(
|
|||
let command = cmd.get_unchecked(LAPCE_UI_COMMAND);
|
||||
match command {
|
||||
LapceUICommand::Focus => {
|
||||
ctx.request_focus();
|
||||
ctx.set_handled();
|
||||
data.main_split.active_tab =
|
||||
Arc::new(Some(self.editor_tab_id));
|
||||
self.request_focus(ctx, data);
|
||||
}
|
||||
LapceUICommand::ShowSettings => {
|
||||
ctx.request_focus();
|
||||
|
|
Loading…
Reference in New Issue