-
-
Notifications
You must be signed in to change notification settings - Fork 118
Expand file tree
/
Copy pathBranchActionDialog.vala
More file actions
105 lines (87 loc) · 3.16 KB
/
BranchActionDialog.vala
File metadata and controls
105 lines (87 loc) · 3.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* Copyright 2025 elementary, Inc. <https://elementary.io>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* Authored by: Jeremy Wootten <jeremywootten@gmail.com>
*/
public enum Scratch.BranchAction {
CHECKOUT,
COMMIT,
PUSH,
PULL,
MERGE,
DELETE,
CREATE
}
public interface Scratch.BranchActionPage : Gtk.Widget {
public abstract BranchAction action { get; }
public abstract Ggit.Ref? branch_ref { get; }
public abstract string new_branch_name { get; }
public virtual void focus_start_widget () {}
}
public class Scratch.Dialogs.BranchActionDialog : Granite.MessageDialog {
public signal void page_activated ();
public BranchAction action {
get {
return ((BranchActionPage)stack.get_visible_child ()).action;
}
}
public Ggit.Ref branch_ref {
get {
return ((BranchActionPage)stack.get_visible_child ()).branch_ref;
}
}
public string new_branch_name {
get {
return ((BranchActionPage)stack.get_visible_child ()).new_branch_name;
}
}
public bool can_apply { get; set; default = false; }
public FolderManager.ProjectFolderItem project { get; construct; }
private Gtk.Stack stack;
public BranchActionDialog (FolderManager.ProjectFolderItem project) {
Object (
project: project
);
}
construct {
transient_for = ((Gtk.Application)(GLib.Application.get_default ())).get_active_window ();
add_button (_("Cancel"), Gtk.ResponseType.CANCEL);
if (project.is_git_repo) {
primary_text = _("Perform branch action on project '%s'").printf (
project.file.file.get_basename ()
);
primary_label.can_focus = false;
image_icon = new ThemedIcon ("git");
var apply_button = add_button (_("Apply"), Gtk.ResponseType.APPLY);
bind_property ("can-apply", apply_button, "sensitive", SYNC_CREATE);
var checkout_page = new BranchCheckoutPage (this);
var create_page = new BranchCreatePage (this);
stack = new Gtk.Stack ();
stack.add_titled (checkout_page, BranchAction.CHECKOUT.to_string (), _("Checkout"));
stack.add_titled (create_page, BranchAction.CREATE.to_string (), _("New"));
var sidebar = new Gtk.StackSidebar () {
stack = stack
};
var content_box = new Gtk.Box (HORIZONTAL, 12);
content_box.add (sidebar);
content_box.add (stack);
custom_bin.add (content_box);
custom_bin.show_all ();
} else {
primary_text = _("'%s' is not a git repository").printf (
project.file.file.get_basename ()
);
secondary_text = _("Unable to perform branch actions");
image_icon = new ThemedIcon ("dialog-error");
}
realize.connect (() => {
((BranchActionPage)stack.get_visible_child ()).focus_start_widget ();
});
page_activated.connect (() => {
if (can_apply) {
response (Gtk.ResponseType.APPLY);
}
});
}
}