AvailableColumnsPanel.c 2.17 KB
Newer Older
Hisham Muhammad's avatar
Hisham Muhammad committed
1
2
3
4
5
6
/*
htop - AvailableColumnsPanel.c
(C) 2004-2011 Hisham H. Muhammad
Released under the GNU GPL, see the COPYING file
in the source distribution for its full text.
*/
Hisham Muhammad's avatar
Hisham Muhammad committed
7

8
#include "AvailableColumnsPanel.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
9

Hisham Muhammad's avatar
Hisham Muhammad committed
10
#include "Header.h"
11
#include "ColumnsPanel.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
12
#include "debug.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
13

Hisham Muhammad's avatar
Hisham Muhammad committed
14
#include <assert.h>
Hisham Muhammad's avatar
Hisham Muhammad committed
15
16
#include <stdlib.h>
#include <ctype.h>
Hisham Muhammad's avatar
Hisham Muhammad committed
17
18

/*{
Hisham Muhammad's avatar
Hisham Muhammad committed
19
20
21
#include "Panel.h"
#include "Settings.h"
#include "ScreenManager.h"
Hisham Muhammad's avatar
Hisham Muhammad committed
22

23
24
25
typedef struct AvailableColumnsPanel_ {
   Panel super;
   Panel* columns;
Hisham Muhammad's avatar
Hisham Muhammad committed
26
27
28

   Settings* settings;
   ScreenManager* scr;
29
} AvailableColumnsPanel;
Hisham Muhammad's avatar
Hisham Muhammad committed
30
31
32

}*/

33
static void AvailableColumnsPanel_delete(Object* object) {
34
35
36
   Panel* super = (Panel*) object;
   AvailableColumnsPanel* this = (AvailableColumnsPanel*) object;
   Panel_done(super);
Hisham Muhammad's avatar
Hisham Muhammad committed
37
38
39
   free(this);
}

40
static HandlerResult AvailableColumnsPanel_eventHandler(Panel* super, int ch) {
41
42
   AvailableColumnsPanel* this = (AvailableColumnsPanel*) super;
   char* text = ((ListItem*) Panel_getSelected(super))->value;
Hisham Muhammad's avatar
Hisham Muhammad committed
43
44
45
46
47
48
49
   HandlerResult result = IGNORED;

   switch(ch) {
      case 13:
      case KEY_ENTER:
      case KEY_F(5):
      {
50
         int at = Panel_getSelectedIndex(this->columns);
51
         Panel_insert(this->columns, at, (Object*) ListItem_new(text, 0));
52
         Panel_setSelected(this->columns, at+1);
53
         ColumnsPanel_update(this->columns);
Hisham Muhammad's avatar
Hisham Muhammad committed
54
55
56
         result = HANDLED;
         break;
      }
57
58
      default:
      {
Hisham Muhammad's avatar
Hisham Muhammad committed
59
60
         if (isalpha(ch))
            result = Panel_selectByTyping(super, ch);
61
62
         break;
      }
Hisham Muhammad's avatar
Hisham Muhammad committed
63
64
65
   }
   return result;
}
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

AvailableColumnsPanel* AvailableColumnsPanel_new(Settings* settings, Panel* columns, ScreenManager* scr) {
   AvailableColumnsPanel* this = (AvailableColumnsPanel*) malloc(sizeof(AvailableColumnsPanel));
   Panel* super = (Panel*) this;
   Panel_init(super, 1, 1, 1, 1, LISTITEM_CLASS, true);
   ((Object*)this)->delete = AvailableColumnsPanel_delete;
   
   this->settings = settings;
   this->scr = scr;
   super->eventHandler = AvailableColumnsPanel_eventHandler;

   Panel_setHeader(super, "Available Columns");

   for (int i = 1; i < LAST_PROCESSFIELD; i++) {
      if (i != COMM)
         Panel_add(super, (Object*) ListItem_new(Process_fieldNames[i], 0));
   }
   this->columns = columns;
   return this;
}