return false;
}
- /* Does this document have multiple representation of molecules? */
+ if (gLoadSaveErrorMessage != NULL)
+ MyAppCallback_showScriptMessage("On loading %s:\n%s\n", p, gLoadSaveErrorMessage);
+
+ /* Does this document have multiple representation of molecules? */
if (MolActionCreateAndPerform(newmol, SCRIPT_ACTION(";i"), "lambda { @aux_mols ? @aux_mols.count : 0 }", &len) == 0 && len > 0) {
wxCommandEvent myEvent(MyDocumentEvent, MyDocumentEvent_openAuxiliaryDocuments);
wxPostEvent(this, myEvent);
{
wxString wildcard;
wxFileName fname(GetFilename());
- wxString fnstr;
- GetPrintableName(fnstr);
+ wxString fnstr = GetUserReadableName();
{
/* File filter is built from MyDocManager information */
wxString desc, filter, ext;
i = MyAppCallback_getGlobalSettingsWithType("global.export_background_color", 'i', &bg_color);
if (i != 0)
bg_color = 0;
- GetPrintableName(fnstr);
+ fnstr = GetUserReadableName();
if ((i = fnstr.Find('.', true)) != wxNOT_FOUND) {
fnstr = fnstr.Mid(0, i);
}
}
ring->count = 0;
mol->needsMDCopyCoordinates = 0; /* This flag needs to be negated because the coordinates come from the MD run */
+ MainViewCallback_updateCanvas(GetMainView());
}
MoleculeUnlock(mol);
}
/* Run a subprocess asynchronically */
long
-MyDocument::RunSubProcess(const char *cmd, int (*callback)(Molecule *, int), int (*timerCallback)(Molecule *, int), FILE *output, FILE *errout)
+MyDocument::RunSubProcess(const char **argv, int (*callback)(Molecule *, int), int (*timerCallback)(Molecule *, int), FILE *output, FILE *errout)
{
if (sCheckIsSubThreadRunning(mol, subThreadKind))
return -1; /* subProcess (or MM/MD subThread) is already running */
mol->mutex = new wxMutex;
mol->requestAbortThread = 0;
- wxString cmdstr(cmd, WX_DEFAULT_CONV);
subProcess = new wxProcess(this, -1);
subProcess->Redirect();
subProcessStdout = output;
subProcessStderr = errout;
- subProcessPID = ::wxExecute(cmdstr, wxEXEC_ASYNC | wxEXEC_MAKE_GROUP_LEADER, subProcess);
+ if (argv[1] != NULL && argv[1][0] == 0) {
+ // If the second argument is an empty string, then we handle the first string
+ // as a single argument. (On the other hand, if the second argument is NULL,
+ // then argv is given to wxExecute as an array containing a single string.)
+ subProcessPID = ::wxExecute(argv[0], wxEXEC_ASYNC | wxEXEC_MAKE_GROUP_LEADER, subProcess);
+ } else {
+ // Array of arguments
+ subProcessPID = ::wxExecuteArgv(argv, wxEXEC_ASYNC | wxEXEC_MAKE_GROUP_LEADER, subProcess);
+ }
if (subProcessPID == 0) {
subProcess->Detach();
subProcess = NULL;
Molecule *
MoleculeCallback_openNewMolecule(const char *fname)
{
+ if (!gUseGUI)
+ return NULL;
wxDocument *doc;
MyDocManager *manager = wxGetApp().DocManager();
if (fname == NULL || *fname == 0) {
void
MoleculeCallback_notifyModification(Molecule *mp, int now_flag)
{
+ if (!gUseGUI)
+ return;
MyDocument *doc = MyDocumentFromMolecule(mp);
if (doc && !doc->isModifyNotificationSent) {
doc->isModifyNotificationSent = true;
Molecule *
MoleculeCallback_currentMolecule(void)
{
+ if (!gUseGUI)
+ return NULL;
MainView *mview = MainViewCallback_activeView();
if (mview != NULL)
return mview->mol;
Molecule *
MoleculeCallback_moleculeAtIndex(int idx)
{
+ if (!gUseGUI)
+ return NULL;
MainView *mview = MainViewCallback_viewWithTag(idx);
if (mview != NULL)
return mview->mol;
void
MoleculeCallback_displayName(Molecule *mol, char *buf, int bufsize)
{
+ if (!gUseGUI) {
+ buf[0] = 0;
+ return;
+ }
MyDocument *doc = MyDocumentFromMolecule(mol);
if (doc != NULL) {
wxString fname;
- doc->GetPrintableName(fname);
+ fname = doc->GetUserReadableName();
strncpy(buf, (const char*)fname.mb_str(wxConvFile), bufsize - 1);
buf[bufsize - 1] = 0;
} else {
void
MoleculeCallback_pathName(Molecule *mol, char *buf, int bufsize)
{
+ if (!gUseGUI) {
+ if (mol != NULL && mol->path != NULL) {
+ strncpy(buf, mol->path, bufsize - 1);
+ buf[bufsize - 1] = 0;
+ } else buf[0] = 0;
+ return;
+ }
MyDocument *doc = MyDocumentFromMolecule(mol);
if (doc != NULL && doc->hasFile)
MainViewCallback_getFilename(mol->mview, buf, bufsize);
int
MoleculeCallback_setDisplayName(Molecule *mol, const char *name)
{
+ if (!gUseGUI) {
+ return 0;
+ }
MyDocument *doc = MyDocumentFromMolecule(mol);
if (doc == NULL || doc->hasFile)
return 1; /* Cannot change file-associated window title */
void
MoleculeCallback_lockMutex(void *mutex)
{
- ((wxMutex *)mutex)->Lock();
+ if (gUseGUI)
+ ((wxMutex *)mutex)->Lock();
}
void
MoleculeCallback_unlockMutex(void *mutex)
{
- ((wxMutex *)mutex)->Unlock();
+ if (gUseGUI)
+ ((wxMutex *)mutex)->Unlock();
}
void
}
int
-MoleculeCallback_callSubProcessAsync(Molecule *mol, const char *cmd, int (*callback)(Molecule *, int), int (*timerCallback)(Molecule *, int), FILE *output, FILE *errout)
+MoleculeCallback_callSubProcessAsync(Molecule *mol, const char **argv, int (*callback)(Molecule *, int), int (*timerCallback)(Molecule *, int), FILE *output, FILE *errout)
{
+ if (!gUseGUI)
+ return -1;
MyDocument *doc = MyDocumentFromMolecule(mol);
if (doc != NULL)
- return doc->RunSubProcess(cmd, callback, timerCallback, output, errout);
+ return doc->RunSubProcess(argv, callback, timerCallback, output, errout);
else return -1;
}
void
MolActionCallback_registerUndo(Molecule *mol, MolAction *action)
{
+ if (!gUseGUI)
+ return;
MyDocument *doc = MyDocumentFromMolecule(mol);
if (doc != NULL && doc->IsUndoEnabled())
doc->PushUndoAction(action);
int
MolActionCallback_setUndoRegistrationEnabled(Molecule *mol, int flag)
{
+ if (!gUseGUI)
+ return 0;
MyDocument *doc = MyDocumentFromMolecule(mol);
if (doc != NULL) {
doc->SetUndoEnabled(flag);
int
MolActionCallback_isUndoRegistrationEnabled(Molecule *mol)
{
+ if (!gUseGUI)
+ return 0;
MyDocument *doc = MyDocumentFromMolecule(mol);
if (doc != NULL && doc->IsUndoEnabled())
return 1;