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

Benjamin C. Pierce bcpierce at cis.upenn.edu
Sat Jan 21 13:05:18 EST 2012


Nice!

On Jan 21, 2012, at 12:55 PM, Alan Schmitt wrote:

> 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)
> 
> _______________________________________________
> Unison-hackers mailing list
> Unison-hackers at lists.seas.upenn.edu
> http://lists.seas.upenn.edu/mailman/listinfo/unison-hackers



More information about the Unison-hackers mailing list