view libgui/src/octave-qt-link.h @ 16547:3cd80afc3509

improve debugging with the GUI * dialog.h, dialog.cc (cd_or_addpath_dialog): New class. (QUIWidgetCreator::signal_debug_cd_or_addpath): New function. (QUIWidgetCreator::create_debug_cd_or_addpath_dialog): New signal. * file-editor-tab.h, file-editor-tab.cc (file_editor_tab::file_in_path): New function. (file_editor_tab::add_breakpoint_callback, file_editor_tab::remove_breakpoint_callback, file_editor_tab::remove_all_breakpoints_callback): Use file_in_path. Don't cd to the directory containing the file. Don't add 1 to the line number. (file_editor_tab::request_add_breakpoint, file_editor_tab::request_remove_breakpoint): Add 1 to the line number. (file_editor_tab::insert_debugger_pointer, file_editor_tab::delete_debugger_pointer, file_editor_tab::do_breakpoint_marker): Subtract 1 from line. (file_editor_tab::bp_info): Also cache full file name. Change all uses. * file-editor.h, file-editor.cc (file_editor::request_open_file, file_editor::handle_delete_debugger_pointer_request): Don't subtract 1 from line numbers. * main-window.h, main-window.cc (main_window::connect_uiwidget_links): Connect uiwidget_creator::create_debug_cd_or_addpath_dialog to main_window::handle_create_debug_cd_or_addpath_dialog. (main_window::handle_create_debug_cd_or_addpath_dialog): New function. * octave-qt-link.h, octave-qt-link.cc (octave_qt_link::do_debug_cd_or_addpath_error): New function. * load-path.h, load-path.cc (load_path::contains_canonical, load_path::do_contains_canonical): New functions. * octave-link.h (octave_link::debug_cd_or_addpath_error, octave_link::do_debug_cd_or_addpath_error): New functions.
author John W. Eaton <jwe@octave.org>
date Fri, 19 Apr 2013 17:36:40 -0400
parents 9bc1f8278966
children 6ae555fc8c43
line wrap: on
line source

/*

Copyright (C) 2013 John W. Eaton
Copyright (C) 2011-2012 Jacob Dawid
Copyright (C) 2011-2012 John P. Swensen

This file is part of Octave.

Octave is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3 of the License, or (at your
option) any later version.

Octave is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with Octave; see the file COPYING.  If not, see
<http://www.gnu.org/licenses/>.

*/

#ifndef OCTAVE_QT_LINK_H
#define OCTAVE_QT_LINK_H

#include <list>
#include <string>

#include <QList>
#include <QObject>
#include <QString>

#include "octave-link.h"
#include "octave-main-thread.h"

// \class OctaveLink
// \brief Provides threadsafe access to octave.
// \author Jacob Dawid
//
// This class is a wrapper around octave and provides thread safety by
// buffering access operations to octave and executing them in the
// readline event hook, which lives in the octave thread.

class octave_qt_link : public QObject, public octave_link
{
  Q_OBJECT

public:

  octave_qt_link (octave_main_thread *mt);

  ~octave_qt_link (void);

  void execute_interpreter (void);

  bool do_exit (int status);

  bool do_edit_file (const std::string& file);

  int do_message_dialog (const std::string& dlg, const std::string& msg,
                         const std::string& title);

  std::pair<std::list<int>, int>
  do_list_dialog (const std::list<std::string>& list,
                  const std::string& mode,
                  int width, int height,
                  const std::list<int>& initial_value,
                  const std::string& name,
                  const std::string& prompt_string,
                  const std::string& ok_string,
                  const std::string& cancel_string);

  std::list<std::string>
  do_input_dialog (const std::list<std::string>& prompt,
                   const std::string& title,
                   const std::list<int>& nr,
                   const std::list<int>& nc,
                   const std::list<std::string>& defaults);

  int
  do_debug_cd_or_addpath_error (const std::string& file,
                                const std::string& dir,
                                bool addpath_option);

  void do_change_directory (const std::string& dir);

  void do_set_workspace (bool top_level,
                         const std::list<workspace_element>& ws);

  void do_clear_workspace (void);

  void do_set_history (const string_vector& hist);
  void do_append_history (const std::string& hist_entry);
  void do_clear_history (void);

  void do_pre_input_event (void);
  void do_post_input_event (void);

  void do_enter_debugger_event (const std::string& file, int line);
  void do_execute_in_debugger_event (const std::string& file, int line);
  void do_exit_debugger_event (void);

  void do_update_breakpoint (bool insert, const std::string& file, int line);

  void do_set_default_prompts (std::string& ps1, std::string& ps2,
                               std::string& ps4);

private:

  // No copying!

  octave_qt_link (const octave_qt_link&);

  octave_qt_link& operator = (const octave_qt_link&);

  void do_insert_debugger_pointer (const std::string& file, int line);
  void do_delete_debugger_pointer (const std::string& file, int line);

  // Thread running octave_main.
  octave_main_thread *main_thread;

signals:

  void exit_signal (int status);

  void edit_file_signal (const QString& file);

  void change_directory_signal (const QString& dir);

  void set_workspace_signal (bool top_level,
                             const QString& scopes,
                             const QStringList& symbols,
                             const QStringList& class_names,
                             const QStringList& dimensions,
                             const QStringList& values);

  void clear_workspace_signal (void);

  void set_history_signal (const QStringList& hist);
  void append_history_signal (const QString& hist_entry);
  void clear_history_signal (void);

  void enter_debugger_signal (void);
  void exit_debugger_signal (void);

  void update_breakpoint_marker_signal (bool insert, const QString& file,
                                        int line);

  void insert_debugger_pointer_signal (const QString&, int);
  void delete_debugger_pointer_signal (const QString&, int);
};

#endif