25 #define YUILogComponent "ncurses"
26 #include <yui/YUILog.h>
28 #include "NCAskForFile.h"
30 #include <yui/YDialog.h>
32 #include "NCWidgetFactory.h"
33 #include "NCLayoutBox.h"
34 #include "NCSpacing.h"
38 #include <sys/types.h>
42 #include <sys/errno.h>
49 NCAskForFile::NCAskForFile(
const wpos at,
50 const std::string & iniDir,
51 const std::string & filter,
52 const std::string & headline )
66 NCAskForFile::~NCAskForFile( )
72 std::string NCAskForFile::checkIniDir( std::string iniDir )
74 std::string dname =
"";
76 struct stat64 statInfo;
77 stat64( iniDir.c_str(), &statInfo );
79 if ( S_ISDIR( statInfo.st_mode ) )
85 std::string::size_type pos;
87 pos = iniDir.find_last_of(
"/" );
89 if ( pos != std::string::npos
92 std::string dir = iniDir.substr( 0, pos );
93 stat64( dir.c_str(), &statInfo );
95 if ( S_ISDIR( statInfo.st_mode ) )
98 iniFileName = iniDir.substr( pos + 1 );
108 const std::string & filter,
109 const std::string & headline,
112 std::string startDir;
113 std::string old_textdomain = textdomain( NULL );
114 setTextdomain(
"ncurses" );
116 startDir = checkIniDir( iniDir );
119 YLayoutBox * split = YUI::widgetFactory()->createVBox(
this );
121 new NCLabel( split, headline,
true,
false );
123 YFrame * frame = YUI::widgetFactory()->createFrame( split,
"" );
126 dirName =
new NCComboBox( frame, _(
"Selected Directory:" ),
false );
127 dirName->setNotify(
true );
128 dirName->setStretchable( YD_HORIZ,
true );
131 YLayoutBox * hSplit = YUI::widgetFactory()->createHBox( split );
134 detailed =
new NCCheckBox( hSplit, _(
"&Detailed View" ),
false );
135 detailed->setNotify(
true );
138 YLayoutBox * hSplit1 = YUI::widgetFactory()->createHBox( split );
141 YTableHeader * dirHeader =
new YTableHeader();
142 dirHeader->addColumn(
" " );
143 dirHeader->addColumn( _(
"Directory name" ) );
148 NCFileSelection::T_Overview,
150 dirList->setSendKeyEvents(
true );
153 YTableHeader * fileHeader =
new YTableHeader();
154 fileHeader->addColumn(
" " );
155 fileHeader->addColumn( _(
"File name" ) );
160 NCFileSelection::T_Overview,
164 fileList->setSendKeyEvents(
true );
166 YLayoutBox * hSplit2 = YUI::widgetFactory()->createHBox( split );
179 fileName->setValue( iniFileName );
183 extension->setStretchable( YD_HORIZ,
true );
184 extension->addItem( filter,
187 YUI::widgetFactory()->createSpacing( split, YD_VERT,
false, 1.0 );
190 YLayoutBox * hSplit3 = YUI::widgetFactory()->createHBox( split );
192 YUI::widgetFactory()->createSpacing( hSplit3, YD_HORIZ,
true, 0.2 );
196 okButton->setFunctionKey( 10 );
197 okButton->setStretchable( YD_HORIZ,
true );
199 YUI::widgetFactory()->createSpacing( hSplit3, YD_HORIZ,
true, 0.4 );
202 cancelButton =
new NCPushButton( hSplit3, _(
"&Cancel" ) );
203 cancelButton->setFunctionKey( 9 );
204 cancelButton->setStretchable( YD_HORIZ,
true );
206 YUI::widgetFactory()->createSpacing( hSplit3, YD_HORIZ,
true, 0.2 );
208 setTextdomain( old_textdomain.c_str() );
216 if ( !dirList || !fileList || !dirName )
221 dirList->setKeyboardFocus();
225 if ( iniFileName ==
"" )
227 fileName->setValue( fileList->getCurrentFile() );
234 while ( postAgain() );
244 return NCurses::cols() - 10;
248 int NCAskForFile::preferredHeight()
250 return NCurses::lines() - 4;
257 return NCursesEvent::cancel;
259 return NCDialog::wHandleInput( ch );
269 if ( iniFileName ==
"" )
271 fileName->setValue( fileList->getCurrentFile() );
275 bool NCAskForFile::postAgain( )
277 if ( !postevent.widget )
280 postevent.detail = NCursesEvent::NODETAIL;
282 if ( postevent.keySymbol ==
"CursorLeft" )
284 dirList->setKeyboardFocus();
287 else if ( postevent.keySymbol ==
"CursorRight" )
289 fileList->setKeyboardFocus();
290 fileName->setValue( fileList->getCurrentFile() );
294 if ( postevent.widget == okButton )
296 postevent.result = dirList->
getCurrentDir() +
"/" + getFileName();
300 else if (( postevent.widget == dirList ) &&
301 ( postevent.result !=
"" ) )
304 dirName->addItem( postevent.result,
308 if ( postevent.reason == YEvent::Activated )
315 else if ( postevent.widget == dirName )
322 else if ( postevent.widget == detailed )
324 bool details = getCheckBoxValue( detailed );
341 else if ( postevent.widget == fileList )
343 if ( postevent.result !=
"" )
345 fileName->setValue( postevent.result );
350 postevent.result =
"";
354 if ( postevent.widget == cancelButton ||
355 postevent == NCursesEvent::cancel )
357 postevent.result =
"";
365 bool NCAskForFile::getCheckBoxValue(
NCCheckBox * checkBox )
370 return ( checkBox->isChecked() );
377 NCAskForExistingFile::NCAskForExistingFile(
const wpos at,
378 const std::string & iniDir,
379 const std::string & filter,
380 const std::string & headline )
390 std::string NCAskForExistingFile::getFileName()
392 if ( fileName->value() ==
"" )
393 return fileList->getCurrentFile();
395 return fileName->value();
399 NCAskForSaveFileName::NCAskForSaveFileName(
const wpos at,
400 const std::string & iniDir,
401 const std::string & filter,
402 const std::string & headline )
412 std::string NCAskForSaveFileName::getFileName()
414 return fileName->value();
void setStartDir(const std::string &start)
void setTableType(NCFileSelectionType type)
NCursesEvent & showDirPopup()
virtual int preferredWidth()
void createLayout(const std::string &iniDir, const std::string &filter, const std::string &headline, bool editable)
std::string getCurrentDir()