comparison libgui/src/octave-qt-link.cc @ 17884:766ad9be2966

Prompt for non-existent new file when using edit.m from GUI (bug #40450) * libgui/src/octave-qt-link.cc(do_prompt_new_edit_file): New function to display question dialog. * libgui/src/octave-qt-link.h(do_prompt_new_edit_file): Add function to header file. * libinterp/corefcn/octave-link.cc(__octave_link_edit_file__): If 2nd argument present, display prompt dialog. * libinterp/corefcn/octave-link.h(prompt_new_edit_file): If octave-link enabled, use prompt dialog box. * scripts/miscellaneous/edit.m: Modify to use new prompt routine. CLI behavior is unchanged.
author Torsten <ttl@justmail.de>
date Fri, 08 Nov 2013 07:40:36 -0800
parents 86e8dbccf7c7
children a38cee8f0a9b
comparison
equal deleted inserted replaced
17883:3851e5fde76d 17884:766ad9be2966
25 #ifdef HAVE_CONFIG_H 25 #ifdef HAVE_CONFIG_H
26 #include <config.h> 26 #include <config.h>
27 #endif 27 #endif
28 28
29 #include <QStringList> 29 #include <QStringList>
30 #include <QDialog>
31 #include <QDir>
30 32
31 #include "str-vec.h" 33 #include "str-vec.h"
32 #include "dialog.h" 34 #include "dialog.h"
33 #include "error.h" 35 #include "error.h"
34 #include "workspace-element.h" 36 #include "workspace-element.h"
37 #include "oct-env.h" 39 #include "oct-env.h"
38 #include "utils.h" 40 #include "utils.h"
39 41
40 #include "octave-qt-link.h" 42 #include "octave-qt-link.h"
41 43
44 #include "resource-manager.h"
45
42 octave_qt_link::octave_qt_link (octave_main_thread *mt) 46 octave_qt_link::octave_qt_link (octave_main_thread *mt)
43 : octave_link (), main_thread (mt) 47 : octave_link (), main_thread (mt)
44 { } 48 { }
45 49
46 octave_qt_link::~octave_qt_link (void) { } 50 octave_qt_link::~octave_qt_link (void) { }
63 octave_qt_link::do_edit_file (const std::string& file) 67 octave_qt_link::do_edit_file (const std::string& file)
64 { 68 {
65 emit edit_file_signal (QString::fromStdString (file)); 69 emit edit_file_signal (QString::fromStdString (file));
66 70
67 return true; 71 return true;
72 }
73
74 bool
75 octave_qt_link::do_prompt_new_edit_file (const std::string& file)
76 {
77 QSettings *settings = resource_manager::get_settings ();
78
79 if (settings->value ("editor/create_new_file",false).toBool ())
80 return true;
81
82 QFileInfo file_info (QString::fromStdString (file));
83 QStringList btn;
84 QStringList role;
85 role << "AcceptRole" << "AcceptRole";
86 btn << tr ("Yes") << tr ("No");
87
88 uiwidget_creator.signal_dialog (
89 tr ("File\n%1\ndoes not exist. Do you want to create it?").
90 arg (QDir::currentPath () + QDir::separator ()
91 + QString::fromStdString (file)),
92 tr ("Octave Editor"), "quest", btn, tr ("Yes"), role );
93
94 // Wait while the user is responding to message box.
95 uiwidget_creator.wait ();
96 // The GUI has sent a signal and the process has been awakened.
97 QString answer = uiwidget_creator.get_dialog_button ();
98
99 return (answer == tr ("Yes"));
68 } 100 }
69 101
70 int 102 int
71 octave_qt_link::do_message_dialog (const std::string& dlg, 103 octave_qt_link::do_message_dialog (const std::string& dlg,
72 const std::string& msg, 104 const std::string& msg,