feat: Make the encoding indicator appear only when an editor is open.
feat: Enable the user to choose whether or not the encoding indicator should be displayed by enabling or disabling `encoding_indicator` in `settings.json`
This commit is contained in:
parent
a3f5e91f0f
commit
3b20229fa1
6 changed files with 34 additions and 9 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -5282,6 +5282,7 @@ dependencies = [
|
|||
"gpui",
|
||||
"language",
|
||||
"picker",
|
||||
"settings",
|
||||
"ui",
|
||||
"util",
|
||||
"workspace",
|
||||
|
|
|
@ -1258,7 +1258,9 @@
|
|||
// Whether to show the active language button in the status bar.
|
||||
"active_language_button": true,
|
||||
// Whether to show the cursor position button in the status bar.
|
||||
"cursor_position_button": true
|
||||
"cursor_position_button": true,
|
||||
// Whether to show the encoding indicator in the status bar.
|
||||
"encoding_indicator": true
|
||||
},
|
||||
// Settings specific to the terminal
|
||||
"terminal": {
|
||||
|
|
|
@ -136,6 +136,11 @@ pub struct StatusBar {
|
|||
///
|
||||
/// Default: true
|
||||
pub cursor_position_button: bool,
|
||||
|
||||
/// Whether to show the encoding indicator in the status bar.
|
||||
///
|
||||
/// Default: true
|
||||
pub encoding_indicator: bool,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
|
||||
|
@ -593,6 +598,10 @@ pub struct StatusBarContent {
|
|||
///
|
||||
/// Default: true
|
||||
pub cursor_position_button: Option<bool>,
|
||||
/// Whether to show the encoding indicator in the status bar.
|
||||
///
|
||||
/// Default: true
|
||||
pub encoding_indicator: Option<bool>,
|
||||
}
|
||||
|
||||
// Toolbar related settings
|
||||
|
|
|
@ -6,15 +6,16 @@ edition.workspace = true
|
|||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
ui.workspace = true
|
||||
workspace.workspace = true
|
||||
gpui.workspace = true
|
||||
picker.workspace = true
|
||||
util.workspace = true
|
||||
fuzzy.workspace = true
|
||||
editor.workspace = true
|
||||
encoding.workspace = true
|
||||
fuzzy.workspace = true
|
||||
gpui.workspace = true
|
||||
language.workspace = true
|
||||
picker.workspace = true
|
||||
settings.workspace = true
|
||||
ui.workspace = true
|
||||
util.workspace = true
|
||||
workspace.workspace = true
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
///! A crate for handling file encodings in the text editor.
|
||||
use editor::Editor;
|
||||
use editor::{Editor, EditorSettings};
|
||||
use encoding::Encoding;
|
||||
use encoding::all::{
|
||||
BIG5_2003, EUC_JP, GB18030, GBK, HZ, IBM866, ISO_2022_JP, ISO_8859_1, ISO_8859_2, ISO_8859_3,
|
||||
|
@ -9,6 +9,7 @@ use encoding::all::{
|
|||
WINDOWS_1253, WINDOWS_1254, WINDOWS_1255, WINDOWS_1256, WINDOWS_1257, WINDOWS_1258,
|
||||
};
|
||||
use gpui::{ClickEvent, Entity, Subscription, WeakEntity};
|
||||
use settings::Settings;
|
||||
use ui::{Button, ButtonCommon, Context, LabelSize, Render, Tooltip, Window, div};
|
||||
use ui::{Clickable, ParentElement};
|
||||
use workspace::{ItemHandle, StatusItemView, Workspace};
|
||||
|
@ -20,6 +21,7 @@ pub struct EncodingIndicator {
|
|||
pub encoding: Option<&'static dyn Encoding>,
|
||||
pub workspace: WeakEntity<Workspace>,
|
||||
observe: Option<Subscription>, // Subscription to observe changes in the active editor
|
||||
show: bool,
|
||||
}
|
||||
|
||||
pub mod selectors;
|
||||
|
@ -28,6 +30,12 @@ impl Render for EncodingIndicator {
|
|||
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl ui::IntoElement {
|
||||
let status_element = div();
|
||||
|
||||
if (EditorSettings::get_global(cx).status_bar.encoding_indicator == false)
|
||||
|| (self.show == false)
|
||||
{
|
||||
return status_element;
|
||||
}
|
||||
|
||||
status_element.child(
|
||||
Button::new("encoding", encoding_name(self.encoding.unwrap_or(UTF_8)))
|
||||
.label_size(LabelSize::Small)
|
||||
|
@ -54,6 +62,7 @@ impl EncodingIndicator {
|
|||
encoding,
|
||||
workspace,
|
||||
observe,
|
||||
show: true,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,10 +93,12 @@ impl StatusItemView for EncodingIndicator {
|
|||
Some(editor) => {
|
||||
self.observe = Some(cx.observe_in(&editor, window, Self::update));
|
||||
self.update(editor, window, cx);
|
||||
self.show = true;
|
||||
}
|
||||
None => {
|
||||
self.encoding = None;
|
||||
self.observe = None;
|
||||
self.show = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1278,7 +1278,8 @@ Each option controls displaying of a particular toolbar element. If all elements
|
|||
```json
|
||||
"status_bar": {
|
||||
"active_language_button": true,
|
||||
"cursor_position_button": true
|
||||
"cursor_position_button": true,
|
||||
"encoding_indicator": true,
|
||||
},
|
||||
```
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue