Skip to content

Commit b8fe239

Browse files
committed
switch to window if one exists instead of create new one
1 parent 55a9e11 commit b8fe239

File tree

2 files changed

+632
-526
lines changed

2 files changed

+632
-526
lines changed

source/clog-gui.lisp

Lines changed: 104 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
(menu-bar generic-function)
4040
(menu-bar-height generic-function)
4141
(window-collection generic-function)
42+
(window-to-top-by-title generic-function)
43+
(window-to-top-by-param generic-function)
44+
(window-by-title generic-function)
45+
(window-by-param generic-function)
4246
(maximize-all-windows generic-function)
4347
(normalize-all-windows generic-function)
4448
(set-on-window-change generic-function)
@@ -47,6 +51,7 @@
4751
(clog-gui-window class)
4852
(create-gui-window generic-function)
4953
(window-title generic-function)
54+
(window-param generic-function)
5055
(window-content generic-function)
5156
(window-focus generic-function)
5257
(window-close generic-function)
@@ -250,6 +255,80 @@ create-gui-menu-bar."))
250255
(let ((app (connection-data-item obj "clog-gui")))
251256
(windows app)))
252257

258+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
259+
;; window-to-top-by-title ;;
260+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
261+
262+
(defgeneric window-to-top-by-title (clog-obj title)
263+
(:documentation "Bring window with TITLE to top and return
264+
window or nil if not found"))
265+
266+
(defmethod window-to-top-by-title ((obj clog-obj) title)
267+
(let ((app (connection-data-item obj "clog-gui"))
268+
(r nil))
269+
(maphash (lambda (key value)
270+
(declare (ignore key))
271+
(when (equalp (window-title value) title)
272+
(window-focus value)
273+
(setf r key)))
274+
(windows app))
275+
r))
276+
277+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
278+
;; window-to-top-by-param ;;
279+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;
280+
281+
(defgeneric window-to-top-by-param (clog-obj param)
282+
(:documentation "Bring window with PARAM to top and return
283+
window or nil if not found"))
284+
285+
(defmethod window-to-top-by-param ((obj clog-obj) param)
286+
(let ((app (connection-data-item obj "clog-gui"))
287+
(r nil))
288+
(maphash (lambda (key value)
289+
(declare (ignore key))
290+
(when (equalp (win-param value) param)
291+
(window-focus value)
292+
(setf r key)))
293+
(windows app))
294+
r))
295+
296+
;;;;;;;;;;;;;;;;;;;;;
297+
;; window-by-title ;;
298+
;;;;;;;;;;;;;;;;;;;;;
299+
300+
(defgeneric window-by-title (clog-obj title)
301+
(:documentation "Bring window with TITLE to top and return
302+
window or nil if not found"))
303+
304+
(defmethod window-by-title ((obj clog-obj) title)
305+
(let ((app (connection-data-item obj "clog-gui"))
306+
(r nil))
307+
(maphash (lambda (key value)
308+
(declare (ignore key))
309+
(when (equalp (window-title value) title)
310+
(setf r key)))
311+
(windows app))
312+
r))
313+
314+
;;;;;;;;;;;;;;;;;;;;;
315+
;; window-by-param ;;
316+
;;;;;;;;;;;;;;;;;;;;;
317+
318+
(defgeneric window-by-param (clog-obj param)
319+
(:documentation "Bring window with PARAM to top and return
320+
window or nil if not found"))
321+
322+
(defmethod window-by-param ((obj clog-obj) param)
323+
(let ((app (connection-data-item obj "clog-gui"))
324+
(r nil))
325+
(maphash (lambda (key value)
326+
(declare (ignore key))
327+
(when (equalp (win-param value) param)
328+
(setf r key)))
329+
(windows app))
330+
r))
331+
253332
;;;;;;;;;;;;;;;;;;;;;;;;;;
254333
;; maximize-all-windows ;;
255334
;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -498,6 +577,10 @@ The on-window-change clog-obj received is the new window"))
498577
((win-title
499578
:accessor win-title
500579
:documentation "Window title clog-element")
580+
(win-param
581+
:accessor win-param
582+
:initform nil
583+
:documentation "Window specific parameter")
501584
(title-bar
502585
:accessor title-bar
503586
:documentation "Window title-bar clog-element")
@@ -678,6 +761,7 @@ The on-window-change clog-obj received is the new window"))
678761
maximize
679762
has-pinner
680763
keep-on-top
764+
window-param
681765
hidden
682766
client-movement
683767
border-class
@@ -690,7 +774,8 @@ at end of drag and on-window-resize at start of resize and
690774
on-window-resize-done at end of resize. If has-pinner a toggle wil appear on
691775
title bar to allow pinning the window in place, if keep-on-top t then when
692776
pinned also will keep-on-top. If had-pinned is nil and keep-on-top t then
693-
the window will be set to keep-on-top always."))
777+
the window will be set to keep-on-top always. window-param is a general parameter
778+
for identifiying the window to use with window-to-top-by-param or window-by-param."))
694779

695780
(defmethod create-gui-window ((obj clog-obj) &key (title "New Window")
696781
(content "")
@@ -701,6 +786,7 @@ the window will be set to keep-on-top always."))
701786
(maximize nil)
702787
(has-pinner nil)
703788
(keep-on-top nil)
789+
(window-param nil)
704790
(hidden nil)
705791
(client-movement nil)
706792
(border-class "w3-card-4 w3-white w3-border")
@@ -760,6 +846,7 @@ the window will be set to keep-on-top always."))
760846
:html-id html-id)))
761847
(setf (win-title win)
762848
(attach-as-child win (format nil "~A-title" html-id)))
849+
(setf (win-param win) window-param)
763850
(setf (title-bar win)
764851
(attach-as-child win (format nil "~A-title-bar" html-id)))
765852
(when has-pinner
@@ -844,6 +931,22 @@ the window will be set to keep-on-top always."))
844931
(setf (inner-html (window-select-item obj)) value))
845932
(setf (inner-html (win-title obj)) value))
846933

934+
;;;;;;;;;;;;;;;;;;
935+
;; window-param ;;
936+
;;;;;;;;;;;;;;;;;;
937+
938+
(defgeneric window-param (clog-gui-window)
939+
(:documentation "Get/setf window param"))
940+
941+
(defmethod window-param ((obj clog-gui-window))
942+
(win-param obj))
943+
944+
(defgeneric (setf window-param) (value clog-gui-window)
945+
(:documentation "Set window param"))
946+
947+
(defmethod (setf window-param) (value (obj clog-gui-window))
948+
(setf (win-param obj) value))
949+
847950
;;;;;;;;;;;;;;;;;;;;
848951
;; window-content ;;
849952
;;;;;;;;;;;;;;;;;;;;

0 commit comments

Comments
 (0)