From 45dafd4f38ab97d64126ac972287a349ef8ba388 Mon Sep 17 00:00:00 2001 From: vision-05 Date: Fri, 28 May 2021 23:28:17 +0000 Subject: [PATCH 1/5] started line numbers, polished the styling more --- bettercode/src/bettercode/core.clj | 6 ++- bettercode/src/bettercode/css.clj | 43 +++++++++++++--------- bettercode/src/bettercode/elements.clj | 6 +-- bettercode/src/bettercode/events.clj | 10 +++-- bettercode/src/bettercode/utilelements.clj | 3 ++ 5 files changed, 42 insertions(+), 26 deletions(-) diff --git a/bettercode/src/bettercode/core.clj b/bettercode/src/bettercode/core.clj index 24608cb..ef205d9 100644 --- a/bettercode/src/bettercode/core.clj +++ b/bettercode/src/bettercode/core.clj @@ -42,7 +42,7 @@ :width 768 :height 1080 :min-width 768 - :min-height 1080 + :min-height 1140 :resizable true :scene {:fx/type :scene :fill "#23282D" @@ -60,6 +60,7 @@ :on-action {:event/type :bettercode.events/openfex :tclient tclient}} {:fx/type :menu-item + :style-class "root-menu-bar-item-sub-item" :text "save" :on-action {:event/type :bettercode.events/saveevent :tclient tclient}}]}]} @@ -97,7 +98,8 @@ :dir-contents dirs :cur-path "/home/tim/foo.txt" :file-explorer-show true - :file-name-entered ""} + :file-name-entered "" + :line-numbers ""} #(cache/lru-cache-factory % :threshold 4096)))] (fx/create-app *context :event-handler bettercode.events/handle-event diff --git a/bettercode/src/bettercode/css.clj b/bettercode/src/bettercode/css.clj index bcfb6d8..25d9d5f 100644 --- a/bettercode/src/bettercode/css.clj +++ b/bettercode/src/bettercode/css.clj @@ -4,32 +4,33 @@ (def style (css/register ::style (let [back-background-color "#2E3440" - status-background-color "#6183AE" + status-background-color "#4C566A" text-color "#ECEFF4" - border-color "#5E81AC" + border-color "#4C566A" background-color "#2E3440" scroll-color "#434C5E22" thumb-color "#4C566A44" - highlight-color "#5E81AC"] + highlight-color "#4C566A" + line-no-color "#4C566A"] {".root" {:-fx-background-color back-background-color :-fx-text-fill text-color "-menu-bar" {:-fx-background-color highlight-color :-fx-text-fill text-color - :-fx-padding 0 - :-fx-margin 0 + :-fx-control-inner-background highlight-color " .label" {:-fx-font-size 12 :-fx-text-fill text-color} "-item" {:-fx-text-fill text-color :-fx-background-color highlight-color - :-fx-padding 0 - :-fx-margin 0 + :-fx-control-inner-background highlight-color + :-fx-border-color highlight-color " .label" {:-fx-font-size 10 :-fx-text-fill text-color} "-sub-item" {:-fx-text-fill text-color - :-fx-padding 0 - :-fx-margin 0 :-fx-background-color highlight-color - :-fx-control-inner-background highlight-color}}} + :-fx-control-inner-background highlight-color + :-fx-padding [4 4 4 4] + ":hover" {:-fx-background-color background-color + :-fx-background-radius 5}}}} "-fsview" {:-fx-control-inner-background back-background-color "-button" {:-fx-background-color back-background-color :-fx-border-color border-color @@ -38,6 +39,11 @@ :-fx-padding [4 4 4 4] ":hover" {:-fx-background-color border-color :-fx-background-radius 5}} + "-filename-input" {:-fx-background-color back-background-color + :-fx-border-color border-color + :-fx-text-fill text-color + :-fx-padding [4 4 4 4] + :-fx-border-radius 5} "> .virtual-flow" {:-fx-background-color background-color :-fx-hbar-policy :as-needed :-fx-vbar-policy :as-needed @@ -46,13 +52,15 @@ " .thumb" {:-fx-background-color thumb-color}} ":vertical" {:-fx-background-color scroll-color " .thumb" {:-fx-background-color thumb-color}}}}} - "-text-area" {"-status" {:-fx-background-color status-background-color + "-text-area" {"-status" {:-fx-background-color back-background-color + :-fx-border-color border-color + :-fx-border-style [:hidden :hidden :solid :hidden] :-fx-text-fill text-color :-fx-highlight-fill status-background-color} "-editor" {:-fx-text-fill text-color :-fx-highlight-fill highlight-color :-fx-background-color back-background-color - :-fx-border-color border-color + ;:-fx-border-color border-color " .content" {:-fx-background-color background-color} " .scroll-pane" {:-fx-background-color background-color :-fx-hbar-policy :as-needed @@ -62,14 +70,13 @@ " .thumb" {:-fx-background-color thumb-color}} ":vertical" {:-fx-background-color scroll-color " .thumb" {:-fx-background-color thumb-color}}}}} - "-numbers" {:-fx-text-fill text-color + "-numbers" {:-fx-text-fill line-no-color :-fx-background-color background-color - :-fx-border-color border-color + ;:-fx-border-color border-color + :-fx-highlight-fill background-color + " *.text" {:-fx-text-alignment :right} " .content" {:-fx-background-color background-color} " .scroll-pane" {:-fx-hbar-policy :never :-fx-vbar-policy :never - :-fx-background-color background-color - :-fx-padding 10 - :-fx-border-insets 10 - :-f-background-insets 10}}}}}))) + :-fx-background-color background-color}}}}}))) diff --git a/bettercode/src/bettercode/elements.clj b/bettercode/src/bettercode/elements.clj index 73c3ed8..160ee95 100644 --- a/bettercode/src/bettercode/elements.clj +++ b/bettercode/src/bettercode/elements.clj @@ -31,7 +31,8 @@ (defn line-numbers [{:keys [fx/context]}] {:fx/type :text-area :editable false - :pref-width 80 + :text (fx/sub context :line-numbers) + :pref-width 40 :pref-height 896 :font "Roboto Mono" :style-class "root-text-area-numbers"}) @@ -52,7 +53,7 @@ :spacing 28 :children [{:fx/type line-numbers :h-box/vgrow :always} - {:fx/type text-edit + {:fx/type text-edit ;this doesn't expand downwards for some reason :tclient tclient :h-box/vgrow :always :h-box/hgrow :always}]}) @@ -61,7 +62,6 @@ {:fx/type :v-box :pref-width 768 :min-width 768 - :pref-height 1080 :min-height 1080 :children [{:fx/type status-row :v-box/hgrow :always} diff --git a/bettercode/src/bettercode/events.clj b/bettercode/src/bettercode/events.clj index b9a132b..6be3579 100644 --- a/bettercode/src/bettercode/events.clj +++ b/bettercode/src/bettercode/events.clj @@ -34,7 +34,8 @@ assoc :file-path file-path-new :text-editor "" - :file-explorer-show false)})) + :file-explorer-show false + :line-numbers "1\n")})) (defmethod handle-event ::openfex [{:keys [fx/event fx/context]}] {:context (fx/swap-context context @@ -61,13 +62,16 @@ :dir-contents dir-contents :cur-path entry-name)})) (= entry-info "FIL: ") (do @(s/put! tclient ["open-file" entry-name]) - (let [file-contents @(s/take! tclient)] + (let [file-contents @(s/take! tclient) + no-of-lines (+ 2 (count (re-seq #"\n" file-contents))) + line-numbers (apply str (map #(str % \newline) (range 1 no-of-lines)))] (println file-contents) {:context (fx/swap-context context assoc :file-path entry-name :text-editor file-contents - :file-explorer-show false)}))))) + :file-explorer-show false + :line-numbers line-numbers)}))))) (defmethod handle-event ::type-text [{:keys [fx/event fx/context tclient]}] (println event) ;get soruce of event, prefereably diff --git a/bettercode/src/bettercode/utilelements.clj b/bettercode/src/bettercode/utilelements.clj index d68026c..8de7480 100644 --- a/bettercode/src/bettercode/utilelements.clj +++ b/bettercode/src/bettercode/utilelements.clj @@ -38,9 +38,12 @@ (defn file-window [{:keys [fx/context tclient]}] {:fx/type :v-box + :padding 2 + :spacing 4 :children [{:fx/type file-view :tclient tclient} {:fx/type :text-field + :style-class "root-fsview-filename-input" :on-key-typed {:event/type :bettercode.events/type-filename :fx/sync true}} {:fx/type button-layout From 51c34554e4f3db41a90fcd7e380889f96f33f202 Mon Sep 17 00:00:00 2001 From: vision-05 Date: Sat, 29 May 2021 11:32:49 +0000 Subject: [PATCH 2/5] line numbers now add and remove dynamically, server now syncs with client on save --- bettercode/src/bettercode/core.clj | 6 +- bettercode/src/bettercode/elements.clj | 9 +-- bettercode/src/bettercode/events.clj | 64 ++++++++++--------- .../src/bettercodeserver/buffer.clj | 23 ++----- .../src/bettercodeserver/core.clj | 2 +- .../src/bettercodeserver/server.clj | 3 +- 6 files changed, 46 insertions(+), 61 deletions(-) diff --git a/bettercode/src/bettercode/core.clj b/bettercode/src/bettercode/core.clj index ef205d9..16525ad 100644 --- a/bettercode/src/bettercode/core.clj +++ b/bettercode/src/bettercode/core.clj @@ -89,14 +89,14 @@ (println "started") (let [c @(client (if hostname hostname "localhost") 8080) msg @(s/put! c ["get-dir"]) - dirs @(s/take! c) + dirs (vec @(s/take! c)) *context (atom (fx/create-context {:title "BetterCode" - :file-path "/home/tim/foo.txt" + :file-path "" :text-editor "" :dir-contents dirs - :cur-path "/home/tim/foo.txt" + :cur-path (bettercode.events/parent-dir (subs (dirs 0) 5)) :file-explorer-show true :file-name-entered "" :line-numbers ""} diff --git a/bettercode/src/bettercode/elements.clj b/bettercode/src/bettercode/elements.clj index 160ee95..892d2e7 100644 --- a/bettercode/src/bettercode/elements.clj +++ b/bettercode/src/bettercode/elements.clj @@ -20,13 +20,8 @@ :font "Roboto Mono" :cursor :text :text (fx/sub context :text-editor) - :style-class "root-text-area-editor" - :on-key-typed {:event/type :bettercode.events/type-text - :fx/sync true - :tclient tclient} - :on-mouse-clicked {:event/type :bettercode.events/mouse-click - :fx/sync true - :tclient tclient}}) + :on-key-typed {:event/type :bettercode.events/text-type} + :style-class "root-text-area-editor"}) (defn line-numbers [{:keys [fx/context]}] {:fx/type :text-area diff --git a/bettercode/src/bettercode/events.clj b/bettercode/src/bettercode/events.clj index 6be3579..b1b7c94 100644 --- a/bettercode/src/bettercode/events.clj +++ b/bettercode/src/bettercode/events.clj @@ -8,9 +8,12 @@ (defmethod handle-event :default [e] (println "non event")) +(defn parent-dir [path] + (clojure.string/join "/" (drop-last (clojure.string/split path #"/")))) + (defn fex-back [context tclient] (let [cur-dir (fx/sub-val context :cur-path) - prev-dir (clojure.string/join "/" (drop-last (clojure.string/split cur-dir #"/"))) + prev-dir (parent-dir cur-dir) msg @(s/put! tclient ["get-dir" prev-dir]) ;get parent from :cur-path dir-contents @(s/take! tclient)] {:context (fx/swap-context context @@ -18,6 +21,21 @@ :dir-contents dir-contents :cur-path prev-dir)})) +(defn get-current-text [event] + (-> event + (.getSource) + (.getParentPopup) + (.getOwnerWindow) + (.getScene) + (.getRoot) + (.getChildren) + (.get 1) + (.getChildren) + (.get 1) + (.getChildren) + (.get 1) + (.getText))) + ;TODO: send event for replacing highlighted text, send event for inserting text (defmethod handle-event ::type-filename [{:keys [fx/event fx/context]}] @@ -37,15 +55,18 @@ :file-explorer-show false :line-numbers "1\n")})) +(defmethod handle-event ::text-type [{:keys [fx/event fx/context]}] + (let [no-of-lines (+ 2 (count (re-seq #"\n" (.getText (.getSource event))))) + line-numbers (apply str (map #(str % \newline) (range 1 no-of-lines)))] + {:context (fx/swap-context context + assoc + :line-numbers line-numbers)})) + (defmethod handle-event ::openfex [{:keys [fx/event fx/context]}] {:context (fx/swap-context context assoc :file-explorer-show true)}) -(defmethod handle-event ::saveevent [{:keys [fx/event fx/context tclient]}] - @(s/put! tclient ["save-file" (fx/sub-val context :file-path)]) - {:context context}) - (defmethod handle-event ::backclick [{:keys [fx/event fx/context tclient]}] (fex-back context tclient)) @@ -73,34 +94,19 @@ :file-explorer-show false :line-numbers line-numbers)}))))) -(defmethod handle-event ::type-text [{:keys [fx/event fx/context tclient]}] - (println event) ;get soruce of event, prefereably - (let [message ["text-edit" (fx/sub-val context :file-path) (.getCharacter event) (.getCaretPosition (.getSource event))] - length (- (fx/sub-val context :anchor-pos) (fx/sub-val context :caret-pos))] - (println length (conj message length)) - @(s/put! tclient (if (> length 0) (assoc (conj message length) 3 (.getAnchor (.getSource event))) message))) - (println @(s/take! tclient)) - {:context (fx/swap-context context - assoc - :anchor-pos (.getAnchor (.getSource event)) - :caret-pos (.getCaretPosition (.getSource event)))}) - -(defmethod handle-event ::mouse-click [{:keys [fx/event fx/context tclient]}] - (println (:fx/event event)) - (println (.getSource event)) - {:context (fx/swap-context context - assoc - :anchor-pos (.getAnchor (.getSource event)) - :caret-pos (.getCaretPosition (.getSource event)))}) - (defmethod handle-event ::close-file [{:keys [fx/event fx/context tclient]}] (println "requesting close file") @(s/put! tclient ["close-file" (fx/sub-val context :file-path)])) -(defmethod handle-event ::save-file [{:keys [fx/event fx/context tclient]}] - (println "saving file") - @(s/put! tclient ["save-file" (fx/sub-val context :file-path)]) - @(s/take! tclient)) +(defmethod handle-event ::saveevent [{:keys [fx/event fx/context tclient]}] + (println (get-current-text event)) + @(s/put! tclient ["save-file" (fx/sub-val context :file-path) (get-current-text event)]) + (let [sync-file @(s/take! tclient)] + (println sync-file) + {:context (fx/swap-context context + assoc + :text-editor + sync-file)})) (defmethod handle-event ::save-all [{:keys [fx/event fx/context tclient]}] (println "saving all buffers") diff --git a/bettercodeserver/src/bettercodeserver/buffer.clj b/bettercodeserver/src/bettercodeserver/buffer.clj index 8bf2421..243d850 100644 --- a/bettercodeserver/src/bettercodeserver/buffer.clj +++ b/bettercodeserver/src/bettercodeserver/buffer.clj @@ -23,25 +23,10 @@ (defn remove-file [agent-name full-file-path] (send agent-name dissoc full-file-path)) -(defn add-string [agent-name full-file-path position insert-str] - (send agent-name update-in [full-file-path] insert-string insert-str position)) - -(defn del-string [agent-name full-file-path position length] - (send agent-name update-in [full-file-path] remove-string position length)) - -(defn del-char [agent-name full-file-path position] - (send agent-name update-in [full-file-path] remove-char (- position 1))) - -(defn text-edit [agent-name full-file-path string index length] - (println "length:" length) - (cond - (and (= string "\b") (> index 0) (= nil length)) (del-char agent-name full-file-path (+ index 1)) - (and (= string "\b") (> index 0)) (del-string agent-name full-file-path index length) - (and (> index -1) (not= string "\b")) (add-string agent-name full-file-path (- index (count string)) string) - :else false)) - -(defn save-file [agent-name full-file-path] - (spit full-file-path (@agent-name full-file-path))) +(defn save-file [agent-name full-file-path text] + (send agent-name assoc full-file-path text) + (spit full-file-path (@agent-name full-file-path)) + text) (defn save-all-files [agent-name] (let [all-files @agent-name] diff --git a/bettercodeserver/src/bettercodeserver/core.clj b/bettercodeserver/src/bettercodeserver/core.clj index 8d44404..97a1abb 100644 --- a/bettercodeserver/src/bettercodeserver/core.clj +++ b/bettercodeserver/src/bettercodeserver/core.clj @@ -6,7 +6,7 @@ (defn -main [] (println "started") - (let [files (agent {"/home/tim/foo.txt" ""}) + (let [files (agent {}) serv (server/start-server (server/event-loop server/parse-request files) 8080)])) diff --git a/bettercodeserver/src/bettercodeserver/server.clj b/bettercodeserver/src/bettercodeserver/server.clj index ae9afcc..9fcdcfc 100644 --- a/bettercodeserver/src/bettercodeserver/server.clj +++ b/bettercodeserver/src/bettercodeserver/server.clj @@ -29,10 +29,9 @@ "This function parses the message and then calls the appropriate function from the command in the message" [message agent-name] (case (message 0) - "text-edit" (buffer/text-edit agent-name (message 1) (message 2) (message 3) (if (= 5 (count message)) (message 4) nil)) "open-file" (buffer/add-file agent-name (message 1)) "close-file" (buffer/remove-file agent-name (message 1)) - "save-file" (buffer/save-file agent-name (message 1)) + "save-file" (do (println message) (buffer/save-file agent-name (message 1) (message 2))) "save-all" (buffer/save-all-files agent-name) "get-dir" (if (> (count message) 1) (fnav/get-folder-contents (message 1)) (fnav/get-folder-contents)))) From e60343417c72b59d27b672a285c926f927e924f1 Mon Sep 17 00:00:00 2001 From: vision-05 Date: Wed, 2 Jun 2021 16:57:55 +0000 Subject: [PATCH 3/5] scrolling now works properly, opening files and saving buffers too, bug with closing files --- bettercode/src/bettercode/core.clj | 8 ++++- bettercode/src/bettercode/css.clj | 32 +++++++++++-------- bettercode/src/bettercode/elements.clj | 2 ++ bettercode/src/bettercode/events.clj | 31 +++++++++++------- .../src/bettercodeserver/buffer.clj | 18 +++++++---- .../src/bettercodeserver/server.clj | 3 +- 6 files changed, 62 insertions(+), 32 deletions(-) diff --git a/bettercode/src/bettercode/core.clj b/bettercode/src/bettercode/core.clj index 16525ad..1c3785d 100644 --- a/bettercode/src/bettercode/core.clj +++ b/bettercode/src/bettercode/core.clj @@ -63,6 +63,11 @@ :style-class "root-menu-bar-item-sub-item" :text "save" :on-action {:event/type :bettercode.events/saveevent + :tclient tclient}} + {:fx/type :menu-item + :style-class "root-menu-bar-item-sub-item" + :text "close file" + :on-action {:event/type :bettercode.events/close-file :tclient tclient}}]}]} {:fx/type bettercode.elements/editor-pane :tclient tclient @@ -99,7 +104,8 @@ :cur-path (bettercode.events/parent-dir (subs (dirs 0) 5)) :file-explorer-show true :file-name-entered "" - :line-numbers ""} + :line-numbers "" + :vscroll 0} #(cache/lru-cache-factory % :threshold 4096)))] (fx/create-app *context :event-handler bettercode.events/handle-event diff --git a/bettercode/src/bettercode/css.clj b/bettercode/src/bettercode/css.clj index 25d9d5f..347e02a 100644 --- a/bettercode/src/bettercode/css.clj +++ b/bettercode/src/bettercode/css.clj @@ -8,8 +8,8 @@ text-color "#ECEFF4" border-color "#4C566A" background-color "#2E3440" - scroll-color "#434C5E22" - thumb-color "#4C566A44" + scroll-color "#434C5E00" + thumb-color "#4C566A22" highlight-color "#4C566A" line-no-color "#4C566A"] {".root" {:-fx-background-color back-background-color @@ -44,14 +44,14 @@ :-fx-text-fill text-color :-fx-padding [4 4 4 4] :-fx-border-radius 5} - "> .virtual-flow" {:-fx-background-color background-color - :-fx-hbar-policy :as-needed - :-fx-vbar-policy :as-needed - "> .corner" {:fx-background-color scroll-color} - "> .scroll-bar" {":horizontal" {:-fx-background-color scroll-color - " .thumb" {:-fx-background-color thumb-color}} - ":vertical" {:-fx-background-color scroll-color - " .thumb" {:-fx-background-color thumb-color}}}}} + "> .virtual-flow" {:-fx-background-color scroll-color + :-fx-hbar-policy :as-needed + :-fx-vbar-policy :as-needed + "> .corner" {:fx-background-color scroll-color} + "> .scroll-bar" {":horizontal" {:-fx-background-color scroll-color + " .thumb" {:-fx-background-color thumb-color}} + ":vertical" {:-fx-background-color scroll-color + " .thumb" {:-fx-background-color thumb-color}}}}} "-text-area" {"-status" {:-fx-background-color back-background-color :-fx-border-color border-color :-fx-border-style [:hidden :hidden :solid :hidden] @@ -62,13 +62,19 @@ :-fx-background-color back-background-color ;:-fx-border-color border-color " .content" {:-fx-background-color background-color} - " .scroll-pane" {:-fx-background-color background-color + " .scroll-pane" {:-fx-background-color :transparent :-fx-hbar-policy :as-needed :-fx-vbar-policy :as-needed "> .corner" {:-fx-background-color scroll-color} - " .scroll-bar" {":horizontal" {:-fx-background-color scroll-color + " .scroll-bar" {" .decrement-button" {:-fx-opacity 0} + " .increment-button" {:-fx-opacity 0} + ":horizontal" {:-fx-background-color :transparent + " .track" {:-fx-opacity 0} + " .track-background" {:-fx-opacity 0} " .thumb" {:-fx-background-color thumb-color}} - ":vertical" {:-fx-background-color scroll-color + ":vertical" {:-fx-background-color :transparent + " .track" {:-fx-opacity 0} + " .track-background" {:-fx-opacity 0} " .thumb" {:-fx-background-color thumb-color}}}}} "-numbers" {:-fx-text-fill line-no-color :-fx-background-color background-color diff --git a/bettercode/src/bettercode/elements.clj b/bettercode/src/bettercode/elements.clj index 892d2e7..51ff93f 100644 --- a/bettercode/src/bettercode/elements.clj +++ b/bettercode/src/bettercode/elements.clj @@ -21,6 +21,7 @@ :cursor :text :text (fx/sub context :text-editor) :on-key-typed {:event/type :bettercode.events/text-type} + :on-scroll {:event/type :bettercode.events/scroll} :style-class "root-text-area-editor"}) (defn line-numbers [{:keys [fx/context]}] @@ -29,6 +30,7 @@ :text (fx/sub context :line-numbers) :pref-width 40 :pref-height 896 + :scroll-top (fx/sub context :vscroll) :font "Roboto Mono" :style-class "root-text-area-numbers"}) diff --git a/bettercode/src/bettercode/events.clj b/bettercode/src/bettercode/events.clj index b1b7c94..4a8e648 100644 --- a/bettercode/src/bettercode/events.clj +++ b/bettercode/src/bettercode/events.clj @@ -38,6 +38,11 @@ ;TODO: send event for replacing highlighted text, send event for inserting text +(defmethod handle-event ::scroll [{:keys [fx/event fx/context]}] + {:context (fx/swap-context context + assoc + :vscroll (.getScrollTop (.getSource event)))}) + (defmethod handle-event ::type-filename [{:keys [fx/event fx/context]}] {:context (fx/swap-context context assoc @@ -47,7 +52,6 @@ (let [file-name (fx/sub-val context :file-name-entered) file-path-new (str (fx/sub-val context :cur-path) "/" (.toString file-name)) msg @(s/put! tclient ["open-file" file-path-new])] - (println "CUR-PATH: " (fx/sub-val context :cur-path)) {:context (fx/swap-context context ;how the fuck do I do this assoc :file-path file-path-new @@ -60,9 +64,14 @@ line-numbers (apply str (map #(str % \newline) (range 1 no-of-lines)))] {:context (fx/swap-context context assoc - :line-numbers line-numbers)})) + :line-numbers line-numbers + :vscroll (.getScrollTop (.getSource event)))})) -(defmethod handle-event ::openfex [{:keys [fx/event fx/context]}] +(defmethod handle-event ::openfex [{:keys [fx/event fx/context tclient]}] + (if (not= (fx/sub-val context :file-path) "") (do + @(s/put! tclient ["update-buffer" (fx/sub-val context :file-path) (get-current-text event)]) + @(s/take! tclient)) + nil) {:context (fx/swap-context context assoc :file-explorer-show true)}) @@ -77,7 +86,6 @@ (cond (= entry-info "DIR: ") (do @(s/put! tclient ["get-dir" entry-name]) (let [dir-contents @(s/take! tclient)] - (println dir-contents) {:context (fx/swap-context context assoc :dir-contents dir-contents @@ -86,7 +94,6 @@ (let [file-contents @(s/take! tclient) no-of-lines (+ 2 (count (re-seq #"\n" file-contents))) line-numbers (apply str (map #(str % \newline) (range 1 no-of-lines)))] - (println file-contents) {:context (fx/swap-context context assoc :file-path entry-name @@ -95,20 +102,22 @@ :line-numbers line-numbers)}))))) (defmethod handle-event ::close-file [{:keys [fx/event fx/context tclient]}] - (println "requesting close file") - @(s/put! tclient ["close-file" (fx/sub-val context :file-path)])) + @(s/put! tclient ["close-file" (fx/sub-val context :file-path)]) + (:context (fx/swap-context context + assoc + :text-editor "" + :line-numbers "" + :file-path "" + :vscroll 0))) (defmethod handle-event ::saveevent [{:keys [fx/event fx/context tclient]}] - (println (get-current-text event)) @(s/put! tclient ["save-file" (fx/sub-val context :file-path) (get-current-text event)]) (let [sync-file @(s/take! tclient)] - (println sync-file) {:context (fx/swap-context context assoc :text-editor sync-file)})) (defmethod handle-event ::save-all [{:keys [fx/event fx/context tclient]}] - (println "saving all buffers") - @(s/put! tclient ["save-all"]) + @(s/put! tclient ["save-all" (fx/sub-val context :file-path (get-current-text event))]) @(s/take! tclient)) \ No newline at end of file diff --git a/bettercodeserver/src/bettercodeserver/buffer.clj b/bettercodeserver/src/bettercodeserver/buffer.clj index 243d850..10bfc9b 100644 --- a/bettercodeserver/src/bettercodeserver/buffer.clj +++ b/bettercodeserver/src/bettercodeserver/buffer.clj @@ -13,9 +13,11 @@ (defn add-file ([agent-name full-file-path] + (await agent-name) + (if (not= nil (@agent-name full-file-path)) (@agent-name full-file-path) (try (let [contents (slurp full-file-path)] (add-file agent-name full-file-path contents)) - (catch java.io.FileNotFoundException e (add-file agent-name full-file-path "")))) + (catch java.io.FileNotFoundException e (add-file agent-name full-file-path ""))))) ([agent-name full-file-path string] (send agent-name assoc full-file-path string) string)) @@ -23,15 +25,19 @@ (defn remove-file [agent-name full-file-path] (send agent-name dissoc full-file-path)) +(defn update-buffer [agent-name full-file-path text] + (send agent-name assoc full-file-path text)) + (defn save-file [agent-name full-file-path text] - (send agent-name assoc full-file-path text) + (update-buffer agent-name full-file-path text) + (await agent-name) (spit full-file-path (@agent-name full-file-path)) text) -(defn save-all-files [agent-name] - (let [all-files @agent-name] - (doseq [file-name all-files] - (save-file agent-name file-name)))) +;(defn save-all-files [agent-name] +; (let [all-files @agent-name] +; (doseq [file-name all-files] +; (save-file agent-name file-name)))) (defn close-all-buffers [] (shutdown-agents)) \ No newline at end of file diff --git a/bettercodeserver/src/bettercodeserver/server.clj b/bettercodeserver/src/bettercodeserver/server.clj index 9fcdcfc..bc0642b 100644 --- a/bettercodeserver/src/bettercodeserver/server.clj +++ b/bettercodeserver/src/bettercodeserver/server.clj @@ -31,8 +31,9 @@ (case (message 0) "open-file" (buffer/add-file agent-name (message 1)) "close-file" (buffer/remove-file agent-name (message 1)) + "update-buffer" (buffer/update-buffer agent-name (message 1) (message 2)) "save-file" (do (println message) (buffer/save-file agent-name (message 1) (message 2))) - "save-all" (buffer/save-all-files agent-name) + ;"save-all" (buffer/save-all-files agent-name) "get-dir" (if (> (count message) 1) (fnav/get-folder-contents (message 1)) (fnav/get-folder-contents)))) From 0f8969dc6e88437c80b05daeb97d808c861fdc5a Mon Sep 17 00:00:00 2001 From: vision-05 Date: Wed, 2 Jun 2021 17:39:08 +0000 Subject: [PATCH 4/5] fixed bug closing files --- bettercode/src/bettercode/events.clj | 22 ++++++++++++------- .../src/bettercodeserver/buffer.clj | 6 ++--- .../src/bettercodeserver/server.clj | 4 +++- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/bettercode/src/bettercode/events.clj b/bettercode/src/bettercode/events.clj index 4a8e648..6648980 100644 --- a/bettercode/src/bettercode/events.clj +++ b/bettercode/src/bettercode/events.clj @@ -15,7 +15,8 @@ (let [cur-dir (fx/sub-val context :cur-path) prev-dir (parent-dir cur-dir) msg @(s/put! tclient ["get-dir" prev-dir]) ;get parent from :cur-path - dir-contents @(s/take! tclient)] + result @(s/take! tclient) + dir-contents (if (= result true) @(s/take! tclient) result)] {:context (fx/swap-context context assoc :dir-contents dir-contents @@ -51,7 +52,8 @@ (defmethod handle-event ::newclick [{:keys [fx/event fx/context tclient]}] (let [file-name (fx/sub-val context :file-name-entered) file-path-new (str (fx/sub-val context :cur-path) "/" (.toString file-name)) - msg @(s/put! tclient ["open-file" file-path-new])] + msg @(s/put! tclient ["open-file" file-path-new]) + foo @(s/take! tclient)] ;open file will return a value even if we don't use it {:context (fx/swap-context context ;how the fuck do I do this assoc :file-path file-path-new @@ -70,8 +72,8 @@ (defmethod handle-event ::openfex [{:keys [fx/event fx/context tclient]}] (if (not= (fx/sub-val context :file-path) "") (do @(s/put! tclient ["update-buffer" (fx/sub-val context :file-path) (get-current-text event)]) - @(s/take! tclient)) - nil) + (println "TAKING " @(s/take! tclient))) + (println "NOT")) {:context (fx/swap-context context assoc :file-explorer-show true)}) @@ -85,13 +87,17 @@ entry-name (subs entry 5)] (cond (= entry-info "DIR: ") (do @(s/put! tclient ["get-dir" entry-name]) - (let [dir-contents @(s/take! tclient)] + (let [result @(s/take! tclient) + dir-contents (if (= result true) @(s/take! tclient) result) + foo (println dir-contents)] {:context (fx/swap-context context assoc :dir-contents dir-contents :cur-path entry-name)})) (= entry-info "FIL: ") (do @(s/put! tclient ["open-file" entry-name]) - (let [file-contents @(s/take! tclient) + (let [result @(s/take! tclient) + file-contents (if (= result true) @(s/take! tclient) result) + foo (println file-contents) no-of-lines (+ 2 (count (re-seq #"\n" file-contents))) line-numbers (apply str (map #(str % \newline) (range 1 no-of-lines)))] {:context (fx/swap-context context @@ -103,12 +109,12 @@ (defmethod handle-event ::close-file [{:keys [fx/event fx/context tclient]}] @(s/put! tclient ["close-file" (fx/sub-val context :file-path)]) - (:context (fx/swap-context context + {:context (fx/swap-context context assoc :text-editor "" :line-numbers "" :file-path "" - :vscroll 0))) + :vscroll 0)}) (defmethod handle-event ::saveevent [{:keys [fx/event fx/context tclient]}] @(s/put! tclient ["save-file" (fx/sub-val context :file-path) (get-current-text event)]) diff --git a/bettercodeserver/src/bettercodeserver/buffer.clj b/bettercodeserver/src/bettercodeserver/buffer.clj index 10bfc9b..b1b461a 100644 --- a/bettercodeserver/src/bettercodeserver/buffer.clj +++ b/bettercodeserver/src/bettercodeserver/buffer.clj @@ -15,9 +15,9 @@ ([agent-name full-file-path] (await agent-name) (if (not= nil (@agent-name full-file-path)) (@agent-name full-file-path) - (try (let [contents (slurp full-file-path)] - (add-file agent-name full-file-path contents)) - (catch java.io.FileNotFoundException e (add-file agent-name full-file-path ""))))) + (try (let [contents (slurp full-file-path)] + (add-file agent-name full-file-path contents)) + (catch java.io.FileNotFoundException e (add-file agent-name full-file-path ""))))) ([agent-name full-file-path string] (send agent-name assoc full-file-path string) string)) diff --git a/bettercodeserver/src/bettercodeserver/server.clj b/bettercodeserver/src/bettercodeserver/server.clj index bc0642b..6b873c7 100644 --- a/bettercodeserver/src/bettercodeserver/server.clj +++ b/bettercodeserver/src/bettercodeserver/server.clj @@ -47,13 +47,15 @@ (when-not (= ::none msg) (d/let-flow [msg-two (d/future (f msg files-agent)) result (cond - (= (class "") (class msg-two)) @(s/put! s msg-two) + (= java.lang.String (class msg-two)) @(s/put! s msg-two) (= clojure.lang.Cons (class msg-two)) @(s/put! s msg-two) (= clojure.lang.LazySeq (class msg-two)) @(s/put! s msg-two) (= clojure.lang.PersistentList (class msg-two)) @(s/put! s msg-two) :else @(s/put! s true))] (when result + (println "\n\n\n") (prn (class msg-two)) + (prn "MSGTWO" msg-two "\n\n\n") (prn @files-agent) (d/recur))))) (d/catch From 61dc2ba8218cc44764970539ad234a61dd41015e Mon Sep 17 00:00:00 2001 From: vision-05 Date: Wed, 2 Jun 2021 17:49:15 +0000 Subject: [PATCH 5/5] fixed uberjar --- bettercode/project.clj | 1 + 1 file changed, 1 insertion(+) diff --git a/bettercode/project.clj b/bettercode/project.clj index db602a7..6d1af40 100644 --- a/bettercode/project.clj +++ b/bettercode/project.clj @@ -15,4 +15,5 @@ :main ^:skip-aot bettercode.core :target-path "target/%s" :profiles {:uberjar {:aot :all + :injections [(javafx.application.Platform/exit)] :jvm-opts ["-Dclojure.compiler.direct-linking=true"]}})