File load cleanup.

This commit is contained in:
leo 2014-10-12 17:34:18 +00:00
parent ebd7c4be5d
commit 50a018f1a7
11 changed files with 184 additions and 299 deletions

View file

@ -34,9 +34,6 @@
enum LC_DIALOG_TYPE enum LC_DIALOG_TYPE
{ {
LC_DIALOG_OPEN_PROJECT,
LC_DIALOG_SAVE_PROJECT,
LC_DIALOG_MERGE_PROJECT,
LC_DIALOG_SAVE_IMAGE, LC_DIALOG_SAVE_IMAGE,
LC_DIALOG_EXPORT_3DSTUDIO, LC_DIALOG_EXPORT_3DSTUDIO,
LC_DIALOG_EXPORT_BRICKLINK, LC_DIALOG_EXPORT_BRICKLINK,
@ -68,7 +65,7 @@ struct lcImageDialogOptions
struct lcHTMLDialogOptions struct lcHTMLDialogOptions
{ {
char PathName[LC_MAXPATH]; QString PathName;
LC_IMAGE_FORMAT ImageFormat; LC_IMAGE_FORMAT ImageFormat;
bool TransparentImages; bool TransparentImages;
bool SinglePage; bool SinglePage;
@ -95,7 +92,7 @@ struct lcPOVRayDialogOptions
struct lcPropertiesDialogOptions struct lcPropertiesDialogOptions
{ {
lcModelProperties Properties; lcModelProperties Properties;
String Title; QString Title;
bool SetDefault; bool SetDefault;
lcArray<lcPartsListEntry> PartsList; lcArray<lcPartsListEntry> PartsList;

View file

@ -222,7 +222,7 @@ bool lcContext::SaveRenderToTextureImage(const QString& FileName, int Width, int
bool Result = Writer.write(QImage(Buffer, Width, Height, QImage::Format_ARGB32)); bool Result = Writer.write(QImage(Buffer, Width, Height, QImage::Format_ARGB32));
if (!Result) if (!Result)
QMessageBox::information(gMainWindow->mHandle, tr("Error"), tr("Cannot save '%1': %2").arg(FileName, Writer.errorString())); QMessageBox::information(gMainWindow->mHandle, tr("Error"), tr("Cannot save '%1':\n%2").arg(FileName, Writer.errorString()));
free(Buffer); free(Buffer);

View file

@ -23,7 +23,7 @@ lcMainWindow::lcMainWindow()
memset(&mSearchOptions, 0, sizeof(mSearchOptions)); memset(&mSearchOptions, 0, sizeof(mSearchOptions));
for (int FileIdx = 0; FileIdx < LC_MAX_RECENT_FILES; FileIdx++) for (int FileIdx = 0; FileIdx < LC_MAX_RECENT_FILES; FileIdx++)
strcpy(mRecentFiles[FileIdx], lcGetProfileString((LC_PROFILE_KEY)(LC_PROFILE_RECENT_FILE1 + FileIdx))); mRecentFiles[FileIdx] = lcGetProfileString((LC_PROFILE_KEY)(LC_PROFILE_RECENT_FILE1 + FileIdx));
gMainWindow = this; gMainWindow = this;
} }
@ -126,18 +126,19 @@ void lcMainWindow::SetLockZ(bool LockZ)
UpdateLockSnap(); UpdateLockSnap();
} }
void lcMainWindow::AddRecentFile(const char* FileName) void lcMainWindow::AddRecentFile(const QString& FileName)
{ {
QString SavedName = FileName;
int FileIdx; int FileIdx;
for (FileIdx = 0; FileIdx < LC_MAX_RECENT_FILES; FileIdx++) for (FileIdx = 0; FileIdx < LC_MAX_RECENT_FILES; FileIdx++)
if (!strcmp(mRecentFiles[FileIdx], FileName)) if (mRecentFiles[FileIdx] == FileName)
break; break;
for (FileIdx = lcMin(FileIdx, LC_MAX_RECENT_FILES - 1); FileIdx > 0; FileIdx--) for (FileIdx = lcMin(FileIdx, LC_MAX_RECENT_FILES - 1); FileIdx > 0; FileIdx--)
strcpy(mRecentFiles[FileIdx], mRecentFiles[FileIdx - 1]); mRecentFiles[FileIdx] = mRecentFiles[FileIdx - 1];
strcpy(mRecentFiles[0], FileName); mRecentFiles[0] = SavedName;
UpdateRecentFiles(); UpdateRecentFiles();
} }
@ -145,9 +146,9 @@ void lcMainWindow::AddRecentFile(const char* FileName)
void lcMainWindow::RemoveRecentFile(int FileIndex) void lcMainWindow::RemoveRecentFile(int FileIndex)
{ {
for (int FileIdx = FileIndex; FileIdx < LC_MAX_RECENT_FILES - 1; FileIdx++) for (int FileIdx = FileIndex; FileIdx < LC_MAX_RECENT_FILES - 1; FileIdx++)
strcpy(mRecentFiles[FileIdx], mRecentFiles[FileIdx + 1]); mRecentFiles[FileIdx] = mRecentFiles[FileIdx + 1];
mRecentFiles[LC_MAX_RECENT_FILES - 1][0] = 0; mRecentFiles[LC_MAX_RECENT_FILES - 1].clear();
UpdateRecentFiles(); UpdateRecentFiles();
} }

View file

@ -128,7 +128,7 @@ public:
void Close(); void Close();
void AddRecentFile(const char* FileName); void AddRecentFile(const QString& FileName);
void RemoveRecentFile(int FileIndex); void RemoveRecentFile(int FileIndex);
void SplitHorizontal(); void SplitHorizontal();
@ -152,14 +152,14 @@ public:
void UpdatePerspective(); void UpdatePerspective();
void UpdateCameraMenu(); void UpdateCameraMenu();
void UpdateCategories(); void UpdateCategories();
void UpdateTitle(const char* Title, bool Modified); void UpdateTitle(const QString& Title, bool Modified);
void UpdateModified(bool Modified); void UpdateModified(bool Modified);
void UpdateRecentFiles(); void UpdateRecentFiles();
void UpdateShortcuts(); void UpdateShortcuts();
lcVector3 GetTransformAmount(); lcVector3 GetTransformAmount();
char mRecentFiles[LC_MAX_RECENT_FILES][LC_MAXPATH]; QString mRecentFiles[LC_MAX_RECENT_FILES];
PiecePreview* mPreviewWidget; PiecePreview* mPreviewWidget;
int mColorIndex; int mColorIndex;
lcSearchOptions mSearchOptions; lcSearchOptions mSearchOptions;

View file

@ -37,7 +37,7 @@ void Project::UpdateInterface()
gMainWindow->UpdateUndoRedo(mUndoHistory.GetSize() > 1 ? mUndoHistory[0]->Description : NULL, !mRedoHistory.IsEmpty() ? mRedoHistory[0]->Description : NULL); gMainWindow->UpdateUndoRedo(mUndoHistory.GetSize() > 1 ? mUndoHistory[0]->Description : NULL, !mRedoHistory.IsEmpty() ? mRedoHistory[0]->Description : NULL);
gMainWindow->UpdatePaste(g_App->mClipboard != NULL); gMainWindow->UpdatePaste(g_App->mClipboard != NULL);
gMainWindow->UpdateCategories(); gMainWindow->UpdateCategories();
gMainWindow->UpdateTitle(m_strTitle, IsModified()); gMainWindow->UpdateTitle(GetTitle(), IsModified());
gMainWindow->SetTool(gMainWindow->GetTool()); gMainWindow->SetTool(gMainWindow->GetTool());
gMainWindow->UpdateFocusObject(GetFocusObject()); gMainWindow->UpdateFocusObject(GetFocusObject());
@ -51,13 +51,6 @@ void Project::UpdateInterface()
UpdateSelection(); UpdateSelection();
} }
void Project::SetTitle(const char* Title)
{
strcpy(m_strTitle, Title);
gMainWindow->UpdateTitle(m_strTitle, IsModified());
}
void Project::LoadDefaults() void Project::LoadDefaults()
{ {
mProperties.LoadDefaults(); mProperties.LoadDefaults();
@ -679,35 +672,22 @@ void Project::FileReadLDraw(lcFile* file, const lcMatrix44& CurrentTransform, in
file->Seek(Offset, SEEK_SET); file->Seek(Offset, SEEK_SET);
} }
bool Project::DoSave(const char* FileName) bool Project::DoSave(const QString& FileName)
{ {
char SaveFileName[LC_MAXPATH]; QString SaveFileName;
if (FileName && FileName[0]) if (!FileName.isEmpty())
strcpy(SaveFileName, FileName); SaveFileName = FileName;
else else
{ {
if (m_strPathName[0]) if (!mFileName.isEmpty())
strcpy(SaveFileName, m_strPathName); SaveFileName = mFileName;
else else
{ SaveFileName = QFileInfo(QDir(QLatin1String(lcGetProfileString(LC_PROFILE_PROJECTS_PATH))), GetTitle()).absoluteFilePath();
strcpy(SaveFileName, lcGetProfileString(LC_PROFILE_PROJECTS_PATH));
int Length = strlen(SaveFileName); SaveFileName = QFileDialog::getSaveFileName(gMainWindow->mHandle, tr("Save Project"), SaveFileName, tr("Supported Files (*.ldr *.dat);;All Files (*.*)"));
if (Length && (SaveFileName[Length - 1] != '/' && SaveFileName[Length - 1] != '\\'))
strcat(SaveFileName, "/");
strcat(SaveFileName, m_strTitle); if (SaveFileName.isEmpty())
// check for dubious filename
int iBad = strcspn(SaveFileName, " #%;/\\");
if (iBad != -1)
SaveFileName[iBad] = 0;
strcat(SaveFileName, ".ldr");
}
if (!gMainWindow->DoDialog(LC_DIALOG_SAVE_PROJECT, SaveFileName))
return false; return false;
} }
@ -730,58 +710,27 @@ bool Project::DoSave(const char* FileName)
mSavedHistory = mUndoHistory[0]; mSavedHistory = mUndoHistory[0];
// reset the title and change the document name SetFileName(SaveFileName);
SetPathName(SaveFileName, true);
return true; // success return true;
} }
// return true if ok to continue bool Project::SaveIfModified()
bool Project::SaveModified()
{ {
if (!IsModified()) if (!IsModified())
return true; // ok to continue return true;
// get name/title of document switch (QMessageBox::question(gMainWindow->mHandle, tr("Save Project"), tr("Save changes to '%1'?").arg(GetTitle()), QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel))
char name[LC_MAXPATH];
if (strlen(m_strPathName) == 0)
{
// get name based on caption
strcpy(name, m_strTitle);
if (strlen(name) == 0)
strcpy(name, "Untitled");
}
else
{
// get name based on file title of path name
char* p;
p = strrchr(m_strPathName, '\\');
if (!p)
p = strrchr(m_strPathName, '/');
if (p)
strcpy(name, ++p);
else
strcpy(name, m_strPathName);
}
char prompt[512];
sprintf(prompt, "Save changes to %s ?", name);
switch (gMainWindow->DoMessageBox(prompt, LC_MB_YESNOCANCEL))
{ {
case LC_CANCEL: case LC_CANCEL:
return false; // don't continue return false;
case LC_YES: case LC_YES:
// If so, either Save or Update, as appropriate if (!DoSave(mFileName))
if (!DoSave(m_strPathName))
return false; return false;
break; break;
case LC_NO: case LC_NO:
// If not saving changes, revert the document
break; break;
} }
@ -790,61 +739,46 @@ bool Project::SaveModified()
bool Project::OnNewDocument() bool Project::OnNewDocument()
{ {
memset(m_strPathName, 0, sizeof(m_strPathName));
DeleteModel(); DeleteModel();
DeleteHistory(); DeleteHistory();
LoadDefaults(); LoadDefaults();
CheckPoint(""); CheckPoint("");
mSavedHistory = mUndoHistory[0]; mSavedHistory = mUndoHistory[0];
SetTitle("Untitled");
SetFileName(QString());
return true; return true;
} }
bool Project::OpenProject(const char* FileName) bool Project::OpenProject(const QString& FileName)
{ {
if (!SaveModified()) if (!SaveIfModified())
return false; return false;
if (!OnOpenDocument(FileName)) if (!OnOpenDocument(FileName))
return false; return false;
SetPathName(FileName, true); SetFileName(FileName);
return true; return true;
} }
bool Project::OnOpenDocument(const char* lpszPathName) bool Project::OnOpenDocument(const QString& FileName)
{ {
lcDiskFile file; lcDiskFile file;
bool bSuccess = false; bool bSuccess = false;
if (!file.Open(lpszPathName, "rb")) if (!file.Open(FileName.toLatin1().constData(), "rb")) // todo: qstring
{ {
// MessageBox("Failed to open file."); // MessageBox("Failed to open file.");
return false; return false;
} }
char ext[4]; QString Extension = QFileInfo(FileName).suffix().toLower();
const char *ptr;
memset(ext, 0, 4);
ptr = strrchr(lpszPathName, '.');
if (ptr != NULL)
{
strncpy(ext, ptr+1, 3);
strlwr(ext);
}
bool datfile = false; bool datfile = (Extension == QLatin1String("dat") || Extension == QLatin1String("ldr"));
bool mpdfile = false; bool mpdfile = (Extension == QLatin1String("mpd"));
// Find out what file type we're loading.
if ((strcmp(ext, "dat") == 0) || (strcmp(ext, "ldr") == 0))
datfile = true;
else if (strcmp(ext, "mpd") == 0)
mpdfile = true;
DeleteModel(); DeleteModel();
DeleteHistory(); DeleteHistory();
@ -877,11 +811,11 @@ bool Project::OnOpenDocument(const char* lpszPathName)
else else
// FileReadLDraw(&file, mat, &ok, 16, &step, FileArray); // FileReadLDraw(&file, mat, &ok, 16, &step, FileArray);
{ {
QFile File(lpszPathName); QFile File(FileName);
if (!File.open(QIODevice::ReadOnly)) if (!File.open(QIODevice::ReadOnly))
{ {
QMessageBox::warning(gMainWindow->mHandle, tr("Error"), tr("Error reading file '%1':\n%2").arg(lpszPathName, File.errorString())); QMessageBox::warning(gMainWindow->mHandle, tr("Error"), tr("Error reading file '%1':\n%2").arg(FileName, File.errorString()));
return false; return false;
} }
@ -923,25 +857,18 @@ bool Project::OnOpenDocument(const char* lpszPathName)
return true; return true;
} }
void Project::SetPathName(const char* PathName, bool bAddToMRU) void Project::SetFileName(const QString& FileName)
{ {
strcpy(m_strPathName, PathName); mFileName = FileName;
// always capture the complete file name including extension (if present) if (!FileName.isEmpty())
const char* lpszTemp = PathName; gMainWindow->AddRecentFile(FileName);
for (const char* lpsz = PathName; *lpsz != '\0'; lpsz++) gMainWindow->UpdateTitle(GetTitle(), IsModified());
{ }
// remember last directory/drive separator
if (*lpsz == '\\' || *lpsz == '/' || *lpsz == ':')
lpszTemp = lpsz + 1;
}
// set the document title based on path name QString Project::GetTitle() const
SetTitle(lpszTemp); {
return mFileName.isEmpty() ? tr("New Project") : QFileInfo(mFileName).fileName();
// add it to the file MRU list
if (bAddToMRU)
gMainWindow->AddRecentFile(m_strPathName);
} }
void Project::CheckPoint(const char* Description) void Project::CheckPoint(const char* Description)
@ -1300,9 +1227,9 @@ void Project::SaveImage()
Options.Start = mCurrentStep; Options.Start = mCurrentStep;
Options.End = LastStep; Options.End = LastStep;
if (m_strPathName[0]) if (!mFileName.isEmpty())
{ {
Options.FileName = m_strPathName; Options.FileName = mFileName;
QString Extension = QFileInfo(Options.FileName).suffix(); QString Extension = QFileInfo(Options.FileName).suffix();
Options.FileName = Options.FileName.mid(0, Options.FileName.length() - Extension.length()); Options.FileName = Options.FileName.mid(0, Options.FileName.length() - Extension.length());
} }
@ -1453,8 +1380,8 @@ void Project::HandleCommand(LC_COMMANDS id)
{ {
case LC_FILE_NEW: case LC_FILE_NEW:
{ {
if (!SaveModified()) if (!SaveIfModified())
return; // leave the original one return;
OnNewDocument(); OnNewDocument();
gMainWindow->UpdateAllViews(); gMainWindow->UpdateAllViews();
@ -1462,30 +1389,35 @@ void Project::HandleCommand(LC_COMMANDS id)
case LC_FILE_OPEN: case LC_FILE_OPEN:
{ {
char FileName[LC_MAXPATH]; QString FileName;
if (m_strPathName[0]) if (!mFileName.isEmpty())
strcpy(FileName, m_strPathName); FileName = mFileName;
else else
strcpy(FileName, lcGetProfileString(LC_PROFILE_PROJECTS_PATH)); FileName = lcGetProfileString(LC_PROFILE_PROJECTS_PATH);
if (gMainWindow->DoDialog(LC_DIALOG_OPEN_PROJECT, FileName)) FileName = QFileDialog::getOpenFileName(gMainWindow->mHandle, tr("Open Project"), FileName, tr("Supported Files (*.lcd *.ldr *.dat *.mpd);;All Files (*.*)"));
if (!FileName.isEmpty())
OpenProject(FileName); OpenProject(FileName);
} break; } break;
case LC_FILE_MERGE: case LC_FILE_MERGE:
{ {
char FileName[LC_MAXPATH]; QString FileName;
if (m_strPathName[0]) if (!mFileName.isEmpty())
strcpy(FileName, m_strPathName); FileName = mFileName;
else else
strcpy(FileName, lcGetProfileString(LC_PROFILE_PROJECTS_PATH)); FileName = lcGetProfileString(LC_PROFILE_PROJECTS_PATH);
if (gMainWindow->DoDialog(LC_DIALOG_MERGE_PROJECT, FileName)) FileName = QFileDialog::getOpenFileName(gMainWindow->mHandle, tr("Merge Project"), FileName, tr("Supported Files (*.lcd *.ldr *.dat *.mpd);;All Files (*.*)"));
if (!FileName.isEmpty())
{ {
// todo: detect format
lcDiskFile file; lcDiskFile file;
if (file.Open(FileName, "rb")) if (file.Open(FileName.toLatin1().constData(), "rb")) // todo: qstring
{ {
if (file.GetLength() != 0) if (file.GetLength() != 0)
{ {
@ -1498,11 +1430,11 @@ void Project::HandleCommand(LC_COMMANDS id)
} break; } break;
case LC_FILE_SAVE: case LC_FILE_SAVE:
DoSave(m_strPathName); DoSave(mFileName);
break; break;
case LC_FILE_SAVEAS: case LC_FILE_SAVEAS:
DoSave(NULL); DoSave(QString());
break; break;
case LC_FILE_SAVE_IMAGE: case LC_FILE_SAVE_IMAGE:
@ -1517,21 +1449,7 @@ void Project::HandleCommand(LC_COMMANDS id)
{ {
lcHTMLDialogOptions Options; lcHTMLDialogOptions Options;
strcpy(Options.PathName, m_strPathName); Options.PathName = QFileInfo(mFileName).canonicalPath();
if (Options.PathName[0] != 0)
{
char* Slash = strrchr(Options.PathName, '/');
if (Slash == NULL)
Slash = strrchr(Options.PathName, '\\');
if (Slash)
{
Slash++;
*Slash = 0;
}
}
int ImageOptions = lcGetProfileInt(LC_PROFILE_HTML_IMAGE_OPTIONS); int ImageOptions = lcGetProfileInt(LC_PROFILE_HTML_IMAGE_OPTIONS);
int HTMLOptions = lcGetProfileInt(LC_PROFILE_HTML_OPTIONS); int HTMLOptions = lcGetProfileInt(LC_PROFILE_HTML_OPTIONS);
@ -1581,11 +1499,8 @@ void Project::HandleCommand(LC_COMMANDS id)
lcSetProfileInt(LC_PROFILE_HTML_PARTS_WIDTH, Options.PartImagesWidth); lcSetProfileInt(LC_PROFILE_HTML_PARTS_WIDTH, Options.PartImagesWidth);
lcSetProfileInt(LC_PROFILE_HTML_PARTS_HEIGHT, Options.PartImagesHeight); lcSetProfileInt(LC_PROFILE_HTML_PARTS_HEIGHT, Options.PartImagesHeight);
int PathLength = strlen(Options.PathName); QDir Dir(Options.PathName);
if (PathLength && Options.PathName[PathLength] != '/' && Options.PathName[PathLength] != '\\') Dir.mkpath(QLatin1String("."));
strcat(Options.PathName, "/");
// TODO: create directory
// TODO: Move to its own function // TODO: Move to its own function
{ {
@ -1607,12 +1522,13 @@ void Project::HandleCommand(LC_COMMANDS id)
htmlext = ".html"; htmlext = ".html";
QString Title = GetTitle();
char m_strTitle[256];
strcpy(m_strTitle, Title.toLatin1().constData()); // todo: qstring
if (Options.SinglePage) if (Options.SinglePage)
{ {
strcpy(fn, Options.PathName); f = fopen(QFileInfo(Dir, Title + htmlext).canonicalFilePath().toLatin1().constData(), "wt");
strcat(fn, m_strTitle);
strcat(fn, htmlext);
f = fopen (fn, "wt");
if (!f) if (!f)
{ {
@ -1641,11 +1557,7 @@ void Project::HandleCommand(LC_COMMANDS id)
{ {
if (Options.IndexPage) if (Options.IndexPage)
{ {
strcpy(fn, Options.PathName); f = fopen(QFileInfo(Dir, Title + "-index" + htmlext).canonicalFilePath().toLatin1().constData(), "wt");
strcat (fn, m_strTitle);
strcat (fn, "-index");
strcat (fn, htmlext);
f = fopen (fn, "wt");
if (!f) if (!f)
{ {
@ -1668,7 +1580,7 @@ void Project::HandleCommand(LC_COMMANDS id)
// Create each step // Create each step
for (lcStep Step = 1; Step <= LastStep; Step++) for (lcStep Step = 1; Step <= LastStep; Step++)
{ {
sprintf(fn, "%s%s-%02d%s", Options.PathName, m_strTitle, Step, htmlext); sprintf(fn, "%s%s-%02d%s", Options.PathName.toLatin1().constData(), m_strTitle, Step, htmlext);
f = fopen(fn, "wt"); f = fopen(fn, "wt");
if (!f) if (!f)
@ -1702,11 +1614,7 @@ void Project::HandleCommand(LC_COMMANDS id)
if (Options.PartsListEnd) if (Options.PartsListEnd)
{ {
strcpy(fn, Options.PathName); f = fopen(QFileInfo(Dir, Title + "-pieces" + htmlext).canonicalFilePath().toLatin1().constData(), "wt");
strcat (fn, m_strTitle);
strcat (fn, "-pieces");
strcat (fn, htmlext);
f = fopen (fn, "wt");
if (!f) if (!f)
{ {
@ -1729,7 +1637,7 @@ void Project::HandleCommand(LC_COMMANDS id)
} }
} }
sprintf(fn, "%s%s-%%1%s", Options.PathName, m_strTitle, ext); sprintf(fn, "%s%s-%%1%s", Options.PathName.toLatin1().constData(), m_strTitle, ext);
SaveStepImages(fn, Options.StepImagesWidth, Options.StepImagesHeight, 1, LastStep); SaveStepImages(fn, Options.StepImagesWidth, Options.StepImagesHeight, 1, LastStep);
if (Options.PartsListImages) if (Options.PartsListImages)
@ -1772,7 +1680,7 @@ void Project::HandleCommand(LC_COMMANDS id)
Info->RenderPiece(Options.PartImagesColor); Info->RenderPiece(Options.PartImagesColor);
glFinish(); glFinish();
sprintf(fn, "%s%s%s", Options.PathName, Info->m_strName, ext); sprintf(fn, "%s%s%s", Options.PathName.toLatin1().constData(), Info->m_strName, ext);
if (!Context->SaveRenderToTextureImage(fn, cx, cy)) if (!Context->SaveRenderToTextureImage(fn, cx, cy))
break; break;
} }
@ -1802,7 +1710,7 @@ void Project::HandleCommand(LC_COMMANDS id)
lcPropertiesDialogOptions Options; lcPropertiesDialogOptions Options;
Options.Properties = mProperties; Options.Properties = mProperties;
Options.Title = m_strTitle; Options.Title = GetTitle();
Options.SetDefault = false; Options.SetDefault = false;
GetPartsList(Options.PartsList); GetPartsList(Options.PartsList);

View file

@ -84,8 +84,6 @@ public:
} }
void UpdateInterface(); void UpdateInterface();
void SetPathName(const char* lpszPathName, bool bAddToMRU);
void SetTitle(const char* lpszTitle);
public: public:
void LoadDefaults(); void LoadDefaults();
@ -113,19 +111,21 @@ protected:
void CreateHTMLPieceList(FILE* f, lcStep Step, bool bImages, const char* ext); void CreateHTMLPieceList(FILE* f, lcStep Step, bool bImages, const char* ext);
void ZoomExtents(int FirstView, int LastView); void ZoomExtents(int FirstView, int LastView);
bool DoSave(const char* FileName); bool DoSave(const QString& FileName);
bool FileLoad(lcFile* file, bool bUndo, bool bMerge); bool FileLoad(lcFile* file, bool bUndo, bool bMerge);
void FileReadLDraw(lcFile* file, const lcMatrix44& CurrentTransform, int* nOk, int DefColor, int* nStep, lcArray<LC_FILEENTRY*>& FileArray); void FileReadLDraw(lcFile* file, const lcMatrix44& CurrentTransform, int* nOk, int DefColor, int* nStep, lcArray<LC_FILEENTRY*>& FileArray);
void FileReadMPD(lcFile& MPD, lcArray<LC_FILEENTRY*>& FileArray) const; void FileReadMPD(lcFile& MPD, lcArray<LC_FILEENTRY*>& FileArray) const;
char m_strTitle[LC_MAXPATH]; void SetFileName(const QString& FileName);
char m_strPathName[LC_MAXPATH]; QString GetTitle() const;
QString mFileName;
public: public:
bool OnNewDocument(); bool OnNewDocument();
bool OnOpenDocument(const char* FileName); bool OnOpenDocument(const QString& FileName);
bool OpenProject(const char* FileName); bool OpenProject(const QString& FileName);
bool SaveModified(); bool SaveIfModified();
}; };
#endif // _PROJECT_H_ #endif // _PROJECT_H_

View file

@ -48,8 +48,7 @@ void lcQHTMLDialog::accept()
return; return;
} }
strcpy(options->PathName, pathName.toLocal8Bit().data()); options->PathName = pathName;
options->ImageFormat = (LC_IMAGE_FORMAT)ui->imageFormat->currentIndex(); options->ImageFormat = (LC_IMAGE_FORMAT)ui->imageFormat->currentIndex();
options->TransparentImages = ui->transparentImages->isChecked(); options->TransparentImages = ui->transparentImages->isChecked();
options->SinglePage = ui->singlePage->isChecked(); options->SinglePage = ui->singlePage->isChecked();

View file

@ -542,7 +542,7 @@ void lcQMainWindow::createStatusBar()
void lcQMainWindow::closeEvent(QCloseEvent *event) void lcQMainWindow::closeEvent(QCloseEvent *event)
{ {
if (lcGetActiveProject()->SaveModified()) if (lcGetActiveProject()->SaveIfModified())
{ {
event->accept(); event->accept();
@ -1264,7 +1264,7 @@ void lcQMainWindow::updateCategories()
partsTree->updateCategories(); partsTree->updateCategories();
} }
void lcQMainWindow::updateTitle(const char* title, bool modified) void lcQMainWindow::updateTitle(const QString& title, bool modified)
{ {
setWindowModified(modified); setWindowModified(modified);
setWindowFilePath(title); setWindowFilePath(title);
@ -1275,23 +1275,23 @@ void lcQMainWindow::updateModified(bool modified)
setWindowModified(modified); setWindowModified(modified);
} }
void lcQMainWindow::updateRecentFiles(const char** fileNames) void lcQMainWindow::updateRecentFiles()
{ {
for (int actionIdx = LC_FILE_RECENT_FIRST; actionIdx <= LC_FILE_RECENT_LAST; actionIdx++) for (int actionIdx = LC_FILE_RECENT_FIRST; actionIdx <= LC_FILE_RECENT_LAST; actionIdx++)
{ {
int fileIdx = actionIdx - LC_FILE_RECENT_FIRST; int fileIdx = actionIdx - LC_FILE_RECENT_FIRST;
QAction *action = actions[actionIdx]; QAction *action = actions[actionIdx];
if (fileNames[fileIdx][0]) if (!gMainWindow->mRecentFiles[fileIdx].isEmpty())
{ {
action->setText(QString("&%1 %2").arg(QString::number(fileIdx + 1), QDir::toNativeSeparators(fileNames[fileIdx]))); action->setText(QString("&%1 %2").arg(QString::number(fileIdx + 1), QDir::toNativeSeparators(gMainWindow->mRecentFiles[fileIdx])));
action->setVisible(true); action->setVisible(true);
} }
else else
action->setVisible(false); action->setVisible(false);
} }
actionFileRecentSeparator->setVisible(fileNames[0][0] != 0); actionFileRecentSeparator->setVisible(!gMainWindow->mRecentFiles[0].isEmpty());
} }
void lcQMainWindow::updateShortcuts() void lcQMainWindow::updateShortcuts()

View file

@ -44,9 +44,9 @@ public:
void updateCurrentCamera(int cameraIndex); void updateCurrentCamera(int cameraIndex);
void updatePerspective(View* view); void updatePerspective(View* view);
void updateCategories(); void updateCategories();
void updateTitle(const char* title, bool modified); void updateTitle(const QString& title, bool modified);
void updateModified(bool modified); void updateModified(bool modified);
void updateRecentFiles(const char** fileNames); void updateRecentFiles();
void updateShortcuts(); void updateShortcuts();
lcVector3 getTransformAmount(); lcVector3 getTransformAmount();

View file

@ -23,7 +23,7 @@ lcQPropertiesDialog::lcQPropertiesDialog(QWidget *parent, void *data) :
options = (lcPropertiesDialogOptions*)data; options = (lcPropertiesDialogOptions*)data;
setWindowTitle(QString(tr("%1 Properties")).arg(options->Title.Buffer())); setWindowTitle(QString(tr("%1 Properties")).arg(options->Title));
ui->descriptionEdit->setText(options->Properties.mDescription); ui->descriptionEdit->setText(options->Properties.mDescription);
ui->authorEdit->setText(options->Properties.mAuthor); ui->authorEdit->setText(options->Properties.mAuthor);

View file

@ -284,9 +284,6 @@ bool lcBaseWindow::DoDialog(LC_DIALOG_TYPE Type, void* Data)
switch (Type) switch (Type)
{ {
case LC_DIALOG_OPEN_PROJECT:
case LC_DIALOG_SAVE_PROJECT:
case LC_DIALOG_MERGE_PROJECT:
case LC_DIALOG_EXPORT_3DSTUDIO: case LC_DIALOG_EXPORT_3DSTUDIO:
case LC_DIALOG_EXPORT_BRICKLINK: case LC_DIALOG_EXPORT_BRICKLINK:
case LC_DIALOG_EXPORT_CSV: case LC_DIALOG_EXPORT_CSV:
@ -297,18 +294,6 @@ bool lcBaseWindow::DoDialog(LC_DIALOG_TYPE Type, void* Data)
switch (Type) switch (Type)
{ {
case LC_DIALOG_OPEN_PROJECT:
result = QFileDialog::getOpenFileName(parent, tr("Open Project"), FileName, tr("Supported Files (*.lcd *.ldr *.dat *.mpd);;All Files (*.*)"));
break;
case LC_DIALOG_SAVE_PROJECT:
result = QFileDialog::getSaveFileName(parent, tr("Save Project"), FileName, tr("Supported Files (*.ldr *.dat);;All Files (*.*)"));
break;
case LC_DIALOG_MERGE_PROJECT:
result = QFileDialog::getOpenFileName(parent, tr("Merge Project"), FileName, tr("Supported Files (*.lcd *.ldr *.dat *.mpd);;All Files (*.*)"));
break;
case LC_DIALOG_EXPORT_3DSTUDIO: case LC_DIALOG_EXPORT_3DSTUDIO:
result = QFileDialog::getSaveFileName(parent, tr("Export 3D Studio"), FileName, tr("3DS Files (*.3ds);;All Files (*.*)")); result = QFileDialog::getSaveFileName(parent, tr("Export 3D Studio"), FileName, tr("3DS Files (*.3ds);;All Files (*.*)"));
break; break;
@ -596,7 +581,7 @@ void lcMainWindow::UpdateCategories()
window->updateCategories(); window->updateCategories();
} }
void lcMainWindow::UpdateTitle(const char* Title, bool Modified) void lcMainWindow::UpdateTitle(const QString& Title, bool Modified)
{ {
lcQMainWindow* window = (lcQMainWindow*)mHandle; lcQMainWindow* window = (lcQMainWindow*)mHandle;
@ -614,15 +599,10 @@ void lcMainWindow::UpdateModified(bool Modified)
void lcMainWindow::UpdateRecentFiles() void lcMainWindow::UpdateRecentFiles()
{ {
const char* fileNames[LC_MAX_RECENT_FILES];
for (int fileIdx = 0; fileIdx < LC_MAX_RECENT_FILES; fileIdx++)
fileNames[fileIdx] = mRecentFiles[fileIdx];
lcQMainWindow* window = (lcQMainWindow*)mHandle; lcQMainWindow* window = (lcQMainWindow*)mHandle;
if (window) if (window)
window->updateRecentFiles(fileNames); window->updateRecentFiles();
} }
void lcMainWindow::UpdateShortcuts() void lcMainWindow::UpdateShortcuts()