Add document statistics
This commit is contained in:
parent
aee972e171
commit
90d2fead9c
3 changed files with 57 additions and 2 deletions
|
|
@ -3,6 +3,13 @@ open-project = Open project
|
|||
|
||||
# Context Pages
|
||||
|
||||
## Document statistics
|
||||
document-statistics = Document statistics
|
||||
word-count = Word count
|
||||
character-count = Characters
|
||||
character-count-no-spaces = Characters (without spaces)
|
||||
line-count = Lines
|
||||
|
||||
## Settings
|
||||
settings = Settings
|
||||
|
||||
|
|
@ -22,7 +29,7 @@ todo = TODO
|
|||
save = Save
|
||||
save-as = Save as...
|
||||
revert-all-changes = Revert all changes
|
||||
document-statistics = Document statistics...
|
||||
menu-document-statistics = Document statistics...
|
||||
document-type = Document type...
|
||||
encoding = Encoding...
|
||||
print = Print
|
||||
|
|
|
|||
45
src/main.rs
45
src/main.rs
|
|
@ -86,12 +86,14 @@ pub enum Message {
|
|||
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum ContextPage {
|
||||
DocumentStatistics,
|
||||
Settings,
|
||||
}
|
||||
|
||||
impl ContextPage {
|
||||
fn title(&self) -> String {
|
||||
match self {
|
||||
Self::DocumentStatistics => fl!("document-statistics"),
|
||||
Self::Settings => fl!("settings"),
|
||||
}
|
||||
}
|
||||
|
|
@ -598,6 +600,49 @@ impl cosmic::Application for App {
|
|||
}
|
||||
|
||||
Some(match self.context_page {
|
||||
ContextPage::DocumentStatistics => {
|
||||
//TODO: calculate in the background
|
||||
let mut character_count = 0;
|
||||
let mut character_count_no_spaces = 0;
|
||||
let line_count;
|
||||
match self.active_tab() {
|
||||
Some(tab) => {
|
||||
let editor = tab.editor.lock().unwrap();
|
||||
let buffer = editor.buffer();
|
||||
|
||||
line_count = buffer.lines.len();
|
||||
for line in buffer.lines.iter() {
|
||||
//TODO: do graphemes?
|
||||
for c in line.text().chars() {
|
||||
character_count += 1;
|
||||
if !c.is_whitespace() {
|
||||
character_count_no_spaces += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
widget::settings::view_column(vec![widget::settings::view_section("")
|
||||
.add(widget::settings::item::builder(fl!("word-count")).control("TODO"))
|
||||
.add(
|
||||
widget::settings::item::builder(fl!("character-count"))
|
||||
.control(widget::text(character_count.to_string())),
|
||||
)
|
||||
.add(
|
||||
widget::settings::item::builder(fl!("character-count-no-spaces"))
|
||||
.control(widget::text(character_count_no_spaces.to_string())),
|
||||
)
|
||||
.add(
|
||||
widget::settings::item::builder(fl!("line-count"))
|
||||
.control(widget::text(line_count.to_string())),
|
||||
)
|
||||
.into()])
|
||||
.into()
|
||||
}
|
||||
ContextPage::Settings => {
|
||||
widget::settings::view_column(vec![widget::settings::view_section(fl!(
|
||||
"keyboard-shortcuts"
|
||||
|
|
|
|||
|
|
@ -110,7 +110,10 @@ pub fn menu_bar<'a>(config: &Config) -> Element<'a, Message> {
|
|||
MenuTree::new(horizontal_rule(1)),
|
||||
menu_item(fl!("revert-all-changes"), Message::Todo),
|
||||
MenuTree::new(horizontal_rule(1)),
|
||||
menu_item(fl!("document-statistics"), Message::Todo),
|
||||
menu_item(
|
||||
fl!("menu-document-statistics"),
|
||||
Message::ToggleContextPage(ContextPage::DocumentStatistics),
|
||||
),
|
||||
menu_item(fl!("document-type"), Message::Todo),
|
||||
menu_item(fl!("encoding"), Message::Todo),
|
||||
menu_item(fl!("print"), Message::Todo),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue