-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgressPanel.m
More file actions
102 lines (83 loc) · 2.44 KB
/
Copy pathProgressPanel.m
File metadata and controls
102 lines (83 loc) · 2.44 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
/*
* ProgressPanel.m - Modal progress panel for NeXTGitHub
* (c) 2026 ARNLTony & Claude. MIT License.
*/
#import <appkit/appkit.h>
#import "ProgressPanel.h"
#import "git_core.h"
@implementation ProgressPanel
- init
{
id contentView;
NXRect panelRect = {{340.0, 340.0}, {400.0, 120.0}};
NXRect msgRect = {{20.0, 60.0}, {360.0, 24.0}};
NXRect btnRect = {{150.0, 16.0}, {100.0, 28.0}};
[super init];
cancelled = 0;
panel = [[Panel alloc] initContent:&panelRect
style:NX_TITLEDSTYLE
backing:NX_BUFFERED
buttonMask:0
defer:YES];
[panel setTitle:"Working..."];
contentView = [panel contentView];
messageField = [[TextField alloc] initFrame:&msgRect];
[messageField setEditable:NO];
[messageField setSelectable:NO];
[messageField setBezeled:NO];
[messageField setStringValue:"Please wait..."];
[contentView addSubview:messageField];
cancelButton = [[Button alloc] initFrame:&btnRect
title:"Cancel"
tag:0
target:self
action:@selector(cancelAction:)
key:0
enabled:YES];
[contentView addSubview:cancelButton];
return self;
}
- (void)showWithMessage:(const char *)msg
{
cancelled = 0;
[messageField setStringValue:msg];
[panel makeKeyAndOrderFront:nil];
[NXApp updateWindows];
}
- (void)updateMessage:(const char *)msg
{
[messageField setStringValue:msg];
[panel display];
}
- (void)hide
{
[panel orderOut:nil];
}
- (int)isCancelled
{
return cancelled;
}
- cancelAction:sender
{
cancelled = 1;
return self;
}
@end
/* C bridge function for GitProgressFn callback */
int progress_panel_bridge(progress, userdata)
void *progress;
void *userdata;
{
GitProgress *p = (GitProgress *)progress;
id panel = (id)userdata;
NXEvent *ev;
[panel updateMessage:p->message];
/* Pump the event loop so the panel stays responsive */
while ((ev = [NXApp peekNextEvent:NX_ALLEVENTS into:NULL
waitFor:0.0 threshold:NX_BASETHRESHOLD]) != NULL) {
ev = [NXApp getNextEvent:NX_ALLEVENTS waitFor:0.0
threshold:NX_BASETHRESHOLD];
if (ev) [NXApp sendEvent:ev];
}
return [panel isCancelled] ? -1 : 0;
}