ui: opening new window i18n support

pull/4656/head
Junyi Du 2022-03-13 19:13:53 +08:00 committed by Tienson Qin
parent d425a60038
commit 7bc731fcee
6 changed files with 27 additions and 21 deletions

View File

@ -205,7 +205,7 @@
:options {:class "ml-1" :options {:class "ml-1"
:on-click (fn [e] :on-click (fn [e]
(if (gobj/get e "shiftKey") (if (gobj/get e "shiftKey")
(repo-handler/open-new-window! e url) (state/pub-event! [:graph/open-new-window url])
(state/pub-event! [:graph/switch url])))}})) (state/pub-event! [:graph/switch url])))}}))
switch-repos) switch-repos)
refresh-link (let [nfs-repo? (config/local-db? current-repo)] refresh-link (let [nfs-repo? (config/local-db? current-repo)]
@ -253,7 +253,7 @@
page-handler/create-today-journal!)))]])))})} page-handler/create-today-journal!)))]])))})}
new-window-link (when (util/electron?) new-window-link (when (util/electron?)
{:title (t :open-new-window) {:title (t :open-new-window)
:options {:on-click repo-handler/open-new-window!}})] :options {:on-click #(state/pub-event! [:graph/open-new-window nil])}})]
(->> (->>
(concat repo-links (concat repo-links
[(when (seq repo-links) {:hr true}) [(when (seq repo-links) {:hr true})

View File

@ -305,6 +305,8 @@
:new-graph "Add new graph" :new-graph "Add new graph"
:graph "Graph" :graph "Graph"
:graph-view "View graph" :graph-view "View graph"
:graph/open-new-window "Logseq is syncing internal status before opening new window, please wait for several seconds."
:graph/open-new-window-error "Internal status sync failed. Unable to open new window."
:cards-view "View cards" :cards-view "View cards"
:publishing "Publishing" :publishing "Publishing"
:export "Export" :export "Export"
@ -1199,6 +1201,8 @@
:new-page "新页面" :new-page "新页面"
:new-file "新文件" :new-file "新文件"
:graph "图谱" :graph "图谱"
:graph/open-new-window "打开新窗口前Logseq正在同步内部状态请等待片刻。"
:graph/open-new-window-error "内部状态同步失败。无法打开新窗口。"
:graph-view "全局图谱" :graph-view "全局图谱"
:cards-view "卡片组" :cards-view "卡片组"
:all-journals "日记" :all-journals "日记"

View File

@ -2,6 +2,7 @@
(:refer-clojure :exclude [run!]) (:refer-clojure :exclude [run!])
(:require [clojure.core.async :as async] (:require [clojure.core.async :as async]
[clojure.set :as set] [clojure.set :as set]
[frontend.context.i18n :refer [t]]
[frontend.components.diff :as diff] [frontend.components.diff :as diff]
[frontend.handler.plugin :as plugin-handler] [frontend.handler.plugin :as plugin-handler]
[frontend.components.plugins :as plugin] [frontend.components.plugins :as plugin]
@ -311,6 +312,16 @@
:path :path
js/decodeURI))) js/decodeURI)))
(defmethod handle :graph/open-new-window [[_ repo]]
; TODO: find out a better way to open a new window with a different repo path
(repo-handler/persist-dbs! {:before #(notification/show!
(ui/loading (t :graph/open-new-window))
:warning)
:on-success #(ui-handler/open-new-window! _ repo)
:on-error #(notification/show!
(t :graph/open-new-window-error)
:error)}))
(defn run! (defn run!
[] []
(let [chan (state/get-events-chan)] (let [chan (state/get-events-chan)]

View File

@ -20,7 +20,6 @@
[frontend.handler.metadata :as metadata-handler] [frontend.handler.metadata :as metadata-handler]
[frontend.idb :as idb] [frontend.idb :as idb]
[frontend.search :as search] [frontend.search :as search]
[frontend.storage :as storage]
[frontend.spec :as spec] [frontend.spec :as spec]
[frontend.state :as state] [frontend.state :as state]
[frontend.util :as util] [frontend.util :as util]
@ -671,18 +670,3 @@
(p/catch (fn [error] (p/catch (fn [error]
(js/console.error error) (js/console.error error)
(on-error))))) (on-error)))))
(defn open-new-window!
([_e]
(open-new-window! _e nil))
([_e repo]
; TODO: find out a better way to open a new window with a different repo path
(when (string? repo) (storage/set :git/current-repo repo))
(persist-dbs! {:before #(notification/show!
"Logseq is syncing internal status before opening new window, please wait for several seconds."
:warning)
:on-success #(ipc/ipc "openNewWindow")
:on-error #(notification/show!
"Logseq internal status syncing failed. Stop opening new window"
:error)})
))

View File

@ -13,7 +13,8 @@
[goog.object :as gobj] [goog.object :as gobj]
[clojure.string :as string] [clojure.string :as string]
[rum.core :as rum] [rum.core :as rum]
[frontend.mobile.util :as mobile])) [frontend.mobile.util :as mobile]
[electron.ipc :as ipc]))
(defn- get-css-var-value (defn- get-css-var-value
[var-name] [var-name]
@ -295,3 +296,10 @@
(state/close-modal!) (state/close-modal!)
(state/pub-event! [:modal/show-cards]))) (state/pub-event! [:modal/show-cards])))
(defn open-new-window!
([_e]
(open-new-window! _e nil))
([_e repo]
; TODO: find out a better way to open a new window with a different repo path
(when (string? repo) (storage/set :git/current-repo repo))
(ipc/ipc "openNewWindow")))

View File

@ -10,7 +10,6 @@
[frontend.handler.journal :as journal-handler] [frontend.handler.journal :as journal-handler]
[frontend.handler.search :as search-handler] [frontend.handler.search :as search-handler]
[frontend.handler.ui :as ui-handler] [frontend.handler.ui :as ui-handler]
[frontend.handler.repo :as repo-handler]
[frontend.handler.plugin :as plugin-handler] [frontend.handler.plugin :as plugin-handler]
[frontend.modules.shortcut.before :as m] [frontend.modules.shortcut.before :as m]
[frontend.state :as state] [frontend.state :as state]
@ -417,7 +416,7 @@
:ui/open-new-window (when (util/electron?) :ui/open-new-window (when (util/electron?)
{:desc "Open another window" {:desc "Open another window"
:binding "mod+n" :binding "mod+n"
:fn repo-handler/open-new-window!}) :fn #(state/pub-event! [:graph/open-new-window nil])})
:command/toggle-favorite {:desc "Add to/remove from favorites" :command/toggle-favorite {:desc "Add to/remove from favorites"
:binding "mod+shift+f" :binding "mod+shift+f"