[Unison-hackers] [Patch] OS X Gui: Warn if no archive is found

Alan Schmitt alan.schmitt at polytechnique.org
Sat Jan 21 12:55:09 EST 2012


Following the feature request on unison-users, here is a patch that will show a modal warning window if there is no archive for the hosts. The user can then choose to exit or proceed (proceed is the default). The window is not shown if "batch" is true.

Alan

Index: uimacbridgenew.ml
===================================================================
--- uimacbridgenew.ml	(revision 480)
+++ uimacbridgenew.ml	(working copy)
@@ -82,7 +82,22 @@
 let fatalError message =
   Trace.log (message ^ "\n");
   displayFatalError message
+    
+(* Defined in MyController.m; display the warning and ask whether to
+   exit or proceed *)
+external displayWarnPanel : string -> bool = "warnPanel";;
 
+let setWarnPrinter() =
+  Util.warnPrinter :=
+    Some(fun s ->
+      Trace.log ("Warning: " ^ s ^ "\n");
+      if not (Prefs.read Globals.batch) then begin
+	if (displayWarnPanel s) then begin
+          Lwt_unix.run (Update.unlockArchives ());
+          exit Uicommon.fatalExit
+	end
+      end)
+
 let doInOtherThread f =
   Thread.create
     (fun () ->
@@ -316,6 +331,9 @@
        Printf.eprintf "\n"
     );
 
+  (* Install the warning panel, hopefully it's not too late *)
+  setWarnPrinter();
+  
   Lwt_unix.run
     (Uicommon.validateAndFixupPrefs () >>=
      Globals.propagatePrefs);
Index: uimacnew09/MyController.h
===================================================================
--- uimacnew09/MyController.h	(revision 480)
+++ uimacnew09/MyController.h	(working copy)
@@ -81,6 +81,8 @@
   NSTimer *_timer;
   NSAlert *_timeoutAlert;
   NSUInteger _secondsRemaining;
+    
+  BOOL shouldExitAfterWarning;
 }
 
 - (id)init;
Index: uimacnew09/MyController.m
===================================================================
--- uimacnew09/MyController.m	(revision 480)
+++ uimacnew09/MyController.m	(working copy)
@@ -307,7 +307,7 @@
 
 - (void)updateToolbar
 {
-    [toolbar validateVisibleItems];	
+  [toolbar validateVisibleItems];	
 	[tableModeSelector setEnabled:((syncable && !duringSync) || afterSync)];
 
 	// Why?
@@ -1175,6 +1175,31 @@
         exit(1);
 }
 
+/* Returns true if we need to exit, false if we proceed */
+
+CAMLprim value warnPanel(value s)
+{
+	NSString *str = [[NSString alloc] initWithUTF8String:String_val(s)];
+    
+  [me performSelectorOnMainThread:@selector(warnPanel:) withObject:str waitUntilDone:TRUE];
+	[str release];
+  if (me -> shouldExitAfterWarning) {
+    return Val_true;
+  } else {
+    return Val_false;
+  }
+}
+
+- (void)warnPanel:(NSString *)msg {
+  int warnVal = NSRunAlertPanel(@"Warning", msg, @"Proceed", @"Exit", nil);
+  NSLog(@"Warning Panel Returned %d",warnVal);
+  if (warnVal == NSAlertAlternateReturn) {
+    shouldExitAfterWarning = YES;
+  } else {
+    shouldExitAfterWarning = FALSE;
+  }
+}
+
 @end
 
 @implementation NSString (_UnisonUtil)



More information about the Unison-hackers mailing list