Skip to content

Commit 68fe256

Browse files
committed
strings: Common string context menu
1 parent b48a01c commit 68fe256

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

src/gui/common.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ pub trait ResponseExt {
2121
texture_cache: Option<&TextureCache>,
2222
is_texture: bool,
2323
) -> Self;
24+
25+
fn string_context(self, s: &str, hash: Option<u32>) -> Self;
2426
}
2527

2628
impl ResponseExt for egui::Response {
@@ -76,6 +78,23 @@ impl ResponseExt for egui::Response {
7678
tag_hover_ui(ui, tag);
7779
})
7880
}
81+
82+
fn string_context(self, string: &str, hash: Option<u32>) -> Self {
83+
self.context_menu(|ui| {
84+
if ui.selectable_label(false, "Copy string").clicked() {
85+
ui.ctx().copy_text(string.to_string());
86+
ui.close();
87+
}
88+
if let Some(hash) = hash
89+
&& ui.selectable_label(false, "Copy hash").clicked()
90+
{
91+
ui.ctx().copy_text(format!("{:08X}", hash));
92+
ui.close();
93+
}
94+
});
95+
96+
self
97+
}
7998
}
8099

81100
pub fn export_texture(texture_cache: &TextureCache, tag: TagHash) {

src/gui/raw_strings.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl View for RawStringsView {
111111
string_height,
112112
self.strings_vec_filtered.len(),
113113
|ui, range| {
114-
for (i, string, tags, _hash) in self.strings_vec_filtered[range].iter() {
114+
for (i, string, tags, hash) in self.strings_vec_filtered[range].iter() {
115115
let response = ui.selectable_label(
116116
*i == self.selected_stringset,
117117
format!(
@@ -129,12 +129,9 @@ impl View for RawStringsView {
129129
self.selected_stringset = *i;
130130
}
131131

132-
response.on_hover_text(string).context_menu(|ui| {
133-
if ui.selectable_label(false, "Copy string").clicked() {
134-
ui.ctx().copy_text(string.clone());
135-
ui.close();
136-
}
137-
});
132+
response
133+
.on_hover_text(string)
134+
.string_context(string, Some(*hash));
138135
}
139136
},
140137
);

src/gui/strings.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,7 @@ impl View for StringsView {
328328
}
329329
}
330330

331-
response.context_menu(|ui| {
332-
if ui.selectable_label(false, "Copy string").clicked() {
333-
ui.ctx().copy_text(strings[0].clone());
334-
ui.close();
335-
}
336-
});
331+
response.string_context(&strings[0], Some(*hash));
337332
}
338333
},
339334
);

src/gui/tag.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,7 @@ impl View for TagView {
11471147
),
11481148
)
11491149
.on_hover_text(strings.join("\n"))
1150+
.string_context(&strings[0], Some(*hash))
11501151
.clicked();
11511152
} else {
11521153
ui.selectable_label(
@@ -1156,6 +1157,7 @@ impl View for TagView {
11561157
strings[0], hash, offset
11571158
),
11581159
)
1160+
.string_context(&strings[0], Some(*hash))
11591161
.clicked();
11601162
}
11611163
}
@@ -1271,7 +1273,8 @@ impl View for TagView {
12711273
.iter()
12721274
.map(|(s, _)| s)
12731275
.join("\n"),
1274-
);
1276+
)
1277+
.string_context(&strings[0].0, Some(*hash));
12751278

12761279
(response, strings[current_string].1)
12771280
} else {
@@ -1287,7 +1290,8 @@ impl View for TagView {
12871290
strings[0].0, hash, offset
12881291
))
12891292
.color(color),
1290-
);
1293+
)
1294+
.string_context(&strings[0].0, Some(*hash));
12911295

12921296
(response, strings[0].1)
12931297
};

0 commit comments

Comments
 (0)