Commit 399d27ce authored by Christoffer Ackelman's avatar Christoffer Ackelman

Changed the behaviour of CoWowRecall to match the Linux terminal.

parent 944da4c0
......@@ -1099,55 +1099,35 @@ CoWowEntryGtk::~CoWowEntryGtk()
gboolean CoWowEntryGtk::event_cb(GtkWidget* w, GdkEvent* event, gpointer data)
{
CoWowEntryGtk* en = (CoWowEntryGtk*)data;
int i;
gboolean sts;
gboolean sts = FALSE;
guint keysym = event->key.keyval;
gchar* text = gtk_editable_get_chars(GTK_EDITABLE(w), 0, -1);
switch (keysym) {
switch (event->key.keyval) {
case GDK_Return:
case GDK_KP_Enter:
case GDK_Linefeed: {
// Insert in recall buffer
if (strcmp(text, "") != 0) {
for (i = en->m_re->m_recall_size - 2; i >= 0; i--)
strcpy(en->m_re->m_recall[i + 1], en->m_re->m_recall[i]);
strncpy(en->m_re->m_recall[0], text, en->m_re->m_line_size);
en->m_re->m_recall[0][en->m_re->m_line_size - 1] = 0;
}
en->m_re->m_current_recall_line = 0;
sts = FALSE;
en->m_re->push(text);
break;
}
case GDK_Up: {
en->m_re->m_current_recall_line++;
if (en->m_re->m_current_recall_line > en->m_re->m_recall_size - 1)
en->m_re->m_current_recall_line = en->m_re->m_recall_size - 1;
gint pos = 0;
gtk_editable_delete_text(GTK_EDITABLE(w), 0, -1);
gtk_editable_insert_text(GTK_EDITABLE(w),
en->m_re->m_recall[en->m_re->m_current_recall_line - 1],
strlen(en->m_re->m_recall[en->m_re->m_current_recall_line - 1]), &pos);
gtk_editable_set_position(GTK_EDITABLE(w), -1);
const char *prev = en->m_re->popUp(text);
if (strcmp(prev, "") != 0) {
gint pos = 0;
gtk_editable_delete_text(GTK_EDITABLE(w), 0, -1);
gtk_editable_insert_text(GTK_EDITABLE(w), prev, strlen(prev), &pos);
gtk_editable_set_position(GTK_EDITABLE(w), -1);
}
sts = TRUE;
break;
}
case GDK_Down: {
if (en->m_re->m_current_recall_line == 0)
gtk_editable_delete_text(GTK_EDITABLE(w), 0, -1);
else if (en->m_re->m_current_recall_line == 1) {
gtk_editable_delete_text(GTK_EDITABLE(w), 0, -1);
en->m_re->m_current_recall_line--;
} else {
en->m_re->m_current_recall_line--;
const char *next = en->m_re->popDown(text);
if (strcmp(next, "") != 0) {
gint pos = 0;
gtk_editable_delete_text(GTK_EDITABLE(w), 0, -1);
gtk_editable_insert_text(GTK_EDITABLE(w),
en->m_re->m_recall[en->m_re->m_current_recall_line - 1],
strlen(en->m_re->m_recall[en->m_re->m_current_recall_line - 1]),
&pos);
gtk_editable_insert_text(GTK_EDITABLE(w), next, strlen(next), &pos);
gtk_editable_set_position(GTK_EDITABLE(w), -1);
}
sts = TRUE;
......@@ -1156,10 +1136,10 @@ gboolean CoWowEntryGtk::event_cb(GtkWidget* w, GdkEvent* event, gpointer data)
case GDK_Escape:
if (en->m_hide_on_esc)
gtk_widget_hide(w);
sts = FALSE;
en->m_re->resetTmp();
break;
default:
sts = FALSE;
break;
}
g_free(text);
return sts;
......
......@@ -659,56 +659,39 @@ CoWowEntryQt::CoWowEntryQt(CoWowRecall* re) : m_re(re), m_hide_on_esc(false)
void CoWowEntryQt::keyPressEvent(QKeyEvent* event)
{
int keysym = event->key();
QString txt = text();
switch (keysym) {
switch (event->key()) {
case Qt::Key_Return:
case Qt::Key_Enter: {
// Insert in recall buffer
if (txt.compare("") != 0) {
for (int i = m_re->m_recall_size - 2; i >= 0; i--) {
strcpy(m_re->m_recall[i + 1], m_re->m_recall[i]);
}
strncpy(m_re->m_recall[0], qPrintable(txt), m_re->m_line_size);
m_re->m_recall[0][m_re->m_line_size - 1] = 0;
}
m_re->m_current_recall_line = 0;
m_re->push(qPrintable(text()));
break;
}
case Qt::Key_Up: {
m_re->m_current_recall_line++;
if (m_re->m_current_recall_line > m_re->m_recall_size - 1) {
m_re->m_current_recall_line = m_re->m_recall_size - 1;
const char *prev = m_re->popUp(qPrintable(text()));
if (strcmp(prev, "") != 0) {
setText(fl(prev));
}
setText(QString::fromLocal8Bit(
m_re->m_recall[m_re->m_current_recall_line - 1]));
end(false);
break;
}
case Qt::Key_Down: {
if (m_re->m_current_recall_line == 0) {
setText("");
} else if (m_re->m_current_recall_line == 1) {
setText("");
m_re->m_current_recall_line--;
} else {
m_re->m_current_recall_line--;
setText(m_re->m_recall[m_re->m_current_recall_line - 1]);
end(false);
const char *next = m_re->popDown(qPrintable(text()));
if (strcmp(next, "") != 0) {
setText(fl(next));
}
end(false);
break;
}
case Qt::Key_Escape:
if (m_hide_on_esc) {
hide();
}
m_re->resetTmp();
break;
default:
QLineEdit::keyPressEvent(event);
break;
}
QLineEdit::keyPressEvent(event);
}
void CoWowEntryQt::hideEvent(QHideEvent* event)
......
......@@ -62,11 +62,55 @@ void CoWowTimer::remove()
{
}
CoWowRecall::CoWowRecall() : m_current_recall_line(0)
CoWowRecall::CoWowRecall() : m_current_recall_line(0), m_current_size(0)
{
memset(m_recall, 0, sizeof(m_recall));
}
void CoWowRecall::push(const char* src)
{
if (strcmp(src, "") != 0 && strcmp(src, m_recall[0]) != 0) {
for (int i = m_recall_size - 2; i >= 0; i--) {
strcpy(m_recall[i + 1], m_recall[i]);
}
strncpy(m_recall[0], src, m_line_size);
m_recall[0][m_line_size - 1] = 0;
m_current_size++;
if (m_current_size > m_recall_size) {
m_current_size = m_recall_size;
}
}
resetTmp();
}
void CoWowRecall::resetTmp()
{
for (int i = 0; i < m_current_size; i++) {
strcpy(tmp[i], m_recall[i]);
}
m_current_recall_line = 0;
}
const char* CoWowRecall::popUp(const char* src)
{
strncpy(tmp[m_current_recall_line], src, m_line_size);
m_current_recall_line++;
if (m_current_recall_line > m_current_size - 1) {
m_current_recall_line = m_current_size - 1;
}
return tmp[m_current_recall_line];
}
const char* CoWowRecall::popDown(const char* src)
{
strncpy(tmp[m_current_recall_line], src, m_line_size);
if (m_current_recall_line <= 0) {
return tmp[m_current_recall_line];
}
m_current_recall_line--;
return tmp[m_current_recall_line];
}
CoWow::CoWow()
{
}
......
......@@ -92,6 +92,13 @@ public:
static const int m_line_size = 160;
char m_recall[m_recall_size][m_line_size];
int m_current_recall_line;
int m_current_size;
char tmp[m_recall_size][m_line_size];
void push(const char* src);
void resetTmp();
const char* popUp(const char* src);
const char* popDown(const char* src);
CoWowRecall();
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment