2016-07-19 00:12:25 +03:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
#include <FL/Fl.H>
|
|
|
|
|
2023-01-27 13:35:05 +03:00
|
|
|
#include "fluid.h"
|
|
|
|
|
2016-07-19 00:12:25 +03:00
|
|
|
#include <errno.h> /* errno */
|
|
|
|
#include <string.h> /* strerror() */
|
|
|
|
#include <sys/types.h> /* stat().. */
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
// ---- ExternalCodeEditor declaration
|
|
|
|
|
2016-07-19 00:12:25 +03:00
|
|
|
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_;
|
2023-02-23 17:42:05 +03:00
|
|
|
Fl_String command_line_;
|
2023-01-27 13:35:05 +03:00
|
|
|
int last_error_;
|
|
|
|
int alert_pipe_[2];
|
2023-01-29 13:51:44 +03:00
|
|
|
bool alert_pipe_open_;
|
2023-01-27 13:35:05 +03:00
|
|
|
static void alert_pipe_cb(FL_SOCKET, void*);
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2016-07-19 00:12:25 +03:00
|
|
|
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);
|
2023-01-29 13:51:44 +03:00
|
|
|
void open_alert_pipe();
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2016-07-19 00:12:25 +03:00
|
|
|
public:
|
|
|
|
ExternalCodeEditor();
|
|
|
|
~ExternalCodeEditor();
|
|
|
|
int is_editing();
|
2020-06-19 04:24:45 +03:00
|
|
|
int reap_editor(pid_t *pid_reaped=NULL);
|
2016-08-17 00:20:06 +03:00
|
|
|
void close_editor();
|
2016-07-19 00:12:25 +03:00
|
|
|
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 */
|