25 #include "NCAskForDirectory.h"
28 #define YUILogComponent "ncurses"
29 #include <yui/YUILog.h>
30 #include <yui/YDialog.h>
31 #include <yui/YTypes.h>
32 #include "NCWidgetFactory.h"
33 #include "NCWidgetFactory.h"
34 #include "NCLayoutBox.h"
35 #include "NCSpacing.h"
39 #include <sys/types.h>
42 #include <sys/errno.h>
50 NCAskForExistingDirectory::NCAskForExistingDirectory(
const wpos at,
51 const std::string & iniDir,
52 const std::string & headline )
60 createLayout( iniDir, headline );
64 NCAskForExistingDirectory::~NCAskForExistingDirectory()
70 const std::string & headline )
72 std::string old_textdomain = textdomain( NULL );
73 setTextdomain(
"ncurses" );
76 YLayoutBox * split = YUI::widgetFactory()->createVBox(
this );
79 new NCLabel( split, headline,
true,
false );
81 YFrame * frame = YUI::widgetFactory()->createFrame( split,
"" );
84 dirName =
new NCComboBox( frame, _(
"Selected Directory:" ),
false );
85 dirName->setNotify(
true );
86 dirName->setStretchable( YD_HORIZ,
true );
89 YLayoutBox * hSplit = YUI::widgetFactory()->createHBox( split );
92 detailed =
new NCCheckBox( hSplit, _(
"&Detailed View" ),
false );
93 detailed->setNotify(
true );
96 YTableHeader * tableHeader =
new YTableHeader();
97 tableHeader->addColumn(
" ", YAlignBegin );
98 tableHeader->addColumn( _(
"Directory Name" ), YAlignBegin );
103 NCFileTable::T_Overview,
106 YUI::widgetFactory()->createSpacing( split, YD_VERT,
false, 1.0 );
109 YLayoutBox * hSplit1 = YUI::widgetFactory()->createHBox( split );
111 YUI::widgetFactory()->createSpacing( hSplit1, YD_HORIZ,
true, 0.2 );
115 okButton->setFunctionKey( 10 );
116 okButton->setStretchable( YD_HORIZ,
true );
118 YUI::widgetFactory()->createSpacing( hSplit1, YD_HORIZ,
true, 0.4 );
121 cancelButton =
new NCPushButton( hSplit1, _(
"&Cancel" ) );
122 cancelButton->setFunctionKey( 9 );
123 cancelButton->setStretchable( YD_HORIZ,
true );
125 YUI::widgetFactory()->createSpacing( hSplit1, YD_HORIZ,
true, 0.2 );
127 setTextdomain( old_textdomain.c_str() );
135 if ( !dirList || !dirName )
140 dirList->setKeyboardFocus();
150 while ( postAgain() );
159 int NCAskForExistingDirectory::preferredWidth()
161 return NCurses::cols() - 10;
165 int NCAskForExistingDirectory::preferredHeight()
167 return NCurses::lines() - 4;
171 NCursesEvent NCAskForExistingDirectory::wHandleInput( wint_t ch )
174 return NCursesEvent::cancel;
176 return NCDialog::wHandleInput( ch );
180 bool NCAskForExistingDirectory::postAgain( )
182 if ( !postevent.widget )
185 postevent.detail = NCursesEvent::NODETAIL;
187 if ( postevent.widget == okButton )
193 else if ( postevent.widget == dirList )
195 if ( postevent.result ==
"" )
199 yuiDebug() <<
"Add item: " << postevent.result << std::endl;
201 dirName->addItem( postevent.result,
204 if ( postevent.reason == YEvent::Activated )
210 else if ( postevent.widget == dirName )
215 else if ( postevent.widget == detailed )
217 bool details = getCheckBoxValue( detailed );
232 postevent.result =
"";
236 if ( postevent.widget == cancelButton ||
237 postevent == NCursesEvent::cancel )
239 postevent.result =
"";
247 bool NCAskForExistingDirectory::getCheckBoxValue(
NCCheckBox * checkBox )
252 return ( checkBox->isChecked() );
void setStartDir(const std::string &start)
void createLayout(const std::string &initialDir, const std::string &headline)
void setTableType(NCFileSelectionType type)
NCursesEvent & showDirPopup()
std::string getCurrentDir()