Skip to content

Commit

Permalink
Merge pull request #25 from Ogefest/feature/upload-file
Browse files Browse the repository at this point in the history
Feature/upload file
  • Loading branch information
Ogefest authored Apr 4, 2021
2 parents 143db9f + e60e352 commit 6bdd2aa
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 25 deletions.
40 changes: 23 additions & 17 deletions src/main/java/notepack/WorkspaceTabController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
import javafx.scene.control.TreeItem;
import javafx.scene.control.TreeView;
import javafx.scene.layout.AnchorPane;
import javafx.stage.FileChooser;
import notepack.app.domain.App;
import notepack.app.domain.Note;
import notepack.app.domain.NoteStorageItem;
import notepack.app.domain.Workspace;
import notepack.app.task.*;

import java.io.File;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -210,34 +212,17 @@ private void treeViewOnDelete(ActionEvent event) {

@FXML
private void treeViewOnRename(ActionEvent event) {

Note n = workspaceStructure.getSelectionModel().getSelectedItem().getValue().getNote();

app.addTask(new NoteSetNamePopup(n));

// TextInputDialog dialog = new TextInputDialog(n.getPath());
// dialog.setTitle("Rename");
// dialog.setHeaderText(null);
// dialog.setContentText("Please enter note name:");
//
// Optional<String> result = dialog.showAndWait();
// if (result.isPresent()) {
// app.renameNote(n, result.get());
// }

}

@FXML
private void onFileWorkspaceAdd(ActionEvent event) {

app.addTask(new WorkspacePopup());

}

public void openWorkspaceEdit(Workspace workspace) {

app.addTask(new WorkspacePopup(workspace));

}

@FXML
Expand All @@ -255,6 +240,27 @@ private void onWorkspaceArchive(ActionEvent event) {
app.addTask(new WorkspaceArchive(workspace));
}

@FXML
private void onImportFile(ActionEvent event) {

FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Import file");
fileChooser.setInitialDirectory(
new File(System.getProperty("user.home"))
);

fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("Supported files", "*.txt", "*.md", "*.csv", "*.ics", "*.pdf", "*.png", "*.jpg", "*.jpeg")
);
File file = fileChooser.showOpenDialog(tabBackground.getScene().getWindow());
if (file != null) {
app.addTask(new WorkspaceUploadFile(workspace, file));
}


}


public void onChecklistNew(ActionEvent actionEvent) {
app.addTask(new TodoNew(workspace));
}
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/notepack/app/storage/Webdav.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;

//import net.fortuna.ical4j.connector.CalendarStore;
//import net.fortuna.ical4j.connector.ObjectNotFoundException;
//import net.fortuna.ical4j.connector.ObjectStoreException;
//import net.fortuna.ical4j.connector.dav.CalDavCalendarCollection;
//import net.fortuna.ical4j.connector.dav.CalDavCalendarStore;
//import net.fortuna.ical4j.connector.dav.PathResolver;


public class Webdav implements NoteStorage {

private NoteStorageConfiguration nsc;
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/notepack/app/task/WorkspaceUploadFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package notepack.app.task;

import notepack.app.domain.Note;
import notepack.app.domain.Task;
import notepack.app.domain.Workspace;
import notepack.app.domain.exception.MessageError;
import notepack.app.listener.WorkspaceListener;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;

public class WorkspaceUploadFile extends BaseTask implements Task, TypeWorkspace {

private File fileSource;
private Workspace workspace;

public WorkspaceUploadFile(Workspace workspace, File fileSource) {
this.workspace = workspace;
this.fileSource = fileSource;
}

@Override
public void notify(WorkspaceListener listener) {
}

@Override
public void backgroundWork() throws MessageError {

byte[] bytesToSave;
try {
bytesToSave = Files.readAllBytes(fileSource.toPath());

Note n = new Note(workspace);
n.setPath(workspace.getStorage().getBasePath() + File.separator + fileSource.getName());
n.setContents(bytesToSave);
n.saveToStorage();

addTaskToQueue(new WorkspaceRefresh(workspace));

} catch (IOException e) {
e.printStackTrace();
throw new MessageError(e.getMessage(), e);
}


}
}
5 changes: 5 additions & 0 deletions src/main/resources/notepack/WorkspaceTabListView.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
<Label styleClass="icon-base,mi-sticker-check-outline"/>
</graphic>
</MenuItem>
<MenuItem mnemonicParsing="false" onAction="#onImportFile" text="Import file">
<graphic>
<Label styleClass="icon-base,mi-file-upload-outline"/>
</graphic>
</MenuItem>

<SeparatorMenuItem mnemonicParsing="false"/>

Expand Down

0 comments on commit 6bdd2aa

Please sign in to comment.