2021-12-08 14:52:15 +00:00
|
|
|
//
|
2025-03-16 21:16:12 +00:00
|
|
|
// Shell Command database header for the Fast Light Tool Kit (FLTK).
|
2021-12-08 14:52:15 +00:00
|
|
|
//
|
2025-03-16 21:16:12 +00:00
|
|
|
// Copyright 1998-2025 by Bill Spitzak and others.
|
2021-12-08 14:52:15 +00:00
|
|
|
//
|
|
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
|
//
|
|
|
|
|
// https://www.fltk.org/COPYING.php
|
|
|
|
|
//
|
|
|
|
|
// Please see the following page on how to report bugs and issues:
|
|
|
|
|
//
|
|
|
|
|
// https://www.fltk.org/bugs.php
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#ifndef _FLUID_SHELL_COMMAND_H
|
|
|
|
|
#define _FLUID_SHELL_COMMAND_H
|
|
|
|
|
|
2025-03-16 21:16:12 +00:00
|
|
|
#include "Fluid.h"
|
2021-12-08 14:52:15 +00:00
|
|
|
|
2023-09-26 14:01:03 +00:00
|
|
|
#include <FL/Enumerations.H>
|
2023-03-19 19:04:01 +00:00
|
|
|
|
2023-09-26 14:01:03 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
2025-03-07 00:15:57 +00:00
|
|
|
#include <string>
|
2021-12-08 14:52:15 +00:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
|
|
|
|
# include <direct.h>
|
|
|
|
|
# include <windows.h>
|
|
|
|
|
# include <io.h>
|
|
|
|
|
# include <fcntl.h>
|
|
|
|
|
# include <commdlg.h>
|
|
|
|
|
# include <FL/platform.H>
|
|
|
|
|
#else
|
|
|
|
|
# include <unistd.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
2025-03-07 23:14:09 +00:00
|
|
|
namespace fld {
|
|
|
|
|
namespace io {
|
|
|
|
|
|
|
|
|
|
class Project_Reader;
|
|
|
|
|
class Project_Writer;
|
|
|
|
|
|
|
|
|
|
} // namespace io
|
|
|
|
|
} // namespace fld
|
|
|
|
|
|
2023-09-26 14:01:03 +00:00
|
|
|
struct Fl_Menu_Item;
|
|
|
|
|
class Fl_Widget;
|
2023-10-21 16:41:51 +00:00
|
|
|
class Fl_Preferences;
|
|
|
|
|
|
2023-12-14 18:40:29 +00:00
|
|
|
void show_terminal_window();
|
2025-03-06 23:48:18 +00:00
|
|
|
void run_shell_command(const std::string &cmd, int flags);
|
2023-11-30 14:02:15 +00:00
|
|
|
bool shell_command_running(void);
|
2021-12-08 14:52:15 +00:00
|
|
|
|
2025-03-16 21:16:12 +00:00
|
|
|
|
2021-12-08 14:52:15 +00:00
|
|
|
class Fl_Process {
|
|
|
|
|
public:
|
|
|
|
|
Fl_Process();
|
|
|
|
|
~Fl_Process();
|
|
|
|
|
|
|
|
|
|
FILE *popen(const char *cmd, const char *mode="r");
|
|
|
|
|
int close();
|
|
|
|
|
|
|
|
|
|
FILE * desc() const;
|
|
|
|
|
char * get_line(char * line, size_t s) const;
|
|
|
|
|
|
|
|
|
|
int get_fileno() const;
|
|
|
|
|
|
2023-01-01 19:05:42 +00:00
|
|
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
2021-12-08 14:52:15 +00:00
|
|
|
protected:
|
|
|
|
|
HANDLE pin[2], pout[2], perr[2];
|
|
|
|
|
char ptmode;
|
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
|
STARTUPINFO si;
|
|
|
|
|
|
|
|
|
|
static bool createPipe(HANDLE * h, BOOL bInheritHnd=TRUE);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
FILE * freeHandles();
|
|
|
|
|
static void clean_close(HANDLE& h);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
protected:
|
2025-03-16 21:16:12 +00:00
|
|
|
FILE * _fpt = nullptr;
|
2021-12-08 14:52:15 +00:00
|
|
|
};
|
|
|
|
|
|
2025-03-16 21:16:12 +00:00
|
|
|
|
2023-09-26 14:01:03 +00:00
|
|
|
class Fd_Shell_Command {
|
|
|
|
|
public:
|
|
|
|
|
enum { ALWAYS, NEVER, MAC_ONLY, UX_ONLY, WIN_ONLY, MAC_AND_UX_ONLY, USER_ONLY, HOST_ONLY, ENV_ONLY }; // conditions
|
2023-12-14 18:40:29 +00:00
|
|
|
enum { SAVE_PROJECT = 1, SAVE_SOURCECODE = 2, SAVE_STRINGS = 4, SAVE_ALL = 7,
|
|
|
|
|
DONT_SHOW_TERMINAL = 8, CLEAR_TERMINAL = 16, CLEAR_HISTORY = 32 }; // flags
|
2023-09-26 14:01:03 +00:00
|
|
|
Fd_Shell_Command();
|
|
|
|
|
Fd_Shell_Command(const Fd_Shell_Command *rhs);
|
2025-03-06 23:48:18 +00:00
|
|
|
Fd_Shell_Command(const std::string &in_name);
|
|
|
|
|
Fd_Shell_Command(const std::string &in_name,
|
|
|
|
|
const std::string &in_label,
|
2023-09-26 14:01:03 +00:00
|
|
|
Fl_Shortcut in_shortcut,
|
2025-03-16 21:16:12 +00:00
|
|
|
fld::Tool_Store in_storage,
|
2023-09-26 14:01:03 +00:00
|
|
|
int in_condition,
|
2025-03-06 23:48:18 +00:00
|
|
|
const std::string &in_condition_data,
|
|
|
|
|
const std::string &in_command,
|
2023-09-26 14:01:03 +00:00
|
|
|
int in_flags);
|
2025-03-16 21:16:12 +00:00
|
|
|
std::string name { };
|
|
|
|
|
std::string label { };
|
|
|
|
|
Fl_Shortcut shortcut = 0;
|
|
|
|
|
fld::Tool_Store storage = fld::Tool_Store::USER;
|
|
|
|
|
int condition = ALWAYS; // always, hide, windows only, linux only, mac only, user, machine
|
|
|
|
|
std::string condition_data { }; // user name, machine name
|
|
|
|
|
std::string command { };
|
|
|
|
|
int flags = 0; // save_project, save_code, save_string, ...
|
2023-09-26 14:01:03 +00:00
|
|
|
Fl_Menu_Item *shell_menu_item_;
|
|
|
|
|
void run();
|
|
|
|
|
void read(Fl_Preferences &prefs);
|
|
|
|
|
void write(Fl_Preferences &prefs, bool save_location = false);
|
2025-03-07 23:14:09 +00:00
|
|
|
void read(class fld::io::Project_Reader*);
|
|
|
|
|
void write(class fld::io::Project_Writer*);
|
2023-09-26 14:01:03 +00:00
|
|
|
void update_shell_menu();
|
|
|
|
|
bool is_active();
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-16 21:16:12 +00:00
|
|
|
|
2023-09-26 14:01:03 +00:00
|
|
|
class Fd_Shell_Command_List {
|
|
|
|
|
public:
|
2025-03-16 21:16:12 +00:00
|
|
|
Fd_Shell_Command **list = nullptr;
|
|
|
|
|
int list_size = 0;
|
|
|
|
|
int list_capacity = 0;
|
|
|
|
|
Fl_Menu_Item *shell_menu_ = nullptr;
|
2023-09-26 14:01:03 +00:00
|
|
|
public:
|
|
|
|
|
Fd_Shell_Command_List();
|
|
|
|
|
~Fd_Shell_Command_List();
|
|
|
|
|
Fd_Shell_Command *at(int index) const;
|
|
|
|
|
void add(Fd_Shell_Command *cmd);
|
|
|
|
|
void insert(int index, Fd_Shell_Command *cmd);
|
|
|
|
|
void remove(int index);
|
|
|
|
|
void clear();
|
2025-03-16 21:16:12 +00:00
|
|
|
void clear(fld::Tool_Store store);
|
2023-09-26 14:01:03 +00:00
|
|
|
// void move_up();
|
|
|
|
|
// void move_down();
|
2025-03-06 23:48:18 +00:00
|
|
|
// int load(const std::string &filename);
|
|
|
|
|
// int save(const std::string &filename);
|
2025-03-16 21:16:12 +00:00
|
|
|
void read(Fl_Preferences &prefs, fld::Tool_Store storage);
|
|
|
|
|
void write(Fl_Preferences &prefs, fld::Tool_Store storage);
|
2025-03-07 23:14:09 +00:00
|
|
|
void read(class fld::io::Project_Reader*);
|
|
|
|
|
void write(class fld::io::Project_Writer*);
|
2023-09-26 14:01:03 +00:00
|
|
|
void rebuild_shell_menu();
|
|
|
|
|
void update_settings_dialog();
|
|
|
|
|
|
|
|
|
|
static Fl_Menu_Item default_menu[];
|
|
|
|
|
static void menu_marker(Fl_Widget*, void*);
|
|
|
|
|
static void export_selected();
|
|
|
|
|
static void import_from_file();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extern Fd_Shell_Command_List *g_shell_config;
|
|
|
|
|
|
2021-12-08 14:52:15 +00:00
|
|
|
#endif // _FLUID_SHELL_COMMAND_H
|