comparison libgui/src/files-dock-widget.cc @ 16542:016073c0cb94

Add popdown toolbutton to files-dock-window toolbar. * libgui/src/files-dock-widget.cc (files_dock_widget::files_dock_widget): added popdown button to toolbar and merged set current dir, show current dir into it as well as adding new dir and new file option. (files_dock_widget::display_directory): change to call process_set_current_dir instead of emit. (files_dock_widget::contextmenu_newfile): change to call process_new_file. (files_dock_widget::contextmenu_newdir): Change to call process_new_dir. (files_dock_widget::contextmenu_setcurrentdir): Change to call process_set_current_dir. (files_dock_widget::popdownmenu_newdir): New function. (files_dock_widget::popdownmenu_newfile): New function. (files_dock_widget::process_new_file): New function. (files_dock_widget::process_new_dir): New function. (iles_dock_widget::process_set_current_dir): New function. * libgui/src/resource.qrc: Added icons/gear.png. * libgui/src/module.mk: Added icons/gear.png. * libgui/src/icons.png: New file.
author John Donoghue <john.donoghue@ieee.org>
date Tue, 16 Apr 2013 22:16:57 -0400
parents e192525236ad
children 04fb96f4bea1
comparison
equal deleted inserted replaced
16541:6afb29359968 16542:016073c0cb94
37 #include <QLineEdit> 37 #include <QLineEdit>
38 #include <QSizePolicy> 38 #include <QSizePolicy>
39 #include <QMenu> 39 #include <QMenu>
40 #include <QInputDialog> 40 #include <QInputDialog>
41 #include <QMessageBox> 41 #include <QMessageBox>
42 #include <QToolButton>
42 43
43 files_dock_widget::files_dock_widget (QWidget *p) 44 files_dock_widget::files_dock_widget (QWidget *p)
44 : octave_dock_widget (p) 45 : octave_dock_widget (p)
45 { 46 {
46 setObjectName ("FilesDockWidget"); 47 setObjectName ("FilesDockWidget");
78 QAction *directory_up_action = new QAction (QIcon(":/actions/icons/up.png"), 79 QAction *directory_up_action = new QAction (QIcon(":/actions/icons/up.png"),
79 "", _navigation_tool_bar); 80 "", _navigation_tool_bar);
80 directory_up_action->setToolTip (tr ("Move up one directory")); 81 directory_up_action->setToolTip (tr ("Move up one directory"));
81 82
82 _sync_browser_directory_action = new QAction (QIcon(":/actions/icons/reload.png"), 83 _sync_browser_directory_action = new QAction (QIcon(":/actions/icons/reload.png"),
83 "", _navigation_tool_bar); 84 tr("Show octave directory"), _navigation_tool_bar);
84 _sync_browser_directory_action->setToolTip (tr ("Goto current octave directory")); 85 _sync_browser_directory_action->setToolTip (tr ("Goto current octave directory"));
85 _sync_browser_directory_action->setEnabled ("false"); 86 _sync_browser_directory_action->setEnabled ("false");
86 87
87 _sync_octave_directory_action = new QAction (QIcon(":/actions/icons/ok.png"), 88 _sync_octave_directory_action = new QAction (QIcon(":/actions/icons/ok.png"),
88 "", _navigation_tool_bar); 89 tr("Set octave directory"), _navigation_tool_bar);
89 _sync_octave_directory_action->setToolTip (tr ("Set octave directroy to current browser directory")); 90 _sync_octave_directory_action->setToolTip (tr ("Set octave directroy to current browser directory"));
90 _sync_octave_directory_action->setEnabled ("false"); 91 _sync_octave_directory_action->setEnabled ("false");
91 92
93 QToolButton * popdown_button = new QToolButton();
94 popdown_button->setToolTip(tr ("Actions on current directory"));
95 QMenu * popdown_menu = new QMenu();
96 popdown_menu->addAction(_sync_browser_directory_action);
97 popdown_menu->addAction(_sync_octave_directory_action);
98 popdown_button->setMenu(popdown_menu);
99 popdown_button->setPopupMode(QToolButton::InstantPopup);
100 popdown_button->setDefaultAction(new QAction(QIcon(":/actions/icons/gear.png"),"", _navigation_tool_bar));
101
102 popdown_menu->addSeparator();
103 popdown_menu->addAction(QIcon(":/actions/icons/filenew.png"),
104 tr ("New File"),
105 this, SLOT(popdownmenu_newfile(bool)));
106 popdown_menu->addAction(QIcon(":/actions/icons/folder_new.png"),
107 tr ("New Directory"),
108 this, SLOT(popdownmenu_newdir(bool)));
109
92 _navigation_tool_bar->addWidget (_current_directory); 110 _navigation_tool_bar->addWidget (_current_directory);
93 _navigation_tool_bar->addAction (directory_up_action); 111 _navigation_tool_bar->addAction (directory_up_action);
94 _navigation_tool_bar->addAction (_sync_browser_directory_action); 112 _navigation_tool_bar->addWidget (popdown_button);
95 _navigation_tool_bar->addAction (_sync_octave_directory_action);
96 113
97 connect (directory_up_action, SIGNAL (triggered ()), this, 114 connect (directory_up_action, SIGNAL (triggered ()), this,
98 SLOT (change_directory_up ())); 115 SLOT (change_directory_up ()));
99 connect (_sync_octave_directory_action, SIGNAL (triggered ()), this, 116 connect (_sync_octave_directory_action, SIGNAL (triggered ()), this,
100 SLOT (do_sync_octave_directory ())); 117 SLOT (do_sync_octave_directory ()));
101 connect (_sync_browser_directory_action, SIGNAL (triggered ()), this, 118 connect (_sync_browser_directory_action, SIGNAL (triggered ()), this,
102 SLOT (do_sync_browser_directory ())); 119 SLOT (do_sync_browser_directory ()));
103
104 // TODO: Add other buttons for creating directories
105 120
106 // Create the QFileSystemModel starting in the actual directory 121 // Create the QFileSystemModel starting in the actual directory
107 QDir curr_dir; 122 QDir curr_dir;
108 _file_system_model = new QFileSystemModel (this); 123 _file_system_model = new QFileSystemModel (this);
109 _file_system_model->setFilter (QDir::NoDotAndDotDot | QDir::AllEntries); 124 _file_system_model->setFilter (QDir::NoDotAndDotDot | QDir::AllEntries);
250 _file_tree_view->setRootIndex (_file_system_model-> 265 _file_tree_view->setRootIndex (_file_system_model->
251 index (fileInfo.absoluteFilePath ())); 266 index (fileInfo.absoluteFilePath ()));
252 _file_system_model->setRootPath (fileInfo.absoluteFilePath ()); 267 _file_system_model->setRootPath (fileInfo.absoluteFilePath ());
253 _file_system_model->sort (0, Qt::AscendingOrder); 268 _file_system_model->sort (0, Qt::AscendingOrder);
254 if (_sync_octave_dir && set_octave_dir) 269 if (_sync_octave_dir && set_octave_dir)
255 emit displayed_directory_changed (fileInfo.absoluteFilePath ()); 270 process_set_current_dir(fileInfo.absoluteFilePath ());
256 271
257 // see if its in the list, and if it is, remove it and then, put at top of the list 272 // see if its in the list, and if it is, remove it and then, put at top of the list
258 int index = _current_directory->findText(fileInfo.absoluteFilePath ()); 273 int index = _current_directory->findText(fileInfo.absoluteFilePath ());
259 if(index != -1) 274 if(index != -1)
260 { 275 {
447 { 462 {
448 QModelIndex index = rows[0]; 463 QModelIndex index = rows[0];
449 464
450 QFileInfo info = _file_system_model->fileInfo(index); 465 QFileInfo info = _file_system_model->fileInfo(index);
451 QString parent_dir = info.filePath(); 466 QString parent_dir = info.filePath();
452 bool ok; 467
453 468 process_new_file(parent_dir);
454 QString name = QInputDialog::getText (this, tr("Create File"), tr("Create file in\n") + parent_dir,
455 QLineEdit::Normal, "New File.txt", &ok);
456 if(ok && name.length()>0)
457 {
458 name = parent_dir + "/" + name;
459
460 QFile file(name);
461 file.open(QIODevice::WriteOnly);
462 _file_system_model->revert();
463 }
464 } 469 }
465 } 470 }
466 471
467 void 472 void
468 files_dock_widget::contextmenu_newdir (bool) 473 files_dock_widget::contextmenu_newdir (bool)
474 { 479 {
475 QModelIndex index = rows[0]; 480 QModelIndex index = rows[0];
476 481
477 QFileInfo info = _file_system_model->fileInfo(index); 482 QFileInfo info = _file_system_model->fileInfo(index);
478 QString parent_dir = info.filePath(); 483 QString parent_dir = info.filePath();
479 bool ok; 484
480 485 process_new_dir(parent_dir);
481 QString name = QInputDialog::getText (this, tr("Create Directory"), tr("Create folder in\n") + parent_dir,
482 QLineEdit::Normal, "New Directory", &ok);
483 if(ok && name.length()>0)
484 {
485 _file_system_model->mkdir(index, name);
486 }
487 } 486 }
488 } 487 }
489 488
490 void 489 void
491 files_dock_widget::contextmenu_setcurrentdir (bool) 490 files_dock_widget::contextmenu_setcurrentdir (bool)
499 498
500 QFileInfo info = _file_system_model->fileInfo(index); 499 QFileInfo info = _file_system_model->fileInfo(index);
501 500
502 if(info.isDir()) 501 if(info.isDir())
503 { 502 {
504 emit displayed_directory_changed (info.absoluteFilePath ()); 503 process_set_current_dir(info.absoluteFilePath ());
505 } 504 }
506 } 505 }
507 } 506 }
508 507
509 void 508 void
533 532
534 if (_sync_octave_dir) 533 if (_sync_octave_dir)
535 display_directory (_octave_dir); // sync browser to octave dir 534 display_directory (_octave_dir); // sync browser to octave dir
536 535
537 } 536 }
537
538 void
539 files_dock_widget::popdownmenu_newdir (bool)
540 {
541 process_new_dir(_file_system_model->rootPath());
542 }
543
544 void
545 files_dock_widget::popdownmenu_newfile (bool)
546 {
547 process_new_file(_file_system_model->rootPath());
548 }
549
550 void
551 files_dock_widget::process_new_file (const QString &parent_dir)
552 {
553 bool ok;
554
555 QString name = QInputDialog::getText (this, tr("Create File"), tr("Create file in\n") + parent_dir,
556 QLineEdit::Normal, "New File.txt", &ok);
557 if(ok && name.length()>0)
558 {
559 name = parent_dir + "/" + name;
560
561 QFile file(name);
562 file.open(QIODevice::WriteOnly);
563 _file_system_model->revert();
564 }
565 }
566
567 void
568 files_dock_widget::process_new_dir (const QString &parent_dir)
569 {
570 bool ok;
571
572 QString name = QInputDialog::getText (this, tr("Create Directory"), tr("Create folder in\n") + parent_dir,
573 QLineEdit::Normal, "New Directory", &ok);
574 if(ok && name.length()>0)
575 {
576 QDir dir(parent_dir);
577 dir.mkdir(name);
578 _file_system_model->revert();
579 }
580 }
581
582 void files_dock_widget::process_set_current_dir(const QString & dir)
583 {
584 emit displayed_directory_changed (dir);
585 }
586