Beispiel #1
0
    public void on_search_button_find_activate(object o, EventArgs ea)
    {
        Gtk.TextView   tv       = (Gtk.TextView)gxml["search_simple_keywords_view"];
        Gtk.TextBuffer tb       = tv.Buffer;
        string         kwstring = tb.GetText(tb.StartIter, tb.EndIter, false).Trim();

//        Console.WriteLine("kwstring: " + kwstring);

        if (kwstring == "")
        {
            return;
        }

        string[] kws = kwstring.Split(',', '\n', '\r');

        if (kws.Length <= 0)
        {
            return;
        }

        for (int i = 0; i < kws.Length; i++)
        {
            kws[i] = kws[i].Trim();
            Console.WriteLine("kw " + i + ": " + kws[i]);
        }
        IIconListAdapter search_adapter = new SimpleSearchIconListAdapter
                                              (repo, kws);

        icon_list.Adapter = search_adapter;
    }
Beispiel #2
0
        public static string GetSelectedText(this Gtk.TextBuffer buffer, out TextIter start, out TextIter end)
        {
            string retval = string.Empty;

            if (buffer.GetSelectionBounds(out start, out end))
            {
                retval = buffer.GetText(start, end, true);
            }
            return(retval);
        }
        // Execute first SQL statement at cursor
        public string GetSqlStatementAtCursor(TextBuffer sqlTextBuffer, out TextIter iter)
        {
            TextIter start_iter, end_iter, insert_iter;
            TextIter match_start1, match_end1, match_start2, match_end2;
            TextIter begin_iter, finish_iter;
            string text = String.Empty;
            int char_count = 0;
            TextMark insert_mark;

            insert_mark = sqlTextBuffer.InsertMark;
            insert_iter = sqlTextBuffer.GetIterAtMark (insert_mark);
            start_iter = sqlTextBuffer.GetIterAtOffset (0);

            char_count = sqlTextBuffer.CharCount;
            end_iter = sqlTextBuffer.GetIterAtOffset (char_count);
            iter = end_iter;

            match_start1 = sqlTextBuffer.GetIterAtOffset (0);
            match_end1 = sqlTextBuffer.GetIterAtOffset (char_count);
            match_start2 = sqlTextBuffer.GetIterAtOffset (0);
            match_end2 = sqlTextBuffer.GetIterAtOffset (char_count);

            begin_iter = sqlTextBuffer.GetIterAtOffset (0);
            finish_iter = sqlTextBuffer.GetIterAtOffset (char_count);

            if (start_iter.IsEnd == false)
            {
                if (insert_iter.BackwardSearch (";", TextSearchFlags.TextOnly,
                        out match_start1, out match_end1, start_iter) == true) {
                    begin_iter = match_start1;
                    begin_iter.ForwardChars (1);
                }

                if (insert_iter.ForwardSearch (";",	TextSearchFlags.TextOnly,
                        out match_start2, out match_end2, end_iter) == true) {
                    finish_iter = match_end2;
                    finish_iter.BackwardChars (1);
                }
                iter = finish_iter;
                text = sqlTextBuffer.GetText (begin_iter, finish_iter, false);

                // FIXME: for this to work.  GetSqlStatement has to rewritten to be line-based
                if (text.Length > 0) {
                    // search does not work if what you are searching for is
                    // at the end of the buffer,
                    // this compensates for this
                    int j = text.Length;
                    int cont = 1;
                    for(int i = text.Length - 1; cont == 1 && i >= 0; i--) {
                        char ch = text[i];
                        switch(ch) {
                        case ' ':
                        case ';':
                            j--;
                            break;
                        default:
                            cont = 0;
                            break;
                        }
                    }

                    if (j != text.Length) {
                        string t = text.Substring(0, j);
                        text = t;
                    }
                }
            }

            return text;
        }
        // get next SQL statement.  Requires GetSqlStatementAtCursor having been called first
        public string GetNextSqlStatement(TextBuffer sqlTextBuffer, ref TextIter iter)
        {
            TextIter start_iter, end_iter;
            TextIter match_start2, match_end2;
            TextIter finish_iter;
            string text = String.Empty;
            int char_count = 0;

            char_count = sqlTextBuffer.CharCount;
            end_iter = sqlTextBuffer.GetIterAtOffset (char_count);
            if (iter.IsEnd == false) {
                iter.ForwardChars (1);
                if (sqlTextBuffer.GetText (iter, end_iter, false).Equals (";"))
                    iter.ForwardChars (1);
            }

            if (iter.IsEnd == true)
                return "";

            start_iter = iter;
            match_start2 = iter;
            match_end2 = sqlTextBuffer.GetIterAtOffset (char_count);
            finish_iter = sqlTextBuffer.GetIterAtOffset (char_count);

            if (start_iter.IsEnd == false) {
                if (iter.ForwardSearch (";", TextSearchFlags.TextOnly,
                        out match_start2, out match_end2, end_iter) == true) 	{
                    finish_iter = match_end2;
                    finish_iter.BackwardChars (1);
                }

                text = sqlTextBuffer.GetText (iter, finish_iter, false);
                iter = finish_iter;

                if(text.Length > 0) {
                    // search does not work if what you are searching for is
                    // at the end of the buffer,
                    // this compensates for this
                    int j = text.Length;
                    int cont = 1;
                    for(int i = text.Length - 1; cont == 1 && i >= 0; i--) {
                        char ch = text[i];
                        switch(ch) {
                        case ' ':
                        case ';':
                            j--;
                            break;
                        default:
                            cont = 0;
                            break;
                        }
                    }

                    if(j != text.Length) {
                        string t = text.Substring(0, j);
                        text = t;
                    }
                }
            }

            return text;
        }