浏览代码

ui: opening new window i18n support

Junyi Du 3 年之前
父节点
当前提交
7bc731fcee

+ 2 - 2
src/main/frontend/components/repo.cljs

@@ -205,7 +205,7 @@
                          :options {:class "ml-1"
                                    :on-click (fn [e]
                                                (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])))}}))
                     switch-repos)
         refresh-link (let [nfs-repo? (config/local-db? current-repo)]
@@ -253,7 +253,7 @@
                                                       page-handler/create-today-journal!)))]])))})}
         new-window-link (when (util/electron?)
                           {: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
              [(when (seq repo-links) {:hr true})

+ 4 - 0
src/main/frontend/dicts.cljs

@@ -305,6 +305,8 @@
         :new-graph "Add new graph"
         :graph "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"
         :publishing "Publishing"
         :export "Export"
@@ -1199,6 +1201,8 @@
            :new-page "新页面"
            :new-file "新文件"
            :graph "图谱"
+           :graph/open-new-window "打开新窗口前,Logseq正在同步内部状态,请等待片刻。"
+           :graph/open-new-window-error "内部状态同步失败。无法打开新窗口。"
            :graph-view "全局图谱"
            :cards-view "卡片组"
            :all-journals "日记"

+ 11 - 0
src/main/frontend/handler/events.cljs

@@ -2,6 +2,7 @@
   (:refer-clojure :exclude [run!])
   (:require [clojure.core.async :as async]
             [clojure.set :as set]
+            [frontend.context.i18n :refer [t]]
             [frontend.components.diff :as diff]
             [frontend.handler.plugin :as plugin-handler]
             [frontend.components.plugins :as plugin]
@@ -311,6 +312,16 @@
            :path
            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!
   []
   (let [chan (state/get-events-chan)]

+ 0 - 16
src/main/frontend/handler/repo.cljs

@@ -20,7 +20,6 @@
             [frontend.handler.metadata :as metadata-handler]
             [frontend.idb :as idb]
             [frontend.search :as search]
-            [frontend.storage :as storage]
             [frontend.spec :as spec]
             [frontend.state :as state]
             [frontend.util :as util]
@@ -671,18 +670,3 @@
    (p/catch (fn [error]
               (js/console.error 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)})
-   ))

+ 9 - 1
src/main/frontend/handler/ui.cljs

@@ -13,7 +13,8 @@
             [goog.object :as gobj]
             [clojure.string :as string]
             [rum.core :as rum]
-            [frontend.mobile.util :as mobile]))
+            [frontend.mobile.util :as mobile]
+            [electron.ipc :as ipc]))
 
 (defn- get-css-var-value
   [var-name]
@@ -295,3 +296,10 @@
     (state/close-modal!)
     (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")))

+ 1 - 2
src/main/frontend/modules/shortcut/config.cljs

@@ -10,7 +10,6 @@
             [frontend.handler.journal :as journal-handler]
             [frontend.handler.search :as search-handler]
             [frontend.handler.ui :as ui-handler]
-            [frontend.handler.repo :as repo-handler]
             [frontend.handler.plugin :as plugin-handler]
             [frontend.modules.shortcut.before :as m]
             [frontend.state :as state]
@@ -417,7 +416,7 @@
    :ui/open-new-window              (when (util/electron?)
                                       {:desc    "Open another window"
                                        :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"
                                      :binding "mod+shift+f"