AvailableColumnsPanel.c 2.2 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

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

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

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

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

}*/

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

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

   switch(ch) {
      case 13:
      case KEY_ENTER:
      case KEY_F(5):
      {
49
         int at = Panel_getSelectedIndex(this->columns);
50
         Panel_insert(this->columns, at, (Object*) ListItem_new(text, 0));
51
         Panel_setSelected(this->columns, at+1);
52
         ColumnsPanel_update(this->columns);
Hisham Muhammad's avatar
Hisham Muhammad committed
53
54
55
         result = HANDLED;
         break;
      }
56
57
      default:
      {
Hisham Muhammad's avatar
Hisham Muhammad committed
58
59
         if (isalpha(ch))
            result = Panel_selectByTyping(super, ch);
60
61
         break;
      }
Hisham Muhammad's avatar
Hisham Muhammad committed
62
63
64
   }
   return result;
}
65

66
67
68
69
70
71
72
73
PanelClass AvailableColumnsPanel_class = {
   .super = {
      .extends = Class(Panel),
      .delete = AvailableColumnsPanel_delete
   },
   .eventHandler = AvailableColumnsPanel_eventHandler
};

74
AvailableColumnsPanel* AvailableColumnsPanel_new(Settings* settings, Panel* columns, ScreenManager* scr) {
75
   AvailableColumnsPanel* this = AllocThis(AvailableColumnsPanel);
76
   Panel* super = (Panel*) this;
77
   Panel_init(super, 1, 1, 1, 1, Class(ListItem), true);
78
79
80
81
82
83
84
85
86
87
88
89
90
   
   this->settings = settings;
   this->scr = scr;

   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;
}