Code: Select all
SetDirectory("/media/disk-1/Documents and Settings/Jim Cobban/My Documents/FamilyTree");
SetFilename("Cobban.GED");
Code: Select all
GetDirectory()=""
GetFilename()=""
What am I not understanding?
Code: Select all
SetDirectory("/media/disk-1/Documents and Settings/Jim Cobban/My Documents/FamilyTree");
SetFilename("Cobban.GED");
Code: Select all
GetDirectory()=""
GetFilename()=""
Code: Select all
class OpenFileDialog : public wxFileDialog
{
public:
OpenFileDialog( GenTool * tool,
wxFrame * parent);
virtual ~OpenFileDialog();
};
Code: Select all
OpenFileDialog::OpenFileDialog( GenTool * tool,
wxFrame * parent)
: wxFileDialog( parent,
"Choose a file",
wxT(std::getenv("HOME")), // directory
"", // initial file name
"GEDCOM files (*.ged)|*.ged;*.GED",
wxFD_FILE_MUST_EXIST + wxFD_CHANGE_DIR)
{
std::cerr << "OpenFileDialog::OpenFileDialog(tool=" << tool <<
", parent=" << parent << ")\n";
std::cerr << "start: GetDirectory()=\"" << GetDirectory()
<< "\", GetFilename()=\"" << GetFilename() << "\"\n";
// get configuration for dialog
wxXmlNode * openCfg = tool->getConfig("open");
wxXmlNode * child = openCfg->GetChildren();
while (child)
{
if (child->GetType() == wxXML_TEXT_NODE)
{
std::cerr << "SetMessage(\"" << child->GetContent().Trim(true) << "\")\n";
SetMessage(child->GetContent().Trim(true));
}
if (child->GetName().Cmp("last") == 0)
{
std::cerr << "last: ";
wxString lastFn = child->GetPropVal(wxT("fn"),
wxT(""));
std::cerr << "lastFn=\"" << lastFn << "\"\n";
size_t endDir = lastFn.find_last_of('/', lastFn.length() - 1);
std::cerr << "endDir=" << endDir << ", length=" << lastFn.length() << "\n";
if (endDir == std::string::npos)
{ // no directory separator
std::cerr << "SetFilename(\"" << lastFn << "\")\n";
SetFilename(lastFn);
}
else
{
std::cerr << "SetDirectory(\"" << lastFn.substr(0, endDir) << "\")\n";
SetDirectory(lastFn.substr(0, endDir));
std::cerr << "SetFilename(\"" << lastFn.substr(endDir + 1) << "\")\n";
SetFilename(lastFn.substr(endDir + 1));
}
}
else
{
std::cerr << "unexpected tag <" << child->GetName() << ">\n";
}
child = child->GetNext();
} // loop through children
std::cerr << "return: GetDirectory()=\"" << GetDirectory()
<< "\", GetFilename()=\"" << GetFilename() << "\"\n";
} // OpenFileDialog::OpenFileDialog
Code: Select all
wxFD_FILE_MUST_EXIST + wxFD_CHANGE_DIR)
Code: Select all
wxT(std::getenv("HOME")),
// try this
wxString(std::getenv("HOME")),
Thank you for trying to help me.protocol wrote:
Works fine for me, you may want to check the return value set by your getenv call.
Even more so, try passing the return to wxString instead of wxT macro. or use http://docs.wxwidgets.org/stable/wx_env ... l#wxgetenv
You seem to be attached to std namespace, keep in mind you are using a mature framework. You should look to it more often for the common tasks and cross-platform compatibility.
Code: Select all
wxGetEnv(wxT("HOME"))
Code: Select all
: wxFileDialog( parent,
"Choose a file",
wxString(std::getenv("HOME")), // directory
"", // initial file name
"GEDCOM files (*.ged)|*.ged;*.GED",
wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR)
Code: Select all
OpenFileDialog::OpenFileDialog(tool=0x99f98e8, parent=0x9a50cd0)
std::getenv("HOME")="/home/jcobban"
start: GetDirectory()="", GetFilename()=""
start: GetWildcard()="GEDCOM files (*.ged)|*.ged;*.GED
GenTool::getConfig(const char * "open")
GenTool::getConfig(wxString "open")
last: lastFn="/media/disk-1/Documents and Settings/Jim Cobban/My Documents/FamilyTree/Cobban.GED"
endDir=71, length=82
SetDirectory("/media/disk-1/Documents and Settings/Jim Cobban/My Documents/FamilyTree")
SetFilename("Cobban.GED")
last: GetDirectory()="", GetFilename()=""
return: GetDirectory()="", GetFilename()=""
Code: Select all
wxString directory, filename;
directory = lastFn.substr(0, endDir);
filename = lastFn.substr(endDir + 1);
std::cerr << "SetDirectory("" << directory << "")\n";
SetDirectory(directory);
std::cerr << "SetFilename("" << filename << "")\n";
SetFilename(filename);
std::cerr << "last: GetDirectory()="" << GetDirectory()
<< "", GetFilename()="" << GetFilename() << ""\n";
'+' for number which are powers of 2 (1, 2, 4, 8 ) is equivalent to '|', logical OR.protocol wrote:I'm not sure I have ever seen the "+" operator used for flags, usually "|" operator is used.Code: Select all
wxFD_FILE_MUST_EXIST + wxFD_CHANGE_DIR)
Sorry, I should have made that clear, as looking through the wxWidgets code I see that there are a lot of specializations and therefore the problem I am having may be specific to a particular implementation.Paulsen wrote:Maybe a dumb question: What platform and build environment are you on? "Documents and Settings" has a definite Windows-tone. Are you sure you are specifying the directory in a way your OS will understand?
I don't understand your question. The methods don't read anything, they just set internal state variables of the dialog. In any event there is no way for the dialog to be able to tell whether the directory in question is on another file system, it is just a string of directory names.Auria wrote:Do the same methods work fine if you don't try to have them read files from another filesystem?
Namespaces are used to denote scope, to provide logical organization. All wxWidget entities are prefixed with "wx". By that virtue, there is really no need for namespaces within wxWidgets. In respects to maturity, that could be called defensive programming; protecting developer classes from name clashes with wxWidget classes.jamescobban wrote: One of my concerns is that wxWidgets does not itself use a name space, which is to my mind a sign of immaturity. C++ namespaces have been around for more than 10 years now.
Well, let me rephrase it, common convention is to use "|" for flags.TrV wrote:'+' for number which are powers of 2 (1, 2, 4, 8 ) is equivalent to '|', logical OR.protocol wrote:I'm not sure I have ever seen the "+" operator used for flags, usually "|" operator is used.Code: Select all
wxFD_FILE_MUST_EXIST + wxFD_CHANGE_DIR)
Having not coded wxFileDialog, I don't know what it doesjamescobban wrote:I don't understand your question. The methods don't read anything, they just set internal state variables of the dialog. In any event there is no way for the dialog to be able to tell whether the directory in question is on another file system, it is just a string of directory names.Auria wrote:Do the same methods work fine if you don't try to have them read files from another filesystem?
The fact that could could pass char* might hint that you are using an ANSI build of wx. Is it the case? if so, I would strongly recommend using a unicode build. Your issue, in this case, might be one of encoding conversion (though i'm not sure how they could happen, but who knows)jamescobban wrote: The bottom line is that the methods work if they are called with a const char * literal, but not if they are called with a wxString variable. My app worked fine until I changed it to initialize the dialog from an XML initialization file, instead of hard-coding the directory and file name.
That can also be a sign of very mature; wxWidgets was started before namespaces existed (or where implemented in common compilers) and changing this at this point would break all existing code for little benifit (though I would approve such a move even then.)One of my concerns is that wxWidgets does not itself use a name space, which is to my mind a sign of immaturity. C++ namespaces have been around for more than 10 years now.
I just did the build according to the instructions in install-gtk.txt. That is I issued "../configure --with-gtk". I did not explicitly request either an ANSI or a unicode build. How would I tell which the configure command chose to do?The fact that could could pass char* might hint that you are using an ANSI build of wx. Is it the case? if so, I would strongly recommend using a unicode build. Your issue, in this case, might be one of encoding conversion (though i'm not sure how they could happen, but who knows)
I rebuilt wxWidgets with Unicode and made the required changes in my code to compile. The problem persists, except that it is now harder to debug because the unicode version of wxString does not behave well with std::cerr, displaying an address (presumably of its buffer) instead of the contents of the string.Auria wrote:To get a unicode build, pass option --enable-unicode (or whatever it's called, see ../configure --help)
It's indeed a shame the readme doesn't mention that; --with-gtk should not be needed, and --enable-unicode is highly recommended. wxWidgets 3.0 will feature major refactor of this (unicode will always be enabled), this may be why it was left this way in 2.8
The diagnostic output from my program is now:jamescobban wrote: I rebuilt wxWidgets with Unicode and made the required changes in my code to compile. The problem persists, except that it is now harder to debug because the unicode version of wxString does not behave well with std::cerr, displaying an address (presumably of its buffer) instead of the contents of the string.
As you can see, from the output of GetWildCard, it is possible for me to correctly initialize a state variable of wxFileDialog given a literal string (L"GEDCOM files (*.ged)|*.ged;*.GED" in the constructor in this case), but I still cannot initialize them from a wxString variable!OpenFileDialog::OpenFileDialog(tool=0x92613f8, parent=0x92baa50)
std::getenv("HOME")="/home/jcobban"
start: GetDirectory()="", GetFilename()=""
start: GetWildcard()="GEDCOM files (*.ged)|*.ged;*.GED
last: lastFn="/media/disk-1/Documents and Settings/Jim Cobban/My Documents/FamilyTree/Cobban.GED"
endDir=71, length=82
SetDirectory("/media/disk-1/Documents and Settings/Jim Cobban/My Documents/FamilyTree")
SetFilename("Cobban.GED")
last: GetDirectory()="", GetFilename()=""
return: GetDirectory()="", GetFilename()=""