1 /* tabprofilesop.cc
2 * This file belongs to Worker, a file manager for UN*X/X11.
3 * Copyright (C) 2017-2021 Ralf Hoffmann.
4 * You can contact me at: ralf@boomerangsworld.de
5 * or http://www.boomerangsworld.de/worker
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "tabprofilesop.hh"
23 #include "listermode.h"
24 #include "worker.h"
25 #include "aguix/awindow.h"
26 #include "aguix/text.h"
27 #include "aguix/button.h"
28 #include "aguix/stringgadget.h"
29 #include "aguix/fieldlistview.h"
30 #include "aguix/acontainerbb.h"
31 #include "aguix/kartei.h"
32 #include "aguix/textview.h"
33 #include "aguix/request.h"
34 #include "worker_locale.h"
35 #include "virtualdirmode.hh"
36 #include "workerinitialsettings.hh"
37 #include "ajson.hh"
38 #include "nwc_os.hh"
39
40 using namespace AJSON;
41
42 const char *TabProfilesOp::name = "TabProfilesOp";
43
TabProfilesOp()44 TabProfilesOp::TabProfilesOp() : FunctionProto(), m_left_l( nullptr ), m_right_l( nullptr )
45 {
46 m_category = FunctionProto::CAT_OTHER;
47 }
48
~TabProfilesOp()49 TabProfilesOp::~TabProfilesOp()
50 {
51 }
52
53 TabProfilesOp*
duplicate() const54 TabProfilesOp::duplicate() const
55 {
56 TabProfilesOp *ta = new TabProfilesOp();
57 return ta;
58 }
59
60 bool
isName(const char * str)61 TabProfilesOp::isName( const char *str )
62 {
63 if ( strcmp( str, name ) == 0 ) return true; else return false;
64 }
65
66 const char *
getName()67 TabProfilesOp::getName()
68 {
69 return name;
70 }
71
72 int
run(std::shared_ptr<WPUContext> wpu,ActionMessage * msg)73 TabProfilesOp::run( std::shared_ptr< WPUContext > wpu, ActionMessage *msg )
74 {
75 m_left_l = msg->getWorker()->getLister( 0 );
76 m_right_l = msg->getWorker()->getLister( 1 );
77
78 return gui();
79 }
80
81 const char *
getDescription()82 TabProfilesOp::getDescription()
83 {
84 return catalog.getLocale( 1308 );
85 }
86
getAvailableProfiles()87 std::vector< std::string > TabProfilesOp::getAvailableProfiles()
88 {
89 std::vector< std::string > res;
90
91 std::string basedir = WorkerInitialSettings::getInstance().getConfigBaseDir();
92
93 basedir += "/tabs/";
94
95 NWC::Dir d( basedir );
96
97 d.readDir( false );
98
99 auto entries = d.getFullnamesOfSubentries();
100
101 for ( auto &e : entries ) {
102 if ( AGUIXUtils::ends_with( e, ".ajson" ) ) {
103 NWC::FSEntry f( e );
104
105 std::string basename = f.getBasename();
106
107 res.push_back( std::string( basename, 0, basename.size() - 6 ) );
108 }
109 }
110
111 return res;
112 }
113
getProfile(const std::string & profile_name)114 std::pair< std::vector< std::string >, std::vector< std::string > > TabProfilesOp::getProfile( const std::string &profile_name )
115 {
116 std::pair< std::vector< std::string >, std::vector< std::string > > res;
117
118 std::string basedir = WorkerInitialSettings::getInstance().getConfigBaseDir();
119
120 basedir += "/tabs/";
121
122 std::string filename = AGUIXUtils::formatStringToString( "%s%s.ajson",
123 basedir.c_str(),
124 profile_name.c_str() );
125
126 auto jroot = as_object( AJSON::load( filename ) );
127
128 if ( ! jroot ) {
129 return res;
130 }
131
132 auto jleft = as_object( jroot->get( "left" ) );
133 auto jright = as_object( jroot->get( "right" ) );
134
135 if ( ! jleft || ! jright ) {
136 return res;
137 }
138
139 auto jleft_opened = as_array( jleft->get( "opened" ) );
140 auto jright_opened = as_array( jright->get( "opened" ) );
141
142 for ( size_t p = 0; p < jleft_opened->size(); p++ ) {
143 auto f = as_string( jleft_opened->get( p ) );
144
145 if ( f ) {
146 res.first.push_back( f->get_value() );
147 }
148 }
149
150 for ( size_t p = 0; p < jright_opened->size(); p++ ) {
151 auto f = as_string( jright_opened->get( p ) );
152
153 if ( f ) {
154 res.second.push_back( f->get_value() );
155 }
156 }
157
158 return res;
159 }
160
show_profile_content(const std::string & profile_name,TextStorageString * storage,TextView * tv)161 void TabProfilesOp::show_profile_content( const std::string &profile_name,
162 TextStorageString *storage,
163 TextView *tv )
164 {
165 auto content = getProfile( profile_name );
166
167 std::string str1;
168
169 str1 += catalog.getLocale( 1192 );
170 str1 += "\n";
171
172 for ( auto &e : content.first ) {
173 str1 += " ";
174 str1 += e;
175 str1 += "\n";
176 }
177
178 str1 += "\n";
179 str1 += catalog.getLocale( 1193 );
180 str1 += "\n";
181
182 for ( auto &e : content.second ) {
183 str1 += " ";
184 str1 += e;
185 str1 += "\n";
186 }
187
188 storage->setContent( str1 );
189 tv->textStorageChanged();
190 }
191
get_current_tabs()192 std::pair< std::vector< std::string >, std::vector< std::string > > TabProfilesOp::get_current_tabs()
193 {
194 VirtualDirMode *left_vdm = nullptr;
195 VirtualDirMode *right_vdm = nullptr;
196
197 if ( m_left_l ) {
198 ListerMode *lm1 = m_left_l->getActiveMode();
199 if ( lm1 ) {
200 if ( auto vdm = dynamic_cast< VirtualDirMode *>( lm1 ) ) {
201 left_vdm = vdm;
202 }
203 }
204 }
205
206 if ( m_right_l ) {
207 ListerMode *lm1 = m_right_l->getActiveMode();
208 if ( lm1 ) {
209 if ( auto vdm = dynamic_cast< VirtualDirMode *>( lm1 ) ) {
210 right_vdm = vdm;
211 }
212 }
213 }
214
215 std::pair< std::vector< std::string >, std::vector< std::string > > res;
216
217 if ( left_vdm ) {
218 res.first = left_vdm->get_tabs();
219 }
220
221 if ( right_vdm ) {
222 res.second = right_vdm->get_tabs();
223 }
224
225 return res;
226 }
227
dump_tabs(const std::string & profile_name)228 int TabProfilesOp::dump_tabs( const std::string &profile_name )
229 {
230 if ( AGUIXUtils::contains( profile_name, "/" ) ) {
231 Requester req( Worker::getAGUIX() );
232
233 std::string t1 = AGUIXUtils::formatStringToString( catalog.getLocale( 1204 ),
234 profile_name.c_str() );
235
236 req.request( catalog.getLocale( 124 ),
237 t1.c_str(),
238 catalog.getLocale( 11 ) );
239 return 1;
240 }
241
242 std::string basedir = WorkerInitialSettings::getInstance().getConfigBaseDir();
243
244 basedir += "/tabs/";
245
246 if ( NWC::OS::make_dirs( basedir ) != 0 ) {
247 return 1;
248 }
249
250 std::string filename = AGUIXUtils::formatStringToString( "%s%s.ajson",
251 basedir.c_str(),
252 profile_name.c_str() );
253
254 NWC::FSEntry fse( filename );
255
256 if ( fse.entryExists() ) {
257 Requester req( Worker::getAGUIX() );
258
259 std::string t1 = AGUIXUtils::formatStringToString( catalog.getLocale( 409 ),
260 profile_name.c_str() );
261 std::string s1 = catalog.getLocale( 280 );
262 s1 += "|";
263 s1 += catalog.getLocale( 8 );
264
265 int res = req.request( catalog.getLocale( 123 ),
266 t1.c_str(),
267 s1.c_str() );
268
269 if ( res == 1 ) {
270 return 1;
271 }
272 }
273
274 auto jroot = make_object();
275
276 auto jleft = make_object();
277 auto jright = make_object();
278
279 auto jleft_opened = make_array();
280 auto jright_opened = make_array();
281
282 auto tabs = get_current_tabs();
283
284 for ( auto &p : tabs.first ) {
285 jleft_opened->append( make_string( p ) );
286 }
287 for ( auto &p : tabs.second ) {
288 jright_opened->append( make_string( p ) );
289 }
290
291 jleft->set( "opened", jleft_opened );
292 jright->set( "opened", jright_opened );
293
294 jroot->set( "left", jleft );
295 jroot->set( "right", jright );
296
297 int res = dump( jroot, filename );
298
299 if ( res != 0 ) {
300 Requester req( Worker::getAGUIX() );
301
302 std::string t1 = AGUIXUtils::formatStringToString( catalog.getLocale( 1194 ),
303 profile_name.c_str() );
304
305 req.request( catalog.getLocale( 124 ),
306 t1.c_str(),
307 catalog.getLocale( 633 ) );
308 }
309
310 return res;
311 }
312
load_tabs(const std::string & profile_name)313 int TabProfilesOp::load_tabs( const std::string &profile_name )
314 {
315 auto tabs = getProfile( profile_name );
316
317 if ( tabs.first.empty() && tabs.second.empty() ) {
318 return 0;
319 }
320
321 VirtualDirMode *left_vdm = nullptr;
322 VirtualDirMode *right_vdm = nullptr;
323
324 if ( m_left_l ) {
325 m_left_l->switch2Mode( 0 );
326
327 ListerMode *lm1 = m_left_l->getActiveMode();
328 if ( lm1 ) {
329 if ( auto vdm = dynamic_cast< VirtualDirMode *>( lm1 ) ) {
330 left_vdm = vdm;
331 }
332 }
333 }
334
335 if ( m_right_l ) {
336 m_right_l->switch2Mode( 0 );
337
338 ListerMode *lm1 = m_right_l->getActiveMode();
339 if ( lm1 ) {
340 if ( auto vdm = dynamic_cast< VirtualDirMode *>( lm1 ) ) {
341 right_vdm = vdm;
342 }
343 }
344 }
345
346 if ( left_vdm ) {
347 left_vdm->open_tabs( tabs.first );
348 }
349
350 if ( right_vdm ) {
351 right_vdm->open_tabs( tabs.second );
352 }
353
354 return 0;
355 }
356
filter_available_profiles(const std::vector<std::string> & profiles,const std::string & filter,FieldListView * lv)357 int TabProfilesOp::filter_available_profiles( const std::vector< std::string > &profiles,
358 const std::string &filter,
359 FieldListView *lv )
360 {
361 lv->setSize( 0 );
362
363 for ( auto &e : profiles ) {
364 if ( AGUIXUtils::contains( e, filter ) ) {
365 int row = lv->addRow();
366
367 lv->setText( row, 0, e );
368 }
369 }
370
371 lv->redraw();
372
373 return 0;
374 }
375
376 int
gui()377 TabProfilesOp::gui()
378 {
379 AGUIX *aguix = Worker::getAGUIX();
380 AGMessage *msg;
381 int endmode = -1;
382
383 auto available_profiles = getAvailableProfiles();
384
385 AWindow *win = new AWindow( aguix, 10, 10, 10, 10, getDescription(), AWindow::AWINDOW_DIALOG );
386 win->create();
387
388 AContainer *ac1 = win->setContainer( new AContainer( win, 1, 2 ), true );
389 ac1->setMinSpace( 5 );
390 ac1->setMaxSpace( 5 );
391
392 RefCount<AFontWidth> lencalc( new AFontWidth( aguix, NULL ) );
393 TextStorageString help_ts( catalog.getLocale( 1195 ), lencalc );
394 TextView *help_tv = ac1->addWidget( new TextView( aguix,
395 0, 0, 50, 80, "", help_ts ),
396 0, 0, AContainer::CO_INCW );
397 help_tv->setLineWrap( true );
398 help_tv->maximizeX( 500 );
399 help_tv->maximizeYLines( 10, 500 );
400 help_tv->showFrame( false );
401 ac1->readLimits();
402 help_tv->show();
403 help_tv->setAcceptFocus( false );
404
405 TextView::ColorDef tv_cd = help_tv->getColors();
406 tv_cd.setBackground( 0 );
407 tv_cd.setTextColor( 1 );
408 help_tv->setColors( tv_cd );
409
410 Kartei *k1 = new Kartei( aguix, 10, 10, 10, 10, "" );
411 ac1->add( k1, 0, 1, AContainer::CO_MIN );
412 k1->create();
413
414 AWindow *subwin11 = new AWindow( aguix, 0, 0, 10, 10, "" );
415 k1->add( subwin11 );
416 subwin11->create();
417
418 AContainer *acsw11 = subwin11->setContainer( new AContainer( subwin11, 1, 5 ), true );
419 acsw11->setMinSpace( 5 );
420 acsw11->setMaxSpace( 5 );
421 acsw11->setBorderWidth( 5 );
422
423 acsw11->add( new Text( aguix, 0, 0, catalog.getLocale( 1196 ) ), 0, 0, AContainer::CO_INCWNR );
424
425 StringGadget *new_profile_name_sg = acsw11->addWidget( new StringGadget( aguix, 0, 0, 50, "tabs1", 0 ),
426 0, 1, AContainer::CO_INCW );
427
428 acsw11->add( new Text( aguix, 0, 0, catalog.getLocale( 1197 ) ), 0, 2, AContainer::CO_INCWNR );
429
430 FieldListView *existing_profiles_lv = acsw11->addWidget( new FieldListView( aguix, 0, 0, 200, 75, 0 ),
431 0, 3,
432 AContainer::CO_MIN );
433 existing_profiles_lv->setHBarState( 2 );
434 existing_profiles_lv->setVBarState( 2 );
435 existing_profiles_lv->setAcceptFocus( true );
436 existing_profiles_lv->setDisplayFocus( true );
437
438 AContainer *ac1_5 = acsw11->add( new AContainer( subwin11, 2, 1 ), 0, 4 );
439 ac1_5->setMinSpace( 5 );
440 ac1_5->setMaxSpace( -1 );
441 ac1_5->setBorderWidth( 0 );
442 Button *saveb =(Button*)ac1_5->add( new Button( aguix,
443 0,
444 0,
445 catalog.getLocale( 7 ),
446 0 ), 0, 0, AContainer::CO_FIX );
447 Button *cancelb = (Button*)ac1_5->add( new Button( aguix,
448 0,
449 0,
450 catalog.getLocale( 8 ),
451 0 ), 1, 0, AContainer::CO_FIX );
452
453 acsw11->readLimits();
454
455 AWindow *subwin12 = new AWindow( aguix, 0, 0, 10, 10, "" );
456 k1->add( subwin12 );
457 subwin12->create();
458
459 AContainer *acsw12 = subwin12->setContainer( new AContainer( subwin12, 1, 4 ), true );
460 acsw12->setMinSpace( 5 );
461 acsw12->setMaxSpace( 5 );
462 acsw12->setBorderWidth( 5 );
463
464 AContainer *acsw12_1 = acsw12->add( new AContainer( subwin12, 2, 1 ), 0, 0 );
465 acsw12_1->setMinSpace( 5 );
466 acsw12_1->setMaxSpace( 5 );
467 acsw12_1->setBorderWidth( 0 );
468
469 acsw12_1->addWidget( new Text( aguix, 0, 0, catalog.getLocale( 758 ), 1, 0 ),
470 0, 0, AContainer::CO_FIX );
471
472 StringGadget *findsg = acsw12_1->addWidget( new StringGadget( aguix, 0, 0, 50, "", 0 ),
473 1, 0, AContainer::CO_INCW );
474
475 acsw12->addWidget( new Text( aguix, 0, 0, catalog.getLocale( 1198 ), 1, 0 ),
476 0, 1, AContainer::CO_INCWNR );
477
478 AContainer *acsw12_2 = acsw12->add( new AContainer( subwin12, 2, 1 ), 0, 2 );
479 acsw12_2->setMinSpace( 5 );
480 acsw12_2->setMaxSpace( 5 );
481 acsw12_2->setBorderWidth( 0 );
482
483 FieldListView *load_profiles_lv = acsw12_2->addWidget( new FieldListView( aguix, 0, 0, 200, 150, 0 ),
484 0, 0,
485 AContainer::CO_MIN );
486 load_profiles_lv->setHBarState( 2 );
487 load_profiles_lv->setVBarState( 2 );
488 load_profiles_lv->setAcceptFocus( true );
489 load_profiles_lv->setDisplayFocus( true );
490
491 AContainer *acsw12_2_1 = acsw12_2->add( new AContainer( subwin12, 1, 2 ), 1, 0 );
492 acsw12_2_1->setMinSpace( 5 );
493 acsw12_2_1->setMaxSpace( 5 );
494 acsw12_2_1->setBorderWidth( 0 );
495
496 acsw12_2_1->addWidget( new Text( aguix, 0, 0, catalog.getLocale( 1199 ), 1, 0 ),
497 0, 0, AContainer::CO_INCWNR );
498
499 TextStorageString content_ts( "", lencalc );
500 TextView *content_tv = acsw12_2_1->addWidget( new TextView( aguix,
501 0, 0, 200, 150, "", content_ts ),
502 0, 1, AContainer::CO_MIN );
503 content_tv->setLineWrap( true );
504 content_tv->showFrame( false );
505 content_tv->maximizeYLines( 10, content_tv->getWidth() );
506 acsw12_2_1->readLimits();
507 content_tv->show();
508 content_tv->setAcceptFocus( false );
509
510 TextView::ColorDef tv_cd2 = content_tv->getColors();
511 tv_cd2.setBackground( 0 );
512 tv_cd2.setTextColor( 1 );
513 content_tv->setColors( tv_cd2 );
514
515 AContainer *acsw12_4 = acsw12->add( new AContainer( subwin12, 4, 1 ), 0, 3 );
516 acsw12_4->setMinSpace( 5 );
517 acsw12_4->setMaxSpace( -1 );
518 acsw12_4->setBorderWidth( 0 );
519 Button *openb = acsw12_4->addWidget( new Button( aguix,
520 0,
521 0,
522 catalog.getLocale( 1200 ),
523 0 ), 0, 0, AContainer::CO_FIX );
524 Button *open_deleteb = acsw12_4->addWidget( new Button( aguix,
525 0,
526 0,
527 catalog.getLocale( 1201 ),
528 0 ), 1, 0, AContainer::CO_FIX );
529 Button *deleteb = acsw12_4->addWidget( new Button( aguix,
530 0,
531 0,
532 catalog.getLocale( 1203 ),
533 0 ), 2, 0, AContainer::CO_FIX );
534 Button *cancel2b = acsw12_4->addWidget( new Button( aguix,
535 0,
536 0,
537 catalog.getLocale( 8 ),
538 0 ), 3, 0, AContainer::CO_FIX );
539
540 acsw12->readLimits();
541
542 std::string str1 = catalog.getLocale( 7 );
543 str1 += " - F1";
544 k1->setOption( subwin11, 0, str1.c_str() );
545 str1 = catalog.getLocale( 1202 );
546 str1 += " - F2";
547 k1->setOption( subwin12, 1, str1.c_str() );
548 k1->maximize();
549 k1->contMaximize();
550 ac1->readLimits();
551
552 win->setDoTabCycling( true );
553 win->contMaximize( true );
554
555 new_profile_name_sg->takeFocus();
556
557 win->show();
558 k1->show();
559
560 existing_profiles_lv->setDefaultColorMode( FieldListView::precolor_t::PRECOLOR_ONLYACTIVE );
561 load_profiles_lv->setDefaultColorMode( FieldListView::precolor_t::PRECOLOR_ONLYACTIVE );
562
563 for ( auto &e : available_profiles ) {
564 int row = existing_profiles_lv->addRow();
565
566 existing_profiles_lv->setText( row, 0, e );
567
568 row = load_profiles_lv->addRow();
569
570 load_profiles_lv->setText( row, 0, e );
571 }
572
573 existing_profiles_lv->redraw();
574 load_profiles_lv->redraw();
575 content_tv->forceRedraw();
576
577 new_profile_name_sg->selectAll();
578
579 for ( ; endmode == -1; ) {
580 msg = aguix->WaitMessage( win );
581 if ( msg != NULL ) {
582 switch ( msg->type ) {
583 case AG_CLOSEWINDOW:
584 if ( msg->closewindow.window == win->getWindow() ) endmode = 1;
585 break;
586 case AG_BUTTONCLICKED:
587 if ( msg->button.button == saveb ) {
588 if ( dump_tabs( new_profile_name_sg->getText() ) == 0 ) {
589 endmode = 0;
590 }
591 } else if ( msg->button.button == openb ||
592 msg->button.button == open_deleteb ) {
593 int row = load_profiles_lv->getActiveRow();
594 if ( load_profiles_lv->isValidRow( row ) == true ) {
595 if ( load_tabs( load_profiles_lv->getText( row, 0 ) ) == 0 ) {
596 endmode = 0;
597
598 if ( msg->button.button == open_deleteb ) {
599 delete_profile( load_profiles_lv->getText( row, 0 ) );
600 }
601 }
602 }
603 } else if ( msg->button.button == deleteb ) {
604 int row = load_profiles_lv->getActiveRow();
605 if ( load_profiles_lv->isValidRow( row ) == true ) {
606 delete_profile( load_profiles_lv->getText( row, 0 ) );
607 endmode = 1;
608 }
609 } else if ( msg->button.button == cancelb ||
610 msg->button.button == cancel2b ) {
611 endmode = 1;
612 }
613 case AG_KEYPRESSED:
614 if ( win->isParent( msg->key.window, false ) == true ) {
615 switch(msg->key.key) {
616 case XK_F1:
617 k1->optionChange( 0 );
618 new_profile_name_sg->takeFocus();
619 break;
620 case XK_F2:
621 k1->optionChange( 1 );
622 findsg->takeFocus();
623 break;
624 case XK_Down:
625 if ( k1->getCurOption() == 0 ) {
626 if ( new_profile_name_sg->getHasFocus() ) {
627 existing_profiles_lv->takeFocus();
628 if ( ! existing_profiles_lv->isValidRow( existing_profiles_lv->getActiveRow() ) &&
629 existing_profiles_lv->getElements() > 0 ) {
630 existing_profiles_lv->setActiveRow( 0 );
631 new_profile_name_sg->setText( existing_profiles_lv->getText( 0, 0 ).c_str() );
632 }
633 }
634 } else if ( k1->getCurOption() == 1 ) {
635 if ( findsg->getHasFocus() ) {
636 load_profiles_lv->takeFocus();
637 if ( ! load_profiles_lv->isValidRow( load_profiles_lv->getActiveRow() ) &&
638 load_profiles_lv->getElements() > 0 ) {
639 load_profiles_lv->setActiveRow( 0 );
640 show_profile_content( load_profiles_lv->getText( 0, 0 ), &content_ts, content_tv );
641 }
642 }
643 }
644 break;
645 case XK_Return:
646 if ( new_profile_name_sg->getHasFocus() == false &&
647 findsg->getHasFocus() == false ) {
648 if ( k1->getCurOption() == 0 ) {
649 if ( dump_tabs( new_profile_name_sg->getText() ) == 0 ) {
650 endmode = 0;
651 }
652 } else if ( k1->getCurOption() == 1 ) {
653 int row = load_profiles_lv->getActiveRow();
654 if ( load_profiles_lv->isValidRow( row ) == true ) {
655 if ( load_tabs( load_profiles_lv->getText( row, 0 ) ) == 0 ) {
656 endmode = 0;
657 }
658 }
659 }
660 }
661 break;
662 case XK_Escape:
663 endmode = 1;
664 break;
665 }
666 }
667 case AG_STRINGGADGET_OK:
668 if ( msg->stringgadget.sg == new_profile_name_sg ) {
669 if ( dump_tabs( new_profile_name_sg->getText() ) == 0 ) {
670 endmode = 0;
671 }
672 } else if ( msg->stringgadget.sg == findsg ) {
673 int row = load_profiles_lv->getActiveRow();
674 if ( load_profiles_lv->isValidRow( row ) == true ) {
675 if ( load_tabs( load_profiles_lv->getText( row, 0 ) ) == 0 ) {
676 endmode = 0;
677 }
678 }
679 }
680 break;
681 case AG_STRINGGADGET_CONTENTCHANGE:
682 if ( msg->stringgadget.sg == findsg ) {
683 int row = load_profiles_lv->getActiveRow();
684 std::string current_profile;
685 if ( load_profiles_lv->isValidRow( row ) == true ) {
686 current_profile = load_profiles_lv->getText( row, 0 );
687 }
688
689 filter_available_profiles( available_profiles,
690 findsg->getText(),
691 load_profiles_lv );
692
693 int p;
694
695 for ( p = 0; p < load_profiles_lv->getElements(); p++ ) {
696 if ( load_profiles_lv->getText( p, 0 ) == current_profile ) {
697 load_profiles_lv->setActiveRow( row );
698 break;
699 }
700 }
701
702 if ( p == load_profiles_lv->getElements() ) {
703 load_profiles_lv->setActiveRow( 0 );
704 }
705
706 row = load_profiles_lv->getActiveRow();
707 if ( load_profiles_lv->isValidRow( row ) == true ) {
708 show_profile_content( load_profiles_lv->getText( row, 0 ), &content_ts, content_tv );
709 }
710 }
711 break;
712 case AG_FIELDLV_ONESELECT:
713 case AG_FIELDLV_MULTISELECT:
714 if ( msg->fieldlv.lv == existing_profiles_lv ) {
715 int row = existing_profiles_lv->getActiveRow();
716 if ( existing_profiles_lv->isValidRow( row ) == true ) {
717 new_profile_name_sg->setText( existing_profiles_lv->getText( row, 0 ).c_str() );
718 }
719 } else if ( msg->fieldlv.lv == load_profiles_lv ) {
720 int row = load_profiles_lv->getActiveRow();
721 if ( load_profiles_lv->isValidRow( row ) == true ) {
722 show_profile_content( load_profiles_lv->getText( row, 0 ), &content_ts, content_tv );
723 }
724 }
725 default:
726 break;
727 }
728 aguix->ReplyMessage( msg );
729 }
730 }
731
732 delete win;
733
734 return endmode;
735 }
736
delete_profile(const std::string & profile_name)737 void TabProfilesOp::delete_profile( const std::string &profile_name )
738 {
739 std::string basedir = WorkerInitialSettings::getInstance().getConfigBaseDir();
740
741 basedir += "/tabs/";
742
743 std::string filename = AGUIXUtils::formatStringToString( "%s%s.ajson",
744 basedir.c_str(),
745 profile_name.c_str() );
746
747 worker_unlink( filename.c_str() );
748 }
749