Mercurial > hg > octave-shane
changeset 16565:e4b94abfeb96
use generic dialog for cd or addpath question
* dialog.h, dialog.cc (cd_or_addpath_dialog): Delete class.
(QUIWidgetCreator::get_dialog_button): Return QString, not QString*.
Change all uses.
(QUIWidgetCreator::signal_debug_cd_or_addpath): Delete.
(QUIWidgetCreator::create_debug_cd_or_addpath_dialog): Delete.
* file-editor-tab.cc (file_editor_tab::file_in_path): Also use
same_file to compare curr_dir and info.path.
* main-window.h, main-window.cc
(main_window::handle_create_debug_cd_or_addpath_dialog): Delete.
(main_window::connect_uiwidget_links): Delete connection from
uiwidget_creator::create_debug_cd_or_addpath_dialog to
main_window::handle_create_debug_cd_or_addpath_dialog.
* octave-qt-link.cc (octave_qt_link::do_debug_cd_or_addpath_error):
Use generic dialog for cd or addpath question.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 25 Apr 2013 00:11:01 -0400 |
parents | aa5299a1d770 |
children | 662a712b8fd5 |
files | libgui/src/dialog.cc libgui/src/dialog.h libgui/src/m-editor/file-editor-tab.cc libgui/src/main-window.cc libgui/src/main-window.h libgui/src/octave-qt-link.cc |
diffstat | 6 files changed, 41 insertions(+), 145 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/dialog.cc +++ b/libgui/src/dialog.cc @@ -403,84 +403,3 @@ { buttonCancel_clicked (); } - - -cd_or_addpath_dialog::cd_or_addpath_dialog (const QString& file, - const QString& dir, - bool addpath_option) - : QDialog () -{ - QString prompt_string - = (addpath_option - ? tr ("The file %1 does not exist in the load path. To debug the function you are editing, you must either change to the directory %2 or add that directory to the load path.").arg(file).arg(dir) - : tr ("The file %1 is shadowed by a file with the same name in the load path. To debug the function you are editing, change to the directory %2.").arg(file).arg(dir)); - - QLabel *label = new QLabel (prompt_string); - label->setFixedWidth (500); - label->setWordWrap (true); - // QIcon *question_mark = new QIcon; - QHBoxLayout *horizontalLayout = new QHBoxLayout; - // horizontalLayout->addWidget (question_mark); - horizontalLayout->addWidget (label); - - QPushButton *buttonCd = new QPushButton (tr ("Change directory")); - QPushButton *buttonAddpath = 0; - if (addpath_option) - buttonAddpath = new QPushButton (tr ("Add directory to load path")); - QPushButton *buttonCancel = new QPushButton (tr ("Cancel")); - - QHBoxLayout *buttonsLayout = new QHBoxLayout; - buttonsLayout->addStretch (1); - buttonsLayout->addWidget (buttonCd); - if (addpath_option) - buttonsLayout->addWidget (buttonAddpath); - buttonsLayout->addWidget (buttonCancel); - - QVBoxLayout *mainLayout = new QVBoxLayout; - mainLayout->addLayout (horizontalLayout); - mainLayout->addSpacing (12); - mainLayout->addLayout (buttonsLayout); - setLayout (mainLayout); - - setWindowTitle (tr ("Change Directory or Add Directory to Load Path")); - - connect (buttonCd, SIGNAL (clicked ()), - this, SLOT (buttonCd_clicked ())); - - if (addpath_option) - connect (buttonAddpath, SIGNAL (clicked ()), - this, SLOT (buttonAddpath_clicked ())); - - connect (buttonCancel, SIGNAL (clicked ()), - this, SLOT (buttonCancel_clicked ())); - - connect (this, SIGNAL (finished (int)), - &uiwidget_creator, SLOT (dialog_finished (int))); -} - -void -cd_or_addpath_dialog::buttonCd_clicked (void) -{ - emit finished (1); - done (QDialog::Accepted); -} - -void -cd_or_addpath_dialog::buttonAddpath_clicked (void) -{ - emit finished (2); - done (QDialog::Accepted); -} - -void -cd_or_addpath_dialog::buttonCancel_clicked (void) -{ - emit finished (-1); - done (QDialog::Rejected); -} - -void -cd_or_addpath_dialog::reject (void) -{ - buttonCancel_clicked (); -}
--- a/libgui/src/dialog.h +++ b/libgui/src/dialog.h @@ -71,7 +71,7 @@ int get_dialog_result (void) { return dialog_result; } - const QString *get_dialog_button (void) { return &dialog_button; } + QString get_dialog_button (void) { return dialog_button; } bool signal_listview (const QStringList& list, const QString& mode, int wd, int ht, const QList<int>& initial, @@ -101,17 +101,6 @@ return true; }; - // The debug dialog functionality may not really belong here, but it - // seems like the easiest thing to do at the moment. - - bool signal_debug_cd_or_addpath (const QString& file, const QString& dir, - bool addpath_option) - { - emit create_debug_cd_or_addpath_dialog (file, dir, addpath_option); - - return true; - } - const QStringList *get_string_list (void) { return string_list; } void wait (void) @@ -133,8 +122,6 @@ const QFloatList&, const QFloatList&, const QStringList&); - void create_debug_cd_or_addpath_dialog (const QString&, const QString&, bool); - public slots: void dialog_button_clicked (QAbstractButton *button); @@ -240,24 +227,4 @@ void reject (void); }; -class cd_or_addpath_dialog : public QDialog -{ - Q_OBJECT - -public: - - cd_or_addpath_dialog (const QString& file, const QString& dir, - bool addpath_option); - -public slots: - - void buttonCd_clicked (void); - - void buttonAddpath_clicked (void); - - void buttonCancel_clicked (void); - - void reject (void); -}; - #endif
--- a/libgui/src/m-editor/file-editor-tab.cc +++ b/libgui/src/m-editor/file-editor-tab.cc @@ -449,7 +449,7 @@ std::string curr_dir = octave_env::get_current_directory (); - if (curr_dir == info.path) + if (same_file (curr_dir, info.path)) ok = true; else {
--- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -592,14 +592,6 @@ SLOT (handle_create_inputlayout (const QStringList&, const QString&, const QFloatList&, const QFloatList&, const QStringList&))); - - connect (&uiwidget_creator, - SIGNAL (create_debug_cd_or_addpath_dialog (const QString&, - const QString&, bool)), - this, - SLOT (handle_create_debug_cd_or_addpath_dialog (const QString&, - const QString&, - bool))); } // Create a message dialog with specified string, buttons and decorative @@ -656,19 +648,6 @@ input_dialog->show (); } -void -main_window::handle_create_debug_cd_or_addpath_dialog (const QString& file, - const QString& dir, - bool addpath_option) - -{ - cd_or_addpath_dialog *dialog - = new cd_or_addpath_dialog (file, dir, addpath_option); - - dialog->setAttribute (Qt::WA_DeleteOnClose); - dialog->show (); -} - // Main subroutine of the constructor void main_window::construct (void)
--- a/libgui/src/main-window.h +++ b/libgui/src/main-window.h @@ -142,9 +142,6 @@ const QFloatList&, const QFloatList&, const QStringList&); - void handle_create_debug_cd_or_addpath_dialog (const QString& file, - const QString& dir, - bool addpath_option); // find files dialog void find_files(const QString &startdir=QDir::currentPath()); void find_files_finished(int);
--- a/libgui/src/octave-qt-link.cc +++ b/libgui/src/octave-qt-link.cc @@ -111,7 +111,7 @@ uiwidget_creator.wait (); // The GUI has sent a signal and the process has been awakened. - return uiwidget_creator.get_dialog_button ()->toStdString (); + return uiwidget_creator.get_dialog_button().toStdString (); } static QStringList @@ -193,13 +193,47 @@ const std::string& dir, bool addpath_option) { - uiwidget_creator.signal_debug_cd_or_addpath (QString::fromStdString (file), - QString::fromStdString (dir), - addpath_option); + int retval = -1; + + QString qdir = QString::fromStdString (dir); + QString qfile = QString::fromStdString (file); + + QString msg + = (addpath_option + ? tr ("The file %1 does not exist in the load path. To debug the function you are editing, you must either change to the directory %2 or add that directory to the load path.").arg(qfile).arg(qdir) + : tr ("The file %1 is shadowed by a file with the same name in the load path. To debug the function you are editing, change to the directory %2.").arg(qfile).arg(qdir)); + + QString title = tr ("Change Directory or Add Directory to Load Path"); + + QString cd_txt = tr ("Change Directory"); + QString addpath_txt = tr ("Add Directory to Load Path"); + QString cancel_txt = tr ("Cancel"); + QStringList btn; + QStringList role; + btn << cd_txt; + role << "AcceptRole"; + if (addpath_option) + { + btn << addpath_txt; + role << "AcceptRole"; + } + btn << cancel_txt; + role << "AcceptRole"; + + uiwidget_creator.signal_dialog (msg, title, "quest", btn, cancel_txt, role); + + // Wait while the user is responding to message box. uiwidget_creator.wait (); - return uiwidget_creator.get_dialog_result (); + QString result = uiwidget_creator.get_dialog_button (); + + if (result == cd_txt) + retval = 1; + else if (result == addpath_txt) + retval = 2; + + return retval; } void