Skip to content

Commit

Permalink
Fixed issue #1081.
Browse files Browse the repository at this point in the history
  • Loading branch information
nilsschmidt1337 committed Jul 21, 2024
1 parent 10370ca commit 623013d
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 12 deletions.
11 changes: 10 additions & 1 deletion src/org/nschmidt/ldparteditor/data/DatFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,15 @@ public static DatFile createDatFileForReview(String path) {
return new DatFile(path, true);
}

public static DatFile createDatFileForReviewInProject(String path, String projectPath) {
final String basePath = new File(Project.DEFAULT_PROJECT_PATH).getAbsolutePath() + File.separator;
String filePathInProject = path.substring(basePath.length());
filePathInProject = projectPath + filePathInProject;
DatFile df = new DatFile(filePathInProject, true);
df.setVirtual(false);
return df;
}

private DatFile(String path, boolean fromPartReview) {
this.projectFile = true;
this.oldName = path;
Expand Down Expand Up @@ -1763,7 +1772,7 @@ public boolean saveAs(String newName) {
}

private boolean checkFileCollision(File theFile) {
if (theFile.lastModified() > lastModified) {
if (theFile.lastModified() > lastModified && lastModified != 0) {
MessageBox messageBox = new MessageBox(Editor3DWindow.getWindow().getShell(), SWT.ICON_QUESTION | SWT.YES | SWT.CANCEL | SWT.NO);
messageBox.setText(I18n.DIALOG_MODIFIED_TITLE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
package org.nschmidt.ldparteditor.dialog.partreview;

import java.text.MessageFormat;

import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
Expand All @@ -26,6 +28,7 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.nschmidt.ldparteditor.dialog.ThemedDialog;
import org.nschmidt.ldparteditor.enumtype.MyLanguage;
import org.nschmidt.ldparteditor.i18n.I18n;
import org.nschmidt.ldparteditor.widget.IntegerSpinner;
import org.nschmidt.ldparteditor.widget.NButton;
Expand All @@ -35,6 +38,7 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
class PartReviewDesign extends ThemedDialog {

static String fileName = ""; //$NON-NLS-1$
static String projectPath = ""; //$NON-NLS-1$

private final boolean alreadyReviewing;

Expand All @@ -46,8 +50,9 @@ protected PartReviewDesign(Shell parentShell, boolean alreadyReviewing) {
private Button[] btnOkPtr = new Button[1];
private Button[] btnCancelPtr = new Button[1];
final Text[] txtFilePtr = new Text[1];
final NButton[] btnVerbosePtr = new NButton[1];
final IntegerSpinner[] spnViewCountPtr = new IntegerSpinner[1];
final NButton[] btnStoreLocallyPtr = new NButton[1];
final NButton[] btnVerbosePtr = new NButton[1];

/**
* Create contents of the dialog.
Expand All @@ -74,10 +79,21 @@ protected Control createDialogArea(Composite parent) {
gd.grabExcessHorizontalSpace = true;
gd.horizontalAlignment = SWT.FILL;
txtFile2.setLayoutData(gd);
txtFile2.setTextLimit(64);

Label lblInfo = Theming.label(cmpContainer, SWT.NONE);
lblInfo.setText(I18n.PARTREVIEW_INFO);

NButton btnStoreLocally = new NButton(cmpContainer, SWT.CHECK);
this.btnStoreLocallyPtr[0] = btnStoreLocally;
btnStoreLocally.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));
Object[] messageArguments = {""}; //$NON-NLS-1$
MessageFormat formatter = new MessageFormat(""); //$NON-NLS-1$
formatter.setLocale(MyLanguage.getLocale());
formatter.applyPattern(I18n.PARTREVIEW_STORE_LOCATION);
btnStoreLocally.setText(formatter.format(messageArguments));
btnStoreLocally.setSelection(WorkbenchManager.getUserSettingState().isPartReviewStoreLocalFiles());

Label lblNumberOf3dViews = Theming.label(cmpContainer, SWT.NONE);
lblNumberOf3dViews.setText(I18n.PARTREVIEW_NUMBER_OF_3D_VIEWS);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

import static org.nschmidt.ldparteditor.helper.WidgetUtility.widgetUtil;

import java.io.File;
import java.text.MessageFormat;

import org.eclipse.swt.widgets.Shell;
import org.nschmidt.ldparteditor.enumtype.MyLanguage;
import org.nschmidt.ldparteditor.i18n.I18n;
import org.nschmidt.ldparteditor.workbench.WorkbenchManager;

public class PartReviewDialog extends PartReviewDesign {
Expand All @@ -30,7 +35,22 @@ public PartReviewDialog(Shell parentShell, boolean alreadyReviewing) {
public int open() {
super.create();
// MARK All final listeners will be configured here..
txtFilePtr[0].addModifyListener(e -> fileName = txtFilePtr[0].getText());
txtFilePtr[0].addModifyListener(e -> {
fileName = txtFilePtr[0].getText();
String formattedFileName = fileName;
if (formattedFileName.endsWith(".dat")) formattedFileName = formattedFileName.substring(0, formattedFileName.length() - 4); //$NON-NLS-1$
if (formattedFileName.contains("/")) formattedFileName = formattedFileName.substring(formattedFileName.lastIndexOf('/') + 1); //$NON-NLS-1$
if (formattedFileName.contains("\\")) formattedFileName = formattedFileName.substring(formattedFileName.lastIndexOf('\\') + 1); //$NON-NLS-1$
formattedFileName = WorkbenchManager.getUserSettingState().getAuthoringFolderPath() + File.separator + I18n.PARTREVIEW_REVIEW + File.separator + formattedFileName + File.separator;
projectPath = formattedFileName;
Object[] messageArguments = {projectPath};
MessageFormat formatter = new MessageFormat(""); //$NON-NLS-1$
formatter.setLocale(MyLanguage.getLocale());
formatter.applyPattern(I18n.PARTREVIEW_STORE_LOCATION);
btnStoreLocallyPtr[0].setText(formatter.format(messageArguments));
btnStoreLocallyPtr[0].getParent().layout();
});
widgetUtil(btnStoreLocallyPtr[0]).addSelectionListener(e -> WorkbenchManager.getUserSettingState().setPartReviewStoreLocalFiles(btnStoreLocallyPtr[0].getSelection()));
widgetUtil(btnVerbosePtr[0]).addSelectionListener(e -> WorkbenchManager.getUserSettingState().setVerbosePartReview(btnVerbosePtr[0].getSelection()));
this.spnViewCountPtr[0].addValueChangeListener(spn ->
WorkbenchManager.getUserSettingState().setPartReview3dViewCount(spnViewCountPtr[0].getValue())
Expand All @@ -41,4 +61,8 @@ public int open() {
public static String getFileName() {
return fileName;
}

public static String getProjectPath() {
return projectPath;
}
}
3 changes: 3 additions & 0 deletions src/org/nschmidt/ldparteditor/i18n/I18n.java
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,9 @@ private static void adjust() { // Calculate line offset
public static final String PARTREVIEW_ERROR = PARTREVIEW.getString(getProperty());
public static final String PARTREVIEW_INFO = PARTREVIEW.getString(getProperty());
public static final String PARTREVIEW_NUMBER_OF_3D_VIEWS = PARTREVIEW.getString(getProperty());
public static final String PARTREVIEW_REVIEW = PARTREVIEW.getString(getProperty());
public static final String PARTREVIEW_STORE_ERROR = PARTREVIEW.getString(getProperty());
public static final String PARTREVIEW_STORE_LOCATION = PARTREVIEW.getString(getProperty());
public static final String PARTREVIEW_TITLE = PARTREVIEW.getString(getProperty());
public static final String PARTREVIEW_VERBOSE = PARTREVIEW.getString(getProperty());
public static final String PARTREVIEW_VERBOSE_MSG = PARTREVIEW.getString(getProperty());
Expand Down
5 changes: 4 additions & 1 deletion src/org/nschmidt/ldparteditor/i18n/PartReview.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ ALREADY = Do you want to end the current part review?
CHECK = Trying to find file on PartsTracker:
ENTER_PART_NAME = Exact part name (with or without *.dat file ending):
ERROR = Could not download the file from the PartsTracker.
INFO = This tool creates different default views and a virtual project with all required files to do the review.\nPlease make sure to save all of your work to avoid possible data loss, although it is not necessary.
INFO = This tool creates different default views and a (virtual) project with all required files to do the review.\nMake sure to save all of your work to avoid possible data loss, although it is not necessary.\nPlease check the option below if you want to save this review as a real project with "Save All" afterwards.
NUMBER_OF_3D_VIEWS = Number of 3D views (1. default / 2. BFC / 3. random colours / 4. wireframe):
REVIEW = review
STORE_ERROR = Could not store the files on your disk.
STORE_LOCATION = "Save All" should store the files under: {0}
TITLE = PartReview
VERBOSE = Verbose
VERBOSE_MSG = Main file:\n {0}\n\nReferenced files:\n\n{1}\n\nPNG textures will be loaded on demand and are stored in-memory (not on your disk).
Original file line number Diff line number Diff line change
Expand Up @@ -3017,6 +3017,7 @@ public void setReviewingAPart(boolean reviewingAPart, Set<DatFile> partsForRevie
// Hide "End Review" button
cmpSyncAndReviewPtr[0].getChildren()[1].dispose();
// Reset project
Project.setDefaultProject(true);
Project.setFileToEdit(View.DUMMY_DATFILE);
Project.setProjectPath(new File(Project.DEFAULT_PROJECT_PATH).getAbsolutePath());
getShell().setText(Version.getApplicationName() + " " + Version.getVersion() + " (" + WorkbenchManager.getUserSettingState().getOpenGLVersionString() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ private static void createWidgets(MiscToolItem miscToolItem) {
btnRoundSelection.setToolTipText(I18n.E3D_ROUND + Cocoa.replaceCtrlByCmd(I18n.E3D_CONTROL_CLICK_MODIFY));
btnRoundSelection.setImage(ResourceManager.getImage("icon16_round.png")); //$NON-NLS-1$

final NButton btnEdger2 = new NButton(miscToolItem, Cocoa.getStyle());
btnEdger2.setText(I18n.E3D_EDGER_2);
KeyStateManager.addTooltipText(btnEdger2, I18n.EDGER_CURRENT_VERBOSE_RUN, Task.EDGER2);
widgetUtil(btnEdger2).addSelectionListener(e -> edger2());

final NButton btnSelect = new NButton(miscToolItem, SWT.PUSH | Cocoa.getStyle());
MiscToolItem.btnSelect2Ptr[0] = btnSelect;
btnSelect.setToolTipText(I18n.E3D_ADVANCED_SELECT);
Expand Down Expand Up @@ -722,11 +727,6 @@ private static void createWidgets(MiscToolItem miscToolItem) {
Editor3DWindow.getWindow().regainFocus();
});

final NButton btnEdger2 = new NButton(miscToolItem, SWT.PUSH | Cocoa.getStyle());
btnEdger2.setText(I18n.E3D_EDGER_2);
KeyStateManager.addTooltipText(btnEdger2, I18n.EDGER_CURRENT_VERBOSE_RUN, Task.EDGER2);
widgetUtil(btnEdger2).addSelectionListener(e -> edger2());

final NButton btnInfographic = new NButton(miscToolItem, SWT.PUSH | Cocoa.getStyle());
btnInfographic.setText(I18n.INFOGRAPHIC_HELP_BUTTON_TITLE);
btnInfographic.setToolTipText(I18n.INFOGRAPHIC_HELP_TOOLTIP);
Expand Down Expand Up @@ -2297,6 +2297,21 @@ public void run(final IProgressMonitor monitor) throws InvocationTargetException
return;
}

if (WorkbenchManager.getUserSettingState().isPartReviewStoreLocalFiles()) {
try {
Files.createDirectories(Path.of(PartReviewDialog.getProjectPath()));
} catch (IOException ex) {
NLogger.debug(MiscToolItem.class, ex);
Display.getDefault().syncExec(() -> {
MessageBox messageBox = new MessageBox(Editor3DWindow.getWindow().getShell(), SWT.ICON_ERROR | SWT.OK);
messageBox.setText(I18n.DIALOG_ERROR);
messageBox.setMessage(I18n.PARTREVIEW_STORE_ERROR);
messageBox.open();
});
return;
}
}

Set<String> files = new HashSet<>();
files.add(fileName);
List<String> list = buildFileList(source, new ArrayList<>(), files, monitor);
Expand Down Expand Up @@ -2333,8 +2348,17 @@ public void run(final IProgressMonitor monitor) throws InvocationTargetException
txtwin.closeAllTabs();
}
}
Project.setDefaultProject(true);
Project.setProjectPath(new File(Project.DEFAULT_PROJECT_PATH).getAbsolutePath());

if (WorkbenchManager.getUserSettingState().isPartReviewStoreLocalFiles()) {
Project.setDefaultProject(false);
Project.setProjectPath(PartReviewDialog.getProjectPath());
// This is a hack to get this PartReview project to the list of recent projects
NewOpenSaveProjectToolItem.addRecentFile(new DatFile(PartReviewDialog.getProjectPath()));
} else {
Project.setDefaultProject(true);
Project.setProjectPath(new File(Project.DEFAULT_PROJECT_PATH).getAbsolutePath());
}

Editor3DWindow.getWindow().getShell().setText(Version.getApplicationName() + " " + Version.getVersion() + " (" + WorkbenchManager.getUserSettingState().getOpenGLVersionString() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
Editor3DWindow.getWindow().getShell().update();
Editor3DWindow.getWindow().getProject().setText(fileName3);
Expand All @@ -2360,7 +2384,13 @@ public void run(final IProgressMonitor monitor) throws InvocationTargetException
TreeItem n;
fileName3 = list.get(i);
source3 = list.get(i + 1);
df = DatFile.createDatFileForReview(fileName3);
if (WorkbenchManager.getUserSettingState().isPartReviewStoreLocalFiles()) {
df = DatFile.createDatFileForReviewInProject(fileName3, PartReviewDialog.getProjectPath());
fileName3 = df.getNewName();
} else {
df = DatFile.createDatFileForReview(fileName3);
}

monitor.beginTask(fileName3, IProgressMonitor.UNKNOWN);
Display.getCurrent().readAndDispatch();
dfsToOpen.add(df);
Expand Down
9 changes: 9 additions & 0 deletions src/org/nschmidt/ldparteditor/workbench/UserSettingState.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ public class UserSettingState implements Serializable {
private Theming theming = Theming.DEFAULT;

private int partReview3dViewCount = 4;
private boolean partReviewStoreLocalFiles = false;

public UserSettingState() {
this.getUserPalette().add(new GColour(0, 0.02f, 0.075f, 0.114f, 1f));
Expand Down Expand Up @@ -1522,4 +1523,12 @@ public int getPartReview3dViewCount() {
public void setPartReview3dViewCount(int partReview3dViewCount) {
this.partReview3dViewCount = partReview3dViewCount;
}

public boolean isPartReviewStoreLocalFiles() {
return partReviewStoreLocalFiles;
}

public void setPartReviewStoreLocalFiles(boolean partReviewStoreLocalFiles) {
this.partReviewStoreLocalFiles = partReviewStoreLocalFiles;
}
}

0 comments on commit 623013d

Please sign in to comment.