Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Preserving Folder Structure #395

Merged
merged 18 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
8b6adfb
Modify function to conform to review feedback
r888800009 Aug 18, 2024
ce2e3a0
Rename "Autosaves" Pane to "File Handling" to make it more versatile.
r888800009 Aug 20, 2024
1188835
Fixed inconsistent display of "Zoom Mode" configuration
r888800009 Aug 20, 2024
c8724e6
Refactor problematic code
r888800009 Aug 20, 2024
aeb8d87
Allow user configuration to import preserve folder structure
r888800009 Aug 20, 2024
255d4b7
Update based on review feedback
r888800009 Aug 20, 2024
d2327a8
Refactor incMessageBox() with enum args and return value
r888800009 Aug 20, 2024
e6e628b
refector incImportKeepFolderStructPop() with enum return value
r888800009 Aug 20, 2024
497eb85
rename incConvertToTinyfdButton() to incDialogButtonToTinyfd()
r888800009 Aug 20, 2024
ce17ff3
reuse DialogButton enum in dialog.d
r888800009 Aug 20, 2024
c50feb5
Implement class DialogHandler and remove incMessageBox() to avoid env…
r888800009 Aug 24, 2024
e841c3a
Revert "Modify function to conform to review feedback"
r888800009 Sep 11, 2024
7e8ffab
Revert "Fixed inconsistent display of "Zoom Mode" configuration"
r888800009 Sep 11, 2024
46cf100
Clone `kra-d` git to fix kra import issue
r888800009 Aug 25, 2024
fcddd84
Duplicate Dialog return value avoids mistakes reuse reference
r888800009 Sep 3, 2024
96b87bc
Merge branch 'v0_8' into v0_8-preserve-layer-structure
r888800009 Sep 11, 2024
0bab131
Update kra-d version
r888800009 Sep 11, 2024
09c8ef8
Update inmath allow other 1.0.x series version
r888800009 Sep 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ authors "Inochi2D Project"
copyright "Copyright © 2020, Inochi2D Project"
license "BSD 2-clause"
dependency "psd-d" version="~>0.6.1"
dependency "inmath" version="~>1.0.5"
dependency "kra-d" version="~>0.5.5"
dependency "inmath" version="~>1.0.6"
dependency "kra-d" version="~>0.5.6"
dependency "tinyfiledialogs" version="~>0.10.1"
dependency "facetrack-d" version="~>0.7.6"
dependency "bindbc-sdl" version="~>1.1.2"
Expand Down
3 changes: 2 additions & 1 deletion source/creator/core/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import std.exception;
import bindbc.sdl;
import bindbc.opengl;
import inochi2d;
import tinyfiledialogs;
import std.string;
import std.stdio;
import std.conv;
Expand Down Expand Up @@ -629,6 +628,8 @@ void incBeginLoopNoEv() {
incRenderDialogs();
}
incStatusUpdate();

incHandleDialogHandlers();
}

void incSetDefaultLayout() {
Expand Down
7 changes: 6 additions & 1 deletion source/creator/core/settings.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ string incSettingsPath() {
void incSettingsLoad() {
if (exists(incSettingsPath())) {
settings = parseJSON(readText(incSettingsPath()));

// File Handling
// Always ask the user whether to preserve the folder structure during import
// also see incGetKeepLayerFolder()
settings["KeepLayerFolder"] = "Ask";
}
}

Expand Down Expand Up @@ -91,4 +96,4 @@ T incSettingsGet(T)(string name, T default_) {
*/
bool incSettingsCanGet(string name) {
return (name in settings) !is null;
}
}
44 changes: 38 additions & 6 deletions source/creator/io/kra.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ private {
bool incImportShowKRADialog() {
TFD_Filter[] filters = [{ ["*.kra"], "Krita Document (*.kra)" }];
string file = incShowImportDialog(filters, _("Import..."));

if (file) {
incImportKRA(file, IncKRAImportSettings(false));
return true;
}
return false;
return incAskImportKRA(file);
}

class IncKRALayer {
Expand Down Expand Up @@ -142,8 +137,45 @@ struct IncKRAImportSettings {
bool keepStructure = false;
}

/**
Imports a KRA file with user prompt.
also see incAskImportPSD()
*/
bool incAskImportKRA(string file) {
if (!file) return false;

KRALoadHandler handler = new KRALoadHandler(file);
return incKeepStructDialog(handler);
}

class KRALoadHandler : ImportKeepHandler {
private string file;

this(string file) {
super();
this.file = file;
}

override
bool load(AskKeepLayerFolder select) {
switch (select) {
case AskKeepLayerFolder.NotPreserve:
incImportKRA(file, IncKRAImportSettings(false));
return true;
case AskKeepLayerFolder.Preserve:
incImportKRA(file, IncKRAImportSettings(true));
return true;
case AskKeepLayerFolder.Cancel:
return false;
default:
throw new Exception("Invalid selection");
}
}
}

/**
Imports a KRA file.
Note: You should invoke incAskImportKRA for UI interaction.
*/
void incImportKRA(string file, IncKRAImportSettings settings = IncKRAImportSettings.init) {
incNewProject();
Expand Down
122 changes: 86 additions & 36 deletions source/creator/io/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public import creator.io.kra;
public import creator.io.inpexport;
public import creator.io.videoexport;
public import creator.io.imageexport;
import creator.widgets: DialogButtons;
import creator.widgets.dialog;

import tinyfiledialogs;
public import tinyfiledialogs : TFD_Filter;
Expand Down Expand Up @@ -73,6 +75,13 @@ private {
}
}

string incToDString(c_str cstr1) {
if (cstr1 !is null) {
return cast(string) cstr1.fromStringz;
}
return null;
}

string incShowImportDialog(const(TFD_Filter)[] filters, string title, bool multiple = false) {
version (linux) {
try {
Expand All @@ -86,19 +95,11 @@ string incShowImportDialog(const(TFD_Filter)[] filters, string title, bool multi

// FALLBACK: If xdg-desktop-portal is not available then try tinyfiledialogs.
c_str filename = tinyfd_openFileDialog(title.toStringz, "", filters, multiple);
if (filename !is null) {
string file = cast(string) filename.fromStringz;
return file.dup;
}
return null;
return incToDString(filename).dup;
}
} else {
c_str filename = tinyfd_openFileDialog(title.toStringz, "", filters, multiple);
if (filename !is null) {
string file = cast(string) filename.fromStringz;
return file.dup;
}
return null;
return incToDString(filename).dup;
}
}

Expand All @@ -114,15 +115,11 @@ string incShowOpenFolderDialog(string title = "Open...") {

// FALLBACK: If xdg-desktop-portal is not available then try tinyfiledialogs.
c_str filename = tinyfd_selectFolderDialog(title.toStringz, null);
if (filename !is null)
return cast(string) filename.fromStringz.dup;
return null;
return incToDString(filename).dup;
}
} else {
c_str filename = tinyfd_selectFolderDialog(title.toStringz, null);
if (filename !is null)
return cast(string) filename.fromStringz.dup;
return null;
return incToDString(filename).dup;
}
}

Expand All @@ -138,19 +135,11 @@ string incShowOpenDialog(const(TFD_Filter)[] filters, string title = "Open...")

// FALLBACK: If xdg-desktop-portal is not available then try tinyfiledialogs.
c_str filename = tinyfd_openFileDialog(title.toStringz, "", filters, false);
if (filename !is null) {
string file = cast(string) filename.fromStringz;
return file.dup;
}
return null;
return incToDString(filename).dup;
}
} else {
c_str filename = tinyfd_openFileDialog(title.toStringz, "", filters, false);
if (filename !is null) {
string file = cast(string) filename.fromStringz;
return file.dup;
}
return null;
return incToDString(filename).dup;
}
}

Expand All @@ -166,19 +155,11 @@ string incShowSaveDialog(const(TFD_Filter)[] filters, string fname, string title

// FALLBACK: If xdg-desktop-portal is not available then try tinyfiledialogs.
c_str filename = tinyfd_saveFileDialog(title.toStringz, fname.toStringz, filters);
if (filename !is null) {
string file = cast(string) filename.fromStringz;
return file.dup;
}
return null;
return incToDString(filename).dup;
}
} else {
c_str filename = tinyfd_saveFileDialog(title.toStringz, fname.toStringz, filters);
if (filename !is null) {
string file = cast(string) filename.fromStringz;
return file.dup;
}
return null;
return incToDString(filename).dup;
}
}

Expand Down Expand Up @@ -221,3 +202,72 @@ void incCreatePartsFromFiles(string[] files) {
}
}
}

string incGetKeepLayerFolder() {
if (incSettingsCanGet("KeepLayerFolder"))
return incSettingsGet!string("KeepLayerFolder");
else
// also see incSettingsLoad()
// Preserve the original behavior for existing users
return "NotPreserve";
}

bool incSetKeepLayerFolder(string select) {
incSettingsSet("KeepLayerFolder", select);
return true;
}

enum AskKeepLayerFolder {
Preserve, NotPreserve, Cancel
}

const(char)* INC_KEEP_STRUCT_DIALOG_NAME = "ImportKeepFolderStructPopup";

/**
Function for importing pop-up dialog
*/
bool incKeepStructDialog(ImportKeepHandler handler) {
if (incGetKeepLayerFolder() == "Preserve") {
handler.load(AskKeepLayerFolder.Preserve);
} else if (incGetKeepLayerFolder() == "NotPreserve") {
handler.load(AskKeepLayerFolder.NotPreserve);
} else {
incRegisterDialogHandler(handler);

// Show dialog
incDialog(
INC_KEEP_STRUCT_DIALOG_NAME,
__("Import File"),
_("Do you want to preserve the folder structure of the imported file? You can change this in the settings."),
DialogLevel.Warning,
DialogButtons.Yes | DialogButtons.No | DialogButtons.Cancel
);
}

return true;
}

class ImportKeepHandler : DialogHandler {
this () {
super(INC_KEEP_STRUCT_DIALOG_NAME);
}

override
bool onClick(DialogButtons button) {
switch (button) {
case DialogButtons.Cancel:
return this.load(AskKeepLayerFolder.Cancel);
case DialogButtons.Yes:
return this.load(AskKeepLayerFolder.Preserve);
case DialogButtons.No:
return this.load(AskKeepLayerFolder.NotPreserve);
default:
throw new Exception("Invalid button");
}
}

bool load(AskKeepLayerFolder select) {
// override this
return false;
}
}
44 changes: 38 additions & 6 deletions source/creator/io/psd.d
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ private {
bool incImportShowPSDDialog() {
TFD_Filter[] filters = [{ ["*.psd"], "Photoshop Document (*.psd)" }];
string file = incShowImportDialog(filters, _("Import..."));

if (file) {
incImportPSD(file, IncPSDImportSettings(false));
return true;
}
return false;
return incAskImportPSD(file);
}

class IncPSDLayer {
Expand Down Expand Up @@ -142,8 +137,45 @@ struct IncPSDImportSettings {
bool keepStructure = false;
}

/**
Imports a PSD file with user prompt.
also see incAskImportKRA()
*/
bool incAskImportPSD(string file) {
if (!file) return false;

PSDLoadHandler handler = new PSDLoadHandler(file);
return incKeepStructDialog(handler);
}

class PSDLoadHandler : ImportKeepHandler {
private string file;

this(string file) {
super();
this.file = file;
}

override
bool load(AskKeepLayerFolder select) {
switch (select) {
case AskKeepLayerFolder.NotPreserve:
incImportPSD(file, IncPSDImportSettings(false));
return true;
case AskKeepLayerFolder.Preserve:
incImportPSD(file, IncPSDImportSettings(true));
return true;
case AskKeepLayerFolder.Cancel:
return false;
default:
throw new Exception("Invalid selection");
}
}
}

/**
Imports a PSD file.
Note: You should invoke incAskImportPSD for UI interaction.
*/
void incImportPSD(string file, IncPSDImportSettings settings = IncPSDImportSettings.init) {
incNewProject();
Expand Down
7 changes: 6 additions & 1 deletion source/creator/panels/viewport.d
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,12 @@ protected:

// Allow dragging PSD in to main window
case ".psd":
incImportPSD(file);
incAskImportPSD(file);
break mainLoop;

// Allow dragging KRA in to main window
case ".kra":
incAskImportKRA(file);
break mainLoop;

default:
Expand Down
1 change: 1 addition & 0 deletions source/creator/viewport/vertex/package.d
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ void incViewportVertexConfirmBar() {
}

// In case of a warning popup preventing application.
// TODO: if incDialogButtonSelected does not work, we may implement a DialogHandler for this.
if (incDialogButtonSelected("CONFIRM_VERTEX_APPLY") == DialogButtons.Yes) {
incMeshEditApply();
}
Expand Down
Loading
Loading