File: curves.h

package info (click to toggle)
curves 0.8.7
  • links: PTS
  • area: main
  • in suites: slink
  • size: 704 kB
  • ctags: 1,001
  • sloc: cpp: 6,197; ansic: 519; makefile: 270; sh: 192; fortran: 149
file content (230 lines) | stat: -rw-r--r-- 7,736 bytes parent folder | download | duplicates (2)
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/* curves.h							-*- C++ -*-
     $Id: curves.h,v 1.34 1998/09/06 21:46:22 elf Exp $

   written by Marc Singer
   20 September 1996

   This file is part of the project CurVeS.  See the file README for
   more information.

   Copyright (C) 1996 Marc Singer

   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
   in a file called COPYING along with this program; if not, write to
   the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
   02139, USA.

   -----------
   DESCRIPTION
   -----------

   Header for CurVeS containment class.  This class contains the state
   of the user's session.


   --------------------
   IMPLEMENTATION NOTES
   --------------------
   
   -- eClass

   The class has two purposes.  It is first an index into a
   color/attribute table such that the unique areas of the screen can
   have identifying color schemes.  It is second a rank for file types
   so that they sort in descending order of interest.

*/

#if !defined (_CURVES_H_)
#    define   _CURVES_H_

// #include "window.h"
#include "directory.h"
#include "cvs.h"
#include "blue6.h"


typedef enum {
  classNul			= 0,  // Unusable due to Curses (attrib. index)
  classEdited			= 1,  // User edited files
  classNewAdd			= 2,  // User added files
  classAdded			= 3,  // Added, but not committed
  classRemoved			= 4,  // Removed, but not committed
  classMerge			= 5,  // User edited with logfile update
  classPatch			= 6,  // Logfile update
  classCheckout			= 7,  // New logfile
  classConflict			= 8,  // Local edits conflict with repository
  classLost			= 9,  // User clobbered file
  classUpToDate			= 10,  // Controlled, but uninteresting
  classUncontrolled		= 11,  // Uncontrolled and really uninteresting
  classNormal			= 11,  //   <alias>
  classDir			= 12, // Attribute for directories

  classStatus			= 13, // Status bar
  classMenu			= 14, // Menu bar
  classCursor			= 15, // Tag and cursor
  classEnd			= 16, // One more than last entry
} eClass;


class LCurves {
protected:
  Termcap m_termcap;
  Window* m_pWindow;		// Main window

  Pane* m_pPaneMenu;		// Window for menu bar, maybe
  Pane* m_pPaneDir;		// Directory listing
  Pane* m_pPaneFile;		// File listing
  Pane* m_pPaneStatus;		// Status
  Pane* m_pPaneCommand;		// Command/menu

  Attribute  m_rgattrClass[classEnd];
  char m_rgClassMark[classEnd];

  unsigned m_fDirtyRoot		: 1;    // Root window dirty
  unsigned m_fDirtyMenu		: 1;	// Menu window dirty
  unsigned m_fDirtyDir		: 1;	// Directory window dirty
  unsigned m_fDirtyFile		: 1;	// File window dirty
  unsigned m_fDirtyStatus	: 1;	// Status window dirty
  unsigned m_fDirtyCommand	: 1;	// Command window dirty

  int m_dxDirectories;		// Width of directory pane

  LDirectory m_dir;		// Working directory
  LCVS m_cvs;			// CVS flags
  int m_cFiles;			// Number of files
  int m_cDirectories;		// Number of directories
  int m_cchFilenameMax;		// Width of longest filename
  int m_cchFileColumn;		// Width of each file display column
  int m_iDirScroll;		// Directory scroll position
  int m_iDirCursor;		// Directory cursor, current dir in list
  int m_iFileScroll;		// File scroll position
  int m_iFileCursor;		// File cursor, current dir in list
//  char m_szSortCriteria[4];	// Sort criteria as characters: acnolst

  int m_color_scheme;		// Color scheme, 0 for linux console

  int m_iPane;			// Current pane number (0 dir, 1 file)

  char** m_rgszMenu;		// Array of menu pointers
  int m_cMenuMax;		// Number of menu entries
  int m_iMenu;			// Index of current menu

  int m_cFilesTagged;		// Count of tagged files

