~soapdog/fafi-browser

c6c8bd7788812c89d70ed992961dcdd3fc441582 — Louis Brauer 3 years ago 8563b87
Enable tab panel reorder and close button
2 files changed, 42 insertions(+), 30 deletions(-)

M CHANGELOG.md
M window.rkt
M CHANGELOG.md => CHANGELOG.md +4 -0
@@ 5,6 5,10 @@
  * close tab with ⌘-w
* New menu items
  * "New Tab" in File menu
* Optimize tab panel
  * Enable close button on tab
  * Enable reorder of tabs
  * Requires Racket v8.0

# Version 0.10


M window.rkt => window.rkt +38 -30
@@ 7,7 7,7 @@
  "multi-transport.rkt"
  "multi-renderer.rkt"
  "config.rkt"
  "utils.rkt" 
  "utils.rkt"
  "history.rkt"
  "persist.rkt"
  "bookmarks-edit.rkt"


@@ 47,7 47,7 @@
(define frame
  (new
   (class frame%
     (super-new) 
     (super-new)

     (define (handle-keycombo key)
       (let ((meta? (send key get-meta-down))


@@ 73,17 73,17 @@
            (new-tab))
           (else
            #f))))
       

     (define/override (on-subwindow-char receiver event)
       (or (handle-keycombo event)
           (send this on-menu-char event)
           (send this on-system-menu-char event)
           (send this on-traverse-char event))))
   
   [label (format "Fafi (~a) is a Gemini Browser" program-version)]   
   [width 900] 
   [height 700] 
   [x 100] 

   [label (format "Fafi (~a) is a Gemini Browser" program-version)]
   [width 900]
   [height 700]
   [x 100]
   [y 100]))

(define toolbar


@@ 95,7 95,7 @@
(define (go-to-url [url #f])
  (when (false? url)
    (set! url (send address-bar get-value)))
  

  (set! history-backward (cons url history-backward))
  (send multi-transport fetch url))



@@ 106,7 106,7 @@
    (send multi-transport fetch url)))

(define (go-back)
    

  (when (> (length history-backward) 1)
    (define url (cadr history-backward))
    (set! history-forward (cons   (car history-backward)  history-forward))


@@ 196,26 196,26 @@
  (when (debug-mode?)
    (begin
      (displayln (format "switch tab: ~a" n))))
  

  (send frame set-status-text "")
  

  (if (non-empty-string? (tab-url tab-n))
      (send address-bar set-value (tab-url tab-n))
      (send address-bar set-value ""))
  

  (cond [(not (false? (tab-content tab-n))) (send multi-renderer render (tab-mime tab-n) (tab-content tab-n))]
        [(not (false? (tab-url tab-n))) (send multi-transport fetch (tab-url tab-n))]
        [else (send multi-renderer render "text/gemini" (new-tab-template))]))

(define (close-tab n)
  (when (> n 0)
  (when (> (length tabs) 1)
    (begin
      (define tab-n (list-ref tabs n))
      (set! tabs (remove tab-n tabs))
      (send browser-tabs delete n)
      (send browser-tabs set-selection (sub1 n))
      (switch-tab (sub1 n)))))
  


(define (resize-browser w h)
  (send multi-renderer on-size w h))


@@ 223,7 223,7 @@
(define (status-change status)
  (begin0
    (when (debug-mode?)
      (displayln (format "status: ~a" status))) 
      (displayln (format "status: ~a" status)))
    (send frame set-status-text status)))

(define (request-complete url mime content)


@@ 231,9 231,9 @@
    (displayln (format "loaded ~a" url)))
  (send address-bar set-value url)
  (send browser-tabs set-item-label (send browser-tabs get-selection) url)
  

  (set! tabs (list-set tabs (send browser-tabs get-selection) (tab url mime content)))
  

  (when (or (empty? history-backward) (not (equal? url (car history-backward))))
    (set! history-backward (cons url history-backward)))



@@ 261,11 261,19 @@
                                          ""))]
          [else ""])))

; to implement on-close-request
(define custom-tab-panel%
  (class tab-panel%
    (define/override (on-close-request index)
      (close-tab index))
    (super-new)))

; needs to be after parent show so that we have parents dimensions
(define browser-tabs
  (new tab-panel%
  (new custom-tab-panel%
       [parent frame]
       [choices '("New Tab")]
       [style (list 'can-reorder 'can-close 'no-border)]
       [callback (lambda (b e)
                   (switch-tab (send browser-tabs get-selection)))]))



@@ 298,13 306,13 @@
         [border 10]
         [width 800]
         [height 600]))
  

  (define panel
    (new horizontal-panel%
         [parent dialog]
         [alignment '(center center)]
         [spacing 10]))
  

  (define version-canvas
    (new editor-canvas%
         [parent panel]


@@ 317,20 325,20 @@

  (send version-text insert version-information)
  (send version-canvas set-editor version-text)
         

  (define ok-button
    (new button%
         [parent dialog]
         [label "Close"]
         [callback (λ _ (send dialog show #f))]))
  

  (send dialog show #t))

(define (initialize-menubar)
  (define menu-bar
    (new menu-bar%
         [parent frame]))
  

  (define file-menu
    (new menu%
         [parent menu-bar]


@@ 343,7 351,7 @@
         [help-string "Opens a new tab"]
         [shortcut #\t]
         [callback (λ _ (new-tab))]))
  

  (define preferences-menu
    (new menu-item%
         [parent file-menu]


@@ 355,7 363,7 @@
  (define file-menu-separator
    (new separator-menu-item%
         [parent file-menu]))
  

  (define quit-menu
    (new menu-item%
         [parent file-menu]


@@ 393,13 401,13 @@
    (new menu%
         [parent menu-bar]
         [label "&Help"]))
  

  (define about-menu
    (new menu-item%
         [parent help-menu]
         [label "&About"]
         [callback (λ _ (about))]))
  

  (define help-menu-separator
    (new separator-menu-item%
         [parent help-menu]))


@@ 409,13 417,13 @@
         [parent help-menu]
         [label "&Fafi Repository"]
         [callback (λ _ (send-url program-site))]))
  

  (define issue-tracker-menu
    (new menu-item%
         [parent help-menu]
         [label "&Issue tracker"]
         [callback (λ _ (send-url issue-tracker))]))
  

  (define kofi-menu
    (new menu-item%
         [parent help-menu]