Skip to content

Commit 1ce47e1

Browse files
committed
Improved UI and profile management features
1 parent b9f6384 commit 1ce47e1

File tree

10 files changed

+564
-185
lines changed

10 files changed

+564
-185
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "stitch"
3-
version = "0.1.5"
3+
version = "0.1.6"
44
edition = "2024"
55
authors = ["Giovanni Ramistella <crimps-78-pax@icloud.com>"]
66
license = "MIT"

src/core/workspace.rs

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub enum ProfileScope {
3131
Local,
3232
}
3333

34-
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
34+
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
3535
pub struct ProfileSelection {
3636
/// Project-relative path using forward slashes.
3737
pub path: String,
@@ -134,11 +134,7 @@ pub fn save_workspace(project_root: &Path, settings: &WorkspaceSettings) -> io::
134134

135135
/* =============================== Profiles IO =============================== */
136136

137-
pub fn save_profile(
138-
project_root: &Path,
139-
profile: &Profile,
140-
scope: ProfileScope,
141-
) -> io::Result<()> {
137+
pub fn save_profile(project_root: &Path, profile: &Profile, scope: ProfileScope) -> io::Result<()> {
142138
ensure_profiles_dirs(project_root)?;
143139
let path = profile_path(project_root, scope, &profile.name);
144140
let tmp = path.with_extension("tmp");
@@ -151,40 +147,56 @@ pub fn save_profile(
151147
/// Returns (Profile, Scope) preferring Local if both exist.
152148
pub fn load_profile(project_root: &Path, name: &str) -> Option<(Profile, ProfileScope)> {
153149
let local = profile_path(project_root, ProfileScope::Local, name);
154-
if let Ok(bytes) = fs::read(&local) {
155-
if let Ok(p) = serde_json::from_slice::<Profile>(&bytes) {
156-
return Some((p, ProfileScope::Local));
157-
}
150+
if let Ok(bytes) = fs::read(&local)
151+
&& let Ok(p) = serde_json::from_slice::<Profile>(&bytes)
152+
{
153+
return Some((p, ProfileScope::Local));
158154
}
159155
let shared = profile_path(project_root, ProfileScope::Shared, name);
160-
if let Ok(bytes) = fs::read(&shared) {
161-
if let Ok(p) = serde_json::from_slice::<Profile>(&bytes) {
162-
return Some((p, ProfileScope::Shared));
163-
}
156+
if let Ok(bytes) = fs::read(&shared)
157+
&& let Ok(p) = serde_json::from_slice::<Profile>(&bytes)
158+
{
159+
return Some((p, ProfileScope::Shared));
164160
}
165161
None
166162
}
167163

164+
pub fn delete_profile(project_root: &Path, scope: ProfileScope, name: &str) -> io::Result<()> {
165+
let path = profile_path(project_root, scope, name);
166+
if path.exists() {
167+
// Best effort delete; ignore if it fails
168+
let _ = fs::remove_file(&path);
169+
}
170+
Ok(())
171+
}
172+
168173
/// Lists all profiles found. If a name exists in both scopes, only the Local one is returned.
169174
pub fn list_profiles(project_root: &Path) -> Vec<ProfileMeta> {
170175
fn scan(dir: &Path, scope: ProfileScope, out: &mut Vec<(String, ProfileScope)>) {
171176
if let Ok(rd) = fs::read_dir(dir) {
172177
for ent in rd.flatten() {
173-
if let Some(ext) = ent.path().extension() {
174-
if ext == "json" {
175-
if let Some(os) = ent.path().file_stem() {
176-
let name = os.to_string_lossy().to_string();
177-
out.push((name, scope));
178-
}
179-
}
178+
if let Some(ext) = ent.path().extension()
179+
&& ext == "json"
180+
&& let Some(os) = ent.path().file_stem()
181+
{
182+
let name = os.to_string_lossy().to_string();
183+
out.push((name, scope));
180184
}
181185
}
182186
}
183187
}
184188

185189
let mut raw: Vec<(String, ProfileScope)> = Vec::new();
186-
scan(&profiles_shared_dir(project_root), ProfileScope::Shared, &mut raw);
187-
scan(&profiles_local_dir(project_root), ProfileScope::Local, &mut raw);
190+
scan(
191+
&profiles_shared_dir(project_root),
192+
ProfileScope::Shared,
193+
&mut raw,
194+
);
195+
scan(
196+
&profiles_local_dir(project_root),
197+
ProfileScope::Local,
198+
&mut raw,
199+
);
188200

189201
// keep a single entry per name, preferring Local
190202
use std::collections::BTreeMap;

src/main.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ use slint::ComponentHandle;
1313
#[cfg(feature = "ui")]
1414
use ui::{
1515
AppState, AppWindow, Row, SelectFromTextDialog, apply_selection_from_text, on_check_updates,
16-
on_copy_output, on_filter_changed, on_generate_output, on_select_folder, on_toggle_check,
17-
on_toggle_expand, on_save_profile_as, on_select_profile, on_save_profile_current
16+
on_copy_output, on_filter_changed, on_generate_output, on_save_profile_as,
17+
on_save_profile_current, on_select_folder, on_select_profile, on_toggle_check,
18+
on_toggle_expand,
1819
};
1920

2021
#[cfg(feature = "ui")]
@@ -37,7 +38,9 @@ fn spawn_window(registry: Rc<RefCell<Vec<AppWindow>>>) -> anyhow::Result<()> {
3738
app.set_output_stats("0 chars • 0 tokens".into());
3839

3940
// Profiles UI defaults
40-
app.set_profiles(slint::ModelRc::new(slint::VecModel::from(Vec::<slint::SharedString>::new())));
41+
app.set_profiles(slint::ModelRc::new(slint::VecModel::from(Vec::<
42+
slint::SharedString,
43+
>::new())));
4144
app.set_selected_profile_index(-1);
4245

4346
let state = Rc::new(RefCell::new(AppState {
@@ -192,6 +195,25 @@ fn spawn_window(registry: Rc<RefCell<Vec<AppWindow>>>) -> anyhow::Result<()> {
192195
});
193196
}
194197

198+
{
199+
let app_weak = app.as_weak();
200+
let state = Rc::clone(&state);
201+
app.on_profile_name_changed(move || {
202+
if let Some(app) = app_weak.upgrade() {
203+
ui::on_profile_name_changed(&app, &state);
204+
}
205+
});
206+
}
207+
{
208+
let app_weak = app.as_weak();
209+
let state = Rc::clone(&state);
210+
app.on_delete_profile(move || {
211+
if let Some(app) = app_weak.upgrade() {
212+
ui::on_delete_profile(&app, &state);
213+
}
214+
});
215+
}
216+
195217
app.show()?;
196218
registry.borrow_mut().push(app);
197219

0 commit comments

Comments
 (0)