1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/* rgfindwindow.cc
*
* Copyright (c) 2003 Michael Vogt
*
* Author: Michael Vogt <mvo@debian.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*/
#include "config.h"
#include <cassert>
#include <cstring>
#include "rgfindwindow.h"
#include "rgutils.h"
#include "i18n.h"
gchar* RGFindWindow::getFindString()
{
return gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(_comboFind));
}
void RGFindWindow::selectText()
{
/* no need to do something hugely special here, on focus the last text is
* selected automatically
*/
gtk_widget_grab_focus(_comboFind);
}
int RGFindWindow::getSearchType()
{
int searchType;
searchType = gtk_combo_box_get_active(GTK_COMBO_BOX(_comboSearchType));
return searchType;
}
void RGFindWindow::doFind(GtkWindow *widget, void *data)
{
//cout << "RGFindWindow::doFind()"<<endl;
RGFindWindow *me = (RGFindWindow *) data;
GtkListStore *prevSearchStore = GTK_LIST_STORE( gtk_combo_box_get_model(
GTK_COMBO_BOX(me->_comboFind)));
GtkTreeIter searchIter;
const gchar *str = me->getFindString();
if(strlen(str) == 0)
return;
me->_prevSearches = g_list_prepend(me->_prevSearches, g_strdup(str));
gtk_list_store_prepend(prevSearchStore, &searchIter);
gtk_list_store_set(prevSearchStore, &searchIter, 0, str, -1);
doClose(widget, data);
gtk_dialog_response(GTK_DIALOG(((RGFindWindow *) data)->window()),
GTK_RESPONSE_OK);
}
void RGFindWindow::doClose(GtkWindow *widget, void *data)
{
//cout << "void RGFindWindow::doClose()" << endl;
RGFindWindow *me = (RGFindWindow *) data;
_config->Set("Synaptic::LastSearchType",
gtk_combo_box_get_active(GTK_COMBO_BOX(me->_comboSearchType)));
me->hide();
}
void RGFindWindow::cbEntryChanged(GtkWindow *widget, void *data)
{
RGFindWindow *me = (RGFindWindow *) data;
if ( strlen(me->getFindString()) > 0 )
gtk_widget_set_sensitive(me->_findB, TRUE);
else
gtk_widget_set_sensitive(me->_findB, FALSE);
}
RGFindWindow::RGFindWindow(RGWindow *win)
: RGGtkBuilderWindow(win, "find"), _prevSearches(0)
{
GtkListStore *comboStore;
GtkTreeIter comboIter;
GtkCellRenderer *crt;
//cout << " RGFindWindow::RGFindWindow(RGWindow *win) "<< endl;
g_signal_connect(gtk_builder_get_object(_builder,
"button_close"),
"clicked",
G_CALLBACK(doClose), this);
_comboFind = GTK_WIDGET(gtk_builder_get_object(_builder, "comboentry_search"));
assert(_comboFind);
g_signal_connect(G_OBJECT(_comboFind), "changed",
G_CALLBACK(cbEntryChanged), this);
crt = gtk_cell_renderer_text_new();
gtk_cell_layout_clear(GTK_CELL_LAYOUT(_comboFind));
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(_comboFind), crt, TRUE);
gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(_comboFind),
crt, "text", 0);
_comboSearchType = GTK_WIDGET(gtk_builder_get_object(_builder, "combo_lookin"));
assert(_comboSearchType);
comboStore = GTK_LIST_STORE(
gtk_combo_box_get_model(
GTK_COMBO_BOX(_comboSearchType)));
for (int i = 0; SearchTypes[i] != NULL; i++) {
gtk_list_store_append(comboStore, &comboIter);
gtk_list_store_set(comboStore, &comboIter, 0, _(SearchTypes[i]), -1);
}
crt = gtk_cell_renderer_text_new();
gtk_cell_layout_clear(GTK_CELL_LAYOUT(_comboSearchType));
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(_comboSearchType), crt, TRUE);
gtk_cell_layout_add_attribute(GTK_CELL_LAYOUT(_comboSearchType),
crt, "text", 0);
gtk_combo_box_set_active(GTK_COMBO_BOX(_comboSearchType),
_config->FindI("Synaptic::LastSearchType",1));
_findB = GTK_WIDGET(gtk_builder_get_object(_builder, "button_find"));
assert(_findB);
g_signal_connect(G_OBJECT(_findB),
"clicked",
G_CALLBACK(doFind), this);
gtk_widget_set_sensitive(_findB, FALSE);
setTitle(_("Find"));
skipTaskbar(true);
}
|