  int _idx_file (int iFile) {
    return iFile + m_cDirectories; }
  int _idx_dir (int iDir) {
    return iDir; }
  FILE_INFO* _info_dir (int iDir) {
    return m_dir.file_info (_idx_dir (iDir)); }
  FILE_INFO* _info_file (int iFile) {
    return m_dir.file_info (_idx_file (iFile)); }

  static bool _explore (const char*, void*);
  const char* _dir (int iDir) {
				// Assertion lifted by looking through
				// the code.  It can happen when the
				// user is in an unreadable directory.
				// Note that the underlying call will
				// correctly return NULL when there is
				// no such directory.
    //    assert_ (iDir >= 0 && iDir < m_cDirectories);
    return m_dir.file (_idx_dir (iDir)); }
  const char* _file (int iFile) {
    assert_ (iFile >= 0 && iFile < m_cFiles);
    return m_dir.file (_idx_file (iFile)); }

  int _columns_of_files (void) {
    return m_pPaneFile->dx ()/m_cchFileColumn; }

  static int _classify (FILE_INFO* pInfo);
  static int _rank (char method, FILE_INFO* pInfo0, FILE_INFO* pInfo1);
  static int _sort_compare (const void* pv0, const void* pv1);

public:
  LCurves () {
    zero (); init (); }
  ~LCurves () {
    release_this (); }
  void zero (void) {
    memset (this, 0, sizeof (*this)); }
  void init (void);
  void init_colors (void);
  void init_menus (char** rgsz, int cMenuMax) {
    m_rgszMenu = rgsz, m_cMenuMax = cMenuMax; }
  void release_screen ();
  void release_this ();

  bool is_files (void) {
    return m_dir.count_files () != 0; }
  Pane* win_command (void) {
    return m_pPaneCommand; }
  Pane* win_menu (void) {
    return m_pPaneMenu; }

  void dirty_path (void) {
     m_fDirtyFile = m_fDirtyDir = m_fDirtyStatus = true; 
     m_iFileScroll = m_iFileCursor = 0; }

  int count_tagged_files (void) {
    return m_cFilesTagged; }
  void cursorpos_dir (int& x, int& y) {
    x = 0; y = m_iDirCursor - m_iDirScroll; }
  void cursorpos_file (int& x, int& y) { 
    x = (m_iFileCursor - m_iFileScroll)/m_pPaneFile->dy ()*m_cchFileColumn;
    y = (m_iFileCursor - m_iFileScroll)%m_pPaneFile->dy (); }
  void explore (void);		// Explore current path
  const char* file (void) {
    return m_cFiles ? _file (m_iFileCursor) : (const char*) NULL; }
  int getch (void);
//  const char* get_sort (void) {
//    return m_szSortCriteria; }
  char* name_tagged_files (bool fFilenameOnly = false) {
    return name_files (fFilenameOnly, flagTag, flagTag); }
  char* name_files (bool fFilenameOnly = false, 
		    int flagMask = 0, int flagSet = 0);
  int menu (void) {
    return m_iMenu; }
  int pane (void) {
    return m_iPane; }
  const char* path (void) {
    return m_dir.path (); }
  const char* path_abbreviate (int cch) {
    return m_dir.abbreviate (cch); }
  void refresh (bool f = false); // Redraw all dirty panes
  void render_dir (int iDir);
  void restore (bool fPrompt);
  void select_pane (int iPane);
  void save (void);
  void set_menu (int iMenu);
  void set_path (const char* szPath);  
  //  void set_sort (const char* szCriteria) {
  //    if (strlen (szCriteria) < sizeof (m_szSortCriteria) && *szCriteria)
  //      strcpy (m_szSortCriteria, szCriteria); }
  void sort (void);
  void tag (int iClass, bool fExclusive);
  void show_cursor (bool fShow); // Show/hide cursor mark
  void update (void) {		// Make changes to the user's screen
    m_pWindow->flush (); }

  void do_directory_move (int direction);
  void do_directory_change (void);
  void do_file_binarytoggle (void);
  void do_file_move (int direction);
  void do_file_tag (void);
  void do_search (const char* sz, bool fReverse);
  void do_update (const char* szFiles);
};

#endif /* _CURVES_H_ */