comparison libgui/src/main-window.cc @ 16502:45ae1038ee89

allow renaming of variables in workspace viewer * main-window.h, main-window.cc (main_window::handle_rename_variable_request): New function. (main_window::construct_octave_qt_link): Connect _workspace_model::rename_variable to main_window::handle_rename_variable_request. (main_window::rename_variable_callback): New function. * octave-qt-link.h, octave-qt-link.cc (octave_qt_link::do_set_workspace, octave_qt_link::set_workspace_signal): New argument, top_level. Change all uses. * octave-link.h, octave-link.cc (octave_link::post_event): Provide two-argument version. (octave_link::set_workspace, octave_link::do_set_workspace): New argument, top_level. Change all uses. * workspace-model.h, workspace-model.cc (workspace_model::flags): Conditionally add Qt::ItemIsEditable to flags. (workspace_model::data): Also return value for column 0 if it is editable. (workspace_model::setData): Handle setting new values. (workspace_model::_top_level): New data member. (workspace_model::set_workspace): New argument, top_level. (workspace_model::rename_variable): New signal. * workspace-view.h, workspace-view.cc (variable_name_editor): New class. (workspace_view::var_name_editor): New data member. (workspace_view::workspace_view): Initialize it. Set var_name_editor as delegate for column 0. (workspace_view::~workspace_view): Delete var_name_editor. (workspace_view::item_double_clicked): Delete. * symtab.h (symbol_table::rename, symbol_table::do_rename, symbol_table::symbol_record::rename): New functions.
author John W. Eaton <jwe@octave.org>
date Fri, 12 Apr 2013 14:50:56 -0400
parents facf00ce97d3
children 49b059bf27c7
comparison
equal deleted inserted replaced
16501:3781abc74540 16502:45ae1038ee89
37 #include <QDesktopWidget> 37 #include <QDesktopWidget>
38 #include <QFileDialog> 38 #include <QFileDialog>
39 #include <QMessageBox> 39 #include <QMessageBox>
40 #include <QIcon> 40 #include <QIcon>
41 41
42 #include <utility>
43
42 #ifdef HAVE_QSCINTILLA 44 #ifdef HAVE_QSCINTILLA
43 #include "file-editor.h" 45 #include "file-editor.h"
44 #endif 46 #endif
45 #include "main-window.h" 47 #include "main-window.h"
46 #include "settings-dialog.h" 48 #include "settings-dialog.h"
47 49
48 #include "cmd-edit.h" 50 #include "cmd-edit.h"
49 51
50 #include "builtin-defun-decls.h" 52 #include "builtin-defun-decls.h"
51 #include "defaults.h" 53 #include "defaults.h"
54 #include "symtab.h"
52 #include "version.h" 55 #include "version.h"
53 56
54 static file_editor_interface * 57 static file_editor_interface *
55 create_default_editor (QWidget *p) 58 create_default_editor (QWidget *p)
56 { 59 {
143 146
144 void 147 void
145 main_window::handle_clear_workspace_request (void) 148 main_window::handle_clear_workspace_request (void)
146 { 149 {
147 octave_link::post_event (this, &main_window::clear_workspace_callback); 150 octave_link::post_event (this, &main_window::clear_workspace_callback);
151 }
152
153 void
154 main_window::handle_rename_variable_request (const QString& old_name,
155 const QString& new_name)
156
157 {
158 name_pair names (old_name.toStdString (), new_name.toStdString ());
159
160 octave_link::post_event (this, &main_window::rename_variable_callback,
161 names);
148 } 162 }
149 163
150 void 164 void
151 main_window::handle_clear_history_request (void) 165 main_window::handle_clear_history_request (void)
152 { 166 {
596 connect (_octave_qt_link, SIGNAL (exit_signal (int)), 610 connect (_octave_qt_link, SIGNAL (exit_signal (int)),
597 this, SLOT (exit (int))); 611 this, SLOT (exit (int)));
598 612
599 connect (_octave_qt_link, 613 connect (_octave_qt_link,
600 SIGNAL (set_workspace_signal 614 SIGNAL (set_workspace_signal
601 (const QString&, const QStringList&, const QStringList&, 615 (bool, const QString&, const QStringList&,
602 const QStringList&, const QStringList&)), 616 const QStringList&, const QStringList&,
617 const QStringList&)),
603 _workspace_model, 618 _workspace_model,
604 SLOT (set_workspace 619 SLOT (set_workspace
605 (const QString&, const QStringList&,const QStringList&, 620 (bool, const QString&, const QStringList&,
606 const QStringList&, const QStringList&))); 621 const QStringList&, const QStringList&,
622 const QStringList&)));
607 623
608 connect (_octave_qt_link, SIGNAL (clear_workspace_signal ()), 624 connect (_octave_qt_link, SIGNAL (clear_workspace_signal ()),
609 _workspace_model, SLOT (clear_workspace ())); 625 _workspace_model, SLOT (clear_workspace ()));
610 626
611 connect (_octave_qt_link, SIGNAL (change_directory_signal (QString)), 627 connect (_octave_qt_link, SIGNAL (change_directory_signal (QString)),
646 662
647 connect (_octave_qt_link, 663 connect (_octave_qt_link,
648 SIGNAL (delete_debugger_pointer_signal (const QString&, int)), 664 SIGNAL (delete_debugger_pointer_signal (const QString&, int)),
649 editor_window, 665 editor_window,
650 SLOT (handle_delete_debugger_pointer_request (const QString&, int))); 666 SLOT (handle_delete_debugger_pointer_request (const QString&, int)));
667
668 connect (_workspace_model,
669 SIGNAL (rename_variable (const QString&, const QString&)),
670 this,
671 SLOT (handle_rename_variable_request (const QString&,
672 const QString&)));
651 673
652 _octave_qt_link->execute_interpreter (); 674 _octave_qt_link->execute_interpreter ();
653 675
654 octave_link::connect_link (_octave_qt_link); 676 octave_link::connect_link (_octave_qt_link);
655 } 677 }
1182 { 1204 {
1183 Fclear (); 1205 Fclear ();
1184 } 1206 }
1185 1207
1186 void 1208 void
1209 main_window::rename_variable_callback (const main_window::name_pair& names)
1210 {
1211 /* bool status = */ symbol_table::rename (names.first, names.second);
1212
1213 // if (status)
1214 octave_link::set_workspace (true, symbol_table::workspace_info ());
1215
1216 // else
1217 // ; // we need an octave_link action that runs a GUI error option.
1218 }
1219
1220 void
1187 main_window::clear_history_callback (void) 1221 main_window::clear_history_callback (void)
1188 { 1222 {
1189 Fhistory (ovl ("-c")); 1223 Fhistory (ovl ("-c"));
1190 } 1224 }
1191 1225