Skip to content

Commit 20e4df2

Browse files
Jeremy WoottenJeremy Wootten
authored andcommitted
Use ngettext for dialog text
1 parent c421b02 commit 20e4df2

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

src/Dialogs/CloseProjectsConfirmationDialog.vala

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,50 @@
1818

1919
public class Scratch.Dialogs.CloseProjectsConfirmationDialog : Granite.MessageDialog {
2020

21-
public CloseProjectsConfirmationDialog (MainWindow parent) {
21+
public uint n_parents { get; construct; }
22+
public uint n_children { get; construct; }
23+
24+
public CloseProjectsConfirmationDialog (MainWindow parent, uint n_parents, uint n_children) {
2225
Object (
2326
buttons: Gtk.ButtonsType.NONE,
24-
transient_for: parent
27+
transient_for: parent,
28+
n_parents: n_parents,
29+
n_children: n_children
2530
);
2631
}
2732

2833
construct {
2934
image_icon = new ThemedIcon ("dialog-warning");
35+
var button_label = "";
36+
// We can assume that either n_parents or n_children is zero (but not both).
37+
// We can assume n_parents is either zero or one
38+
if (n_children > 0) {
39+
primary_text = ngettext (
40+
_("This folder is the parent of an open project"),
41+
_("This folder is the parent of %u open projects").printf (n_children),
42+
(ulong) n_children
43+
);
44+
;
45+
secondary_text = ngettext (
46+
_("Opening this folder will close the child project"),
47+
_("Opening this folder will close all child projects"),
48+
(ulong) n_children
49+
);
3050

31-
primary_text = _("This folder is a parent or child of an existing open project");
32-
secondary_text = _("Opening this folder will close all parent or child projects");
51+
button_label = ngettext (
52+
_("Close Child Project"),
53+
_("Close Child Projects"),
54+
(ulong) n_children
55+
);
56+
} else {
57+
primary_text = _("This folder is a child of an open project");
58+
secondary_text = _("Opening this folder will close the parent project");
59+
button_label = _("Close Parent Project");
60+
}
3361

3462
add_button (_("Don't Open"), Gtk.ResponseType.REJECT);
3563

36-
var ignore_button = (Gtk.Button) add_button (_("Close Other Projects"), Gtk.ResponseType.ACCEPT);
64+
var ignore_button = (Gtk.Button) add_button (button_label, Gtk.ResponseType.ACCEPT);
3765
ignore_button.get_style_context ().add_class (Gtk.STYLE_CLASS_DESTRUCTIVE_ACTION);
3866
}
3967
}

src/FolderManager/FileView.vala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -522,16 +522,22 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
522522
foreach (var child in root.children) {
523523
var item = (ProjectFolderItem) child;
524524
if (add_file.get_relative_path (item.file.file) != null) {
525-
critical ("Trying to add parent of existing project");
525+
debug ("Trying to add parent of existing project");
526526
children.append (item);
527527
} else if (item.file.file.get_relative_path (add_file) != null) {
528-
critical ("Trying to add child of existing project");
528+
debug ("Trying to add child of existing project");
529529
parents.append (item);
530530
}
531531
}
532532

533533
if (parents.length () > 0 || children.length () > 0) {
534-
var dialog = new Scratch.Dialogs.CloseProjectsConfirmationDialog ((MainWindow) get_toplevel ());
534+
assert (parents.length () <= 1);
535+
assert (parents.length () == 0 || children.length () == 0);
536+
var dialog = new Scratch.Dialogs.CloseProjectsConfirmationDialog (
537+
(MainWindow) get_toplevel (),
538+
parents.length (),
539+
children.length ()
540+
);
535541

536542
var close_projects = false;
537543
dialog.response.connect ((res) => {
@@ -554,7 +560,6 @@ public class Scratch.FolderManager.FileView : Code.Widgets.SourceList, Code.Pane
554560
} else {
555561
return;
556562
}
557-
558563
}
559564

560565
// Process any closed signals emitted before proceeding

0 commit comments

Comments
 (0)