first version
This commit is contained in:
commit
5f771264e5
4 changed files with 4188 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
/target
|
4032
Cargo.lock
generated
Normal file
4032
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
[package]
|
||||||
|
name = "bookmarks-reader"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
eframe = "0.30.0"
|
||||||
|
egui_extras = "0.30.0"
|
||||||
|
rfd = { version = "0.15.2", features = ["gtk3"], default-features = false }
|
||||||
|
serde = "1.0.217"
|
||||||
|
serde_json = { version = "1.0.137", features = ["raw_value"] }
|
144
src/main.rs
Normal file
144
src/main.rs
Normal file
|
@ -0,0 +1,144 @@
|
||||||
|
use eframe::egui;
|
||||||
|
use serde_json::{Result, value::RawValue};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::BufReader;
|
||||||
|
use std::path::Path;
|
||||||
|
use egui_extras::{TableBuilder, Column};
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
#[derive(Clone, Deserialize, Serialize)]
|
||||||
|
struct Tweet {
|
||||||
|
id: String,
|
||||||
|
created_at: String,
|
||||||
|
full_text: String,
|
||||||
|
media: Vec<Box<RawValue>>,
|
||||||
|
screen_name: String,
|
||||||
|
name: Box<RawValue>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq)]
|
||||||
|
enum State {
|
||||||
|
NoFile, // au démarrage
|
||||||
|
FileLoading, // parsing du fichier
|
||||||
|
Loaded, // fichier parsé et pouvant être affiché
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
|
struct MyApp {
|
||||||
|
path_file: Option<PathBuf>,
|
||||||
|
tweets: Option<Vec<Tweet>>,
|
||||||
|
saved: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() -> eframe::Result {
|
||||||
|
//env_logger::init(); // Log to stderr (if you run with `RUST_LOG=debug`).
|
||||||
|
//
|
||||||
|
let native_options = eframe::NativeOptions {
|
||||||
|
viewport: egui::ViewportBuilder::default()
|
||||||
|
.with_inner_size([400.0, 300.0])
|
||||||
|
.with_min_inner_size([300.0, 220.0]),
|
||||||
|
/*
|
||||||
|
.with_icon(
|
||||||
|
eframe::icon_data::from_png_bytes(&include_bytes!("../assets/icon-256.png")[..])
|
||||||
|
.expect("Failed to load icon"),
|
||||||
|
),
|
||||||
|
*/
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
eframe::run_native(
|
||||||
|
"eframe template",
|
||||||
|
native_options,
|
||||||
|
//Box::new(|cc| Ok(Box::new(eframe_template::TemplateApp::new(cc)))),
|
||||||
|
Box::new(|_cc| Ok(Box::<MyApp>::default())),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl eframe::App for MyApp {
|
||||||
|
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
|
||||||
|
egui::CentralPanel::default().show(ctx, |ui| {
|
||||||
|
ui.label("Drag-and-drop files onto the window!");
|
||||||
|
|
||||||
|
if ui.button("Quitter").clicked() {
|
||||||
|
println!("Soon");
|
||||||
|
}
|
||||||
|
|
||||||
|
let tweets = self.tweets.clone();
|
||||||
|
|
||||||
|
if let Some(path) = &self.path_file {
|
||||||
|
if let Some(tweets) = &tweets {
|
||||||
|
if ui.button("Save").clicked() {
|
||||||
|
let mut file = File::create("pouet.json").unwrap();
|
||||||
|
if let Ok(_) = serde_json::to_writer_pretty(&file, tweets) {
|
||||||
|
self.saved = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.saved {
|
||||||
|
ui.label("Sauvgardé !");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut builder = TableBuilder::new(ui)
|
||||||
|
.min_scrolled_height(0.0)
|
||||||
|
.column(Column::auto())
|
||||||
|
.column(Column::auto())
|
||||||
|
.column(Column::auto())
|
||||||
|
.header(32.0, |mut header| {
|
||||||
|
header.col(|ui| {
|
||||||
|
ui.strong("URL");
|
||||||
|
});
|
||||||
|
|
||||||
|
header.col(|ui| {
|
||||||
|
ui.strong("Texte");
|
||||||
|
});
|
||||||
|
|
||||||
|
header.col(|ui| {
|
||||||
|
ui.strong("Supprimer");
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.body(|mut body| {
|
||||||
|
body.rows(64.0, tweets.len(), |mut row| {
|
||||||
|
let index = row.index();
|
||||||
|
row.col(|ui| {
|
||||||
|
let t = tweets.get(index).unwrap();
|
||||||
|
let mut tmp = String::from("https://twitter.com/");
|
||||||
|
tmp.push_str(&t.screen_name);
|
||||||
|
tmp.push_str("/status/");
|
||||||
|
tmp.push_str(&t.id);
|
||||||
|
ui.hyperlink_to("Tweet", tmp);
|
||||||
|
});
|
||||||
|
row.col(|ui| {
|
||||||
|
ui.label(tweets.get(index).unwrap().full_text.clone());
|
||||||
|
});
|
||||||
|
row.col(|ui| {
|
||||||
|
if ui.button("Supprimer").clicked() {
|
||||||
|
self.remove_tweet(index);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
ui.label("Loading file");
|
||||||
|
let file = File::open(path).unwrap();
|
||||||
|
let reader = BufReader::new(file);
|
||||||
|
self.tweets = serde_json::from_reader(reader).unwrap();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if ui.button("Open file").clicked() {
|
||||||
|
if let Some(path) = rfd::FileDialog::new().pick_file() {
|
||||||
|
self.path_file = Some(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MyApp {
|
||||||
|
fn remove_tweet(&mut self, index: usize) {
|
||||||
|
if let Some(ref mut tweets) = &mut self.tweets {
|
||||||
|
tweets.remove(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue