Exemplo n.º 1
0
bool wxArrayStringUpdatePos(wxArrayString& arr, size_t pos, int num, bool no_error)
{
    if (num == 0)
        return false;
    else if (num > 0)
    {
        // if no_error check if <= GetCount, else let array error out
        if (!no_error || (pos <= arr.GetCount()))
            arr.Insert( wxEmptyString, pos, num );
    }
    else // if (num < 0)
    {
        const int count = arr.GetCount();
        if (no_error && (int(pos) - num > count))
        {
            num = -(count - int(pos));
            if ((num >= 0) || (count == 0)) return false;
        }
        else
        {
            wxCHECK_MSG( int(pos) - num <= count, false,
                wxString::Format(wxT("Called wxArrayStringUpdatePos(pos=%d, N=%d)\nPos value is invalid for present array with %d elements"),
                                int(pos), num, count) );
        }

        if ((pos == 0u) && (num == count))
            arr.Clear();
        else
            arr.RemoveAt( pos, -num );
    }

    return true;
}
Exemplo n.º 2
0
void EditorConfig::GetRecentItems(wxArrayString& files, const wxString& nodeName)
{
    if(nodeName.IsEmpty()) { return; }

    if(m_cacheRecentItems.count(nodeName)) {
        files = m_cacheRecentItems.find(nodeName)->second;
        // files.Sort(clSortStringsFunc);
        return;
    }

    // find the root node
    wxXmlNode* node = XmlUtils::FindFirstByTagName(m_doc->GetRoot(), nodeName);
    if(node) {
        wxXmlNode* child = node->GetChildren();
        while(child) {
            if(child->GetName() == wxT("File")) {
                wxString fileName = XmlUtils::ReadString(child, wxT("Name"));
                // wxXmlDocument Saves/Loads items in reverse order, so prepend, not add.
                if(wxFileExists(fileName)) files.Insert(fileName, 0);
            }
            child = child->GetNext();
        }
    }
    // files.Sort(clSortStringsFunc);
}
Exemplo n.º 3
0
void wxSTEPrependArrayString(const wxString &str, wxArrayString &strArray, int count)
{
    const int idx = strArray.Index(str);
    if (idx == 0)
        return;
    if (idx != wxNOT_FOUND)
        strArray.RemoveAt(idx);

    strArray.Insert(str, 0);
    if ((count > 0) && ((int)strArray.GetCount() > count))
        strArray.RemoveAt(count, strArray.GetCount()-count);
}
Exemplo n.º 4
0
/* TextEntryPanel::TextEntryPanel
 * TextEntryPanel class constructor
 *******************************************************************/
TextEntryPanel::TextEntryPanel(wxWindow* parent)
	: EntryPanel(parent, "text")
{
	// Create the text area
	text_area = new TextEditor(this, -1);
	sizer_main->Add(text_area, 1, wxEXPAND, 0);

	// Add 'Text Language' choice to toolbar
	SToolBarGroup* group_language = new SToolBarGroup(toolbar, "Text Language", true);
	languages = TextLanguage::getLanguageNames();
	languages.Sort();
	languages.Insert("None", 0, 1);
	choice_text_language = new wxChoice(group_language, -1, wxDefaultPosition, wxDefaultSize, languages);
	choice_text_language->Select(0);
	group_language->addCustomControl(choice_text_language);
	toolbar->addGroup(group_language);

	// Add 'Word Wrap' checkbox to top sizer
	sizer_bottom->AddStretchSpacer();
	cb_wordwrap = new wxCheckBox(this, -1, "Word Wrapping");
	sizer_bottom->Add(cb_wordwrap, 0, wxEXPAND, 0);

	// Add 'Jump To' button to top sizer
	btn_jump_to = new wxButton(this, -1, "Jump To");
	sizer_bottom->Add(btn_jump_to, 0, wxEXPAND|wxRIGHT, 4);

	// Add 'Find/Replace' button to top sizer
	btn_find_replace = new wxButton(this, -1, "Find + Replace");
	sizer_bottom->Add(btn_find_replace, 0, wxEXPAND, 0);

	// Bind events
	choice_text_language->Bind(wxEVT_CHOICE, &TextEntryPanel::onChoiceLanguageChanged, this);
	text_area->Bind(wxEVT_STC_CHANGE, &TextEntryPanel::onTextModified, this);
	btn_find_replace->Bind(wxEVT_BUTTON, &TextEntryPanel::onBtnFindReplace, this);
	text_area->Bind(wxEVT_STC_UPDATEUI, &TextEntryPanel::onUpdateUI, this);
	cb_wordwrap->Bind(wxEVT_CHECKBOX, &TextEntryPanel::onWordWrapChanged, this);
	btn_jump_to->Bind(wxEVT_BUTTON, &TextEntryPanel::onBtnJumpTo, this);

	// Custom toolbar
	custom_toolbar_actions = "arch_scripts_compileacs;arch_scripts_compilehacs";
	toolbar->addActionGroup("Scripts", wxSplit(custom_toolbar_actions, ';'));

	Layout();
}
Exemplo n.º 5
0
/* TextEntryPanel::TextEntryPanel
 * TextEntryPanel class constructor
 *******************************************************************/
TextEntryPanel::TextEntryPanel(wxWindow* parent)
	: EntryPanel(parent, "text")
{
	// Create the text area
	text_area = new TextEditor(this, -1);
	sizer_main->Add(text_area, 1, wxEXPAND, 0);

	// Add 'Text Language' choice
	languages = TextLanguage::getLanguageNames();
	languages.Sort();
	languages.Insert("None", 0, 1);
	choice_text_language = new wxChoice(this, -1, wxDefaultPosition, wxDefaultSize, languages);
	choice_text_language->Select(0);
	sizer_bottom->Add(new wxStaticText(this, -1, "Text Language:"), 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
	sizer_bottom->Add(choice_text_language, 0, wxEXPAND);

	// Add 'Word Wrap' checkbox to top sizer
	sizer_top->AddStretchSpacer();
	cb_wordwrap = new wxCheckBox(this, -1, "Word Wrapping");
	sizer_top->Add(cb_wordwrap, 0, wxEXPAND, 0);

	// Add 'Jump To' button to top sizer
	btn_jump_to = new wxButton(this, -1, "Jump To");
	sizer_top->Add(btn_jump_to, 0, wxEXPAND|wxRIGHT, 4);

	// Add 'Find/Replace' button to top sizer
	btn_find_replace = new wxButton(this, -1, "Find + Replace");
	sizer_top->Add(btn_find_replace, 0, wxEXPAND, 0);

	// Bind events
	choice_text_language->Bind(wxEVT_COMMAND_CHOICE_SELECTED, &TextEntryPanel::onChoiceLanguageChanged, this);
	text_area->Bind(wxEVT_STC_CHANGE, &TextEntryPanel::onTextModified, this);
	btn_find_replace->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &TextEntryPanel::onBtnFindReplace, this);
	text_area->Bind(wxEVT_STC_UPDATEUI, &TextEntryPanel::onUpdateUI, this);
	cb_wordwrap->Bind(wxEVT_COMMAND_CHECKBOX_CLICKED, &TextEntryPanel::onWordWrapChanged, this);
	btn_jump_to->Bind(wxEVT_COMMAND_BUTTON_CLICKED, &TextEntryPanel::onBtnJumpTo, this);

	// Custom toolbar
	custom_toolbar_actions = "arch_scripts_compileacs;arch_scripts_compilehacs";

	Layout();
}
Exemplo n.º 6
0
/** Find an arbitrary number of delimited strings at the end of a file.  This
 * function provides the core of our last-lines-loader implementation.
 *
 * @param fd File descriptor to operate on.  This must be opened for reading.
 *
 * @param bytes Delimiter sequence.
 *
 * @param bytes_length Number of significant bytes in @p bytes.
 *
 * @param count Number of tail sequences to find.
 *
 * @param out Destination string array.
 */
