summaryrefslogtreecommitdiff
path: root/fluid/ExternalCodeEditor_UNIX.h
blob: a619cd352abdf2894c6a4b8efef7c01dac0e91d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
//       External code editor management class for Unix
//
//       Handles starting and keeping track of an external text editor,
//       including process start, temp file creation/removal, bookkeeping, killing..
//
#ifndef _EXTCODEEDITOR_H
#define _EXTCODEEDITOR_H

#include <FL/Fl.H>

#include "fluid.h"

#include <errno.h>      /* errno */
#include <string.h>     /* strerror() */
#include <sys/types.h>  /* stat().. */
#include <sys/stat.h>
#include <unistd.h>

// ---- ExternalCodeEditor declaration

class ExternalCodeEditor {
  int pid_;
  time_t file_mtime_;                   // last modify time of the file (used to determine if file changed)
  size_t file_size_;                    // last file size (used to determine if changed)
  const char *filename_;
  Fl_String command_line_;
  int last_error_;
  int alert_pipe_[2];
  bool alert_pipe_open_;
  static void alert_pipe_cb(FL_SOCKET, void*);

protected:
  void kill_editor();
  const char *create_tmpdir();
  const char *tmp_filename();
  int start_editor(const char *cmd, const char *filename);
  void set_filename(const char *val);
  void open_alert_pipe();

public:
  ExternalCodeEditor();
  ~ExternalCodeEditor();
  int is_editing();
  int reap_editor(pid_t *pid_reaped=NULL);
  void close_editor();
  const char *filename() { return filename_; }
  int open_editor(const char *editor_cmd, const char *code);
  int handle_changes(const char **code, int force=0);
  int remove_tmpfile();
  // Public static methods
  static void start_update_timer();
  static void stop_update_timer();
  static const char* tmpdir_name();
  static void tmpdir_clear();
  static int editors_open();
  static void set_update_timer_callback(Fl_Timeout_Handler);
};

#endif /*_EXTCODEEDITOR_H */