forked from JDimproved/JDim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
selectdialog.cpp
169 lines (126 loc) · 4.54 KB
/
selectdialog.cpp
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
// ライセンス: GPL2
//#define _DEBUG
#include "jddebug.h"
#include "selectdialog.h"
#include "selectlistview.h"
#include "columns.h"
#include "viewfactory.h"
#include "command.h"
#include "session.h"
#include "type.h"
#include "sharedbuffer.h"
using namespace BBSLIST;
enum
{
SELECTDIAG_WIDTH = 600,
SELECTDIAG_TREEHEIGHT = 300
};
SelectListDialog::SelectListDialog( Gtk::Window* parent, const std::string& url, Glib::RefPtr< Gtk::TreeStore >& treestore )
: SKELETON::PrefDiag( parent, url, true ),
m_treestore( treestore ),
m_label_name( CORE::SBUF_size() == 1, "名前 :" ),
m_label_dirs( "ディレクトリ :" ),
m_bt_show_tree( "詳細" ),
m_selectview( NULL )
{
const int mrg = 8;
if( CORE::SBUF_size() ) m_label_name.set_text( ( *CORE::SBUF_list_info().begin() ).name );
set_activate_entry( m_label_name );
m_hbox_dirs.set_spacing( mrg );
m_hbox_dirs.pack_start( m_label_dirs, Gtk::PACK_SHRINK );
m_hbox_dirs.pack_start( m_combo_dirs, Gtk::PACK_EXPAND_WIDGET );
m_hbox_dirs.pack_start( m_bt_show_tree, Gtk::PACK_SHRINK );
// コンボボックスにディレクトリをセット
int active_row = 0;
Glib::ustring name;
name = "お気に入りの先頭に追加";
m_combo_dirs.append( name );
if( ! active_row && name == SESSION::get_dir_select_favorite() ) active_row = m_vec_path.size();
m_vec_path.push_back( "-1" );
name = "お気に入りの最後に追加";
m_combo_dirs.append( name );
if( ! active_row && name == SESSION::get_dir_select_favorite() ) active_row = m_vec_path.size();
m_vec_path.push_back( "" );
BBSLIST::TreeColumns columns;
Gtk::TreeModel::Children child = m_treestore->children();
Gtk::TreeModel::Children::iterator it = child.begin();
for( ; it != child.end() ; ++it ){
Gtk::TreeModel::Row row = ( *it );
const int type = row[ columns.m_type ];
if( type == TYPE_DIR ){
name = row[ columns.m_name ];
m_combo_dirs.append( name );
if( ! active_row && name == SESSION::get_dir_select_favorite() ) active_row = m_vec_path.size();
Gtk::TreePath path = m_treestore->get_path( row );
m_vec_path.push_back( path.to_string() );
#ifdef _DEBUG
std::cout << row[ columns.m_name ] << " path = " << path.to_string() << std::endl;
#endif
}
}
#ifdef _DEBUG
std::cout << "active_row = " << active_row << std::endl;
#endif
m_combo_dirs.set_active( active_row );
get_vbox()->pack_start( m_label_name, Gtk::PACK_SHRINK );
get_vbox()->pack_start( m_hbox_dirs, Gtk::PACK_SHRINK );
m_bt_show_tree.signal_clicked().connect( sigc::mem_fun( this, &SelectListDialog::slot_show_tree ) );
set_title( "お気に入り追加先選択" );
resize( SELECTDIAG_WIDTH, 1 );
set_default_response( Gtk::RESPONSE_OK );
grab_ok();
show_all_children();
}
SelectListDialog::~SelectListDialog()
{
if( m_selectview ) delete m_selectview;
}
//
// OKを押した
//
void SelectListDialog::slot_ok_clicked()
{
if( ! m_selectview ) SESSION::set_dir_select_favorite( m_combo_dirs.get_active_text() );
}
std::string SelectListDialog::get_name()
{
return m_label_name.get_text();
}
std::string SelectListDialog::get_path()
{
std::string path;
if( m_selectview ) path = m_selectview->get_current_path().to_string();
else path = m_vec_path[ m_combo_dirs.get_active_row_number() ];
#ifdef _DEBUG
std::cout << "SelectListDialog::get_path path = " << path << std::endl;
#endif
return path;
}
void SelectListDialog::slot_show_tree()
{
#ifdef _DEBUG
std::cout << "SelectListDialog::slot_show_tree\n";
#endif
if( m_bt_show_tree.get_active() ){
if( ! m_selectview ) m_selectview = dynamic_cast< SelectListView* > ( Gtk::manage( CORE::ViewFactory( CORE::VIEW_SELECTLIST, get_url() ) ) );
if( m_selectview ){
m_selectview->set_parent_win( this );
m_selectview->copy_treestore( m_treestore );
m_selectview->sig_close_dialog().connect( sigc::mem_fun(*this, &SelectListDialog::hide ) );
get_vbox()->pack_start(* m_selectview );
m_selectview->set_size_request( -1, SELECTDIAG_TREEHEIGHT );
m_selectview->focus_view();
show_all_children();
}
}
else if( m_selectview ){
get_vbox()->remove( *m_selectview );
resize( get_width(), 1 );
delete m_selectview;
m_selectview = NULL;
}
}
void SelectListDialog::timeout()
{
if( m_selectview ) m_selectview->clock_in();
}