Ejemplo n.º 1
0
void InsertCurrentStyle(void)
{
    if (g_current_style==NULL)
        InsertStyle("Normal");
    else
        InsertStyle(g_current_style);
}
Ejemplo n.º 2
0
/* if the_style ends with '0' then do not insert the style sequence \s2
   and just insert the rtf commands, otherwise do both 
   This is needed so that chapter headings work properly in the table
   of contents
*/
void InsertStyle(const char *the_style)
{
    char *rtf, *last_char;
    int how = INSERT_STYLE_NORMAL;
    char *style = strdup(the_style);

    last_char = style + strlen(style) - 1;
    if (*last_char == '0') {
        how = INSERT_STYLE_NO_STYLE;
        *last_char = '\0'; 
    }
    
    if (strcmp(style,"Normal")==0) {

        if (getAlignment()==CENTERED) {
            InsertStyle("centerpar");
            free(style);
            return;
        }
        if (getAlignment()==RIGHT) {
            InsertStyle("rightpar");
            free(style);
            return;
        }
        if (getAlignment()==LEFT) {
            InsertStyle("leftpar");
            free(style);
            return;
        }
    }

    diagnostics(4, "InsertStyle(%s)", style);
    rtf = SearchCfgRtf(style, STYLE_A);
    if (rtf == NULL) {
        diagnostics(WARNING, "Cannot find '%s' style using 'Normal' style", style);
        SetCurrentStyle("Normal");
        rtf = SearchCfgRtf("Normal", STYLE_A);
        InsertBasicStyle(rtf, INSERT_STYLE_NORMAL);
    } else {
        SetCurrentStyle(style);
        InsertBasicStyle(rtf, how);
    }
    
    free(style);
}
Ejemplo n.º 3
0
void PreviewDlg::UpdateBrowser(cxUpdateMode mode) {
	if (m_thread) return; // update in process

	// Do we have a temp file
	if (m_tempPath.empty()) {
		m_tempPath = wxFileName::CreateTempFileName(wxEmptyString);
		m_tempPath += wxT(".html");
		m_isFirst = true;
	}

	// Load the text of entire doc
	vector<char> text;
	if (m_pinnedEditor) {
		m_pinnedEditor->GetText(text);
		m_truePath = m_pinnedEditor->GetPath();
	}
	else {
		m_editorCtrl->GetText(text);
		m_truePath = m_editorCtrl->GetPath();
	}

	m_uncPath = ConvertPathToUNC(m_truePath);

	// Make sure we only update when the editor changes
	m_editorChangeToken = m_editorCtrl->GetChangeToken();
	m_editorCtrl->MarkPreviewDone();

	if (m_pipeCmd.empty()) {
		wxFile tempFile(m_tempPath, wxFile::write);
		if (!tempFile.IsOpened()) return;

		if (!text.empty()) {
			if (!m_truePath.empty()) {
				InsertBase(text, m_truePath);

				// Check if we should also save the current css file
				// (does not work with remote files as file has to be
				//  saved in same location as source)
				if (m_pinnedEditor && !m_editorCtrl->IsRemote()) {
					if (InsertStyle(text)) {
						wxFileOutputStream cssFile(m_tempCssPath);
						if (!cssFile.IsOk()) return;
						m_editorCtrl->WriteText(cssFile);
					}
				}
			}

			tempFile.Write(&*text.begin(), text.size());
		}

		if (mode == cxUPDATE_RELOAD || m_isFirst) RefreshBrowser(cxUPDATE_RELOAD);
		else RefreshBrowser(cxUPDATE_REFRESH);
	}
	else {
		cxEnv env;
		m_editorCtrl->SetEnv(env, true);
		const wxString cmd = m_editorCtrl->GetBashCommand(m_pipeCmd, env);
		if (cmd.empty()) return;

		// Thread will send event and delete itself when done
		m_thread = new CommandThread(cmd, text, m_tempPath, m_truePath, *this, env);
	}

	m_isOnPreview = true;
}