diff --git a/src/main/frontend/components/page.cljs b/src/main/frontend/components/page.cljs index efaa8e6c03..d0bece7f31 100644 --- a/src/main/frontend/components/page.cljs +++ b/src/main/frontend/components/page.cljs @@ -292,97 +292,96 @@ (not sidebar?) (not config/publishing?)) - (let [contents? (= (string/lower-case (str page-name)) "contents") - links (->> - [(when-not contents? - {:title (t :page/add-to-contents) - :options {:on-click (fn [] (page-handler/handle-add-page-to-contents! page-original-name))}}) + (let [contents? (= (string/lower-case (str page-name)) "contents") + links (fn [] (->> + [(when-not contents? + {:title (t :page/add-to-contents) + :options {:on-click (fn [] (page-handler/handle-add-page-to-contents! page-original-name))}}) - (when-not contents? - {:title (t :page/rename) - :options {:on-click #(state/set-modal! (rename-page-dialog title page-name))}}) + (when-not contents? + {:title (t :page/rename) + :options {:on-click #(state/set-modal! (rename-page-dialog title page-name))}}) - (when (and file-path (util/electron?)) - [{:title (t :page/open-in-finder) - :options {:on-click #(js/window.apis.showItemInFolder file-path)}} - {:title (t :page/open-with-default-app) - :options {:on-click #(js/window.apis.openPath file-path)}}]) + (when-let [file-path (and (util/electron?) (page-handler/get-page-file-path))] + [{:title (t :page/open-in-finder) + :options {:on-click #(js/window.apis.showItemInFolder file-path)}} + {:title (t :page/open-with-default-app) + :options {:on-click #(js/window.apis.openPath file-path)}}]) - (when-not contents? - {:title (t :page/delete) - :options {:on-click #(state/set-modal! (delete-page-dialog page-name))}}) + (when-not contents? + {:title (t :page/delete) + :options {:on-click #(state/set-modal! (delete-page-dialog page-name))}}) - (when (state/get-current-page) - {:title (t :export) - :options {:on-click #(state/set-modal! export/export-page)}}) + (when (state/get-current-page) + {:title (t :export) + :options {:on-click #(state/set-modal! export/export-page)}}) - (when (util/electron?) - {:title (t (if public? :page/make-private :page/make-public)) - :options {:on-click - (fn [] - (page-handler/update-public-attribute! - page-name - (if public? false true)) - (state/close-modal!))}}) + (when (util/electron?) + {:title (t (if public? :page/make-private :page/make-public)) + :options {:on-click + (fn [] + (page-handler/update-public-attribute! + page-name + (if public? false true)) + (state/close-modal!))}}) - (when developer-mode? - {:title "(Dev) Show page data" - :options {:on-click (fn [] - (let [page-data (with-out-str (pprint/pprint (db/pull (:db/id page))))] - (println page-data) - (notification/show! - [:div - [:pre.code page-data] - [:br] - (ui/button "Copy to clipboard" - :on-click #(.writeText js/navigator.clipboard page-data))] - :success - false)))}})] - (flatten) - (remove nil?))] - [:div {:style {:position "absolute" - :right 0 - :top 20}} - [:div.flex.flex-row - [:a.opacity-30.hover:opacity-100.page-op.mr-2 - {:title "Search in current page" - :on-click #(route-handler/go-to-search! :page)} - svg/search] - (when (not config/mobile?) - (presentation repo page)) - (when (seq links) - (ui/dropdown-with-links + (when developer-mode? + {:title "(Dev) Show page data" + :options {:on-click (fn [] + (let [page-data (with-out-str (pprint/pprint (db/pull (:db/id page))))] + (println page-data) + (notification/show! + [:div + [:pre.code page-data] + [:br] + (ui/button "Copy to clipboard" + :on-click #(.writeText js/navigator.clipboard page-data))] + :success + false)))}})] + (flatten) + (remove nil?)))] + [:div {:style {:position "absolute" + :right 0 + :top 20}} + [:div.flex.flex-row + [:a.opacity-30.hover:opacity-100.page-op.mr-2 + {:title "Search in current page" + :on-click #(route-handler/go-to-search! :page)} + svg/search] + (when (not config/mobile?) + (presentation repo page)) + (ui/dropdown-with-links (fn [{:keys [toggle-fn]}] [:a.opacity-30.hover:opacity-100 - {:title "More options" + {:title "More options" :on-click toggle-fn} (svg/vertical-dots {:class (util/hiccup->class "opacity-30.hover:opacity-100.h-5.w-5")})]) links {:modal-class (util/hiccup->class - "origin-top-right.absolute.right-0.top-10.mt-2.rounded-md.shadow-lg.whitespace-no-wrap.dropdown-overflow-auto.page-drop-options") - :z-index 1}))]])) - (when (and (not sidebar?) - (not block?)) - [:a {:on-click (fn [e] - (.preventDefault e) - (when (gobj/get e "shiftKey") - (when-let [page (db/pull repo '[*] [:block/name page-name])] - (state/sidebar-add-block! - repo - (:db/id page) - :page - {:page page}))))} - [:h1.title {:style {:margin-left -2}} - (if page-original-name - (if (and (string/includes? page-original-name "[[") - (string/includes? page-original-name "]]")) - (let [ast (mldoc/->edn page-original-name (mldoc/default-config format))] - (block/markup-element-cp {} (ffirst ast))) - page-original-name) - (or - page-name - path-page-name))]]) - [:div + "origin-top-right.absolute.right-0.top-10.mt-2.rounded-md.shadow-lg.whitespace-no-wrap.dropdown-overflow-auto.page-drop-options") + :z-index 1})]])) + (when (and (not sidebar?) + (not block?)) + [:a {:on-click (fn [e] + (.preventDefault e) + (when (gobj/get e "shiftKey") + (when-let [page (db/pull repo '[*] [:block/name page-name])] + (state/sidebar-add-block! + repo + (:db/id page) + :page + {:page page}))))} + [:h1.title {:style {:margin-left -2}} + (if page-original-name + (if (and (string/includes? page-original-name "[[") + (string/includes? page-original-name "]]")) + (let [ast (mldoc/->edn page-original-name (mldoc/default-config format))] + (block/markup-element-cp {} (ffirst ast))) + page-original-name) + (or + page-name + path-page-name))]]) + [:div ;; [:div.content ;; (when (and file-path ;; (not sidebar?) diff --git a/src/main/frontend/handler/page.cljs b/src/main/frontend/handler/page.cljs index a76885c53d..c262e58170 100644 --- a/src/main/frontend/handler/page.cljs +++ b/src/main/frontend/handler/page.cljs @@ -43,6 +43,11 @@ ;; Win10 file path has a length limit of 260 chars (util/safe-subs s 0 200))) +(defn get-page-file-path + ([] (get-page-file-path (state/get-current-page))) + ([page-name] (when-let [page (db/entity [:block/name page-name])] + (:file/path (:block/file page))))) + (defn create! ([title] (create! title {})) @@ -350,7 +355,6 @@ (fn [] (init-commands!)))) - ;; TODO: add use :file/last-modified-at (defn get-pages-with-modified-at [repo] diff --git a/src/main/frontend/ui.cljs b/src/main/frontend/ui.cljs index f6dd41c487..f7faa992f3 100644 --- a/src/main/frontend/ui.cljs +++ b/src/main/frontend/ui.cljs @@ -87,7 +87,7 @@ (fn [{:keys [close-fn] :as state}] [:div.py-1.rounded-md.shadow-xs (when links-header links-header) - (for [{:keys [options title icon]} links] + (for [{:keys [options title icon]} (if (fn? links) (links) links)] (let [new-options (assoc options :on-click (fn [e]