File tree Expand file tree Collapse file tree
src/main/java/org/markdownwriterfx Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ Markdown Writer FX Change Log
33
44## 0.8
55
6+ - Open markdown files by dropping them to main window.
67- Support Definition lists extension (FlexMark only).
78- "Cut", "Copy", "Paste" and "Select All" commands added to "Edit" menu.
89- "Cut" and "Copy" now cut/copy whole line if selection is empty.
Original file line number Diff line number Diff line change 5252import javafx .scene .control .ToolBar ;
5353import javafx .scene .input .KeyCode ;
5454import javafx .scene .input .KeyEvent ;
55+ import javafx .scene .input .TransferMode ;
5556import javafx .scene .layout .BorderPane ;
5657import javafx .scene .layout .HBox ;
5758import javafx .scene .layout .Priority ;
@@ -120,6 +121,22 @@ class MainWindow
120121 e .consume ();
121122 });
122123
124+ // open markdown files dropped to main window
125+ scene .setOnDragOver (e -> {
126+ if (e .getDragboard ().hasFiles ())
127+ e .acceptTransferModes (TransferMode .COPY );
128+ e .consume ();
129+ });
130+ scene .setOnDragDropped (e -> {
131+ boolean success = false ;
132+ if (e .getDragboard ().hasFiles ()) {
133+ fileEditorTabPane .openEditors (e .getDragboard ().getFiles (), 0 );
134+ success = true ;
135+ }
136+ e .setDropCompleted (success );
137+ e .consume ();
138+ });
139+
123140 Platform .runLater (() -> stageFocusedProperty .bind (scene .getWindow ().focusedProperty ()));
124141 }
125142
Original file line number Diff line number Diff line change @@ -67,6 +67,14 @@ private void createNodes() {
6767 webView = new WebView ();
6868 webView .setFocusTraversable (false );
6969
70+ // disable WebView default drag and drop handler to allow dropping markdown files
71+ webView .setOnDragEntered (null );
72+ webView .setOnDragExited (null );
73+ webView .setOnDragOver (null );
74+ webView .setOnDragDropped (null );
75+ webView .setOnDragDetected (null );
76+ webView .setOnDragDone (null );
77+
7078 webView .getEngine ().getLoadWorker ().stateProperty ().addListener ((ob ,o ,n ) -> {
7179 if (n == State .SUCCEEDED && !runWhenLoadedList .isEmpty ()) {
7280 ArrayList <Runnable > runnables = new ArrayList <>(runWhenLoadedList );
You can’t perform that action at this time.
0 commit comments