* wl-summary.el (wl-summary-buffer-event-handler): New internal
authorhmurata <hmurata>
Sat, 6 Nov 2004 11:11:45 +0000 (11:11 +0000)
committerhmurata <hmurata>
Sat, 6 Nov 2004 11:11:45 +0000 (11:11 +0000)
variable.
(wl-summary-event-handler): New class.
(elmo-event-handler-flag-changed): Define to update persistent
mark.
(wl-summary-buffer-set-folder): Register event handler to
elmo-folder.
(wl-summary-exit): Unregister event handler.
(wl-summary-goto-folder-subr): Ditto.
(wl-summary-mark-as-read-all): Does not call
`wl-summary-update-persistent-mark' directly.
(wl-summary-mark-as-read-internal): Ditto.
(wl-summary-set-persistent-mark-internal): Ditto.
(wl-summary-set-flags-internal): Ditto.

* elmo.el (elmo-folder): Added handlers slot.
(elmo-event-handler): New class.
(elmo-event-handler-flag-changed): New API.
(elmo-folder-add-handler): New function.
(elmo-folder-remove-handler): Ditto.
(elmo-folder-notify-event): Ditto.
(elmo-folder-set-flag): Call `elmo-folder-notify-event' with event
`flag-changed'.
(elmo-folder-unset-flag): Ditto.

* elmo-pipe.el (elmo-folder-set-flag): Ditto.
(elmo-folder-unset-flag): Ditto.

* elmo-multi.el (elmo-folder-set-flag): Ditto.
(elmo-folder-unset-flag): Ditto.

* elmo-filter.el (elmo-folder-set-flag): Ditto.
(elmo-folder-unset-flag): Ditto.

elmo/ChangeLog
elmo/elmo-filter.el
elmo/elmo-multi.el
elmo/elmo-pipe.el
elmo/elmo.el
wl/ChangeLog
wl/wl-summary.el

index 77fdcc5..7311f64 100644 (file)
@@ -1,5 +1,24 @@
 2004-11-06  Hiroya Murata  <lapis-lazuli@pop06.odn.ne.jp>
 
+       * elmo.el (elmo-folder): Added handlers slot.
+       (elmo-event-handler): New class.
+       (elmo-event-handler-flag-changed): New API.
+       (elmo-folder-add-handler): New function.
+       (elmo-folder-remove-handler): Ditto.
+       (elmo-folder-notify-event): Ditto.
+       (elmo-folder-set-flag): Call `elmo-folder-notify-event' with event
+       `flag-changed'.
+       (elmo-folder-unset-flag): Ditto.
+
+       * elmo-pipe.el (elmo-folder-set-flag): Ditto.
+       (elmo-folder-unset-flag): Ditto.
+
+       * elmo-multi.el (elmo-folder-set-flag): Ditto.
+       (elmo-folder-unset-flag): Ditto.
+
+       * elmo-filter.el (elmo-folder-set-flag): Ditto.
+       (elmo-folder-unset-flag): Ditto.
+
        * elmo-version.el (elmo-version): Up to 2.11.33.
 
 2004-10-25  Hiroya Murata  <lapis-lazuli@pop06.odn.ne.jp>
index 8c59e89..d8b0461 100644 (file)
   (elmo-filter-folder-countup-message-flags folder numbers -1)
   (elmo-folder-set-flag (elmo-filter-folder-target-internal folder)
                        numbers flag is-local)
-  (elmo-filter-folder-countup-message-flags folder numbers))
+  (elmo-filter-folder-countup-message-flags folder numbers)
+  (elmo-folder-notify-event folder 'flag-changed numbers))
 
 (luna-define-method elmo-folder-unset-flag ((folder elmo-filter-folder)
                                            numbers
   (elmo-filter-folder-countup-message-flags folder numbers -1)
   (elmo-folder-unset-flag (elmo-filter-folder-target-internal folder)
                          numbers flag is-local)
-  (elmo-filter-folder-countup-message-flags folder numbers))
+  (elmo-filter-folder-countup-message-flags folder numbers)
+  (elmo-folder-notify-event folder 'flag-changed numbers))
 
 (luna-define-method elmo-message-folder ((folder elmo-filter-folder)
                                         number)
index 5f3d5df..5903b1c 100644 (file)
                                          flag
                                          &optional is-local)
   (dolist (pair (elmo-multi-make-folder-numbers-list folder numbers))
-    (elmo-folder-set-flag (car pair) (cdr pair) flag is-local)))
+    (elmo-folder-set-flag (car pair) (cdr pair) flag is-local))
+  (elmo-folder-notify-event folder 'flag-changed numbers))
 
 (luna-define-method elmo-folder-unset-flag ((folder elmo-multi-folder)
                                            numbers
                                            &optional is-local)
   (dolist (pair (elmo-multi-make-folder-numbers-list folder numbers))
     (ignore-errors
-     (elmo-folder-unset-flag (car pair) (cdr pair) flag is-local))))
+     (elmo-folder-unset-flag (car pair) (cdr pair) flag is-local)))
+  (elmo-folder-notify-event folder 'flag-changed numbers))
 
 (luna-define-method elmo-folder-list-flagged ((folder elmo-multi-folder)
                                              flag
index 5e02dab..d7e90dd 100644 (file)
                                          flag
                                          &optional is-local)
   (elmo-folder-set-flag (elmo-pipe-folder-dst-internal folder)
-                       numbers flag is-local))
+                       numbers flag is-local)
+  (elmo-folder-notify-event folder 'flag-changed numbers))
 
 (luna-define-method elmo-folder-unset-flag ((folder elmo-pipe-folder)
                                            numbers
                                            flag
                                            &optional is-local)
   (elmo-folder-unset-flag (elmo-pipe-folder-dst-internal folder)
-                         numbers flag is-local))
+                         numbers flag is-local)
+  (elmo-folder-notify-event folder 'flag-changed numbers))
 
 (luna-define-method elmo-folder-pack-numbers ((folder elmo-pipe-folder))
   (elmo-folder-pack-numbers (elmo-pipe-folder-dst-internal folder)))
index 6cedb36..7a8b781 100644 (file)
@@ -123,6 +123,7 @@ If a folder name begins with PREFIX, use BACKEND."
                                     persistent   ; non-nil if persistent.
                                     process-duplicates  ; read or hide
                                     biff   ; folder for biff
+                                    handlers     ; list of event handler.
                                     ))
   (luna-define-internal-accessors 'elmo-folder))
 
@@ -1282,7 +1283,8 @@ VALUE is a value to set.")
          (elmo-global-flag-set flag folder number message-id)))
       (elmo-msgdb-set-flag (elmo-folder-msgdb folder)
                           number
-                          flag))))
+                          flag))
+    (elmo-folder-notify-event folder 'flag-changed numbers)))
 
 (defun elmo-message-has-global-flag-p (folder number)
   "Return non-nil when the message in the FOLDER with NUMBER has global flag."
@@ -1320,7 +1322,8 @@ If Optional LOCAL is non-nil, don't update server flag."
        (elmo-global-flag-detach flag folder number 'always))
       (elmo-msgdb-unset-flag (elmo-folder-msgdb folder)
                             number
-                            flag))))
+                            flag))
+    (elmo-folder-notify-event folder 'flag-changed numbers)))
 
 (luna-define-method elmo-folder-process-crosspost ((folder elmo-folder))
   ;; Do nothing.
@@ -1650,6 +1653,31 @@ Return a hashtable for newsgroups."
     (elmo-make-directory temp-dir)
     temp-dir))
 
+;; Event notification/observer framework
+(eval-and-compile
+  (luna-define-class elmo-event-handler ()))
+
+(luna-define-generic elmo-event-handler-flag-changed (handler numbers)
+  "Notify flag of the messages with NUMBERS is changed.")
+
+(defun elmo-folder-add-handler (folder handler)
+  (unless (memq handler (elmo-folder-handlers-internal folder))
+    (elmo-folder-set-handlers-internal
+     folder
+     (cons handler (elmo-folder-handlers-internal folder)))))
+
+(defun elmo-folder-remove-handler (folder handler)
+  (elmo-folder-set-handlers-internal
+   folder
+   (delq handler (elmo-folder-handlers-internal folder))))
+
+(defun elmo-folder-notify-event (folder event &rest args)
+  (when (elmo-folder-handlers-internal folder)
+    (let ((message (format "elmo-event-handler-%s" event)))
+      (dolist (handler (elmo-folder-handlers-internal folder))
+       (apply #'luna-send handler message handler args)))))
+
+;;;
 (defun elmo-init ()
   "Initialize ELMO module."
   (elmo-crosspost-message-alist-load)
index da6e216..30e9d11 100644 (file)
@@ -1,5 +1,20 @@
 2004-11-06  Hiroya Murata  <lapis-lazuli@pop06.odn.ne.jp>
 
+       * wl-summary.el (wl-summary-buffer-event-handler): New internal
+       variable.
+       (wl-summary-event-handler): New class.
+       (elmo-event-handler-flag-changed): Define to update persistent
+       mark.
+       (wl-summary-buffer-set-folder): Register event handler to
+       elmo-folder.
+       (wl-summary-exit): Unregister event handler.
+       (wl-summary-goto-folder-subr): Ditto.
+       (wl-summary-mark-as-read-all): Does not call
+       `wl-summary-update-persistent-mark' directly.
+       (wl-summary-mark-as-read-internal): Ditto.
+       (wl-summary-set-persistent-mark-internal): Ditto.
+       (wl-summary-set-flags-internal): Ditto.
+
        * Version number is increased to 2.11.33.
 
 2004-10-28  TAKAHASHI Kaoru  <kaoru@kaisei.org>