static inline size_t
find_tail_sequences(int fd, const char* bytes, size_t bytes_length, size_t count, wxArrayString& out)
{
    size_t count_added ( 0 );

    /* We overlap the file reads a little to avoid splitting (and thus missing) the
       delimiter sequence.  */
    const size_t read_overlap ( bytes_length - 1 );
    const size_t read_size ( BUFSIZ );

    const off_t log_length ( lseek(fd, 0, SEEK_END) );
    bool have_last_pos ( false );
    char buf[read_size];
    off_t last_found_pos ( 0 );
    off_t last_read_position ( log_length + read_overlap );

    /* We read `read_size'-byte blocks of the file, starting at the end and working backwards. */
    while ( count_added < count && last_read_position > 0 ) {
        off_t read_position ( next_read_position(last_read_position, read_size, read_overlap) );
        size_t bytes_read ( pread(fd, buf, std::min(static_cast<off_t>(read_size), last_read_position - read_position), read_position) );

        /* In each block, we search for `bytes', starting at the end.  */
        for ( ssize_t i = bytes_read - read_overlap - 1; i >= 0; i-- ) {
            if ( !strncmp((buf + i), bytes, bytes_length) ) {
                off_t this_found_pos ( read_position + i );

                if ( have_last_pos && count_added < count ) {
                    size_t line_length ( last_found_pos - this_found_pos - bytes_length );

                    if ( line_length > 0 ) {
                        char* source ( NULL );

                        if ( last_found_pos >= read_position + (off_t) bytes_read ) {
                            source = new char[ line_length + 1];
                            memset(source, 0, line_length + 1);

                            if ( pread(fd, source, line_length, this_found_pos + bytes_length) < (ssize_t) line_length ) {
                                wxLogWarning(_T("ChatLog::find_tail_sequences: Read-byte count less than expected"));
                            }
                        } else {
                            source = buf + i + bytes_length;
                        }

                        if (  strncmp(source, "##", 2) != 0 ) {
                            out.Insert(wxString(L'\0', 0), 0);
                            wxLogMessage(_T("ChatLog::find_tail_sequences: fetching write buffer for %lu bytes"), sizeof(wxChar) * (line_length + 1));
#if !defined(HAVE_WX28) || defined(SL_QT_MODE)
                            wxStringBufferLength outzero_buf(out[0], sizeof(wxChar) * (line_length + 1));
                            wxConvUTF8.ToWChar(outzero_buf, line_length, source);
                            outzero_buf.SetLength(line_length);
#else
                            wxConvUTF8.MB2WC(out[0].GetWriteBuf(sizeof(wxChar) * (line_length + 1)), source, line_length);
                            out[0].UngetWriteBuf(line_length);
#endif

                            ++count_added;
                        }

                        if ( last_found_pos >= read_position + (off_t) bytes_read )
                            delete[] source;

                        if ( count_added >= count )
                            i = -1; /* short-circuit the `for' loop. */
                    }
                }
                last_found_pos = this_found_pos;
                have_last_pos = true;
                i -= bytes_length - 1;
            }
        }

        last_read_position = read_position;
    }

    return count_added;
}
Exemplo n.º 7
0
int WXDLLIMPEXP_BASE wxParseCommonDialogsFilter(const wxString& filterStr,
                                           wxArrayString& descriptions,
                                           wxArrayString& filters)
{
    descriptions.Clear();
    filters.Clear();

    wxString str(filterStr);

    wxString description, filter;
    int pos = 0;
    while( pos != wxNOT_FOUND )
    {
        pos = str.Find(wxT('|'));
        if ( pos == wxNOT_FOUND )
        {
            // if there are no '|'s at all in the string just take the entire
            // string as filter and make description empty for later autocompletion
            if ( filters.IsEmpty() )
            {
                descriptions.Add(wxEmptyString);
                filters.Add(filterStr);
            }
            else
            {
                wxFAIL_MSG( wxT("missing '|' in the wildcard string!") );
            }

            break;
        }

        description = str.Left(pos);
        str = str.Mid(pos + 1);
        pos = str.Find(wxT('|'));
        if ( pos == wxNOT_FOUND )
        {
            filter = str;
        }
        else
        {
            filter = str.Left(pos);
            str = str.Mid(pos + 1);
        }

        descriptions.Add(description);
        filters.Add(filter);
    }

#if defined(__WXMOTIF__)
    // split it so there is one wildcard per entry
    for( size_t i = 0 ; i < descriptions.GetCount() ; i++ )
    {
        pos = filters[i].Find(wxT(';'));
        if (pos != wxNOT_FOUND)
        {
            // first split only filters
            descriptions.Insert(descriptions[i],i+1);
            filters.Insert(filters[i].Mid(pos+1),i+1);
            filters[i]=filters[i].Left(pos);

            // autoreplace new filter in description with pattern:
            //     C/C++ Files(*.cpp;*.c;*.h)|*.cpp;*.c;*.h
            // cause split into:
            //     C/C++ Files(*.cpp)|*.cpp
            //     C/C++ Files(*.c;*.h)|*.c;*.h
            // and next iteration cause another split into:
            //     C/C++ Files(*.cpp)|*.cpp
            //     C/C++ Files(*.c)|*.c
            //     C/C++ Files(*.h)|*.h
            for ( size_t k=i;k<i+2;k++ )
            {
                pos = descriptions[k].Find(filters[k]);
                if (pos != wxNOT_FOUND)
                {
                    wxString before = descriptions[k].Left(pos);
                    wxString after = descriptions[k].Mid(pos+filters[k].Len());
                    pos = before.Find(wxT('('),true);
                    if (pos>before.Find(wxT(')'),true))
                    {
                        before = before.Left(pos+1);
                        before << filters[k];
                        pos = after.Find(wxT(')'));
                        int pos1 = after.Find(wxT('('));
                        if (pos != wxNOT_FOUND && (pos<pos1 || pos1==wxNOT_FOUND))
                        {
                            before << after.Mid(pos);
                            descriptions[k] = before;
                        }
                    }
                }
            }
        }
    }
#endif

    // autocompletion
    for( size_t j = 0 ; j < descriptions.GetCount() ; j++ )
    {
        if ( descriptions[j].empty() && !filters[j].empty() )
        {
            descriptions[j].Printf(_("Files (%s)"), filters[j].c_str());
        }
    }

    return filters.GetCount();
}
Exemplo n.º 8
0
/* TextEntryPanel::TextEntryPanel
 * TextEntryPanel class constructor
 *******************************************************************/
TextEntryPanel::TextEntryPanel(wxWindow* parent)
	: EntryPanel(parent, "text")
{
	// Create the text area
	text_area = new TextEditor(this, -1);
	sizer_main->Add(text_area, 1, wxEXPAND, 0);

	// Create the find+replace panel
	panel_fr = new FindReplacePanel(this, text_area);
	text_area->setFindReplacePanel(panel_fr);
	panel_fr->Hide();
	sizer_main->Add(panel_fr, 0, wxEXPAND|wxTOP, 8);
	sizer_main->AddSpacer(4);

	// Add 'Text Language' choice to toolbar
	SToolBarGroup* group_language = new SToolBarGroup(toolbar, "Text Language", true);
	languages = TextLanguage::getLanguageNames();
	languages.Sort();
	languages.Insert("None", 0, 1);
	choice_text_language = new wxChoice(group_language, -1, wxDefaultPosition, wxDefaultSize, languages);
	choice_text_language->Select(0);
	group_language->addCustomControl(choice_text_language);
	toolbar->addGroup(group_language);

	// Add 'Jump To' choice to toolbar
	SToolBarGroup* group_jump_to = new SToolBarGroup(toolbar, "Jump To", true);
	choice_jump_to = new wxChoice(group_jump_to, -1, wxDefaultPosition, wxSize(200, -1));
	group_jump_to->addCustomControl(choice_jump_to);
	toolbar->addGroup(group_jump_to);
	text_area->setJumpToControl(choice_jump_to);

	// Bind events
	choice_text_language->Bind(wxEVT_CHOICE, &TextEntryPanel::onChoiceLanguageChanged, this);
	text_area->Bind(wxEVT_STC_CHANGE, &TextEntryPanel::onTextModified, this);
	text_area->Bind(wxEVT_STC_UPDATEUI, &TextEntryPanel::onUpdateUI, this);

	// Custom toolbar
	custom_toolbar_actions = "arch_scripts_compileacs;arch_scripts_compilehacs";
	toolbar->addActionGroup("Scripts", wxSplit(custom_toolbar_actions, ';'));


	// --- Custom menu ---
	menu_custom = new wxMenu();
	theApp->getAction("ptxt_find_replace")->addToMenu(menu_custom);
	theApp->getAction("ptxt_jump_to_line")->addToMenu(menu_custom);

	// 'Code Folding' submenu
	wxMenu* menu_fold = new wxMenu();
	menu_custom->AppendSubMenu(menu_fold, "Code Folding");
	theApp->getAction("ptxt_fold_foldall")->addToMenu(menu_fold);
	theApp->getAction("ptxt_fold_unfoldall")->addToMenu(menu_fold);

	// 'Compile' submenu
	wxMenu* menu_scripts = new wxMenu();
	menu_custom->AppendSubMenu(menu_scripts, "Compile");
	theApp->getAction("arch_scripts_compileacs")->addToMenu(menu_scripts);
	theApp->getAction("arch_scripts_compilehacs")->addToMenu(menu_scripts);

	menu_custom->AppendSeparator();

	theApp->getAction("ptxt_wrap")->addToMenu(menu_custom);
	custom_menu_name = "Text";


	Layout();
}
Exemplo n.º 9
0
/** Find an arbitrary number of delimited strings at the end of a file.  This
 * function provides the core of our last-lines-loader implementation.
 *
 * @param fd File descriptor to operate on.  This must be opened for reading.
 *
 * @param bytes Delimiter sequence.
 *
 * @param bytes_length Number of significant bytes in @p bytes.
 *
 * @param count Number of tail sequences to find.
 *
 * @param out Destination string array.
 */
static size_t find_tail_sequences(wxFile& fd, const char* bytes, size_t bytes_length, size_t count, wxArrayString& out)
{
	size_t count_added(0);

	/* We overlap the file reads a little to avoid splitting (and thus missing) the
	   delimiter sequence.  */
	const size_t read_overlap = bytes_length - 1;
	const size_t read_size = BUFSIZ;

	const off_t log_length = fd.SeekEnd();
	bool have_last_pos = false;
	char buf[read_size];
	off_t last_found_pos = 0;
	off_t last_read_position = log_length + read_overlap;

	/* We read `read_size'-byte blocks of the file, starting at the end and working backwards. */
	while (count_added < count && last_read_position > 0) {
		const off_t read_position = next_read_position(last_read_position, read_size, read_overlap);
		const size_t bytes_read = readblock(fd, buf, std::min(static_cast<off_t>(read_size), last_read_position - read_position), read_position);

		/* In each block, we search for `bytes', starting at the end.  */
		for (ssize_t i = bytes_read - read_overlap - 1; i >= 0; i--) {
			if (strncmp((buf + i), bytes, bytes_length) == 0) {
				const off_t this_found_pos = read_position + i;

				if (have_last_pos) {
					const size_t line_length = last_found_pos - this_found_pos - bytes_length;

					if (line_length > 0) {
						char* source = NULL;

						if (last_found_pos >= read_position + (off_t)bytes_read) {
							source = new char[line_length + 1];
							memset(source, 0, line_length + 1);

							if (readblock(fd, source, line_length, this_found_pos + bytes_length) < (ssize_t)line_length) {
								wxLogWarning(_T("ChatLog::find_tail_sequences: Read-byte count less than expected"));
							}
						} else {
							source = buf + i + bytes_length;
						}
						source[line_length] = 0;
						wxString tmp = wxString::FromUTF8(source);
						out.Insert(tmp, 0);
						if (last_found_pos >= read_position + (off_t)bytes_read)
							delete[] source;

						count_added++;
						if (count_added >= count)
							break;
					}
				}
				last_found_pos = this_found_pos;
				have_last_pos = true;
				i -= bytes_length - 1;
			}
		}

		last_read_position = read_position;
	}

	return count_added;
}