@@ -333,11 +333,50 @@ private void OnTreeGUI(Rect rect)
333333 GUILayout . Space ( rect . y - initialRect . y ) ;
334334 }
335335
336- private void CheckoutRemoteBranch ( string selectedNodeName )
336+ private GenericMenu CreateContextMenuForLocalBranchNode ( TreeNode node )
337+ {
338+ var genericMenu = new GenericMenu ( ) ;
339+
340+ var deleteGuiContent = new GUIContent ( "Delete" ) ;
341+ var switchGuiContent = new GUIContent ( "Switch" ) ;
342+
343+ if ( node . IsActive )
344+ {
345+ genericMenu . AddDisabledItem ( deleteGuiContent ) ;
346+ genericMenu . AddDisabledItem ( switchGuiContent ) ;
347+ }
348+ else
349+ {
350+ genericMenu . AddItem ( deleteGuiContent , false , ( ) => {
351+ DeleteLocalBranch ( node . Name ) ;
352+ } ) ;
353+
354+ genericMenu . AddItem ( switchGuiContent , false , ( ) => {
355+ SwitchBranch ( node . Name ) ;
356+ } ) ;
357+ }
358+
359+ return genericMenu ;
360+ }
361+
362+ private GenericMenu CreateContextMenuForRemoteBranchNode ( TreeNode node )
363+ {
364+ var genericMenu = new GenericMenu ( ) ;
365+
366+ var checkoutGuiContent = new GUIContent ( "Checkout" ) ;
367+
368+ genericMenu . AddItem ( checkoutGuiContent , false , ( ) => {
369+ CheckoutRemoteBranch ( node . Name ) ;
370+ } ) ;
371+
372+ return genericMenu ;
373+ }
374+
375+ private void CheckoutRemoteBranch ( string branch )
337376 {
338- var indexOfFirstSlash = selectedNodeName . IndexOf ( '/' ) ;
339- var originName = selectedNodeName . Substring ( 0 , indexOfFirstSlash ) ;
340- var branchName = selectedNodeName . Substring ( indexOfFirstSlash + 1 ) ;
377+ var indexOfFirstSlash = branch . IndexOf ( '/' ) ;
378+ var originName = branch . Substring ( 0 , indexOfFirstSlash ) ;
379+ var branchName = branch . Substring ( indexOfFirstSlash + 1 ) ;
341380
342381 if ( Repository . LocalBranches . Any ( localBranch => localBranch . Name == branchName ) )
343382 {
@@ -347,93 +386,54 @@ private void CheckoutRemoteBranch(string selectedNodeName)
347386 else
348387 {
349388 var confirmCheckout = EditorUtility . DisplayDialog ( ConfirmCheckoutBranchTitle ,
350- String . Format ( ConfirmCheckoutBranchMessage , selectedNodeName , originName ) , ConfirmCheckoutBranchOK ,
389+ String . Format ( ConfirmCheckoutBranchMessage , branch , originName ) , ConfirmCheckoutBranchOK ,
351390 ConfirmCheckoutBranchCancel ) ;
352391
353392 if ( confirmCheckout )
354393 {
355- GitClient . CreateBranch ( branchName , selectedNodeName ) . FinallyInUI ( ( success , e ) => {
394+ GitClient . CreateBranch ( branchName , branch ) . FinallyInUI ( ( success , e ) => {
356395 if ( success )
357396 {
358397 Redraw ( ) ;
359398 }
360399 else
361400 {
362401 EditorUtility . DisplayDialog ( Localization . SwitchBranchTitle ,
363- String . Format ( Localization . SwitchBranchFailedDescription , selectedNodeName ) , Localization . Ok ) ;
402+ String . Format ( Localization . SwitchBranchFailedDescription , branch ) , Localization . Ok ) ;
364403 }
365404 } ) . Start ( ) ;
366405 }
367406 }
368407 }
369408
370- private GenericMenu CreateContextMenuForLocalBranchNode ( TreeNode node )
409+ private void SwitchBranch ( string branch )
371410 {
372- var genericMenu = new GenericMenu ( ) ;
373-
374- var deleteGuiContent = new GUIContent ( "Delete" ) ;
375- var switchGuiContent = new GUIContent ( "Switch" ) ;
376-
377- if ( node . IsActive )
378- {
379- genericMenu . AddDisabledItem ( deleteGuiContent ) ;
380- genericMenu . AddDisabledItem ( switchGuiContent ) ;
381- }
382- else
383- {
384- genericMenu . AddItem ( deleteGuiContent , false , ( ) => {
385- DeleteLocalBranch ( node . Name ) ;
386- } ) ;
387-
388- genericMenu . AddItem ( switchGuiContent , false , ( ) => {
389- SwitchBranch ( node . Name ) ;
390- } ) ;
391- }
392-
393- return genericMenu ;
394- }
395-
396- private void SwitchBranch ( string branchName )
397- {
398- if ( EditorUtility . DisplayDialog ( ConfirmSwitchTitle , String . Format ( ConfirmSwitchMessage , branchName ) , ConfirmSwitchOK ,
411+ if ( EditorUtility . DisplayDialog ( ConfirmSwitchTitle , String . Format ( ConfirmSwitchMessage , branch ) , ConfirmSwitchOK ,
399412 ConfirmSwitchCancel ) )
400413 {
401- GitClient . SwitchBranch ( branchName ) . FinallyInUI ( ( success , e ) => {
414+ GitClient . SwitchBranch ( branch ) . FinallyInUI ( ( success , e ) => {
402415 if ( success )
403416 {
404417 Redraw ( ) ;
405418 }
406419 else
407420 {
408421 EditorUtility . DisplayDialog ( Localization . SwitchBranchTitle ,
409- String . Format ( Localization . SwitchBranchFailedDescription , branchName ) , Localization . Ok ) ;
422+ String . Format ( Localization . SwitchBranchFailedDescription , branch ) , Localization . Ok ) ;
410423 }
411424 } ) . Start ( ) ;
412425 }
413426 }
414427
415- private void DeleteLocalBranch ( string branchName )
428+ private void DeleteLocalBranch ( string branch )
416429 {
417- var dialogMessage = string . Format ( DeleteBranchMessageFormatString , branchName ) ;
430+ var dialogMessage = string . Format ( DeleteBranchMessageFormatString , branch ) ;
418431 if ( EditorUtility . DisplayDialog ( DeleteBranchTitle , dialogMessage , DeleteBranchButton , CancelButtonLabel ) )
419432 {
420- GitClient . DeleteBranch ( branchName , true ) . Start ( ) ;
433+ GitClient . DeleteBranch ( branch , true ) . Start ( ) ;
421434 }
422435 }
423436
424- private GenericMenu CreateContextMenuForRemoteBranchNode ( TreeNode node )
425- {
426- var genericMenu = new GenericMenu ( ) ;
427-
428- var checkoutGuiContent = new GUIContent ( "Checkout" ) ;
429-
430- genericMenu . AddItem ( checkoutGuiContent , false , ( ) => {
431- CheckoutRemoteBranch ( node . Name ) ;
432- } ) ;
433-
434- return genericMenu ;
435- }
436-
437437 private int CompareBranches ( GitBranch a , GitBranch b )
438438 {
439439 if ( a . Name . Equals ( "master" ) )
0 commit comments