set directory of file dialog when opening file by double-click, recent files list or drag and drop
This commit is contained in:
parent
e71e4bf562
commit
2c5c0c2347
|
@ -1364,8 +1364,9 @@ std::list<std::string> Application::getCmdLineFiles()
|
|||
return files;
|
||||
}
|
||||
|
||||
void Application::processFiles(const std::list<std::string>& files)
|
||||
std::list<std::string> Application::processFiles(const std::list<std::string>& files)
|
||||
{
|
||||
std::list<std::string> processed;
|
||||
Base::Console().Log("Init: Processing command line files\n");
|
||||
for (std::list<std::string>::const_iterator it = files.begin(); it != files.end(); ++it) {
|
||||
Base::FileInfo file(*it);
|
||||
|
@ -1376,17 +1377,21 @@ void Application::processFiles(const std::list<std::string>& files)
|
|||
if (file.hasExtension("fcstd") || file.hasExtension("std")) {
|
||||
// try to open
|
||||
Application::_pcSingleton->openDocument(file.filePath().c_str());
|
||||
processed.push_back(*it);
|
||||
}
|
||||
else if (file.hasExtension("fcscript") || file.hasExtension("fcmacro")) {
|
||||
Base::Interpreter().runFile(file.filePath().c_str(), true);
|
||||
processed.push_back(*it);
|
||||
}
|
||||
else if (file.hasExtension("py")) {
|
||||
try{
|
||||
Base::Interpreter().loadModule(file.fileNamePure().c_str());
|
||||
processed.push_back(*it);
|
||||
}
|
||||
catch(const PyException&) {
|
||||
// if loading the module does not work, try just running the script (run in __main__)
|
||||
Base::Interpreter().runFile(file.filePath().c_str(),true);
|
||||
processed.push_back(*it);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -1398,6 +1403,7 @@ void Application::processFiles(const std::list<std::string>& files)
|
|||
Base::Interpreter().runStringArg("import %s",mods.front().c_str());
|
||||
Base::Interpreter().runStringArg("%s.open(u\"%s\")",mods.front().c_str(),
|
||||
escapedstr.c_str());
|
||||
processed.push_back(*it);
|
||||
Base::Console().Log("Command line open: %s.open(u\"%s\")\n",mods.front().c_str(),escapedstr.c_str());
|
||||
}
|
||||
else {
|
||||
|
@ -1415,6 +1421,8 @@ void Application::processFiles(const std::list<std::string>& files)
|
|||
Console().Error("Unknown exception while processing file: %s \n", file.filePath().c_str());
|
||||
}
|
||||
}
|
||||
|
||||
return processed; // successfully processed files
|
||||
}
|
||||
|
||||
void Application::processCmdLineFiles(void)
|
||||
|
|
|
@ -230,7 +230,7 @@ public:
|
|||
static void destructObserver(void);
|
||||
static void processCmdLineFiles(void);
|
||||
static std::list<std::string> getCmdLineFiles();
|
||||
static void processFiles(const std::list<std::string>&);
|
||||
static std::list<std::string> processFiles(const std::list<std::string>&);
|
||||
static void runApplication(void);
|
||||
friend Application &GetApplication(void);
|
||||
static std::map<std::string,std::string> &Config(void){return mConfig;}
|
||||
|
|
|
@ -89,7 +89,7 @@
|
|||
#include "Control.h"
|
||||
#include "DocumentRecovery.h"
|
||||
#include "TransactionObject.h"
|
||||
#include "TaskView/TaskView.h"
|
||||
#include "FileDialog.h"
|
||||
|
||||
#include "SplitView3DInventor.h"
|
||||
#include "View3DInventor.h"
|
||||
|
@ -113,13 +113,14 @@
|
|||
#include "ViewProviderPart.h"
|
||||
#include "ViewProviderOrigin.h"
|
||||
#include "ViewProviderMaterialObject.h"
|
||||
#include "ViewProviderGroupExtension.h"
|
||||
|
||||
#include "Language/Translator.h"
|
||||
#include "TaskView/TaskView.h"
|
||||
#include "TaskView/TaskDialogPython.h"
|
||||
#include <Gui/Quarter/Quarter.h>
|
||||
#include "View3DViewerPy.h"
|
||||
#include "ViewProviderGroupExtension.h"
|
||||
#include "GuiInitScript.h"
|
||||
#include <Gui/GuiInitScript.h>
|
||||
|
||||
|
||||
using namespace Gui;
|
||||
|
@ -529,7 +530,9 @@ void Application::open(const char* FileName, const char* Module)
|
|||
Command::doCommand(Command::Gui, "Gui.SendMsgToActiveView(\"ViewFit\")");
|
||||
}
|
||||
// the original file name is required
|
||||
getMainWindow()->appendRecentFile(QString::fromUtf8(File.filePath().c_str()));
|
||||
QString filename = QString::fromUtf8(File.filePath().c_str());
|
||||
getMainWindow()->appendRecentFile(filename);
|
||||
FileDialog::setWorkingDirectory(filename);
|
||||
}
|
||||
catch (const Base::PyException& e){
|
||||
// Usually thrown if the file is invalid somehow
|
||||
|
@ -577,7 +580,9 @@ void Application::importFrom(const char* FileName, const char* DocName, const ch
|
|||
}
|
||||
|
||||
// the original file name is required
|
||||
getMainWindow()->appendRecentFile(QString::fromUtf8(File.filePath().c_str()));
|
||||
QString filename = QString::fromUtf8(File.filePath().c_str());
|
||||
getMainWindow()->appendRecentFile(filename);
|
||||
FileDialog::setWorkingDirectory(filename);
|
||||
}
|
||||
catch (const Base::PyException& e){
|
||||
// Usually thrown if the file is invalid somehow
|
||||
|
@ -1625,6 +1630,10 @@ void Application::runApplication(void)
|
|||
QIcon::setThemeName(QLatin1String("FreeCAD-default"));
|
||||
#endif
|
||||
|
||||
//#if defined(FC_OS_LINUX)
|
||||
// FileDialog::setWorkingDirectory(QDir::currentPath());
|
||||
//#endif
|
||||
|
||||
Application app(true);
|
||||
MainWindow mw;
|
||||
mw.setWindowTitle(mainApp.applicationName());
|
||||
|
|
|
@ -158,6 +158,7 @@ QString FileDialog::getSaveFileName (QWidget * parent, const QString & caption,
|
|||
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation));
|
||||
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
|
||||
urls << QUrl::fromLocalFile(getWorkingDirectory());
|
||||
urls << QUrl::fromLocalFile(QDir::currentPath());
|
||||
|
||||
QString file;
|
||||
FileDialog dlg(parent);
|
||||
|
@ -237,6 +238,7 @@ QString FileDialog::getOpenFileName(QWidget * parent, const QString & caption, c
|
|||
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation));
|
||||
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
|
||||
urls << QUrl::fromLocalFile(getWorkingDirectory());
|
||||
urls << QUrl::fromLocalFile(QDir::currentPath());
|
||||
|
||||
QString file;
|
||||
FileDialog dlg(parent);
|
||||
|
@ -295,6 +297,7 @@ QStringList FileDialog::getOpenFileNames (QWidget * parent, const QString & capt
|
|||
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::PicturesLocation));
|
||||
urls << QUrl::fromLocalFile(QDesktopServices::storageLocation(QDesktopServices::MoviesLocation));
|
||||
urls << QUrl::fromLocalFile(getWorkingDirectory());
|
||||
urls << QUrl::fromLocalFile(QDir::currentPath());
|
||||
|
||||
QStringList files;
|
||||
FileDialog dlg(parent);
|
||||
|
@ -354,7 +357,10 @@ void FileDialog::setWorkingDirectory(const QString& dir)
|
|||
QString dirName = dir;
|
||||
if (!dir.isEmpty()) {
|
||||
QFileInfo info(dir);
|
||||
dirName = info.absolutePath();
|
||||
if (info.isFile())
|
||||
dirName = info.absolutePath();
|
||||
else
|
||||
dirName = info.absoluteFilePath();
|
||||
}
|
||||
|
||||
Base::Reference<ParameterGrp> hPath = App::GetApplication().GetUserParameter().GetGroup("BaseApp")
|
||||
|
|
|
@ -1026,7 +1026,11 @@ void MainWindow::processMessages(const QList<QByteArray> & msg)
|
|||
if (it->startsWith(action))
|
||||
files.push_back(std::string(it->mid(action.size()).constData()));
|
||||
}
|
||||
App::Application::processFiles(files);
|
||||
files = App::Application::processFiles(files);
|
||||
for (std::list<std::string>::iterator it = files.begin(); it != files.end(); ++it) {
|
||||
QString filename = QString::fromUtf8(it->c_str(), it->size());
|
||||
FileDialog::setWorkingDirectory(filename);
|
||||
}
|
||||
}
|
||||
catch (const Base::SystemExitException&) {
|
||||
}
|
||||
|
@ -1036,7 +1040,12 @@ void MainWindow::delayedStartup()
|
|||
{
|
||||
// processing all command line files
|
||||
try {
|
||||
App::Application::processCmdLineFiles();
|
||||
std::list<std::string> files = App::Application::getCmdLineFiles();
|
||||
files = App::Application::processFiles(files);
|
||||
for (std::list<std::string>::iterator it = files.begin(); it != files.end(); ++it) {
|
||||
QString filename = QString::fromUtf8(it->c_str(), it->size());
|
||||
FileDialog::setWorkingDirectory(filename);
|
||||
}
|
||||
}
|
||||
catch (const Base::SystemExitException&) {
|
||||
throw;
|
||||
|
|
Loading…
Reference in New Issue
Block a user