Example #1
0
void FilePath::getWorkingDirectory()
{
    char buf[1000];
    pathStdStr().clear();
    if(getcwd(buf, sizeof(buf)))
    {
        pathStdStr().append(buf);
    }
    FilePathEnsureLastPathSep(pathStdStr());
}
bool ProjectSettingsDialog::runDialog()
    {
    GtkEntry *projDirEntry = GTK_ENTRY(Builder::getBuilder()->getWidget(
            "OovaideProjectDirEntry"));
    GtkTextView *excDirsTextView = GTK_TEXT_VIEW(Builder::getBuilder()->getWidget(
            "ExcludeDirsTextview"));
    GtkEntry *srcDirEntry = GTK_ENTRY(Builder::getBuilder()->getWidget(
            "RootSourceDirEntry"));

    OovString origSourceDir = Project::getSourceRootDirectory();
    if(mEditStyle == PS_NewProject)
        {
        Gui::clear(projDirEntry);
        Gui::clear(srcDirEntry);
        Gui::clear(excDirsTextView);
        }
    else
        {
        Gui::setText(projDirEntry, Project::getProjectDirectory());
        Gui::setText(srcDirEntry, Project::getSourceRootDirectory());
        CompoundValue excDirs(mProjectOptions.getValue(OptProjectExcludeDirs), ';');
        Gui::setText(excDirsTextView, excDirs.getAsString('\n'));
        }

    bool editSrc = (mEditStyle == PS_NewProject ||
        mEditStyle == PS_OpenProjectEditSource);
    Gui::setEnabled(srcDirEntry, editSrc);
    Gui::setEnabled(GTK_BUTTON(Builder::getBuilder()->getWidget(
            "RootSourceDirButton")), editSrc);
    Gui::setEnabled(GTK_BUTTON(Builder::getBuilder()->getWidget(
            "OovaideProjectDirButton")), mEditStyle == PS_NewProject);
    Gui::setEnabled(projDirEntry, mEditStyle == PS_NewProject);

    bool ok = run(true);
    if(ok)
        {
        OovStatus status(true, SC_File);
        if(!FileIsDirOnDisk(getRootSrcDir(), status))
            {
            ok = Gui::messageBox("The source directory does not exist. "
                "Do you want to create it?", GTK_MESSAGE_QUESTION,
                GTK_BUTTONS_YES_NO);
            if(ok)
                {
                FilePath dir(getRootSrcDir(), FP_Dir);
                status = FileEnsurePathExists(dir);
                }
            }
        if(status.needReport())
            {
            ok = false;
            status.report(ET_Error, "Unable to access directory");
            }
        }
    if(ok)
        {
        mExcludeDirs.parseString(Gui::getText(excDirsTextView), '\n');
        mExcludeDirs.deleteEmptyStrings();
        Project::setSourceRootDirectory(getRootSrcDir());

        // Update the project options.
        if(mEditStyle == PS_NewProject)
            {
            // The project dir is used by setDefaultOptions.
            OovString projectDir = getProjectDir();
            Project::setProjectDirectory(projectDir);
            FilePathEnsureLastPathSep(projectDir);
            OovStatus status = FileEnsurePathExists(projectDir);
            OptionsDefaults optionDefaults(getProjectOptions());
            optionDefaults.setDefaultOptions();
            sProjectSettingsDialog->getGuiOptions().setDefaultOptions();
            }
        FilePath rootSrcText(getRootSrcDir(), FP_Dir);
        getProjectOptions().setNameValue(OptSourceRootDir, rootSrcText);
        }
    return ok;
    }