Moved UI strings in to separate file
This commit is contained in:
1 parent
0ca6c46d6b
commit
425c73da4f
12 files changed
+1139
-498
No files matched your search
+33
-33
@@ -20,6 +20,7 @@ use crate::effects::{Effect, FileOp};
|
||||
use crate::history::HistoryEntry;
|
||||
use crate::settings::Settings;
|
||||
use crate::state::*;
|
||||
use crate::strings as txt;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Action {
|
||||
@@ -281,7 +282,7 @@ pub fn update(state: &mut AppState, action: Action) -> Vec<Effect> {
|
||||
let src = f.request_source(0).unwrap_or("").to_string();
|
||||
new_tab(state, r, None, src);
|
||||
}
|
||||
None => state.set_error("No request in that text"),
|
||||
None => state.set_error(txt::msg::NO_REQUEST_IN_TEXT),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,10 +297,10 @@ pub fn update(state: &mut AppState, action: Action) -> Vec<Effect> {
|
||||
req.name = t.request.name.clone();
|
||||
}
|
||||
edit(state, id, |r| *r = req);
|
||||
state.set_info("Imported the curl command");
|
||||
state.set_info(txt::msg::CURL_IMPORTED);
|
||||
}
|
||||
Err(e) => {
|
||||
state.set_error(format!("Could not import curl command: {e}"));
|
||||
state.set_error(txt::msg::curl_import_failed(e));
|
||||
edit(state, id, |r| r.url = url);
|
||||
}
|
||||
}
|
||||
@@ -352,8 +353,8 @@ pub fn update(state: &mut AppState, action: Action) -> Vec<Effect> {
|
||||
t.request = r;
|
||||
t.source_error = None;
|
||||
}
|
||||
0 => t.source_error = Some("No request line found".into()),
|
||||
n => t.source_error = Some(format!("The source must contain exactly one request (found {n})")),
|
||||
0 => t.source_error = Some(txt::msg::NO_REQUEST_LINE.into()),
|
||||
n => t.source_error = Some(txt::msg::not_one_request(n)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -380,7 +381,7 @@ pub fn update(state: &mut AppState, action: Action) -> Vec<Effect> {
|
||||
if let Some(t) = state.tab_mut(id) {
|
||||
if let Some(f) = t.in_flight.take() {
|
||||
f.cancel.cancel();
|
||||
t.error = Some("Cancelled".into());
|
||||
t.error = Some(txt::msg::CANCELLED.into());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -448,11 +449,7 @@ pub fn update(state: &mut AppState, action: Action) -> Vec<Effect> {
|
||||
.iter()
|
||||
.find(|c| root.starts_with(&c.root) || c.root.starts_with(&root))
|
||||
{
|
||||
state.set_error(format!(
|
||||
"{} overlaps the open collection {}; close that one first",
|
||||
root.display(),
|
||||
other.root.display()
|
||||
));
|
||||
state.set_error(txt::msg::overlaps(root.display(), other.root.display()));
|
||||
return fx;
|
||||
}
|
||||
state.settings.add_recent(root.clone());
|
||||
@@ -500,7 +497,7 @@ pub fn update(state: &mut AppState, action: Action) -> Vec<Effect> {
|
||||
state.active_collection = Some(root);
|
||||
}
|
||||
}
|
||||
Action::CollectionLoaded(Err(e)) => state.set_error(format!("Could not open the collection: {e}")),
|
||||
Action::CollectionLoaded(Err(e)) => state.set_error(txt::msg::collection_failed(e)),
|
||||
Action::CollectionLoaded(Ok(c)) => collection_loaded(state, c, &mut fx),
|
||||
Action::EnvironmentsLoaded { root, result } => {
|
||||
if let Some(c) = state.collection_mut(&root) {
|
||||
@@ -548,11 +545,11 @@ pub fn update(state: &mut AppState, action: Action) -> Vec<Effect> {
|
||||
};
|
||||
let path = dir.join(name);
|
||||
if state.collection_of(&path).is_some_and(|c| c.files.contains_key(&path)) {
|
||||
state.set_error(format!("{} already exists", path.display()));
|
||||
state.set_error(txt::msg::already_exists(path.display()));
|
||||
return fx;
|
||||
}
|
||||
let req = Request {
|
||||
title: Some("New request".into()),
|
||||
title: Some(txt::common::NEW_REQUEST.into()),
|
||||
..Request::default()
|
||||
};
|
||||
let text = render_request(&req, "\n");
|
||||
@@ -564,7 +561,7 @@ pub fn update(state: &mut AppState, action: Action) -> Vec<Effect> {
|
||||
let Some(f) = file_of(state, &file) else { return fx };
|
||||
let n = f.request_count();
|
||||
let req = Request {
|
||||
title: Some(unique_title(f, "New request")),
|
||||
title: Some(unique_title(f, txt::common::NEW_REQUEST)),
|
||||
..Request::default()
|
||||
};
|
||||
let text = f.insert_request(None, &req);
|
||||
@@ -613,10 +610,10 @@ pub fn update(state: &mut AppState, action: Action) -> Vec<Effect> {
|
||||
let Some(src) = f.request_source(index) else { return fx };
|
||||
let orig = f.request(index).cloned().unwrap_or_default();
|
||||
// Re-title the copy so its key is unique.
|
||||
let base = orig.display_name().unwrap_or("Request").to_string();
|
||||
let base = orig.display_name().unwrap_or(txt::names::REQUEST).to_string();
|
||||
let mut copy = HttpFile::parse(src.to_string());
|
||||
let mut r = copy.request(0).cloned().unwrap_or_default();
|
||||
r.title = Some(unique_title(f, &format!("{base} copy")));
|
||||
r.title = Some(unique_title(f, &txt::names::copy_of(&base)));
|
||||
r.name = r.name.as_ref().map(|_| slug_name(r.title.as_deref().unwrap()));
|
||||
if let Some(t) = copy.replace_request(0, &r) {
|
||||
copy = HttpFile::parse(t);
|
||||
@@ -724,8 +721,8 @@ pub fn update(state: &mut AppState, action: Action) -> Vec<Effect> {
|
||||
.unwrap_or("http".into());
|
||||
let dir = path.parent().map(Path::to_path_buf).unwrap_or_default();
|
||||
let taken = |p: &PathBuf| state.collection_of(p).is_some_and(|c| c.files.contains_key(p));
|
||||
let copy = std::iter::once(dir.join(format!("{stem} copy.{ext}")))
|
||||
.chain((2..).map(|n| dir.join(format!("{stem} copy {n}.{ext}"))))
|
||||
let copy = std::iter::once(dir.join(txt::names::file_copy(&stem, &ext)))
|
||||
.chain((2..).map(|n| dir.join(txt::names::file_copy_n(&stem, n, &ext))))
|
||||
.find(|p| !taken(p))
|
||||
.unwrap();
|
||||
fx.push(file_ops(state, vec![FileOp::Write(copy.clone(), text.clone())], true));
|
||||
@@ -801,7 +798,7 @@ pub fn update(state: &mut AppState, action: Action) -> Vec<Effect> {
|
||||
dirty: false,
|
||||
});
|
||||
} else {
|
||||
state.set_error("Open a collection folder first; environments live next to the .http files");
|
||||
state.set_error(txt::msg::NEED_COLLECTION_FOR_ENVS);
|
||||
}
|
||||
}
|
||||
Action::EnvEditorChanged(e) => state.env_editor = Some(e),
|
||||
@@ -850,9 +847,9 @@ pub fn update(state: &mut AppState, action: Action) -> Vec<Effect> {
|
||||
) {
|
||||
Ok(r) => {
|
||||
fx.push(Effect::CopyToClipboard(to_curl(&r)));
|
||||
state.set_info("Copied as curl");
|
||||
state.set_info(txt::msg::COPIED_CURL);
|
||||
}
|
||||
Err(e) => state.set_error(format!("Cannot build the curl command: {e}")),
|
||||
Err(e) => state.set_error(txt::msg::curl_failed(e)),
|
||||
}
|
||||
}
|
||||
Action::CopyAsHttp(id) => {
|
||||
@@ -863,7 +860,7 @@ pub fn update(state: &mut AppState, action: Action) -> Vec<Effect> {
|
||||
t.source.clone()
|
||||
};
|
||||
fx.push(Effect::CopyToClipboard(text));
|
||||
state.set_info("Copied as .http");
|
||||
state.set_info(txt::msg::COPIED_HTTP);
|
||||
}
|
||||
Action::ImportPostman => fx.push(Effect::PickPostmanImport),
|
||||
Action::PostmanImported { root, files, warnings } => {
|
||||
@@ -1065,7 +1062,7 @@ fn send(state: &mut AppState, id: TabId, fx: &mut Vec<Effect>) {
|
||||
if let Some(e) = &t.source_error {
|
||||
let e = e.clone();
|
||||
if let Some(t) = state.tab_mut(id) {
|
||||
t.error = Some(format!("Fix the source first: {e}"));
|
||||
t.error = Some(txt::msg::fix_source(e));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -1426,7 +1423,10 @@ fn unique_title(f: &HttpFile, base: &str) -> String {
|
||||
if !taken(base) {
|
||||
return base.to_string();
|
||||
}
|
||||
(2..).map(|n| format!("{base} {n}")).find(|t| !taken(t)).unwrap()
|
||||
(2..)
|
||||
.map(|n| txt::names::numbered(base, n))
|
||||
.find(|t| !taken(t))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn slug_name(title: &str) -> String {
|
||||
@@ -1621,23 +1621,23 @@ fn apply_consolidation(state: &mut AppState, plan: ConsolidateAuth, fx: &mut Vec
|
||||
settings.auth = FolderAuth::Header(target.clone());
|
||||
ops.push(FileOp::Write(folder::settings_path(&plan.dir), settings.to_json()));
|
||||
c.folders.insert(plan.dir.clone(), settings);
|
||||
msg.push(format!("set the folder auth to `{target}`"));
|
||||
msg.push(txt::consolidate::set_folder(target));
|
||||
}
|
||||
}
|
||||
if dropped > 0 {
|
||||
msg.push(format!("{dropped} request(s) now inherit it"));
|
||||
msg.push(txt::consolidate::dropped(dropped));
|
||||
}
|
||||
if pinned > 0 {
|
||||
msg.push(format!("{pinned} request(s) keep their auth explicitly"));
|
||||
msg.push(txt::consolidate::pinned(pinned));
|
||||
}
|
||||
if !plan.skipped_dirty.is_empty() {
|
||||
msg.push(format!("{} with unsaved edits skipped", plan.skipped_dirty.len()));
|
||||
msg.push(txt::consolidate::skipped(plan.skipped_dirty.len()));
|
||||
}
|
||||
if !ops.is_empty() {
|
||||
fx.push(Effect::FileOps { ops, rescan: None });
|
||||
}
|
||||
if msg.is_empty() {
|
||||
state.set_info("Auth: nothing to change");
|
||||
state.set_info(txt::consolidate::NOTHING_TO_CHANGE);
|
||||
} else {
|
||||
let mut text = msg.join(", ");
|
||||
text[..1].make_ascii_uppercase();
|
||||
@@ -1649,7 +1649,7 @@ fn save(state: &mut AppState, id: TabId, fx: &mut Vec<Effect>) {
|
||||
let Some(t) = state.tab(id) else { return };
|
||||
if let Some(e) = &t.source_error {
|
||||
let e = e.clone();
|
||||
state.set_error(format!("Cannot save: {e}"));
|
||||
state.set_error(txt::msg::cannot_save(e));
|
||||
return;
|
||||
}
|
||||
let Some(origin) = t.origin.clone() else {
|
||||
@@ -1657,11 +1657,11 @@ fn save(state: &mut AppState, id: TabId, fx: &mut Vec<Effect>) {
|
||||
return;
|
||||
};
|
||||
let Some(f) = file_of(state, &origin.file) else {
|
||||
state.set_error(format!("{} is not loaded", origin.file.display()));
|
||||
state.set_error(txt::msg::not_loaded(origin.file.display()));
|
||||
return;
|
||||
};
|
||||
let Some(index) = f.find(&origin.key) else {
|
||||
state.set_error("The request is no longer in its file; use Save As");
|
||||
state.set_error(txt::msg::NO_LONGER_IN_FILE);
|
||||
return;
|
||||
};
|
||||
let new_text = if t.source_authoritative {
|
||||
|
||||
Reference in new issue
Block a user