racket / drracket

DrRacket, IDE for Racket
http://www.racket-lang.org/
Other
445 stars 93 forks source link

New file menu item - Reopen Closed Tab #543

Closed squarebat closed 2 years ago

squarebat commented 2 years ago

As discussed in Issue #508 , this PR implements the functionality for reopening previously closed tabs. It has been added to the file menu after Open Require Path... as 'Reopen Closed Tab'. Since Ctrl-Shift-T is reserved for 'Spell Check Test' in the edit menu, I gave this the shortcut Ctrl-*, which might be a bit unintuitive.

As in @Metaxal 's quickscript, the callback reopen-closed-tab finds the first file in recently-opened-files that isn't already open and still exists. If no tabs were closed in the current session, it will open files that were active in previous sessions. However, after the recently-opened-files list is exhausted, it will just open new tabs. I thought it would be best for the callback to reside in unit.rkt where related methods create-new-tab and open-in-new-tab are stored.

This has only been manually tested, how should I write the tests for it? I couldn't find an appropriate file in the repository for testing GUI related features.

I will admit I couldn't look into this issue for a long time, and I am extremely sorry about the delay ;-;

The corresponding PR to add the new string constant reopen-closed-tab - string-constants/pull/56

rfindler commented 2 years ago

Thanks for putting some time into this!

I don't think that using 'framework:recently-opened-files/pos will work. That's not only recently closed files, but it is updated at other times too. I think this needs to be a new preference.

Also, since \<menukey>-shift-t is so widely used for this shortcut, I wouldn't mind changing that.

squarebat commented 2 years ago

@rfindler on futher exploring, recently-opened-files does behave unexpectedly for this feature. I'll set up a new preference that maintains a list of closed tabs.

rfindler commented 2 years ago

Great! The preference will probably need to be initialized and maintained in the racket/gui repo (in the framework, near to where 'framework:recently-opened-files/pos is maintained).

squarebat commented 2 years ago

I have added a new preference recently-closed-tabs. This list is updated whenever a tab is closed, and also when a tab is reopened. It works as expected but it is still incomplete with respect to :

rfindler commented 2 years ago
#lang racket

(define (truncate-list l n)
  (define len (length l))
  (cond
    [(<= len n) l]
    [else (drop-right l (- len n))]))

(require rackunit)
(check-equal? (truncate-list '(1 2 3) 10) '(1 2 3))
(check-equal? (truncate-list '(1 2 3) 3) '(1 2 3))
(check-equal? (truncate-list '(1 2 3) 2) '(1 2))
(check-equal? (truncate-list '(1 2 3) 1) '(1))
(check-equal? (truncate-list '(1 2 3 4 5 6) 2) '(1 2))
squarebat commented 2 years ago
rfindler commented 2 years ago

I see what you mean about removing items from the list (because they were opened elsewhere). I think we could achieve that goal if we wanted to (I can dig around to find the single point of control -- I am sure there is one or we could make one), but if you think it would be clearer to the users to not do that, I am on board.

Robby

squarebat commented 2 years ago

I think it would be more straightforward to just reopen the first file, even if it is already open. But rather than reopening the same file again, we can change to the tab where the file is open. Another issue with removing from the list is that there isn't really an easy way to remove files that don't exist anymore. So we would still have to loop through the list while reopening closed tabs until we find a suitable entry. That being said, digging around to find the single point sounds fun, I'll see if I find anything.

rfindler commented 2 years ago

That's a great point about just moving to the active tab. Indeed, unless we go to some lengths, just opening the file will send them to the tab where it is already open! Great!

squarebat commented 2 years ago

unless we go to some lengths

Indeed, the only way I was able to open the same file twice was by playing around with reopen-closed-tabs In the latest commit, I have added the preference to drracket/private/main. As discussed, if a closed file has already been opened, \-shift-t will redirect to active tab. I have also added code to remove duplicates from list and introduced an upper limit - recently-closed-tabs-max-count.

One problem though. I have retrieved the insertion positions from get-definitions-text, but the values will be lost since reopen-closed-tabs calls (open-in-new-tab filename) which ultimately calls create-new-tab where a new text object is created. Updating that new text object with the saved positions is fairly straightforward, but it'll require changing the create-new-tab method and adding default value parameters to it. Shall I go ahead with that?

rfindler commented 2 years ago

I think adding a keyword, optional argument that specifies the position to create-new-tab and open-in-new-tab is great. (The docs would need to be updated too, tho.)

I think that 'drracket:recently-closed-tabs-max-count can default to a larger number. The 50 in the other one is because they get put into a menu somewhere. But these won't be.

Because the definition of truncate-list is in a class, it is going to be a private field (i.e. per-object storage), so probably best to change it to define/private so that it will be a method (no extra storage in the object it is just once in the class).

Probably good to remove the shortcut for the other item -- or is that not in DrR? I'm forgetting where it is.

And there eventually needs to be an update to HISTORY.txt and an update to the documentation because there is a new menu item.

squarebat commented 2 years ago
squarebat commented 2 years ago

Are there any updates on this?

rfindler commented 2 years ago

Sorry for the long delay here @squarebat . I think that it is basically ready to go. I can address the two comments I put in and merge it, if you want?

squarebat commented 2 years ago

Sure!

On Fri, 1 Apr 2022, 20:16 Robby Findler, @.***> wrote:

Sorry for the long delay here @squarebat https://github.com/squarebat . I think that it is basically ready to go. I can address the two comments I put in and merge it, if you want?

— Reply to this email directly, view it on GitHub https://github.com/racket/drracket/pull/543#issuecomment-1085990716, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOCT4DMCPM7DYL634IKFIPTVC4D3PANCNFSM5MD5PBSQ . You are receiving this because you were mentioned.Message ID: @.***>