@@ -866,6 +866,9 @@ webui.SideBarView = function(mainView, noEventHandlers) {
866
866
'<section id="sidebar-stash">' +
867
867
'<h4>Stash</h4>' +
868
868
'</section>' +
869
+ '<section id="sidebarDiscarded">' +
870
+ '<h4>Discarded Files</h4>' +
871
+ '</section>' +
869
872
'<section id="sidebar-local-branches">' +
870
873
'<h4 class="mt-3">Local Branches' +
871
874
'<button type="button" class="btn btn-default btn-sidebar-icon btn-add shadow-none" >' +
@@ -904,6 +907,13 @@ webui.SideBarView = function(mainView, noEventHandlers) {
904
907
self . mainView . stashView . update ( 0 ) ;
905
908
} ) ;
906
909
910
+ var discardedElement = $ ( "#sidebarDiscarded" , self . element ) ;
911
+ discardedElement . click ( function ( ) {
912
+ $ ( "*" , self . element ) . removeClass ( "active" ) ;
913
+ discardedElement . addClass ( "active" ) ;
914
+ self . mainView . discardedView . show ( ) ;
915
+ } ) ;
916
+
907
917
$ ( ".btn-add" , self . element ) . click ( self . createNewLocalBranch ) ;
908
918
$ ( '.btn-prune-remote-branches' , self . element ) . click ( self . pruneRemoteBranches ) ;
909
919
$ ( "#sidebar-settings" , self . element ) . click ( self . goToSettingsPage ) ;
@@ -1823,6 +1833,28 @@ webui.DiffView = function(sideBySide, hunkSelectionAllowed, parent, stashedCommi
1823
1833
var gitApplyType = "stage" ;
1824
1834
} ;
1825
1835
1836
+ webui . DiscardedView = function ( mainView ) {
1837
+ var self = this ;
1838
+
1839
+ self . show = function ( ) {
1840
+ self . update ( ) ;
1841
+ mainView . switchTo ( self . element ) ;
1842
+ } ;
1843
+
1844
+ self . getDiscardedStates = function ( ) {
1845
+ $ . get ( "discarded-states" , function ( discarded ) {
1846
+ console . log ( discarded ) ;
1847
+ } ) ;
1848
+ }
1849
+
1850
+ self . update = function ( ) {
1851
+ self . getDiscardedStates ( ) ;
1852
+ }
1853
+
1854
+ self . element = $ ( '<div id="discardedView"></div>' ) [ 0 ] ;
1855
+
1856
+ }
1857
+
1826
1858
/*
1827
1859
* == TreeView ================================================================
1828
1860
*/
@@ -2366,7 +2398,7 @@ webui.NewChangedFilesView = function(workspaceView) {
2366
2398
if ( selectedItemsFromOtherUser . length > 0 ) {
2367
2399
self . confirmActionOnOtherUsersChanges ( "discard" ) ;
2368
2400
} else {
2369
- self . discard ( ) ;
2401
+ self . confirmDiscard ( ) ;
2370
2402
}
2371
2403
} ) ;
2372
2404
@@ -2383,6 +2415,59 @@ webui.NewChangedFilesView = function(workspaceView) {
2383
2415
} ) ;
2384
2416
}
2385
2417
2418
+ self . confirmDiscard = function ( ) {
2419
+ function removePopup ( popup ) {
2420
+ $ ( popup ) . children ( ".modal-fade" ) . modal ( "hide" ) ;
2421
+ $ ( ".modal-backdrop" ) . remove ( ) ;
2422
+ $ ( "#confirmDiscard" ) . remove ( ) ;
2423
+ }
2424
+
2425
+ var popup = $ (
2426
+ '<div class="modal fade" tabindex="-1" id="confirmDiscard" role="dialog" data-backdrop="static">' +
2427
+ '<div class="modal-dialog modal-md" role="document">' +
2428
+ '<div class="modal-content">' +
2429
+ '<div class="modal-header">' +
2430
+ '<h5 class="modal-title">Confirm Discard</h5>' +
2431
+ '<button type="button" class="btn btn-default close" data-dismiss="modal">' + webui . largeXIcon + '</button>' +
2432
+ '</div>' +
2433
+ '<div class="modal-body">' +
2434
+ '<div class="row">' +
2435
+ '<div class="col-sm-1">' +
2436
+ webui . warningIcon +
2437
+ '</div>' +
2438
+ '<div class="col-sm-11">' +
2439
+ '<p>Careful, discarding changes will delete all changes made to your file since the last commit. This will mean deleting a newly created file.</p>' + // Removed extra closing </p> tag
2440
+ '</div>' +
2441
+ '</div>' +
2442
+ '</div>' +
2443
+ '<div class="modal-footer"></div>' +
2444
+ '</div>' +
2445
+ '</div>' +
2446
+ '</div>'
2447
+ ) [ 0 ] ;
2448
+
2449
+ $ ( "body" ) . append ( popup ) ;
2450
+
2451
+ var popupFooter = $ ( ".modal-footer" , popup ) [ 0 ] ;
2452
+ webui . detachChildren ( popupFooter ) ;
2453
+
2454
+ $ (
2455
+ '<button class="btn btn-sm btn-warning action-btn" id="confirmDiscardBtn">Confirm discard</button>' +
2456
+ '<button class="btn btn-sm btn-secondary action-btn" id="cancelDiscardBtn">Cancel</button>'
2457
+ ) . appendTo ( popupFooter ) ;
2458
+
2459
+ $ ( popup ) . modal ( 'show' ) ;
2460
+
2461
+ $ ( "#confirmDiscardBtn" ) . on ( 'click' , function ( ) {
2462
+ removePopup ( popup ) ;
2463
+ self . discard ( ) ;
2464
+ } ) ;
2465
+
2466
+ $ ( "#confirmDiscard" ) . find ( ".close, #cancelDiscardBtn" ) . click ( function ( ) {
2467
+ removePopup ( popup ) ;
2468
+ } )
2469
+ }
2470
+
2386
2471
self . confirmAmend = function ( ) {
2387
2472
function removePopup ( popup ) {
2388
2473
$ ( popup ) . children ( ".modal-fade" ) . modal ( "hide" ) ;
@@ -2395,7 +2480,7 @@ webui.NewChangedFilesView = function(workspaceView) {
2395
2480
'<div class="modal-dialog modal-md" role="document">' +
2396
2481
'<div class="modal-content">' +
2397
2482
'<div class="modal-header">' +
2398
- '<h5 class="modal-title">Confirm amend </h5>' +
2483
+ '<h5 class="modal-title">Confirm Amend </h5>' +
2399
2484
'<button type="button" class="btn btn-default close" data-dismiss="modal">' + webui . largeXIcon + '</button>' +
2400
2485
'</div>' +
2401
2486
'<div class="modal-body"></div>' +
@@ -2482,6 +2567,11 @@ webui.NewChangedFilesView = function(workspaceView) {
2482
2567
$ ( '<div>' +
2483
2568
'<p>Careful, amending commits will rewrite the branch history. The amended commit will not be pushed to remote, even if the previous commit was.</p>' +
2484
2569
'</div>' ) . appendTo ( popupContent ) ;
2570
+ } else if ( action == "discard" ) {
2571
+ $ (
2572
+ '<div>' +
2573
+ '<p>Careful, discarding changes will delete all changes made to your file since the last commit. This will mean deleting a newly created file.</p>' +
2574
+ '</div>' ) . appendTo ( popupContent ) ;
2485
2575
}
2486
2576
2487
2577
var popupFooter = $ ( ".modal-footer" , popup ) [ 0 ] ;
@@ -2624,9 +2714,8 @@ webui.NewChangedFilesView = function(workspaceView) {
2624
2714
}
2625
2715
2626
2716
self . discard = function ( ) {
2627
- var selectedFilesAsString = selectedItems . join ( " " ) ;
2628
- webui . git ( "add -- " + selectedFilesAsString , function ( ) {
2629
- webui . git ( "restore --staged --worktree -- " + selectedFilesAsString , function ( ) {
2717
+ webui . git_command ( [ "add" , "--" ] . concat ( selectedItems ) , function ( ) {
2718
+ webui . git_command ( [ "restore" , "--staged" , "--worktree" , "--" ] . concat ( selectedItems ) , function ( ) {
2630
2719
workspaceView . update ( ) ;
2631
2720
} ) ;
2632
2721
} ) ;
@@ -2733,6 +2822,7 @@ function MainUi() {
2733
2822
if ( ! webui . viewonly ) {
2734
2823
self . workspaceView = new webui . WorkspaceView ( self ) ;
2735
2824
self . stashView = new webui . StashView ( self ) ;
2825
+ self . discardedView = new webui . DiscardedView ( self ) ;
2736
2826
}
2737
2827
self . sideBarView . selectRef ( "HEAD" ) ;
2738
2828
} ) ;
0 commit comments