index d1b2f1b..afedf62 100644 (file)
 (defvar wl-summary-buffer-mode-line nil)
 (defvar wl-summary-buffer-display-mime-mode 'mime)
 (defvar wl-summary-buffer-display-all-header nil)
+(defvar wl-summary-buffer-event-handler nil)
 
 (defvar wl-thread-indent-level-internal nil)
 (defvar wl-thread-have-younger-brother-str-internal nil)
 (make-variable-buffer-local 'wl-summary-buffer-mode-line)
 (make-variable-buffer-local 'wl-summary-buffer-display-mime-mode)
 (make-variable-buffer-local 'wl-summary-buffer-display-all-header)
+(make-variable-buffer-local 'wl-summary-buffer-event-handler)
 
 (defvar wl-datevec)
 (defvar wl-thr-indent-string)
@@ -618,6 +620,22 @@ See also variable `wl-use-petname'."
        (wl-summary-lazy-update-mark
         (list 'wl-summary-update-mark-window))))
 
+;; Handler of event from elmo-folder
+(eval-and-compile
+  (luna-define-class wl-summary-event-handler (elmo-event-handler)
+                    (buffer))
+  (luna-define-internal-accessors 'wl-summary-event-handler))
+
+(luna-define-method elmo-event-handler-flag-changed ((handler
+                                                     wl-summary-event-handler)
+                                                    numbers)
+  (with-current-buffer (wl-summary-event-handler-buffer-internal handler)
+    (save-excursion
+      (dolist (number numbers)
+       (when (and (wl-summary-message-visible-p number)
+                  (wl-summary-jump-to-msg number))
+         (wl-summary-update-persistent-mark number))))))
+
 (defun wl-status-update ()
   (interactive)
   (wl-address-init))
@@ -801,6 +819,11 @@ you."
   (setq wl-summary-buffer-persistent
        (wl-folder-persistent-p (elmo-folder-name-internal folder)))
   (elmo-folder-set-persistent-internal folder wl-summary-buffer-persistent)
+  (elmo-folder-add-handler folder
+                          (setq wl-summary-buffer-event-handler
+                                (luna-make-entity
+                                 'wl-summary-event-handler
+                                 :buffer (current-buffer))))
   ;; process duplicates.
   (elmo-folder-set-process-duplicates-internal
    folder (cdr (elmo-string-matched-assoc
@@ -1173,7 +1196,10 @@ Entering Folder mode calls the value of `wl-summary-mode-hook'."
          (progn
            (wl-summary-save-view)
            (if (or force-exit (not sticky))
-               (elmo-folder-close wl-summary-buffer-elmo-folder)
+               (progn
+                 (elmo-folder-close wl-summary-buffer-elmo-folder)
+                 (elmo-folder-remove-handler wl-summary-buffer-elmo-folder
+                                             wl-summary-buffer-event-handler))
              (elmo-folder-commit wl-summary-buffer-elmo-folder)
              (elmo-folder-check wl-summary-buffer-elmo-folder))
            (if wl-use-scoring (wl-score-save)))
@@ -1663,11 +1689,6 @@ If ARG is non-nil, checking is omitted."
         folder
         (elmo-folder-list-flagged folder 'unread 'in-msgdb)
         'unread)
-       (save-excursion
-         (goto-char (point-min))
-         (while (not (eobp))
-           (wl-summary-update-persistent-mark)
-           (forward-line 1)))
        (wl-folder-update-unread (wl-summary-buffer-folder-name) 0)
        (setq wl-summary-buffer-unread-count 0)
        (setq wl-summary-buffer-new-count    0)
@@ -2299,6 +2320,9 @@ If ARG, without confirm."
          (if other-window
              (delete-other-windows))
          (set-buffer buf)
+         (when wl-summary-buffer-event-handler
+           (elmo-folder-remove-handler wl-summary-buffer-elmo-folder
+                                       wl-summary-buffer-event-handler))
          (unless (eq major-mode 'wl-summary-mode)
            (wl-summary-mode))
          (wl-summary-buffer-set-folder folder)
@@ -3015,7 +3039,7 @@ Return non-nil if the mark is updated"
   (save-excursion
     (let ((folder wl-summary-buffer-elmo-folder)
          unread-message number
-         number-list visible)
+         number-list)
       (setq number-list (cond ((numberp number-or-numbers)
                               (setq unread-message
                                     (elmo-message-flagged-p
@@ -3039,14 +3063,11 @@ Return non-nil if the mark is updated"
        (if inverse
            (elmo-folder-set-flag folder number-list 'unread no-folder-mark)
          (elmo-folder-unset-flag folder number-list 'unread no-folder-mark))
-       (dolist (number number-list)
-         (setq visible (wl-summary-jump-to-msg number))
-         (unless inverse
-           (when unread-message
-             (run-hooks 'wl-summary-unread-message-hook)))
-         ;; set mark on buffer
-         (when visible
-           (wl-summary-update-persistent-mark)))
+       (when (and unread-message
+                  (not inverse))
+         (dolist (number number-list)
+           (wl-summary-jump-to-msg number)
+           (run-hooks 'wl-summary-unread-message-hook)))
        (unless no-modeline-update
          ;; Update unread numbers.
          (wl-summary-count-unread)
@@ -3082,7 +3103,7 @@ Return non-nil if the mark is updated"
   "Set persistent mark."
   (save-excursion
     (let ((folder wl-summary-buffer-elmo-folder)
-         number number-list visible)
+         number number-list)
       (setq number-list (cond ((numberp number-or-numbers)
                               (list number-or-numbers))
                              ((and (not (null number-or-numbers))
@@ -3099,10 +3120,6 @@ Return non-nil if the mark is updated"
              (if inverse
                  (elmo-folder-unset-flag folder number-list flag no-server)
                (elmo-folder-set-flag folder number-list flag no-server))
-             (dolist (number number-list)
-               ;; set mark on buffer
-               (when (wl-summary-jump-to-msg number)
-                 (wl-summary-update-persistent-mark)))
              (unless no-modeline-update
                ;; Update unread numbers.
                ;; should elmo-flag-mark-as-read return unread numbers?
@@ -3241,7 +3258,7 @@ Return non-nil if the mark is updated"
                                        remove-all)
   (save-excursion
     (let ((folder wl-summary-buffer-elmo-folder)
-         number number-list visible)
+         number number-list)
       (setq number-list (cond ((numberp number-or-numbers)
                               (list number-or-numbers))
                              ((and (not (null number-or-numbers))
@@ -3257,11 +3274,7 @@ Return non-nil if the mark is updated"
       (if (null number-list)
          (message "No message.")
        (dolist (number number-list)
-         (elmo-message-set-global-flags folder number flags local)
-         (setq visible (wl-summary-jump-to-msg number))
-         ;; set mark on buffer
-         (when visible
-           (wl-summary-update-persistent-mark))))
+         (elmo-message-set-global-flags folder number flags local)))
       flags)))
 
 (defun wl-summary-set-flags (&optional remove)