~ubuntu-branches/ubuntu/jaunty/cmake/jaunty-security

« back to all changes in this revision

Viewing changes to Source/CursesDialog/cmCursesPathWidget.cxx

  • Committer: Bazaar Package Importer
  • Author(s): A. Maitland Bottoms
  • Date: 2005-03-02 09:22:44 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050302092244-y6o9j8wr27vqcqvx
Tags: 2.0.5-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=========================================================================
 
2
 
 
3
  Program:   CMake - Cross-Platform Makefile Generator
 
4
  Module:    $RCSfile: cmCursesPathWidget.cxx,v $
 
5
  Language:  C++
 
6
  Date:      $Date: 2003/12/15 22:26:00 $
 
7
  Version:   $Revision: 1.9 $
 
8
 
 
9
  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
 
10
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
 
11
 
 
12
     This software is distributed WITHOUT ANY WARRANTY; without even 
 
13
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
 
14
     PURPOSE.  See the above copyright notices for more information.
 
15
 
 
16
=========================================================================*/
1
17
#include "cmCursesPathWidget.h"
2
18
 
 
19
#include "cmCursesMainForm.h"
 
20
#include "cmSystemTools.h"
 
21
 
3
22
cmCursesPathWidget::cmCursesPathWidget(int width, int height, 
4
 
                                           int left, int top) :
 
23
                                           int left, int top) :
5
24
  cmCursesStringWidget(width, height, left, top)
6
25
{
7
26
  m_Type = cmCacheManager::PATH;
8
 
}
9
 
 
 
27
  m_Cycle = false;
 
28
  m_CurrentIndex = 0;
 
29
}
 
30
 
 
31
void cmCursesPathWidget::OnType(int& key, cmCursesMainForm* fm, WINDOW* w)
 
32
{
 
33
  m_Cycle = false;
 
34
  m_CurrentIndex = 0;
 
35
  m_LastGlob = "";
 
36
  this->cmCursesStringWidget::OnType(key, fm, w);
 
37
}
 
38
 
 
39
void cmCursesPathWidget::OnTab(cmCursesMainForm* fm, WINDOW* w)
 
40
{
 
41
  if ( !this->GetString() )
 
42
    {
 
43
    return;
 
44
    }
 
45
  FORM* form = fm->GetForm();
 
46
  form_driver(form, REQ_NEXT_FIELD);
 
47
  form_driver(form, REQ_PREV_FIELD);
 
48
  std::string cstr = this->GetString();
 
49
  cstr = cstr.substr(0, cstr.find_last_not_of(" \t\n\r")+1);
 
50
  if ( m_LastString != cstr )
 
51
    {
 
52
    m_Cycle = false;
 
53
    m_CurrentIndex = 0;
 
54
    m_LastGlob = "";
 
55
    }
 
56
  std::string glob;
 
57
  if ( m_Cycle )
 
58
    {
 
59
    glob = m_LastGlob;
 
60
    }
 
61
  else
 
62
    {
 
63
    glob = cstr + "*";
 
64
    }
 
65
  std::vector<cmStdString> dirs;
 
66
 
 
67
  cmSystemTools::SimpleGlob(glob.c_str(), dirs, (m_Type == cmCacheManager::PATH?-1:0));
 
68
  if ( m_CurrentIndex < dirs.size() )
 
69
    {
 
70
    cstr = dirs[m_CurrentIndex];
 
71
    }
 
72
  if ( cstr[cstr.size()-1] == '*' )
 
73
    {
 
74
    cstr = cstr.substr(0, cstr.size()-1);
 
75
    }
 
76
 
 
77
  if ( cmSystemTools::FileIsDirectory(cstr.c_str()) )
 
78
    {
 
79
    cstr += "/";
 
80
    }
 
81
 
 
82
  this->SetString(cstr.c_str());
 
83
  touchwin(w); 
 
84
  wrefresh(w); 
 
85
  form_driver(form, REQ_END_FIELD);
 
86
  m_LastGlob = glob;
 
87
  m_LastString = cstr;
 
88
  m_Cycle = true;
 
89
  m_CurrentIndex ++;
 
90
  if ( m_CurrentIndex >= dirs.size() )
 
91
    {
 
92
    m_CurrentIndex = 0;
 
93
    }
 
94
}
 
95
 
 
96
void cmCursesPathWidget::OnReturn(cmCursesMainForm* fm, WINDOW* w)
 
97
{
 
98
  this->cmCursesStringWidget::OnReturn(fm, w);
 
99
}