Skip to content

Commit 9af9c32

Browse files
committed
Add progress dialog for macOS
1 parent 0ca7b6f commit 9af9c32

7 files changed

+135
-8
lines changed

NX_Game_Info_macOS_SD_Card.png

528 KB
Loading

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ These files should be put in the same directory as the executable for Windows or
4949
# macOS
5050
### Open File/Directory
5151
![NX_Game_Info_macOS.png](NX_Game_Info_macOS.png)
52+
### Open SD Card
53+
![NX_Game_Info_macOS_SD_Card.png](NX_Game_Info_macOS_SD_Card.png)
5254

5355
# Windows
5456
### Open File/Directory

Windows/Main.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ private void backgroundWorkerProcess_DoWork(object sender, System.ComponentModel
163163
}
164164
}
165165

166-
worker.ReportProgress(100, "");
166+
if (!worker.CancellationPending)
167+
{
168+
worker.ReportProgress(100, "");
169+
}
167170
}
168171
else if (e.Argument is string sdpath)
169172
{
@@ -183,7 +186,10 @@ private void backgroundWorkerProcess_DoWork(object sender, System.ComponentModel
183186
}
184187
}
185188

186-
worker.ReportProgress(100, "");
189+
if (!worker.CancellationPending)
190+
{
191+
worker.ReportProgress(100, "");
192+
}
187193
}
188194

189195
e.Result = titles;

macOS/Info.plist

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
<key>CFBundleIdentifier</key>
88
<string>com.garoxas.NX_Game_Info</string>
99
<key>CFBundleShortVersionString</key>
10-
<string>0.3</string>
10+
<string>0.3.1</string>
1111
<key>CFBundleVersion</key>
12-
<string>4</string>
12+
<string>5</string>
1313
<key>LSMinimumSystemVersion</key>
1414
<string>10.9</string>
1515
<key>CFBundleDevelopmentRegion</key>

macOS/MainWindow.xib

+43
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
<objects>
99
<customObject id="-2" userLabel="File's Owner" customClass="MainWindowController">
1010
<connections>
11+
<outlet property="cancel" destination="2SK-K2-DYw" id="y7R-fi-Ppm"/>
12+
<outlet property="message" destination="CaA-hy-YGi" id="5kn-Kf-oJl"/>
13+
<outlet property="progress" destination="9Qy-Rn-Xtc" id="2Ke-nM-a8w"/>
14+
<outlet property="sheet" destination="QI1-j4-PZV" id="cP1-eX-iWX"/>
1115
<outlet property="tableView" destination="Yy4-24-icq" id="Rcw-pc-HtK"/>
1216
<outlet property="window" destination="2" id="6"/>
1317
</connections>
@@ -264,5 +268,44 @@
264268
</subviews>
265269
</view>
266270
</window>
271+
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" id="QI1-j4-PZV">
272+
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
273+
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
274+
<rect key="contentRect" x="163" y="199" width="480" height="120"/>
275+
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
276+
<view key="contentView" id="gQc-yn-Onv">
277+
<rect key="frame" x="0.0" y="0.0" width="480" height="120"/>
278+
<autoresizingMask key="autoresizingMask"/>
279+
<subviews>
280+
<progressIndicator wantsLayer="YES" maxValue="100" style="bar" id="9Qy-Rn-Xtc">
281+
<rect key="frame" x="20" y="50" width="440" height="20"/>
282+
<autoresizingMask key="autoresizingMask" widthSizable="YES"/>
283+
</progressIndicator>
284+
<button verticalHuggingPriority="750" id="2SK-K2-DYw">
285+
<rect key="frame" x="384" y="13" width="82" height="32"/>
286+
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxY="YES"/>
287+
<buttonCell key="cell" type="push" title="Cancel" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="9bP-ZQ-RxV">
288+
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
289+
<font key="font" metaFont="system"/>
290+
<string key="keyEquivalent" base64-UTF8="YES">
291+
Gw
292+
</string>
293+
</buttonCell>
294+
<connections>
295+
<action selector="cancelProgress:" target="-2" id="8z3-C2-DEI"/>
296+
</connections>
297+
</button>
298+
<textField verticalHuggingPriority="750" id="CaA-hy-YGi">
299+
<rect key="frame" x="18" y="78" width="440" height="22"/>
300+
<autoresizingMask key="autoresizingMask"/>
301+
<textFieldCell key="cell" lineBreakMode="truncatingMiddle" sendsActionOnEndEditing="YES" title="Please wait until the current process is finished" id="j0y-sq-LUR">
302+
<font key="font" usesAppearanceFont="YES"/>
303+
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
304+
<color key="backgroundColor" name="controlBackgroundColor" catalog="System" colorSpace="catalog"/>
305+
</textFieldCell>
306+
</textField>
307+
</subviews>
308+
</view>
309+
</window>
267310
</objects>
268311
</document>

macOS/MainWindowController.cs

+45-4
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ public override void WindowDidLoad()
7171

7272
backgroundWorker = new BackgroundWorker
7373
{
74-
WorkerReportsProgress = true
74+
WorkerReportsProgress = true,
75+
WorkerSupportsCancellation = true
7576
};
7677
backgroundWorker.DoWork += BackgroundWorker_DoWork;
7778
backgroundWorker.ProgressChanged += BackgroundWorker_ProgressChanged;
@@ -110,6 +111,11 @@ public void OpenFile(NSMenuItem menuItem)
110111
Common.Settings.Default.InitialDirectory = Path.GetDirectoryName(filenames.First());
111112
Common.Settings.Default.Save();
112113

114+
message.StringValue = "";
115+
progress.DoubleValue = 0;
116+
117+
Window.BeginSheet(sheet, ProgressComplete);
118+
113119
backgroundWorker.RunWorkerAsync(filenames);
114120
}
115121
}
@@ -145,6 +151,11 @@ public void OpenDirectory(NSMenuItem menuItem)
145151
Common.Settings.Default.InitialDirectory = openPanel.Urls.First().Path;
146152
Common.Settings.Default.Save();
147153

154+
message.StringValue = "";
155+
progress.DoubleValue = 0;
156+
157+
Window.BeginSheet(sheet, ProgressComplete);
158+
148159
backgroundWorker.RunWorkerAsync(filenames);
149160
}
150161
}
@@ -198,6 +209,11 @@ public void OpenSDCard(NSMenuItem menuItem)
198209
Common.Settings.Default.InitialDirectory = openPanel.Urls.First().Path;
199210
Common.Settings.Default.Save();
200211

212+
message.StringValue = "";
213+
progress.DoubleValue = 0;
214+
215+
Window.BeginSheet(sheet, ProgressComplete);
216+
201217
backgroundWorker.RunWorkerAsync(openPanel.Urls.First().Path);
202218
}
203219
}
@@ -214,6 +230,8 @@ void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
214230

215231
foreach (var filename in filenames)
216232
{
233+
if (worker.CancellationPending) break;
234+
217235
worker.ReportProgress(100 * index++ / count, filename);
218236

219237
Title title = Process.processFile(filename);
@@ -223,7 +241,10 @@ void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
223241
}
224242
}
225243

226-
worker.ReportProgress(100, "");
244+
if (!worker.CancellationPending)
245+
{
246+
worker.ReportProgress(100, "");
247+
}
227248
}
228249
else if (e.Argument is string sdpath)
229250
{
@@ -232,6 +253,8 @@ void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
232253

233254
foreach (var sdtitle in sdtitles)
234255
{
256+
if (worker.CancellationPending) break;
257+
235258
worker.ReportProgress(100 * index++ / count, sdtitle.MainNca?.Filename);
236259

237260
Title title = Process.processTitle(sdtitle);
@@ -241,24 +264,42 @@ void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
241264
}
242265
}
243266

244-
worker.ReportProgress(100, "");
267+
if (!worker.CancellationPending)
268+
{
269+
worker.ReportProgress(100, "");
270+
}
245271
}
246272

247273
e.Result = titles;
248274
}
249275

250276
void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
251277
{
252-
278+
message.StringValue = e.UserState as string;
279+
progress.DoubleValue = e.ProgressPercentage;
253280
}
254281

255282
void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
256283
{
257284
tableViewDataSource.Titles.AddRange((List<Title>)e.Result);
258285

259286
tableView.ReloadData();
287+
288+
Window.EndSheet(sheet);
289+
}
290+
291+
[Export("cancelProgress:")]
292+
public void CancelProgress(NSObject sender)
293+
{
294+
message.StringValue = "Please wait until the current process is finished";
295+
296+
backgroundWorker.CancelAsync();
260297
}
261298

299+
void ProgressComplete(nint obj)
300+
{
301+
302+
}
262303
}
263304

264305
public class TableViewDataSource : NSTableViewDataSource

macOS/MainWindowController.designer.cs

+35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)