1998-10-21 20:29:01 +04:00
|
|
|
//
|
|
|
|
// FLUID main entry for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2023-03-18 19:33:27 +03:00
|
|
|
// Copyright 1998-2023 by Bill Spitzak and others.
|
1998-10-21 20:29:01 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04: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:
|
|
|
|
//
|
2020-03-11 16:38:02 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
1998-10-21 20:29:01 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2005-04-16 04:13:17 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
1998-10-21 20:29:01 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
#include "fluid.h"
|
|
|
|
|
|
|
|
#include "Fl_Type.h"
|
|
|
|
#include "Fl_Function_Type.h"
|
|
|
|
#include "Fl_Group_Type.h"
|
|
|
|
#include "Fl_Window_Type.h"
|
|
|
|
#include "widget_browser.h"
|
|
|
|
#include "shell_command.h"
|
|
|
|
#include "factory.h"
|
|
|
|
#include "pixmaps.h"
|
|
|
|
#include "undo.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "code.h"
|
|
|
|
|
|
|
|
#include "alignment_panel.h"
|
|
|
|
#include "function_panel.h"
|
2023-08-29 03:20:45 +03:00
|
|
|
#include "sourceview_panel.h"
|
2021-12-08 17:52:15 +03:00
|
|
|
#include "template_panel.h"
|
|
|
|
#include "about_panel.h"
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <FL/Fl.H>
|
2016-03-26 17:36:11 +03:00
|
|
|
#ifdef __APPLE__
|
2018-02-01 00:17:17 +03:00
|
|
|
#include <FL/platform.H> // for fl_open_callback
|
2016-03-26 17:36:11 +03:00
|
|
|
#endif
|
2001-09-29 18:38:59 +04:00
|
|
|
#include <FL/Fl_Help_Dialog.H>
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <FL/Fl_Menu_Bar.H>
|
2011-01-24 20:04:22 +03:00
|
|
|
#include <FL/Fl_PNG_Image.H>
|
2011-09-21 18:11:44 +04:00
|
|
|
#include <FL/Fl_Native_File_Chooser.H>
|
2011-09-23 03:03:12 +04:00
|
|
|
#include <FL/Fl_Printer.H>
|
2022-01-16 21:02:36 +03:00
|
|
|
#include <FL/fl_string_functions.h>
|
2020-08-22 14:35:42 +03:00
|
|
|
#include <locale.h> // setlocale()..
|
2002-04-01 20:19:32 +04:00
|
|
|
#include "../src/flstring.h"
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2005-03-20 20:41:56 +03:00
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#if defined(HAVE_LIBPNG) && defined(HAVE_LIBZ)
|
|
|
|
# include <zlib.h>
|
|
|
|
# ifdef HAVE_PNG_H
|
|
|
|
# include <png.h>
|
|
|
|
# else
|
|
|
|
# include <libpng/png.h>
|
|
|
|
# endif // HAVE_PNG_H
|
|
|
|
#endif // HAVE_LIBPNG && HAVE_LIBZ
|
|
|
|
}
|
|
|
|
|
2023-09-26 13:39:48 +03:00
|
|
|
/// \defgroup globals Fluid Global Variables, Functions and Callbacks
|
2021-12-08 17:52:15 +03:00
|
|
|
/// \{
|
|
|
|
|
2016-07-19 00:12:25 +03:00
|
|
|
//
|
|
|
|
// Globals..
|
|
|
|
//
|
2021-12-08 17:52:15 +03:00
|
|
|
|
|
|
|
/// Fluid-wide help dialog.
|
2001-09-29 18:38:59 +04:00
|
|
|
static Fl_Help_Dialog *help_dialog = 0;
|
2001-08-11 20:09:26 +04:00
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
Fl_Menu_Bar *main_menubar = NULL;
|
|
|
|
Fl_Window *main_window;
|
|
|
|
|
2023-09-26 13:39:48 +03:00
|
|
|
/// Fluid application preferences, always accessible, will be flushed when app closes.
|
2023-03-18 19:33:27 +03:00
|
|
|
Fl_Preferences fluid_prefs(Fl_Preferences::USER_L, "fltk.org", "fluid");
|
2021-12-08 17:52:15 +03:00
|
|
|
|
|
|
|
/// Show guides in the design window when positioning widgets, saved in app preferences.
|
2005-02-26 23:27:19 +03:00
|
|
|
int show_guides = 1;
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2023-07-12 00:13:46 +03:00
|
|
|
/// Show areas of restricted use in overlay plane.
|
2023-09-26 13:39:48 +03:00
|
|
|
/// Restricted areas are widget that overlap each other, widgets that are outside
|
|
|
|
/// of their parent's bounds (except children of Scroll groups), and areas
|
2023-07-12 00:13:46 +03:00
|
|
|
/// within an Fl_Tile that are not covered by children.
|
|
|
|
int show_restricted = 1;
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/// Show widget comments in the browser, saved in app preferences.
|
2008-09-19 01:11:28 +04:00
|
|
|
int show_comments = 1;
|
2021-12-08 17:52:15 +03:00
|
|
|
|
|
|
|
/// Use external editor for editing Fl_Code_Type, saved in app preferences.
|
2016-07-19 00:12:25 +03:00
|
|
|
int G_use_external_editor = 0;
|
2021-12-08 17:52:15 +03:00
|
|
|
|
|
|
|
/// Debugging help for external Fl_Code_Type editor.
|
2016-07-19 00:12:25 +03:00
|
|
|
int G_debug = 0;
|
2021-12-08 17:52:15 +03:00
|
|
|
|
|
|
|
/// Run this command to load an Fl_Code_Type into an external editor, save in app preferences.
|
2016-07-19 00:12:25 +03:00
|
|
|
char G_external_editor_command[512];
|
2021-12-08 17:52:15 +03:00
|
|
|
|
|
|
|
|
2021-12-11 21:43:00 +03:00
|
|
|
/// If set, if the `current` node is a group, and a new group is added, it will
|
|
|
|
/// be added as sibling to the first group instead of inside the group.
|
|
|
|
/// \todo Needs to be verified.
|
2021-12-08 17:52:15 +03:00
|
|
|
int force_parent = 0;
|
|
|
|
|
|
|
|
/// This is set to create different labels when creating new widgets.
|
|
|
|
/// \todo Details unclear.
|
|
|
|
int reading_file = 0;
|
|
|
|
|
2002-04-30 22:11:49 +04:00
|
|
|
|
|
|
|
// File history info...
|
2021-12-08 17:52:15 +03:00
|
|
|
|
|
|
|
/// Stores the absolute filename of the last 10 design files, saved in app preferences.
|
2020-07-01 19:03:10 +03:00
|
|
|
char absolute_history[10][FL_PATH_MAX];
|
2021-12-08 17:52:15 +03:00
|
|
|
|
|
|
|
/// This list of filenames is computed from \c absolute_history and displayed in the main menu.
|
2020-07-01 19:03:10 +03:00
|
|
|
char relative_history[10][FL_PATH_MAX];
|
2002-04-30 22:11:49 +04:00
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/// Menuitem to save a .fl design file, will be deactivated if the design is unchanged.
|
|
|
|
Fl_Menu_Item *save_item = NULL;
|
2002-04-30 22:11:49 +04:00
|
|
|
|
2023-09-26 13:39:48 +03:00
|
|
|
/// First Menuitem that shows the .fl design file history.
|
2021-12-08 17:52:15 +03:00
|
|
|
Fl_Menu_Item *history_item = NULL;
|
2001-08-11 20:09:26 +04:00
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/// Menuitem to show or hide the widget bin, label will change if bin is visible.
|
|
|
|
Fl_Menu_Item *widgetbin_item = NULL;
|
|
|
|
|
|
|
|
/// Menuitem to show or hide the source view, label will change if view is visible.
|
|
|
|
Fl_Menu_Item *sourceview_item = NULL;
|
2010-02-26 16:03:21 +03:00
|
|
|
|
2021-12-08 22:52:33 +03:00
|
|
|
/// Menuitem to show or hide the editing overlay, label will change if overlay visibility changes.
|
|
|
|
Fl_Menu_Item *overlay_item = NULL;
|
|
|
|
|
2023-03-18 19:33:27 +03:00
|
|
|
/// Menuitem to show or hide the editing guides, label will change if overlay visibility changes.
|
|
|
|
Fl_Menu_Item *guides_item = NULL;
|
|
|
|
|
2023-07-12 00:13:46 +03:00
|
|
|
/// Menuitem to show or hide the restricted area overlys, label will change if overlay visibility changes.
|
|
|
|
Fl_Menu_Item *restricted_item = NULL;
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/// Filename of the current .fl design file
|
|
|
|
static const char *filename = NULL;
|
|
|
|
|
|
|
|
/// Set if the current design has been modified compared to the associated .fl design file.
|
|
|
|
int modflag = 0;
|
|
|
|
|
2021-12-10 03:22:15 +03:00
|
|
|
/// Set if the code files are older than the current design.
|
|
|
|
int modflag_c = 0;
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/// Application work directory, stored here when temporarily changing to the source code directory.
|
|
|
|
/// \see goto_source_dir()
|
2023-08-26 18:27:29 +03:00
|
|
|
static Fl_String app_work_dir;
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2022-11-15 19:48:06 +03:00
|
|
|
/// Used as a counter to set the .fl project dir as the current directory.
|
|
|
|
/// \see enter_project_dir(), leave_project_dir()
|
|
|
|
static char in_project_dir = 0;
|
2021-12-08 17:52:15 +03:00
|
|
|
|
|
|
|
/// Set, if Fluid was started with the command line argument -u
|
|
|
|
int update_file = 0; // fluid -u
|
|
|
|
|
|
|
|
/// Set, if Fluid was started with the command line argument -c
|
|
|
|
int compile_file = 0; // fluid -c
|
|
|
|
|
|
|
|
/// Set, if Fluid was started with the command line argument -cs
|
2023-09-26 13:39:48 +03:00
|
|
|
int compile_strings = 0; // fluid -cs
|
2021-12-08 17:52:15 +03:00
|
|
|
|
|
|
|
/// Set, if Fluid runs in batch mode, and no user interface is activated.
|
|
|
|
int batch_mode = 0; // if set (-c, -u) don't open display
|
|
|
|
|
2023-09-26 13:39:48 +03:00
|
|
|
/// command line arguments override settings in the project file
|
2023-02-23 17:42:05 +03:00
|
|
|
Fl_String g_code_filename_arg;
|
|
|
|
Fl_String g_header_filename_arg;
|
2023-09-05 16:11:09 +03:00
|
|
|
Fl_String g_launch_path;
|
2022-11-29 02:04:47 +03:00
|
|
|
|
2023-09-26 17:01:03 +03:00
|
|
|
Fl_String tmpdir_path;
|
|
|
|
bool tmpdir_create_called = false;
|
|
|
|
|
2023-01-01 22:05:42 +03:00
|
|
|
/** \var int Fluid_Project::header_file_set
|
2023-09-26 13:39:48 +03:00
|
|
|
If set, command line overrides header file name in .fl file.
|
2022-11-26 03:35:50 +03:00
|
|
|
*/
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2023-01-01 22:05:42 +03:00
|
|
|
/** \var int Fluid_Project::code_file_set
|
2023-09-26 13:39:48 +03:00
|
|
|
If set, command line overrides source code file name in .fl file.
|
2022-11-26 03:35:50 +03:00
|
|
|
*/
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2023-01-01 22:05:42 +03:00
|
|
|
/** \var int Fluid_Project::header_file_name
|
2022-11-26 03:35:50 +03:00
|
|
|
Hold the default extension for header files, or the entire filename if set via command line.
|
|
|
|
*/
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2023-01-01 22:05:42 +03:00
|
|
|
/** \var int Fluid_Project::code_file_name
|
2022-11-26 03:35:50 +03:00
|
|
|
Hold the default extension for source code files, or the entire filename if set via command line.
|
|
|
|
*/
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2023-01-01 22:05:42 +03:00
|
|
|
/** \var int Fluid_Project::i18n_type
|
2022-11-26 03:35:50 +03:00
|
|
|
Saved in the .fl design file.
|
|
|
|
\todo document me
|
|
|
|
*/
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2023-07-15 00:42:09 +03:00
|
|
|
/** \var int Fluid_Project::i18n_gnu_include
|
|
|
|
Include file for GNU i18n, writes an #include statement into the
|
2021-12-19 03:09:13 +03:00
|
|
|
source file.
|
|
|
|
|
2023-07-15 00:42:09 +03:00
|
|
|
This is usually `<libintl.h>` or `"gettext.h"` for GNU gettext.
|
2021-12-19 03:09:13 +03:00
|
|
|
|
|
|
|
Fluid accepts filenames in quotes or in \< and \>. If neither is found,
|
|
|
|
double quotes are added.
|
2023-07-15 00:42:09 +03:00
|
|
|
If this value is empty, no include statement will be generated.
|
|
|
|
|
|
|
|
Saved in the .fl design file if GNU i18n is selected.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \var int Fluid_Project::i18n_pos_include
|
|
|
|
Include file for Posix i18n, write a #include statement into the
|
|
|
|
source file.
|
|
|
|
|
|
|
|
This is usually `<nl_types.h>` for Posix catgets.
|
|
|
|
|
|
|
|
Fluid accepts filenames in quotes or in \< and \>. If neither is found,
|
|
|
|
double quotes are added.
|
|
|
|
If this value is empty, no include statement will be generated.
|
2021-12-19 03:09:13 +03:00
|
|
|
|
|
|
|
Saved in the .fl design file.
|
|
|
|
*/
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2023-07-15 00:42:09 +03:00
|
|
|
/** \var int Fluid_Project::i18n_gnu_conditional
|
2022-11-26 03:35:50 +03:00
|
|
|
Saved in the .fl design file.
|
|
|
|
\todo document me
|
|
|
|
*/
|
2021-12-19 03:09:13 +03:00
|
|
|
|
2023-07-15 00:42:09 +03:00
|
|
|
/** \var int Fluid_Project::i18n_pos_conditional
|
|
|
|
Saved in the .fl design file.
|
|
|
|
\todo document me
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \var int Fluid_Project::i18n_gnu_function
|
2021-12-19 03:09:13 +03:00
|
|
|
For the gettext/intl.h options, this is the function that translates text
|
|
|
|
at runtime.
|
|
|
|
|
|
|
|
This is usually "gettext" or "_".
|
|
|
|
This should not be empty.
|
|
|
|
Saved in the .fl design file.
|
|
|
|
*/
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2023-07-15 00:42:09 +03:00
|
|
|
/** \var int Fluid_Project::i18n_gnu_static_function
|
2021-12-19 03:09:13 +03:00
|
|
|
For the gettext/intl.h options, this is the function that marks the
|
|
|
|
translation of text at initialisation time.
|
|
|
|
|
|
|
|
This is usually "gettext_noop" or "N_".
|
|
|
|
This should not be empty.
|
|
|
|
Fluid will translate static text (usually in menu items) later when used
|
|
|
|
for the first time.
|
|
|
|
|
|
|
|
Saved in the .fl design file.
|
|
|
|
*/
|
|
|
|
|
2023-07-15 00:42:09 +03:00
|
|
|
/** \var int Fluid_Project::i18n_pos_file
|
2022-11-26 03:35:50 +03:00
|
|
|
Saved in the .fl design file.
|
|
|
|
\todo document me
|
|
|
|
*/
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2023-07-15 00:42:09 +03:00
|
|
|
/** \var int Fluid_Project::i18n_pos_set
|
2022-11-26 03:35:50 +03:00
|
|
|
Saved in the .fl design file.
|
|
|
|
\todo document me
|
|
|
|
*/
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2023-07-15 00:42:09 +03:00
|
|
|
/** \var int Fluid_Project::basename
|
2022-11-26 03:35:50 +03:00
|
|
|
\todo document me
|
|
|
|
*/
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2021-12-11 21:43:00 +03:00
|
|
|
/// Offset in pixels when adding widgets from an .fl file.
|
2021-12-08 17:52:15 +03:00
|
|
|
int pasteoffset = 0;
|
|
|
|
|
2021-12-11 21:43:00 +03:00
|
|
|
/// Paste offset incrementing at every paste command.
|
2021-12-08 17:52:15 +03:00
|
|
|
static int ipasteoffset = 0;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2022-11-26 03:35:50 +03:00
|
|
|
// ---- project settings
|
|
|
|
|
2023-01-01 22:05:42 +03:00
|
|
|
Fluid_Project g_project;
|
2022-11-26 03:35:50 +03:00
|
|
|
|
2023-01-01 22:05:42 +03:00
|
|
|
Fluid_Project::Fluid_Project() :
|
2022-11-26 03:35:50 +03:00
|
|
|
i18n_type(0),
|
|
|
|
include_H_from_C(1),
|
|
|
|
use_FL_COMMAND(0),
|
|
|
|
utf8_in_src(0),
|
|
|
|
avoid_early_includes(0),
|
|
|
|
header_file_set(0),
|
|
|
|
code_file_set(0),
|
|
|
|
header_file_name(".h"),
|
|
|
|
code_file_name(".cxx")
|
|
|
|
{ }
|
|
|
|
|
2023-01-01 22:05:42 +03:00
|
|
|
Fluid_Project::~Fluid_Project() {
|
2022-11-26 03:35:50 +03:00
|
|
|
}
|
|
|
|
|
2023-01-01 22:05:42 +03:00
|
|
|
void Fluid_Project::reset() {
|
2022-11-26 03:35:50 +03:00
|
|
|
::delete_all();
|
|
|
|
i18n_type = 0;
|
2023-07-15 00:42:09 +03:00
|
|
|
|
|
|
|
i18n_gnu_include = "<libintl.h>";
|
|
|
|
i18n_gnu_conditional = "";
|
|
|
|
i18n_gnu_function = "gettext";
|
|
|
|
i18n_gnu_static_function = "gettext_noop";
|
|
|
|
|
|
|
|
i18n_pos_include = "<nl_types.h>";
|
|
|
|
i18n_pos_conditional = "";
|
|
|
|
i18n_pos_file = "";
|
|
|
|
i18n_pos_set = "1";
|
|
|
|
|
2022-11-26 03:35:50 +03:00
|
|
|
include_H_from_C = 1;
|
|
|
|
use_FL_COMMAND = 0;
|
|
|
|
utf8_in_src = 0;
|
|
|
|
avoid_early_includes = 0;
|
|
|
|
header_file_set = 0;
|
|
|
|
code_file_set = 0;
|
|
|
|
header_file_name = ".h";
|
|
|
|
code_file_name = ".cxx";
|
|
|
|
}
|
2021-12-08 17:52:15 +03:00
|
|
|
|
2023-03-19 22:04:01 +03:00
|
|
|
void Fluid_Project::update_settings_dialog() {
|
|
|
|
if (settings_window) {
|
|
|
|
w_settings_project_tab->do_callback(w_settings_project_tab, LOAD);
|
|
|
|
w_settings_i18n_tab->do_callback(w_settings_i18n_tab, LOAD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-26 17:01:03 +03:00
|
|
|
// make sure that a path name ends with a forward slash
|
|
|
|
static Fl_String end_with_slash(const Fl_String &str) {
|
|
|
|
char last = str[str.size()-1];
|
|
|
|
if (last !='/' && last != '\\')
|
|
|
|
return str + "/";
|
|
|
|
else
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Generate a path to a directory for temporary data storage.
|
|
|
|
The path is stored in g_tmpdir.
|
|
|
|
*/
|
|
|
|
static void create_tmpdir() {
|
|
|
|
if (tmpdir_create_called)
|
|
|
|
return;
|
|
|
|
tmpdir_create_called = true;
|
|
|
|
|
|
|
|
char buf[128];
|
|
|
|
#if _WIN32
|
|
|
|
// The usual temp file locations on Windows are
|
|
|
|
// %system%\Windows\Temp
|
|
|
|
// %userprofiles%\AppData\Local
|
|
|
|
// usually resolving into
|
|
|
|
// C:/Windows/Temp/
|
|
|
|
// C:\Users\<username>\AppData\Local\Temp
|
|
|
|
fl_snprintf(buf, sizeof(buf)-1, "fluid-%d/", (long)GetCurrentProcessId());
|
|
|
|
Fl_String name = buf;
|
|
|
|
wchar_t tempdirW[FL_PATH_MAX+1];
|
|
|
|
char tempdir[FL_PATH_MAX+1];
|
|
|
|
unsigned len = GetTempPathW(FL_PATH_MAX, tempdirW);
|
|
|
|
if (len == 0) {
|
|
|
|
strcpy(tempdir, "c:/windows/temp/");
|
|
|
|
} else {
|
|
|
|
unsigned wn = fl_utf8fromwc(tempdir, FL_PATH_MAX, tempdirW, len);
|
|
|
|
tempdir[wn] = 0;
|
|
|
|
}
|
|
|
|
Fl_String path = tempdir;
|
|
|
|
end_with_slash(path);
|
|
|
|
path += name;
|
|
|
|
fl_make_path(path.c_str());
|
|
|
|
if (fl_access(path.c_str(), 6) == 0) tmpdir_path = path;
|
|
|
|
#else
|
|
|
|
fl_snprintf(buf, sizeof(buf)-1, "fluid-%d/", getpid());
|
|
|
|
Fl_String name = buf;
|
|
|
|
Fl_String path = fl_getenv("TMPDIR");
|
|
|
|
if (!path.empty()) {
|
|
|
|
end_with_slash(path);
|
|
|
|
path += name;
|
|
|
|
fl_make_path(path.c_str());
|
|
|
|
if (fl_access(path.c_str(), 6) == 0) tmpdir_path = path;
|
|
|
|
}
|
|
|
|
if (tmpdir_path.empty()) {
|
|
|
|
path = Fl_String("/tmp/") + name;
|
|
|
|
fl_make_path(path.c_str());
|
|
|
|
if (fl_access(path.c_str(), 6) == 0) tmpdir_path = path;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (tmpdir_path.empty()) {
|
|
|
|
char pbuf[FL_PATH_MAX+1];
|
|
|
|
fluid_prefs.get_userdata_path(pbuf, FL_PATH_MAX);
|
|
|
|
path = Fl_String(pbuf);
|
|
|
|
end_with_slash(path);
|
|
|
|
path += name;
|
|
|
|
fl_make_path(path.c_str());
|
|
|
|
if (fl_access(path.c_str(), 6) == 0) tmpdir_path = path;
|
|
|
|
}
|
|
|
|
if (tmpdir_path.empty())
|
|
|
|
fl_alert("Can't create directory for temporary data storage.");
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Delete the temporary directory that was created in set_tmpdir. */
|
|
|
|
static void delete_tmpdir() {
|
|
|
|
// was a temporary directory created
|
|
|
|
if (!tmpdir_create_called)
|
|
|
|
return;
|
|
|
|
if (tmpdir_path.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// first delete all files that may still be left in the temp directory
|
|
|
|
struct dirent **de;
|
|
|
|
int n_de = fl_filename_list(tmpdir_path.c_str(), &de);
|
|
|
|
if (n_de >= 0) {
|
|
|
|
for (int i=0; i<n_de; i++) {
|
|
|
|
Fl_String path = tmpdir_path + de[i]->d_name;
|
|
|
|
fl_unlink(path.c_str());
|
|
|
|
}
|
|
|
|
fl_filename_free_list(&de, n_de);
|
|
|
|
}
|
|
|
|
|
|
|
|
// then delete the directory itself
|
|
|
|
if (fl_rmdir(tmpdir_path.c_str()) < 0) {
|
|
|
|
fl_alert("WARNING: Can't delete tmpdir '%s': %s", tmpdir_path.c_str(), strerror(errno));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Return the path to a temporary directory for this instance of FLUID.
|
|
|
|
Fluid will do its best to clear and delete this directory when exiting.
|
|
|
|
\return the path to the temporary directory, ending in a '/', or and empty
|
|
|
|
string is no directory could be created.
|
|
|
|
*/
|
|
|
|
const Fl_String &get_tmpdir() {
|
|
|
|
if (!tmpdir_create_called)
|
|
|
|
create_tmpdir();
|
|
|
|
return tmpdir_path;
|
|
|
|
}
|
|
|
|
|
2023-08-28 17:29:08 +03:00
|
|
|
/**
|
|
|
|
Give the user the opportunity to save a project before clearing it.
|
|
|
|
|
|
|
|
If the project has unsaved changes, this function pops up a dialog, that
|
|
|
|
allows the user to save the project, continue without saving the project,
|
|
|
|
or to cancel the operation.
|
|
|
|
|
|
|
|
If the user chooses to save, and no filename was set, a file dialog allows
|
|
|
|
the user to pick a name and location, or to cancel the operation.
|
|
|
|
|
|
|
|
\return false if the user aborted the operation and the calling function
|
|
|
|
should abort as well
|
|
|
|
*/
|
|
|
|
bool confirm_project_clear() {
|
|
|
|
if (modflag == 0) return true;
|
|
|
|
switch (fl_choice("This project has unsaved changes. Do you want to save\n"
|
|
|
|
"the project file before proceeding?",
|
|
|
|
"Cancel", "Save", "Don't Save"))
|
|
|
|
{
|
|
|
|
case 0 : /* Cancel */
|
|
|
|
return false;
|
|
|
|
case 1 : /* Save */
|
|
|
|
save_cb(NULL, NULL);
|
|
|
|
if (modflag) return false; // user canceled the "Save As" dialog
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
// ----
|
|
|
|
|
2022-12-10 15:11:49 +03:00
|
|
|
extern Fl_Window *the_panel;
|
|
|
|
// make sure that a currently changed text widgets propagates its contents
|
|
|
|
void flush_text_widgets() {
|
|
|
|
if (Fl::focus() && (Fl::focus()->top_window() == the_panel)) {
|
|
|
|
Fl_Widget *old_focus = Fl::focus();
|
2023-08-28 17:29:08 +03:00
|
|
|
Fl::focus(NULL); // trigger callback of the widget that is losing focus
|
2022-12-10 15:11:49 +03:00
|
|
|
Fl::focus(old_focus);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// ----
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
2022-11-15 19:48:06 +03:00
|
|
|
Change the current working directory to the .fl project directory.
|
|
|
|
|
|
|
|
Every call to enter_project_dir() must have a corresponding leave_project_dir()
|
|
|
|
call. Enter and leave calls can be nested.
|
|
|
|
|
|
|
|
The first call to enter_project_dir() remembers the original directory, usually
|
|
|
|
the launch directory of the application. Nested calls will increment a nesting
|
|
|
|
counter. When the nesting counter is back to 0, leave_project_dir() will return
|
|
|
|
to the original directory.
|
|
|
|
|
|
|
|
The global variable 'filename' must be set to the current project file with
|
|
|
|
absolute or relative path information.
|
|
|
|
|
|
|
|
\see leave_project_dir(), pwd, in_project_dir
|
2021-12-08 17:52:15 +03:00
|
|
|
*/
|
2022-11-15 19:48:06 +03:00
|
|
|
void enter_project_dir() {
|
|
|
|
if (in_project_dir<0) {
|
|
|
|
fprintf(stderr, "** Fluid internal error: enter_project_dir() calls unmatched\n");
|
|
|
|
return;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2022-11-15 19:48:06 +03:00
|
|
|
in_project_dir++;
|
|
|
|
// check if we are already in the project dir and do nothing if so
|
|
|
|
if (in_project_dir>1) return;
|
|
|
|
// check if there is an active project, and do nothing if there is none
|
|
|
|
if (!filename || !*filename) {
|
|
|
|
fprintf(stderr, "** Fluid internal error: enter_project_dir() no filename set\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// store the current working directory for later
|
2023-08-26 18:27:29 +03:00
|
|
|
app_work_dir = fl_getcwd();
|
|
|
|
// set the current directory to the path of our .fl file
|
2023-09-26 17:01:03 +03:00
|
|
|
Fl_String project_path = fl_filename_path(fl_filename_absolute(filename));
|
2023-08-26 18:27:29 +03:00
|
|
|
if (fl_chdir(project_path.c_str()) == -1) {
|
2022-11-15 19:48:06 +03:00
|
|
|
fprintf(stderr, "** Fluid internal error: enter_project_dir() can't chdir to %s: %s\n",
|
2023-08-26 18:27:29 +03:00
|
|
|
project_path.c_str(), strerror(errno));
|
2017-11-12 21:00:45 +03:00
|
|
|
return;
|
|
|
|
}
|
2023-08-26 18:27:29 +03:00
|
|
|
//fprintf(stderr, "chdir from %s to %s\n", app_work_dir.c_str(), fl_getcwd().c_str());
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
2022-11-15 19:48:06 +03:00
|
|
|
Change the current working directory to the previous directory.
|
|
|
|
\see enter_project_dir(), pwd, in_project_dir
|
2021-12-08 17:52:15 +03:00
|
|
|
*/
|
2022-11-15 19:48:06 +03:00
|
|
|
void leave_project_dir() {
|
|
|
|
if (in_project_dir == 0) {
|
|
|
|
fprintf(stderr, "** Fluid internal error: leave_project_dir() calls unmatched\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
in_project_dir--;
|
|
|
|
// still nested, stay in the project directory
|
|
|
|
if (in_project_dir > 0) return;
|
|
|
|
// no longer nested, return to the original, usually the application working directory
|
2023-08-26 18:27:29 +03:00
|
|
|
if (fl_chdir(app_work_dir.c_str()) < 0) {
|
2022-11-15 19:48:06 +03:00
|
|
|
fprintf(stderr, "** Fluid internal error: leave_project_dir() can't chdir back to %s : %s\n",
|
2023-08-26 18:27:29 +03:00
|
|
|
app_work_dir.c_str(), strerror(errno));
|
2022-11-10 01:12:55 +03:00
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2008-11-29 20:06:31 +03:00
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Position the given window window based on entries in the app preferences.
|
2023-09-26 13:39:48 +03:00
|
|
|
Customisable by user; feature can be switched off.
|
2021-12-08 17:52:15 +03:00
|
|
|
The window is not shown or hidden by this function, but a value is returned
|
|
|
|
to indicate the state to the caller.
|
|
|
|
\param[in] w position this window
|
|
|
|
\param[in] prefsName name of the preferences item that stores the window settings
|
|
|
|
\param[in] Visible default value if window is hidden or shown
|
|
|
|
\param[in] X, Y, W, H default size and position if nothing is specified in the preferences
|
|
|
|
\return 1 if the caller should make the window visible, 0 if hidden.
|
|
|
|
*/
|
2023-08-29 03:20:45 +03:00
|
|
|
char position_window(Fl_Window *w, const char *prefsName, int Visible, int X, int Y, int W, int H) {
|
2002-10-31 21:49:05 +03:00
|
|
|
Fl_Preferences pos(fluid_prefs, prefsName);
|
2002-11-03 03:01:21 +03:00
|
|
|
if (prevpos_button->value()) {
|
|
|
|
pos.get("x", X, X);
|
|
|
|
pos.get("y", Y, Y);
|
|
|
|
if ( W!=0 ) {
|
|
|
|
pos.get("w", W, W);
|
|
|
|
pos.get("h", H, H);
|
|
|
|
w->resize( X, Y, W, H );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
w->position( X, Y );
|
2002-10-31 21:49:05 +03:00
|
|
|
}
|
2002-11-03 03:01:21 +03:00
|
|
|
pos.get("visible", Visible, Visible);
|
|
|
|
return Visible;
|
2002-10-31 21:49:05 +03:00
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Save the position and visibility state of a window to the app preferences.
|
|
|
|
\param[in] w save this window data
|
|
|
|
\param[in] prefsName name of the preferences item that stores the window settings
|
|
|
|
*/
|
2002-10-31 21:49:05 +03:00
|
|
|
void save_position(Fl_Window *w, const char *prefsName) {
|
|
|
|
Fl_Preferences pos(fluid_prefs, prefsName);
|
|
|
|
pos.set("x", w->x());
|
|
|
|
pos.set("y", w->y());
|
|
|
|
pos.set("w", w->w());
|
|
|
|
pos.set("h", w->h());
|
2004-09-08 00:59:18 +04:00
|
|
|
pos.set("visible", (int)(w->shown() && w->visible()));
|
2002-10-31 21:49:05 +03:00
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Return the path and filename of a temporary file for cut or duplicated data.
|
|
|
|
\param[in] which 0 gets the cut/copy/paste buffer, 1 gets the duplication buffer
|
|
|
|
\return a pointer to a string in a static buffer
|
|
|
|
*/
|
2005-03-21 00:27:20 +03:00
|
|
|
static char* cutfname(int which = 0) {
|
2010-12-20 00:20:10 +03:00
|
|
|
static char name[2][FL_PATH_MAX];
|
2005-03-21 00:27:20 +03:00
|
|
|
static char beenhere = 0;
|
|
|
|
|
|
|
|
if (!beenhere) {
|
|
|
|
beenhere = 1;
|
|
|
|
fluid_prefs.getUserdataPath(name[0], sizeof(name[0]));
|
|
|
|
strlcat(name[0], "cut_buffer", sizeof(name[0]));
|
|
|
|
fluid_prefs.getUserdataPath(name[1], sizeof(name[1]));
|
|
|
|
strlcat(name[1], "dup_buffer", sizeof(name[1]));
|
|
|
|
}
|
|
|
|
|
|
|
|
return name[which];
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Timer to watch for external editor modifications.
|
|
|
|
|
|
|
|
If one or more external editors open, check if their files were modified.
|
|
|
|
If so: reload to ram, update size/mtime records, and change fluid's
|
|
|
|
'modified' state.
|
|
|
|
*/
|
2016-07-19 00:12:25 +03:00
|
|
|
static void external_editor_timer(void*) {
|
|
|
|
int editors_open = ExternalCodeEditor::editors_open();
|
|
|
|
if ( G_debug ) printf("--- TIMER --- External editors open=%d\n", editors_open);
|
|
|
|
if ( editors_open > 0 ) {
|
|
|
|
// Walk tree looking for files modified by external editors.
|
|
|
|
int modified = 0;
|
|
|
|
for (Fl_Type *p = Fl_Type::first; p; p = p->next) {
|
|
|
|
if ( p->is_code() ) {
|
|
|
|
Fl_Code_Type *code = (Fl_Code_Type*)p;
|
|
|
|
// Code changed by external editor?
|
2020-07-01 19:03:10 +03:00
|
|
|
if ( code->handle_editor_changes() ) { // updates ram, file size/mtime
|
2016-07-19 00:12:25 +03:00
|
|
|
modified++;
|
|
|
|
}
|
|
|
|
if ( code->is_editing() ) { // editor open?
|
|
|
|
code->reap_editor(); // Try to reap; maybe it recently closed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ( modified ) set_modflag(1);
|
|
|
|
}
|
|
|
|
// Repeat timeout if editors still open
|
|
|
|
// The ExternalCodeEditor class handles start/stopping timer, we just
|
|
|
|
// repeat_timeout() if it's already on. NOTE: above code may have reaped
|
|
|
|
// only open editor, which would disable further timeouts. So *recheck*
|
|
|
|
// if editors still open, to ensure we don't accidentally re-enable them.
|
|
|
|
//
|
|
|
|
if ( ExternalCodeEditor::editors_open() ) {
|
|
|
|
Fl::repeat_timeout(2.0, external_editor_timer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Save the current design to the file given by \c filename.
|
2023-09-26 13:39:48 +03:00
|
|
|
If automatic, this overwrites an existing file. If interactive, if will
|
2021-12-08 17:52:15 +03:00
|
|
|
verify with the user.
|
|
|
|
\param[in] v if v is not NULL, or no filename is set, open a filechooser.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void save_cb(Fl_Widget *, void *v) {
|
2022-12-10 15:11:49 +03:00
|
|
|
flush_text_widgets();
|
2011-09-21 18:11:44 +04:00
|
|
|
Fl_Native_File_Chooser fnfc;
|
1998-10-06 22:21:25 +04:00
|
|
|
const char *c = filename;
|
2020-07-01 19:03:10 +03:00
|
|
|
if (v || !c || !*c) {
|
2011-09-21 18:11:44 +04:00
|
|
|
fnfc.title("Save To:");
|
|
|
|
fnfc.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
|
|
|
|
fnfc.filter("FLUID Files\t*.f[ld]");
|
|
|
|
if (fnfc.show() != 0) return;
|
|
|
|
c = fnfc.filename();
|
2017-10-15 14:47:01 +03:00
|
|
|
if (!fl_access(c, 0)) {
|
2023-08-28 17:29:08 +03:00
|
|
|
Fl_String basename = fl_filename_name(Fl_String(c));
|
2005-03-19 11:38:21 +03:00
|
|
|
if (fl_choice("The file \"%s\" already exists.\n"
|
|
|
|
"Do you want to replace it?", "Cancel",
|
2023-08-28 17:29:08 +03:00
|
|
|
"Replace", NULL, basename.c_str()) == 0) return;
|
2005-03-19 11:38:21 +03:00
|
|
|
}
|
|
|
|
|
2005-03-24 19:31:59 +03:00
|
|
|
if (v != (void *)2) set_filename(c);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
if (!write_file(c)) {
|
2005-03-20 20:41:56 +03:00
|
|
|
fl_alert("Error writing %s: %s", c, strerror(errno));
|
1998-10-06 22:21:25 +04:00
|
|
|
return;
|
|
|
|
}
|
2005-03-24 19:31:59 +03:00
|
|
|
|
|
|
|
if (v != (void *)2) {
|
2021-12-10 03:22:15 +03:00
|
|
|
set_modflag(0, 1);
|
2005-03-24 19:31:59 +03:00
|
|
|
undo_save = undo_current;
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Save a design template.
|
|
|
|
\todo We should document the concept of templates.
|
|
|
|
*/
|
2005-03-20 20:41:56 +03:00
|
|
|
void save_template_cb(Fl_Widget *, void *) {
|
2005-03-21 00:27:20 +03:00
|
|
|
// Setup the template panel...
|
|
|
|
if (!template_panel) make_template_panel();
|
2005-03-20 20:41:56 +03:00
|
|
|
|
2005-03-21 00:27:20 +03:00
|
|
|
template_clear();
|
|
|
|
template_browser->add("New Template");
|
|
|
|
template_load();
|
|
|
|
|
|
|
|
template_name->show();
|
|
|
|
template_name->value("");
|
|
|
|
|
|
|
|
template_instance->hide();
|
|
|
|
|
|
|
|
template_delete->show();
|
|
|
|
template_delete->deactivate();
|
|
|
|
|
|
|
|
template_submit->label("Save");
|
|
|
|
template_submit->deactivate();
|
|
|
|
|
|
|
|
template_panel->label("Save Template");
|
|
|
|
|
|
|
|
// Show the panel and wait for the user to do something...
|
|
|
|
template_panel->show();
|
|
|
|
while (template_panel->shown()) Fl::wait();
|
|
|
|
|
|
|
|
// Get the template name, return if it is empty...
|
|
|
|
const char *c = template_name->value();
|
|
|
|
if (!c || !*c) return;
|
|
|
|
|
|
|
|
// Convert template name to filename_with_underscores
|
2010-12-20 00:20:10 +03:00
|
|
|
char safename[FL_PATH_MAX], *safeptr;
|
2005-03-21 00:27:20 +03:00
|
|
|
strlcpy(safename, c, sizeof(safename));
|
|
|
|
for (safeptr = safename; *safeptr; safeptr ++) {
|
|
|
|
if (isspace(*safeptr)) *safeptr = '_';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Find the templates directory...
|
2010-12-20 00:20:10 +03:00
|
|
|
char filename[FL_PATH_MAX];
|
2005-03-20 20:41:56 +03:00
|
|
|
fluid_prefs.getUserdataPath(filename, sizeof(filename));
|
|
|
|
|
|
|
|
strlcat(filename, "templates", sizeof(filename));
|
2016-04-27 20:02:57 +03:00
|
|
|
if (fl_access(filename, 0)) fl_mkdir(filename, 0777);
|
2005-03-20 20:41:56 +03:00
|
|
|
|
|
|
|
strlcat(filename, "/", sizeof(filename));
|
2005-03-21 00:27:20 +03:00
|
|
|
strlcat(filename, safename, sizeof(filename));
|
2005-03-20 20:41:56 +03:00
|
|
|
|
|
|
|
char *ext = filename + strlen(filename);
|
|
|
|
if (ext >= (filename + sizeof(filename) - 5)) {
|
|
|
|
fl_alert("The template name \"%s\" is too long!", c);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-03-21 00:27:20 +03:00
|
|
|
// Save the .fl file...
|
2005-03-20 20:41:56 +03:00
|
|
|
strcpy(ext, ".fl");
|
|
|
|
|
2017-10-15 14:47:01 +03:00
|
|
|
if (!fl_access(filename, 0)) {
|
2005-03-20 20:41:56 +03:00
|
|
|
if (fl_choice("The template \"%s\" already exists.\n"
|
|
|
|
"Do you want to replace it?", "Cancel",
|
2020-07-01 19:03:10 +03:00
|
|
|
"Replace", NULL, c) == 0) return;
|
2005-03-20 20:41:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!write_file(filename)) {
|
|
|
|
fl_alert("Error writing %s: %s", filename, strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(HAVE_LIBPNG) && defined(HAVE_LIBZ)
|
|
|
|
// Get the screenshot, if any...
|
|
|
|
Fl_Type *t;
|
|
|
|
|
|
|
|
for (t = Fl_Type::first; t; t = t->next) {
|
|
|
|
// Find the first window...
|
2023-07-19 21:41:58 +03:00
|
|
|
if (t->is_a(Fl_Type::ID_Window)) break;
|
2005-03-20 20:41:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!t) return;
|
|
|
|
|
|
|
|
// Grab a screenshot...
|
|
|
|
Fl_Window_Type *wt = (Fl_Window_Type *)t;
|
|
|
|
uchar *pixels;
|
|
|
|
int w, h;
|
|
|
|
|
|
|
|
if ((pixels = wt->read_image(w, h)) == NULL) return;
|
|
|
|
|
|
|
|
// Save to a PNG file...
|
|
|
|
strcpy(ext, ".png");
|
|
|
|
|
2021-11-09 21:55:35 +03:00
|
|
|
errno = 0;
|
2021-11-11 22:58:09 +03:00
|
|
|
if (fl_write_png(filename, pixels, w, h, 3) != 0) {
|
2005-03-20 20:41:56 +03:00
|
|
|
delete[] pixels;
|
|
|
|
fl_alert("Error writing %s: %s", filename, strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
# if 0 // The original PPM output code...
|
|
|
|
strcpy(ext, ".ppm");
|
2010-11-18 23:00:01 +03:00
|
|
|
fp = fl_fopen(filename, "wb");
|
2005-03-20 20:41:56 +03:00
|
|
|
fprintf(fp, "P6\n%d %d 255\n", w, h);
|
|
|
|
fwrite(pixels, w * h, 3, fp);
|
|
|
|
fclose(fp);
|
|
|
|
# endif // 0
|
|
|
|
|
|
|
|
delete[] pixels;
|
|
|
|
#endif // HAVE_LIBPNG && HAVE_LIBZ
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Reload the file set by \c filename, replacing the current design.
|
|
|
|
If the design was modified, a dialog will ask for confirmation.
|
|
|
|
*/
|
2005-03-24 19:31:59 +03:00
|
|
|
void revert_cb(Fl_Widget *,void *) {
|
|
|
|
if (modflag) {
|
|
|
|
if (!fl_choice("This user interface has been changed. Really revert?",
|
|
|
|
"Cancel", "Revert", NULL)) return;
|
|
|
|
}
|
|
|
|
undo_suspend();
|
|
|
|
if (!read_file(filename, 0)) {
|
|
|
|
undo_resume();
|
2021-12-17 20:34:51 +03:00
|
|
|
widget_browser->rebuild();
|
2023-03-19 22:04:01 +03:00
|
|
|
g_project.update_settings_dialog();
|
2005-03-24 19:31:59 +03:00
|
|
|
fl_message("Can't read %s: %s", filename, strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
2021-12-17 20:34:51 +03:00
|
|
|
widget_browser->rebuild();
|
2005-03-24 19:31:59 +03:00
|
|
|
undo_resume();
|
2021-12-10 03:22:15 +03:00
|
|
|
set_modflag(0, 0);
|
2005-03-24 19:31:59 +03:00
|
|
|
undo_clear();
|
2023-03-19 22:04:01 +03:00
|
|
|
g_project.update_settings_dialog();
|
2005-03-24 19:31:59 +03:00
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Exit Fluid; we hope you had a nice experience.
|
|
|
|
If the design was modified, a dialog will ask for confirmation.
|
|
|
|
*/
|
1999-04-19 03:43:42 +04:00
|
|
|
void exit_cb(Fl_Widget *,void *) {
|
2022-12-10 15:11:49 +03:00
|
|
|
flush_text_widgets();
|
2016-07-19 00:12:25 +03:00
|
|
|
|
2023-08-28 17:29:08 +03:00
|
|
|
// verify user intention
|
|
|
|
if (confirm_project_clear() == false)
|
|
|
|
return;
|
|
|
|
|
2016-07-19 00:12:25 +03:00
|
|
|
// Stop any external editor update timers
|
|
|
|
ExternalCodeEditor::stop_update_timer();
|
|
|
|
|
2002-10-31 21:49:05 +03:00
|
|
|
save_position(main_window,"main_window_pos");
|
|
|
|
|
|
|
|
if (widgetbin_panel) {
|
|
|
|
save_position(widgetbin_panel,"widgetbin_pos");
|
|
|
|
delete widgetbin_panel;
|
|
|
|
}
|
2005-11-03 23:43:19 +03:00
|
|
|
if (sourceview_panel) {
|
|
|
|
Fl_Preferences svp(fluid_prefs, "sourceview");
|
|
|
|
svp.set("autorefresh", sv_autorefresh->value());
|
|
|
|
svp.set("autoposition", sv_autoposition->value());
|
|
|
|
svp.set("tab", sv_tab->find(sv_tab->value()));
|
|
|
|
save_position(sourceview_panel,"sourceview_pos");
|
|
|
|
delete sourceview_panel;
|
2017-11-18 21:13:06 +03:00
|
|
|
sourceview_panel = 0;
|
2005-11-03 23:43:19 +03:00
|
|
|
}
|
2023-07-22 17:01:49 +03:00
|
|
|
if (shell_run_window) {
|
|
|
|
save_position(shell_run_window,"shell_run_Window_pos");
|
|
|
|
}
|
|
|
|
|
2001-08-11 20:09:26 +04:00
|
|
|
if (about_panel)
|
|
|
|
delete about_panel;
|
|
|
|
if (help_dialog)
|
|
|
|
delete help_dialog;
|
|
|
|
|
2023-09-26 17:01:03 +03:00
|
|
|
if (g_shell_config)
|
|
|
|
g_shell_config->write(fluid_prefs, FD_STORE_USER);
|
2023-03-18 19:33:27 +03:00
|
|
|
g_layout_list.write(fluid_prefs, FD_STORE_USER);
|
|
|
|
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_clear();
|
|
|
|
|
2016-07-19 00:12:25 +03:00
|
|
|
// Destroy tree
|
|
|
|
// Doing so causes dtors to automatically close all external editors
|
|
|
|
// and cleans up editor tmp files. Then remove fluid tmpdir /last/.
|
2023-01-01 22:05:42 +03:00
|
|
|
g_project.reset();
|
2016-07-19 00:12:25 +03:00
|
|
|
ExternalCodeEditor::tmpdir_clear();
|
2023-09-26 17:01:03 +03:00
|
|
|
delete_tmpdir();
|
2016-07-19 00:12:25 +03:00
|
|
|
|
1999-04-19 03:43:42 +04:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
2023-08-28 17:29:08 +03:00
|
|
|
Clear the current project and create a new, empty one.
|
2003-06-01 04:23:57 +04:00
|
|
|
|
2023-08-28 17:29:08 +03:00
|
|
|
If the current project was modified, FLUID will give the user the opportunity
|
|
|
|
to save the old project first.
|
2003-06-01 04:23:57 +04:00
|
|
|
|
2023-08-28 17:29:08 +03:00
|
|
|
\return false if the operation was canceled
|
2021-12-08 17:52:15 +03:00
|
|
|
*/
|
2023-08-28 17:29:08 +03:00
|
|
|
bool new_project() {
|
|
|
|
// verify user intention
|
|
|
|
if (confirm_project_clear() == false)
|
|
|
|
return false;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2023-08-28 17:29:08 +03:00
|
|
|
// clear the current project
|
2023-01-01 22:05:42 +03:00
|
|
|
g_project.reset();
|
2019-02-02 01:16:49 +03:00
|
|
|
set_filename(NULL);
|
2021-12-10 03:22:15 +03:00
|
|
|
set_modflag(0, 0);
|
2021-12-17 20:34:51 +03:00
|
|
|
widget_browser->rebuild();
|
2023-03-19 22:04:01 +03:00
|
|
|
g_project.update_settings_dialog();
|
2023-08-28 17:29:08 +03:00
|
|
|
|
|
|
|
// all is clear to continue
|
|
|
|
return true;
|
2019-02-02 01:16:49 +03:00
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Open the template browser and load a new file from templates.
|
2023-08-28 17:29:08 +03:00
|
|
|
|
|
|
|
If the current project was modified, FLUID will give the user the opportunity
|
|
|
|
to save the old project first.
|
|
|
|
|
|
|
|
\return false if the operation was canceled or failed otherwise
|
2021-12-08 17:52:15 +03:00
|
|
|
*/
|
2023-08-28 17:29:08 +03:00
|
|
|
bool new_project_from_template() {
|
|
|
|
// clear the current project first
|
|
|
|
if (new_project() == false)
|
|
|
|
return false;
|
2019-02-02 01:16:49 +03:00
|
|
|
|
2005-03-21 00:27:20 +03:00
|
|
|
// Setup the template panel...
|
|
|
|
if (!template_panel) make_template_panel();
|
|
|
|
|
|
|
|
template_clear();
|
|
|
|
template_browser->add("Blank");
|
|
|
|
template_load();
|
|
|
|
|
|
|
|
template_name->hide();
|
|
|
|
template_name->value("");
|
|
|
|
|
|
|
|
template_instance->show();
|
|
|
|
template_instance->deactivate();
|
|
|
|
template_instance->value("");
|
|
|
|
|
2019-02-02 01:16:49 +03:00
|
|
|
template_delete->show();
|
2005-03-21 00:27:20 +03:00
|
|
|
|
|
|
|
template_submit->label("New");
|
|
|
|
template_submit->deactivate();
|
|
|
|
|
|
|
|
template_panel->label("New");
|
|
|
|
|
2019-02-02 01:16:49 +03:00
|
|
|
//if ( template_browser->size() == 1 ) { // only one item?
|
2023-08-28 17:29:08 +03:00
|
|
|
template_browser->value(1); // select it
|
|
|
|
template_browser->do_callback();
|
2019-02-02 01:16:49 +03:00
|
|
|
//}
|
2016-10-17 22:20:36 +03:00
|
|
|
|
2005-03-21 00:27:20 +03:00
|
|
|
// Show the panel and wait for the user to do something...
|
|
|
|
template_panel->show();
|
|
|
|
while (template_panel->shown()) Fl::wait();
|
|
|
|
|
|
|
|
// See if the user chose anything...
|
|
|
|
int item = template_browser->value();
|
2023-08-28 17:29:08 +03:00
|
|
|
if (item < 1) return false;
|
2005-03-21 00:27:20 +03:00
|
|
|
|
|
|
|
// Load the template, if any...
|
|
|
|
const char *tname = (const char *)template_browser->data(item);
|
|
|
|
|
|
|
|
if (tname) {
|
|
|
|
// Grab the instance name...
|
|
|
|
const char *iname = template_instance->value();
|
|
|
|
|
|
|
|
if (iname && *iname) {
|
|
|
|
// Copy the template to a temp file, then read it in...
|
|
|
|
char line[1024], *ptr, *next;
|
|
|
|
FILE *infile, *outfile;
|
|
|
|
|
2010-11-18 23:00:01 +03:00
|
|
|
if ((infile = fl_fopen(tname, "r")) == NULL) {
|
2020-07-01 19:03:10 +03:00
|
|
|
fl_alert("Error reading template file \"%s\":\n%s", tname,
|
|
|
|
strerror(errno));
|
|
|
|
set_modflag(0);
|
|
|
|
undo_clear();
|
2023-08-28 17:29:08 +03:00
|
|
|
return false;
|
2005-03-21 00:27:20 +03:00
|
|
|
}
|
|
|
|
|
2010-11-18 23:00:01 +03:00
|
|
|
if ((outfile = fl_fopen(cutfname(1), "w")) == NULL) {
|
2020-07-01 19:03:10 +03:00
|
|
|
fl_alert("Error writing buffer file \"%s\":\n%s", cutfname(1),
|
|
|
|
strerror(errno));
|
|
|
|
fclose(infile);
|
|
|
|
set_modflag(0);
|
|
|
|
undo_clear();
|
2023-08-28 17:29:08 +03:00
|
|
|
return false;
|
2005-03-21 00:27:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
while (fgets(line, sizeof(line), infile)) {
|
2020-07-01 19:03:10 +03:00
|
|
|
// Replace @INSTANCE@ with the instance name...
|
|
|
|
for (ptr = line; (next = strstr(ptr, "@INSTANCE@")) != NULL; ptr = next + 10) {
|
|
|
|
fwrite(ptr, next - ptr, 1, outfile);
|
|
|
|
fputs(iname, outfile);
|
|
|
|
}
|
2005-03-21 00:27:20 +03:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
fputs(ptr, outfile);
|
2005-03-21 00:27:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose(infile);
|
|
|
|
fclose(outfile);
|
|
|
|
|
|
|
|
undo_suspend();
|
|
|
|
read_file(cutfname(1), 0);
|
2017-10-15 13:18:53 +03:00
|
|
|
fl_unlink(cutfname(1));
|
2005-03-21 00:27:20 +03:00
|
|
|
undo_resume();
|
|
|
|
} else {
|
|
|
|
// No instance name, so read the template without replacements...
|
|
|
|
undo_suspend();
|
|
|
|
read_file(tname, 0);
|
|
|
|
undo_resume();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-17 20:34:51 +03:00
|
|
|
widget_browser->rebuild();
|
2023-03-19 22:04:01 +03:00
|
|
|
g_project.update_settings_dialog();
|
2005-03-19 11:38:21 +03:00
|
|
|
set_modflag(0);
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_clear();
|
2023-08-28 17:29:08 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Open a native file chooser to allow choosing a project file for reading.
|
|
|
|
|
|
|
|
Path and filename are preset with the current project filename, if there
|
|
|
|
is one.
|
|
|
|
|
|
|
|
\param title a text describing the action after selecting a file (load, merge, ...)
|
|
|
|
\return the file path and name, or an empty string if the operation was canceled
|
|
|
|
*/
|
|
|
|
Fl_String open_project_filechooser(const Fl_String &title) {
|
|
|
|
Fl_Native_File_Chooser dialog;
|
|
|
|
dialog.title(title.c_str());
|
|
|
|
dialog.type(Fl_Native_File_Chooser::BROWSE_FILE);
|
|
|
|
dialog.filter("FLUID Files\t*.f[ld]\n");
|
|
|
|
if (filename) {
|
|
|
|
Fl_String current_project_file = filename;
|
|
|
|
dialog.directory(fl_filename_path(current_project_file).c_str());
|
|
|
|
dialog.preset_file(fl_filename_name(current_project_file).c_str());
|
|
|
|
}
|
|
|
|
if (dialog.show() != 0)
|
|
|
|
return Fl_String();
|
|
|
|
return Fl_String(dialog.filename());
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
2023-08-28 17:29:08 +03:00
|
|
|
/**
|
|
|
|
Load a project from the give file name and path.
|
|
|
|
|
|
|
|
The project file is inserted at the currently selected type.
|
|
|
|
|
|
|
|
If no filename is given, FLUID will open a file chooser dialog.
|
|
|
|
|
|
|
|
\param[in] new_filename path and name of the new project file
|
|
|
|
\return false if the operation failed
|
|
|
|
*/
|
|
|
|
bool merge_project_file(const Fl_String &filename_arg) {
|
|
|
|
bool is_a_merge = (Fl_Type::first != NULL);
|
|
|
|
Fl_String title = is_a_merge ? "Merge Project File" : "Open Project File";
|
|
|
|
|
|
|
|
// ask for a filename if none was given
|
|
|
|
Fl_String new_filename = filename_arg;
|
|
|
|
if (new_filename.empty()) {
|
|
|
|
new_filename = open_project_filechooser(title);
|
|
|
|
if (new_filename.empty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *c = new_filename.c_str();
|
|
|
|
const char *oldfilename = filename;
|
|
|
|
filename = NULL;
|
|
|
|
set_filename(c);
|
|
|
|
if (is_a_merge) undo_checkpoint();
|
|
|
|
undo_suspend();
|
|
|
|
if (!read_file(c, is_a_merge)) {
|
|
|
|
undo_resume();
|
|
|
|
widget_browser->rebuild();
|
|
|
|
g_project.update_settings_dialog();
|
|
|
|
fl_message("Can't read %s: %s", c, strerror(errno));
|
|
|
|
free((void *)filename);
|
|
|
|
filename = oldfilename;
|
|
|
|
if (main_window) set_modflag(modflag);
|
2023-08-29 03:20:45 +03:00
|
|
|
return false;
|
2023-08-28 17:29:08 +03:00
|
|
|
}
|
|
|
|
undo_resume();
|
|
|
|
widget_browser->rebuild();
|
|
|
|
if (is_a_merge) {
|
|
|
|
// Inserting a file; restore the original filename...
|
|
|
|
free((void *)filename);
|
|
|
|
filename = oldfilename;
|
|
|
|
set_modflag(1);
|
|
|
|
} else {
|
|
|
|
// Loaded a file; free the old filename...
|
|
|
|
set_modflag(0, 0);
|
|
|
|
undo_clear();
|
|
|
|
if (oldfilename) free((void *)oldfilename);
|
|
|
|
}
|
|
|
|
g_project.update_settings_dialog();
|
2023-08-29 03:20:45 +03:00
|
|
|
return true;
|
2023-08-28 17:29:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Open a file chooser and load an exiting project file.
|
|
|
|
|
|
|
|
If the current project was modified, FLUID will give the user the opportunity
|
|
|
|
to save the old project first.
|
|
|
|
|
|
|
|
If no filename is given, FLUID will open a file chooser dialog.
|
|
|
|
|
|
|
|
\param[in] filename_arg load from this file, or show file chooser if empty
|
|
|
|
\return false if the operation was canceled or failed otherwise
|
|
|
|
*/
|
|
|
|
bool open_project_file(const Fl_String &new_filename) {
|
|
|
|
// verify user intention
|
|
|
|
if (new_project() == false)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return merge_project_file(new_filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
/**
|
|
|
|
Handle app launch with an associated filename (macOS only).
|
|
|
|
Should there be a modified design already, Fluid asks for user confirmation.
|
|
|
|
\param[in] c the filename of the new design
|
|
|
|
*/
|
|
|
|
void apple_open_cb(const char *c) {
|
|
|
|
open_project_file(Fl_String(c));
|
|
|
|
}
|
|
|
|
#endif // __APPLE__
|
|
|
|
|
2023-09-05 16:11:09 +03:00
|
|
|
/**
|
|
|
|
Get the absolute path of the project file, for example `/Users/matt/dev/`.
|
|
|
|
*/
|
|
|
|
Fl_String Fluid_Project::projectfile_path() const {
|
|
|
|
return end_with_slash(fl_filename_absolute(fl_filename_path(filename), g_launch_path));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Get the project file name including extension, for example `test.fl`.
|
|
|
|
*/
|
|
|
|
Fl_String Fluid_Project::projectfile_name() const {
|
|
|
|
return fl_filename_name(filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Get the absolute path of the generated C++ code file, for example `/Users/matt/dev/src/`.
|
|
|
|
*/
|
|
|
|
Fl_String Fluid_Project::codefile_path() const {
|
|
|
|
Fl_String path = fl_filename_path(code_file_name);
|
|
|
|
if (batch_mode)
|
|
|
|
return end_with_slash(fl_filename_absolute(path, g_launch_path));
|
|
|
|
else
|
|
|
|
return end_with_slash(fl_filename_absolute(path, projectfile_path()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Get the generated C++ code file name including extension, for example `test.cxx`.
|
|
|
|
*/
|
|
|
|
Fl_String Fluid_Project::codefile_name() const {
|
|
|
|
Fl_String name = fl_filename_name(code_file_name);
|
|
|
|
if (name.empty()) {
|
|
|
|
return fl_filename_setext(fl_filename_name(filename), ".cxx");
|
|
|
|
} else if (name[0] == '.') {
|
|
|
|
return fl_filename_setext(fl_filename_name(filename), code_file_name);
|
|
|
|
} else {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Get the absolute path of the generated C++ header file, for example `/Users/matt/dev/src/`.
|
|
|
|
*/
|
|
|
|
Fl_String Fluid_Project::headerfile_path() const {
|
|
|
|
Fl_String path = fl_filename_path(header_file_name);
|
|
|
|
if (batch_mode)
|
|
|
|
return end_with_slash(fl_filename_absolute(path, g_launch_path));
|
|
|
|
else
|
|
|
|
return end_with_slash(fl_filename_absolute(path, projectfile_path()));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Get the generated C++ header file name including extension, for example `test.cxx`.
|
|
|
|
*/
|
|
|
|
Fl_String Fluid_Project::headerfile_name() const {
|
|
|
|
Fl_String name = fl_filename_name(header_file_name);
|
|
|
|
if (name.empty()) {
|
|
|
|
return fl_filename_setext(fl_filename_name(filename), ".h");
|
|
|
|
} else if (name[0] == '.') {
|
|
|
|
return fl_filename_setext(fl_filename_name(filename), header_file_name);
|
|
|
|
} else {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Get the absolute path of the generated i18n strings file, for example `/Users/matt/dev/`.
|
|
|
|
Although it may be more useful to put the text file into the same directory
|
|
|
|
with the source and header file, historically, the text is always saved with
|
|
|
|
the project file in interactive mode, and in the FLUID launch directory in
|
|
|
|
batch mode.
|
|
|
|
*/
|
|
|
|
Fl_String Fluid_Project::stringsfile_path() const {
|
|
|
|
if (batch_mode)
|
|
|
|
return end_with_slash(g_launch_path);
|
|
|
|
else
|
|
|
|
return projectfile_path();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Get the generated i18n text file name including extension, for example `test.po`.
|
|
|
|
*/
|
|
|
|
Fl_String Fluid_Project::stringsfile_name() const {
|
|
|
|
switch (i18n_type) {
|
|
|
|
default: return fl_filename_setext(fl_filename_name(filename), ".txt");
|
|
|
|
case 1: return fl_filename_setext(fl_filename_name(filename), ".po");
|
|
|
|
case 2: return fl_filename_setext(fl_filename_name(filename), ".msg");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Get the name of the project file without the filename extension.
|
|
|
|
*/
|
|
|
|
Fl_String Fluid_Project::basename() const {
|
|
|
|
return fl_filename_setext(fl_filename_name(filename), "");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Generate the C++ source and header filenames and write those files.
|
2021-12-06 01:30:41 +03:00
|
|
|
|
|
|
|
This function creates the source filename by setting the file
|
2021-12-08 17:52:15 +03:00
|
|
|
extension to \c code_file_name and a header filename
|
2021-12-06 01:30:41 +03:00
|
|
|
with the extension \c code_file_name which are both
|
|
|
|
settable by the user.
|
|
|
|
|
2023-01-26 17:23:43 +03:00
|
|
|
If the code filename has not been set yet, a "save file as" dialog will be
|
|
|
|
presented to the user.
|
2021-12-06 01:30:41 +03:00
|
|
|
|
2023-01-26 17:23:43 +03:00
|
|
|
In batch_mode, the function will either be silent, or, if opening or writing
|
|
|
|
the files fails, write an error message to \c stderr and exit with exit code 1.
|
|
|
|
|
|
|
|
In interactive mode, it will pop up an error message, or, if the user
|
|
|
|
hasn't disabled that, pop up a confirmation message.
|
2021-12-06 01:30:41 +03:00
|
|
|
|
|
|
|
\return 1 if the operation failed, 0 if it succeeded
|
|
|
|
*/
|
2023-09-05 16:11:09 +03:00
|
|
|
int write_code_files()
|
|
|
|
{
|
|
|
|
// -- handle user interface issues
|
2022-12-10 15:11:49 +03:00
|
|
|
flush_text_widgets();
|
1998-10-06 22:21:25 +04:00
|
|
|
if (!filename) {
|
|
|
|
save_cb(0,0);
|
2021-12-06 01:46:11 +03:00
|
|
|
if (!filename) return 1;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2023-09-05 16:11:09 +03:00
|
|
|
|
|
|
|
// -- generate the file names with absolute paths
|
2023-01-26 17:23:43 +03:00
|
|
|
Fd_Code_Writer f;
|
2023-09-05 16:11:09 +03:00
|
|
|
Fl_String code_filename = g_project.codefile_path() + g_project.codefile_name();
|
|
|
|
Fl_String header_filename = g_project.headerfile_path() + g_project.headerfile_name();
|
|
|
|
|
|
|
|
// -- write the code and header files
|
|
|
|
if (!batch_mode) enter_project_dir();
|
|
|
|
int x = f.write_code(code_filename.c_str(), header_filename.c_str());
|
2023-09-26 01:29:14 +03:00
|
|
|
Fl_String code_filename_rel = fl_filename_relative(code_filename);
|
|
|
|
Fl_String header_filename_rel = fl_filename_relative(header_filename);
|
2022-11-15 19:48:06 +03:00
|
|
|
if (!batch_mode) leave_project_dir();
|
2023-09-05 16:11:09 +03:00
|
|
|
|
|
|
|
// -- print error message in batch mode or pop up an error or confirmation dialog box
|
2015-03-09 23:37:45 +03:00
|
|
|
if (batch_mode) {
|
2023-09-05 16:11:09 +03:00
|
|
|
if (!x) {
|
|
|
|
fprintf(stderr, "%s and %s: %s\n",
|
2023-09-26 01:29:14 +03:00
|
|
|
code_filename_rel.c_str(),
|
|
|
|
header_filename_rel.c_str(),
|
2023-09-05 16:11:09 +03:00
|
|
|
strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
} else {
|
|
|
|
if (!x) {
|
2023-09-26 01:29:14 +03:00
|
|
|
fl_message("Can't write %s or %s: %s",
|
|
|
|
code_filename_rel.c_str(),
|
|
|
|
header_filename_rel.c_str(),
|
2023-09-05 16:11:09 +03:00
|
|
|
strerror(errno));
|
2021-12-10 03:22:15 +03:00
|
|
|
} else {
|
|
|
|
set_modflag(-1, 0);
|
|
|
|
if (completion_button->value()) {
|
2023-09-05 16:11:09 +03:00
|
|
|
fl_message("Wrote %s and %s",
|
2023-09-26 01:29:14 +03:00
|
|
|
code_filename_rel.c_str(),
|
|
|
|
header_filename_rel.c_str());
|
2021-12-10 03:22:15 +03:00
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
}
|
2021-12-06 01:46:11 +03:00
|
|
|
return 0;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Callback to write C++ code and header files.
|
|
|
|
*/
|
2021-12-06 01:30:41 +03:00
|
|
|
void write_cb(Fl_Widget *, void *) {
|
|
|
|
write_code_files();
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Write the strings that are used in i18n.
|
|
|
|
*/
|
2000-04-24 22:22:50 +04:00
|
|
|
void write_strings_cb(Fl_Widget *, void *) {
|
2022-12-10 15:11:49 +03:00
|
|
|
flush_text_widgets();
|
2000-04-24 22:22:50 +04:00
|
|
|
if (!filename) {
|
|
|
|
save_cb(0,0);
|
|
|
|
if (!filename) return;
|
|
|
|
}
|
2023-09-05 16:11:09 +03:00
|
|
|
Fl_String filename = g_project.stringsfile_path() + g_project.stringsfile_name();
|
|
|
|
int x = write_strings(filename);
|
2015-03-09 23:37:45 +03:00
|
|
|
if (batch_mode) {
|
2023-09-05 16:11:09 +03:00
|
|
|
if (x) {
|
|
|
|
fprintf(stderr, "%s : %s\n", filename.c_str(), strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
2000-04-24 22:22:50 +04:00
|
|
|
} else {
|
|
|
|
if (x) {
|
2023-09-05 16:11:09 +03:00
|
|
|
fl_message("Can't write %s: %s", filename.c_str(), strerror(errno));
|
2002-04-30 22:11:49 +04:00
|
|
|
} else if (completion_button->value()) {
|
2023-09-05 16:11:09 +03:00
|
|
|
fl_message("Wrote %s", g_project.stringsfile_name().c_str());
|
2000-04-24 22:22:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Show the editor for the \c current Fl_Type.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void openwidget_cb(Fl_Widget *, void *) {
|
|
|
|
if (!Fl_Type::current) {
|
|
|
|
fl_message("Please select a widget");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Fl_Type::current->open();
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
User chose to copy the currently selected widgets.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void copy_cb(Fl_Widget*, void*) {
|
2022-12-10 15:11:49 +03:00
|
|
|
flush_text_widgets();
|
2005-03-18 00:57:17 +03:00
|
|
|
if (!Fl_Type::current) {
|
|
|
|
fl_beep();
|
|
|
|
return;
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
ipasteoffset = 10;
|
|
|
|
if (!write_file(cutfname(),1)) {
|
1998-11-05 19:04:53 +03:00
|
|
|
fl_message("Can't write %s: %s", cutfname(), strerror(errno));
|
1998-10-06 22:21:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
User chose to cut the currently selected widgets.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void cut_cb(Fl_Widget *, void *) {
|
2005-03-18 00:57:17 +03:00
|
|
|
if (!Fl_Type::current) {
|
|
|
|
fl_beep();
|
|
|
|
return;
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
if (!write_file(cutfname(),1)) {
|
1998-11-05 19:04:53 +03:00
|
|
|
fl_message("Can't write %s: %s", cutfname(), strerror(errno));
|
1998-10-06 22:21:25 +04:00
|
|
|
return;
|
|
|
|
}
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_checkpoint();
|
|
|
|
set_modflag(1);
|
|
|
|
ipasteoffset = 0;
|
|
|
|
Fl_Type *p = Fl_Type::current->parent;
|
|
|
|
while (p && p->selected) p = p->parent;
|
1998-10-06 22:21:25 +04:00
|
|
|
delete_all(1);
|
|
|
|
if (p) select_only(p);
|
2021-12-17 20:34:51 +03:00
|
|
|
widget_browser->rebuild();
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
User chose to delete the currently selected widgets.
|
|
|
|
*/
|
2005-03-20 04:49:46 +03:00
|
|
|
void delete_cb(Fl_Widget *, void *) {
|
|
|
|
if (!Fl_Type::current) {
|
|
|
|
fl_beep();
|
|
|
|
return;
|
|
|
|
}
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_checkpoint();
|
|
|
|
set_modflag(1);
|
2005-03-20 04:49:46 +03:00
|
|
|
ipasteoffset = 0;
|
|
|
|
Fl_Type *p = Fl_Type::current->parent;
|
|
|
|
while (p && p->selected) p = p->parent;
|
|
|
|
delete_all(1);
|
|
|
|
if (p) select_only(p);
|
2021-12-17 20:34:51 +03:00
|
|
|
widget_browser->rebuild();
|
2005-03-20 04:49:46 +03:00
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
User chose to paste the widgets from the cut buffer.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void paste_cb(Fl_Widget*, void*) {
|
2003-07-19 10:10:20 +04:00
|
|
|
//if (ipasteoffset) force_parent = 1;
|
1998-10-06 22:21:25 +04:00
|
|
|
pasteoffset = ipasteoffset;
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_checkpoint();
|
|
|
|
undo_suspend();
|
2021-12-11 21:43:00 +03:00
|
|
|
Strategy strategy = kAddAfterCurrent;
|
|
|
|
if (Fl_Type::current && Fl_Type::current->is_group())
|
|
|
|
strategy = kAddAsLastChild;
|
|
|
|
if (!read_file(cutfname(), 1, strategy)) {
|
2021-12-17 20:34:51 +03:00
|
|
|
widget_browser->rebuild();
|
1998-11-05 19:04:53 +03:00
|
|
|
fl_message("Can't read %s: %s", cutfname(), strerror(errno));
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_resume();
|
2021-12-17 20:34:51 +03:00
|
|
|
widget_browser->display(Fl_Type::current);
|
|
|
|
widget_browser->rebuild();
|
1998-10-06 22:21:25 +04:00
|
|
|
pasteoffset = 0;
|
|
|
|
ipasteoffset += 10;
|
|
|
|
force_parent = 0;
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Duplicate the selected widgets.
|
|
|
|
*/
|
2005-03-18 00:57:17 +03:00
|
|
|
void duplicate_cb(Fl_Widget*, void*) {
|
|
|
|
if (!Fl_Type::current) {
|
|
|
|
fl_beep();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-12-10 15:11:49 +03:00
|
|
|
flush_text_widgets();
|
|
|
|
|
2005-03-18 00:57:17 +03:00
|
|
|
if (!write_file(cutfname(1),1)) {
|
|
|
|
fl_message("Can't write %s: %s", cutfname(1), strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pasteoffset = 0;
|
|
|
|
force_parent = 1;
|
|
|
|
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_checkpoint();
|
|
|
|
undo_suspend();
|
2021-12-11 21:43:00 +03:00
|
|
|
if (!read_file(cutfname(1), 1, kAddAfterCurrent)) {
|
2005-03-18 00:57:17 +03:00
|
|
|
fl_message("Can't read %s: %s", cutfname(1), strerror(errno));
|
|
|
|
}
|
2017-10-15 13:18:53 +03:00
|
|
|
fl_unlink(cutfname(1));
|
2021-12-17 20:34:51 +03:00
|
|
|
widget_browser->display(Fl_Type::current);
|
|
|
|
widget_browser->rebuild();
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_resume();
|
2005-03-18 00:57:17 +03:00
|
|
|
|
|
|
|
force_parent = 0;
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
User wants to sort selected widgets by y coordinate.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
static void sort_cb(Fl_Widget *,void *) {
|
2022-11-26 03:35:50 +03:00
|
|
|
undo_checkpoint();
|
2021-12-08 17:52:15 +03:00
|
|
|
sort((Fl_Type*)NULL);
|
2021-12-17 20:34:51 +03:00
|
|
|
widget_browser->rebuild();
|
2022-11-26 03:35:50 +03:00
|
|
|
set_modflag(1);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Open the "About" dialog.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void about_cb(Fl_Widget *, void *) {
|
2002-01-01 18:11:33 +03:00
|
|
|
if (!about_panel) make_about_panel();
|
1998-10-06 22:21:25 +04:00
|
|
|
about_panel->show();
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Open a dialog to show the HTML help page form the FLTK documentation folder.
|
|
|
|
\param[in] name name of the HTML help file.
|
|
|
|
*/
|
2001-09-23 17:08:03 +04:00
|
|
|
void show_help(const char *name) {
|
2020-07-01 19:03:10 +03:00
|
|
|
const char *docdir;
|
|
|
|
char helpname[FL_PATH_MAX];
|
2008-11-29 20:06:31 +03:00
|
|
|
|
2001-09-29 18:38:59 +04:00
|
|
|
if (!help_dialog) help_dialog = new Fl_Help_Dialog();
|
2001-09-23 17:08:03 +04:00
|
|
|
|
2017-10-13 17:58:30 +03:00
|
|
|
if ((docdir = fl_getenv("FLTK_DOCDIR")) == NULL) {
|
2001-12-21 21:16:50 +03:00
|
|
|
docdir = FLTK_DOCDIR;
|
|
|
|
}
|
2008-11-29 20:06:31 +03:00
|
|
|
snprintf(helpname, sizeof(helpname), "%s/%s", docdir, name);
|
2001-09-23 17:08:03 +04:00
|
|
|
|
2011-01-24 20:04:22 +03:00
|
|
|
// make sure that we can read the file
|
|
|
|
FILE *f = fopen(helpname, "rb");
|
|
|
|
if (f) {
|
|
|
|
fclose(f);
|
|
|
|
help_dialog->load(helpname);
|
|
|
|
} else {
|
|
|
|
// if we can not read the file, we display the canned version instead
|
|
|
|
// or ask the native browser to open the page on www.fltk.org
|
|
|
|
if (strcmp(name, "fluid.html")==0) {
|
|
|
|
if (!Fl_Shared_Image::find("embedded:/fluid-org.png"))
|
|
|
|
new Fl_PNG_Image("embedded:/fluid-org.png", fluid_org_png, sizeof(fluid_org_png));
|
|
|
|
help_dialog->value
|
|
|
|
(
|
|
|
|
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n"
|
|
|
|
"<html><head><title>FLTK: Programming with FLUID</title></head><body>\n"
|
|
|
|
"<h2>What is FLUID?</h2>\n"
|
|
|
|
"The Fast Light User Interface Designer, or FLUID, is a graphical editor "
|
|
|
|
"that is used to produce FLTK source code. FLUID edits and saves its state "
|
|
|
|
"in <code>.fl</code> files. These files are text, and you can (with care) "
|
|
|
|
"edit them in a text editor, perhaps to get some special effects.<p>\n"
|
|
|
|
"FLUID can \"compile\" the <code>.fl</code> file into a <code>.cxx</code> "
|
|
|
|
"and a <code>.h</code> file. The <code>.cxx</code> file defines all the "
|
|
|
|
"objects from the <code>.fl</code> file and the <code>.h</code> file "
|
|
|
|
"declares all the global ones. FLUID also supports localization "
|
|
|
|
"(Internationalization) of label strings using message files and the GNU "
|
|
|
|
"gettext or POSIX catgets interfaces.<p>\n"
|
|
|
|
"A simple program can be made by putting all your code (including a <code>"
|
|
|
|
"main()</code> function) into the <code>.fl</code> file and thus making the "
|
|
|
|
"<code>.cxx</code> file a single source file to compile. Most programs are "
|
|
|
|
"more complex than this, so you write other <code>.cxx</code> files that "
|
|
|
|
"call the FLUID functions. These <code>.cxx</code> files must <code>"
|
|
|
|
"#include</code> the <code>.h</code> file or they can <code>#include</code> "
|
|
|
|
"the <code>.cxx</code> file so it still appears to be a single source file.<p>"
|
|
|
|
"<img src=\"embedded:/fluid-org.png\"></p>"
|
|
|
|
"<p>More information is available online at <a href="
|
2020-04-08 01:53:16 +03:00
|
|
|
"\"https://www.fltk.org/doc-1.4/fluid.html\">https://www.fltk.org/</a>"
|
2011-01-24 20:04:22 +03:00
|
|
|
"</body></html>"
|
|
|
|
);
|
|
|
|
} else if (strcmp(name, "license.html")==0) {
|
2020-04-08 01:53:16 +03:00
|
|
|
fl_open_uri("https://www.fltk.org/doc-1.4/license.html");
|
2011-01-24 20:04:22 +03:00
|
|
|
return;
|
|
|
|
} else if (strcmp(name, "index.html")==0) {
|
2020-04-08 01:53:16 +03:00
|
|
|
fl_open_uri("https://www.fltk.org/doc-1.4/index.html");
|
2011-01-24 20:04:22 +03:00
|
|
|
return;
|
|
|
|
} else {
|
2020-04-08 01:53:16 +03:00
|
|
|
snprintf(helpname, sizeof(helpname), "https://www.fltk.org/%s", name);
|
2011-01-24 20:04:22 +03:00
|
|
|
fl_open_uri(helpname);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2001-08-11 20:09:26 +04:00
|
|
|
help_dialog->show();
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
User wants help on Fluid.
|
|
|
|
*/
|
2001-09-23 17:08:03 +04:00
|
|
|
void help_cb(Fl_Widget *, void *) {
|
|
|
|
show_help("fluid.html");
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
User wants to see the Fluid manual.
|
|
|
|
*/
|
2001-08-11 20:09:26 +04:00
|
|
|
void manual_cb(Fl_Widget *, void *) {
|
2011-01-24 20:04:22 +03:00
|
|
|
show_help("index.html");
|
2001-08-11 20:09:26 +04:00
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
// ---- Printing
|
2005-03-21 07:51:16 +03:00
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Open the dialog to allow the user to print the current window.
|
|
|
|
*/
|
2005-03-21 07:51:16 +03:00
|
|
|
void print_menu_cb(Fl_Widget *, void *) {
|
2011-09-21 18:11:44 +04:00
|
|
|
int w, h, ww, hh;
|
|
|
|
int frompage, topage;
|
2020-07-01 19:03:10 +03:00
|
|
|
Fl_Type *t; // Current widget
|
|
|
|
int num_windows; // Number of windows
|
|
|
|
Fl_Window_Type *windows[1000]; // Windows to print
|
|
|
|
int winpage; // Current window page
|
2011-09-21 18:11:44 +04:00
|
|
|
Fl_Window *win;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-09-21 18:11:44 +04:00
|
|
|
for (t = Fl_Type::first, num_windows = 0; t; t = t->next) {
|
2023-07-19 21:41:58 +03:00
|
|
|
if (t->is_a(Fl_Type::ID_Window)) {
|
2005-03-21 07:51:16 +03:00
|
|
|
windows[num_windows] = (Fl_Window_Type *)t;
|
2011-06-10 17:37:07 +04:00
|
|
|
if (!((Fl_Window*)(windows[num_windows]->o))->shown()) continue;
|
2011-09-21 18:11:44 +04:00
|
|
|
num_windows ++;
|
2005-03-21 22:35:43 +03:00
|
|
|
}
|
2005-03-21 07:51:16 +03:00
|
|
|
}
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2011-09-21 18:11:44 +04:00
|
|
|
Fl_Printer printjob;
|
|
|
|
if ( printjob.start_job(num_windows, &frompage, &topage) ) return;
|
|
|
|
int pagecount = 0;
|
|
|
|
for (winpage = 0; winpage < num_windows; winpage++) {
|
|
|
|
float scale = 1, scale_x = 1, scale_y = 1;
|
|
|
|
if (winpage+1 < frompage || winpage+1 > topage) continue;
|
|
|
|
printjob.start_page();
|
|
|
|
printjob.printable_rect(&w, &h);
|
2023-08-28 17:29:08 +03:00
|
|
|
|
2005-03-21 07:51:16 +03:00
|
|
|
// Get the time and date...
|
|
|
|
time_t curtime = time(NULL);
|
|
|
|
struct tm *curdate = localtime(&curtime);
|
|
|
|
char date[1024];
|
|
|
|
strftime(date, sizeof(date), "%c", curdate);
|
2011-09-21 18:11:44 +04:00
|
|
|
fl_font(FL_HELVETICA, 12);
|
|
|
|
fl_color(FL_BLACK);
|
|
|
|
fl_draw(date, (w - (int)fl_width(date))/2, fl_height());
|
|
|
|
sprintf(date, "%d/%d", ++pagecount, topage-frompage+1);
|
|
|
|
fl_draw(date, w - (int)fl_width(date), fl_height());
|
2023-08-28 17:29:08 +03:00
|
|
|
|
2011-09-21 18:11:44 +04:00
|
|
|
// Get the base filename...
|
2023-08-28 17:29:08 +03:00
|
|
|
Fl_String basename = fl_filename_name(Fl_String(filename));
|
|
|
|
fl_draw(basename.c_str(), 0, fl_height());
|
|
|
|
|
|
|
|
// print centered and scaled to fit in the page
|
2011-09-21 18:11:44 +04:00
|
|
|
win = (Fl_Window*)windows[winpage]->o;
|
|
|
|
ww = win->decorated_w();
|
|
|
|
if(ww > w) scale_x = float(w)/ww;
|
|
|
|
hh = win->decorated_h();
|
|
|
|
if(hh > h) scale_y = float(h)/hh;
|
|
|
|
if (scale_x < scale) scale = scale_x;
|
|
|
|
if (scale_y < scale) scale = scale_y;
|
|
|
|
if (scale < 1) {
|
|
|
|
printjob.scale(scale);
|
|
|
|
printjob.printable_rect(&w, &h);
|
2023-08-28 17:29:08 +03:00
|
|
|
}
|
2011-09-21 18:11:44 +04:00
|
|
|
printjob.origin(w/2, h/2);
|
|
|
|
printjob.print_window(win, -ww/2, -hh/2);
|
|
|
|
printjob.end_page();
|
2005-03-21 07:51:16 +03:00
|
|
|
}
|
2011-09-21 18:11:44 +04:00
|
|
|
printjob.end_job();
|
2005-03-21 07:51:16 +03:00
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
// ---- Main menu bar
|
|
|
|
|
2023-03-18 19:33:27 +03:00
|
|
|
extern void select_layout_preset_cb(Fl_Widget *, void *user_data);
|
|
|
|
extern void layout_suite_marker(Fl_Widget *, void *user_data);
|
|
|
|
|
2023-08-28 17:29:08 +03:00
|
|
|
static void menu_file_new_cb(Fl_Widget *, void *) { new_project(); }
|
|
|
|
static void menu_file_new_from_template_cb(Fl_Widget *, void *) { new_project_from_template(); }
|
|
|
|
static void menu_file_open_cb(Fl_Widget *, void *) { open_project_file(""); }
|
|
|
|
static void menu_file_insert_cb(Fl_Widget *, void *) { merge_project_file(""); }
|
|
|
|
static void menu_file_open_history_cb(Fl_Widget *, void *v) { open_project_file(Fl_String((const char*)v)); }
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
This is the main Fluid menu.
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
Design history is manipulated right inside this menu structure.
|
2023-09-26 13:39:48 +03:00
|
|
|
Some menu items change or deactivate correctly, but most items just trigger
|
2021-12-08 17:52:15 +03:00
|
|
|
various callbacks.
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
\c New_Menu creates new widgets and is explained in detail in another location.
|
2005-03-20 03:12:21 +03:00
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
\see New_Menu
|
2023-09-05 16:11:09 +03:00
|
|
|
\todo This menu need some major modernisation. Menus are too long and their
|
2021-12-08 17:52:15 +03:00
|
|
|
sorting is not always obvious.
|
2023-08-26 16:17:28 +03:00
|
|
|
\todo Shortcuts are all over the place (Alt, Ctrl, Command, Shift-Ctrl,
|
2021-12-08 17:52:15 +03:00
|
|
|
function keys), and there should be a help page listing all shortcuts.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Menu_Item Main_Menu[] = {
|
1999-01-19 22:10:39 +03:00
|
|
|
{"&File",0,0,0,FL_SUBMENU},
|
2023-08-28 17:29:08 +03:00
|
|
|
{"&New", FL_COMMAND+'n', menu_file_new_cb},
|
|
|
|
{"&Open...", FL_COMMAND+'o', menu_file_open_cb},
|
|
|
|
{"&Insert...", FL_COMMAND+'i', menu_file_insert_cb, 0, FL_MENU_DIVIDER},
|
2006-10-14 08:35:24 +04:00
|
|
|
{"&Save", FL_COMMAND+'s', save_cb, 0},
|
|
|
|
{"Save &As...", FL_COMMAND+FL_SHIFT+'s', save_cb, (void*)1},
|
2005-03-24 19:31:59 +03:00
|
|
|
{"Sa&ve A Copy...", 0, save_cb, (void*)2},
|
|
|
|
{"&Revert...", 0, revert_cb, 0, FL_MENU_DIVIDER},
|
2023-08-28 17:29:08 +03:00
|
|
|
{"New &From Template...", FL_COMMAND+'N', menu_file_new_from_template_cb, 0},
|
2019-02-02 01:16:49 +03:00
|
|
|
{"Save As &Template...", 0, save_template_cb, 0, FL_MENU_DIVIDER},
|
2006-10-14 08:35:24 +04:00
|
|
|
{"&Print...", FL_COMMAND+'p', print_menu_cb},
|
|
|
|
{"Write &Code...", FL_COMMAND+FL_SHIFT+'c', write_cb, 0},
|
|
|
|
{"&Write Strings...", FL_COMMAND+FL_SHIFT+'w', write_strings_cb, 0, FL_MENU_DIVIDER},
|
2023-08-28 17:29:08 +03:00
|
|
|
{relative_history[0], FL_COMMAND+'0', menu_file_open_history_cb, absolute_history[0]},
|
|
|
|
{relative_history[1], FL_COMMAND+'1', menu_file_open_history_cb, absolute_history[1]},
|
|
|
|
{relative_history[2], FL_COMMAND+'2', menu_file_open_history_cb, absolute_history[2]},
|
|
|
|
{relative_history[3], FL_COMMAND+'3', menu_file_open_history_cb, absolute_history[3]},
|
|
|
|
{relative_history[4], FL_COMMAND+'4', menu_file_open_history_cb, absolute_history[4]},
|
|
|
|
{relative_history[5], FL_COMMAND+'5', menu_file_open_history_cb, absolute_history[5]},
|
|
|
|
{relative_history[6], FL_COMMAND+'6', menu_file_open_history_cb, absolute_history[6]},
|
|
|
|
{relative_history[7], FL_COMMAND+'7', menu_file_open_history_cb, absolute_history[7]},
|
|
|
|
{relative_history[8], FL_COMMAND+'8', menu_file_open_history_cb, absolute_history[8]},
|
|
|
|
{relative_history[9], FL_COMMAND+'9', menu_file_open_history_cb, absolute_history[9], FL_MENU_DIVIDER},
|
2006-10-14 08:35:24 +04:00
|
|
|
{"&Quit", FL_COMMAND+'q', exit_cb},
|
1998-10-06 22:21:25 +04:00
|
|
|
{0},
|
1999-01-19 22:10:39 +03:00
|
|
|
{"&Edit",0,0,0,FL_SUBMENU},
|
2006-10-14 08:35:24 +04:00
|
|
|
{"&Undo", FL_COMMAND+'z', undo_cb},
|
|
|
|
{"&Redo", FL_COMMAND+FL_SHIFT+'z', redo_cb, 0, FL_MENU_DIVIDER},
|
|
|
|
{"C&ut", FL_COMMAND+'x', cut_cb},
|
|
|
|
{"&Copy", FL_COMMAND+'c', copy_cb},
|
|
|
|
{"&Paste", FL_COMMAND+'v', paste_cb},
|
|
|
|
{"Dup&licate", FL_COMMAND+'u', duplicate_cb},
|
2005-03-20 17:35:18 +03:00
|
|
|
{"&Delete", FL_Delete, delete_cb, 0, FL_MENU_DIVIDER},
|
2006-10-14 08:35:24 +04:00
|
|
|
{"Select &All", FL_COMMAND+'a', select_all_cb},
|
|
|
|
{"Select &None", FL_COMMAND+FL_SHIFT+'a', select_none_cb, 0, FL_MENU_DIVIDER},
|
2005-03-20 17:35:18 +03:00
|
|
|
{"Pr&operties...", FL_F+1, openwidget_cb},
|
2002-05-01 23:17:24 +04:00
|
|
|
{"&Sort",0,sort_cb},
|
|
|
|
{"&Earlier", FL_F+2, earlier_cb},
|
|
|
|
{"&Later", FL_F+3, later_cb},
|
|
|
|
{"&Group", FL_F+7, group_cb},
|
2005-03-20 03:12:21 +03:00
|
|
|
{"Ung&roup", FL_F+8, ungroup_cb,0, FL_MENU_DIVIDER},
|
2006-10-14 08:35:24 +04:00
|
|
|
{"Hide O&verlays",FL_COMMAND+FL_SHIFT+'o',toggle_overlays},
|
2023-03-18 19:33:27 +03:00
|
|
|
{"Hide Guides",FL_COMMAND+FL_SHIFT+'g',toggle_guides},
|
2023-07-12 00:13:46 +03:00
|
|
|
{"Hide Restricted",FL_COMMAND+FL_SHIFT+'r',toggle_restricted},
|
2005-11-03 23:43:19 +03:00
|
|
|
{"Show Widget &Bin...",FL_ALT+'b',toggle_widgetbin_cb},
|
|
|
|
{"Show Source Code...",FL_ALT+FL_SHIFT+'s', (Fl_Callback*)toggle_sourceview_cb, 0, FL_MENU_DIVIDER},
|
2023-03-19 22:04:01 +03:00
|
|
|
{"Settings...",FL_ALT+'p',show_settings_cb},
|
1998-10-06 22:21:25 +04:00
|
|
|
{0},
|
1999-01-19 22:10:39 +03:00
|
|
|
{"&New", 0, 0, (void *)New_Menu, FL_SUBMENU_POINTER},
|
2002-05-01 21:35:30 +04:00
|
|
|
{"&Layout",0,0,0,FL_SUBMENU},
|
|
|
|
{"&Align",0,0,0,FL_SUBMENU},
|
|
|
|
{"&Left",0,(Fl_Callback *)align_widget_cb,(void*)10},
|
2002-05-01 23:17:24 +04:00
|
|
|
{"&Center",0,(Fl_Callback *)align_widget_cb,(void*)11},
|
2002-05-01 21:35:30 +04:00
|
|
|
{"&Right",0,(Fl_Callback *)align_widget_cb,(void*)12},
|
|
|
|
{"&Top",0,(Fl_Callback *)align_widget_cb,(void*)13},
|
2002-05-01 23:17:24 +04:00
|
|
|
{"&Middle",0,(Fl_Callback *)align_widget_cb,(void*)14},
|
2002-05-01 21:35:30 +04:00
|
|
|
{"&Bottom",0,(Fl_Callback *)align_widget_cb,(void*)15},
|
|
|
|
{0},
|
|
|
|
{"&Space Evenly",0,0,0,FL_SUBMENU},
|
|
|
|
{"&Across",0,(Fl_Callback *)align_widget_cb,(void*)20},
|
|
|
|
{"&Down",0,(Fl_Callback *)align_widget_cb,(void*)21},
|
|
|
|
{0},
|
|
|
|
{"&Make Same Size",0,0,0,FL_SUBMENU},
|
|
|
|
{"&Width",0,(Fl_Callback *)align_widget_cb,(void*)30},
|
|
|
|
{"&Height",0,(Fl_Callback *)align_widget_cb,(void*)31},
|
|
|
|
{"&Both",0,(Fl_Callback *)align_widget_cb,(void*)32},
|
|
|
|
{0},
|
2023-03-18 19:33:27 +03:00
|
|
|
{"&Center In Group",0,0,0,FL_SUBMENU|FL_MENU_DIVIDER},
|
2002-05-01 21:35:30 +04:00
|
|
|
{"&Horizontal",0,(Fl_Callback *)align_widget_cb,(void*)40},
|
|
|
|
{"&Vertical",0,(Fl_Callback *)align_widget_cb,(void*)41},
|
|
|
|
{0},
|
2023-03-18 19:33:27 +03:00
|
|
|
{"&Grid and Size Settings...",FL_COMMAND+'g',show_grid_cb, NULL, FL_MENU_DIVIDER},
|
2023-04-26 21:24:33 +03:00
|
|
|
{"Presets", 0, layout_suite_marker, (void*)main_layout_submenu_, FL_SUBMENU_POINTER },
|
2023-03-18 19:33:27 +03:00
|
|
|
{"Application", 0, select_layout_preset_cb, (void*)0, FL_MENU_RADIO|FL_MENU_VALUE },
|
|
|
|
{"Dialog", 0, select_layout_preset_cb, (void*)1, FL_MENU_RADIO },
|
|
|
|
{"Toolbox", 0, select_layout_preset_cb, (void*)2, FL_MENU_RADIO },
|
2002-05-01 21:35:30 +04:00
|
|
|
{0},
|
2023-09-26 17:01:03 +03:00
|
|
|
{"&Shell", 0, Fd_Shell_Command_List::menu_marker, (void*)Fd_Shell_Command_List::default_menu, FL_SUBMENU_POINTER},
|
1999-01-19 22:10:39 +03:00
|
|
|
{"&Help",0,0,0,FL_SUBMENU},
|
2010-02-28 01:38:25 +03:00
|
|
|
{"&Rapid development with FLUID...",0,help_cb},
|
|
|
|
{"&FLTK Programmers Manual...",0,manual_cb, 0, FL_MENU_DIVIDER},
|
2002-05-01 23:17:24 +04:00
|
|
|
{"&About FLUID...",0,about_cb},
|
1998-10-06 22:21:25 +04:00
|
|
|
{0},
|
|
|
|
{0}};
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Change the app's and hence preview the design's scheme.
|
2023-01-01 23:53:07 +03:00
|
|
|
|
|
|
|
The scheme setting is stored in the app preferences
|
|
|
|
- in key \p 'scheme_name' since 1.4.0
|
|
|
|
- in key \p 'scheme' (index: 0 - 4) in 1.3.x
|
|
|
|
|
|
|
|
This callback is triggered by changing the scheme in the
|
|
|
|
Fl_Scheme_Choice widget (\p Edit/GUI Settings).
|
|
|
|
|
|
|
|
\see init_scheme() for choice values and backwards compatibility
|
2021-12-08 17:52:15 +03:00
|
|
|
*/
|
2023-01-01 23:53:07 +03:00
|
|
|
void scheme_cb(Fl_Scheme_Choice *choice, void *) {
|
2015-03-09 23:37:45 +03:00
|
|
|
if (batch_mode)
|
2005-07-15 13:48:09 +04:00
|
|
|
return;
|
|
|
|
|
2023-01-01 23:53:07 +03:00
|
|
|
// set the new scheme only if the scheme was changed
|
|
|
|
const char *new_scheme = choice->text(choice->value());
|
|
|
|
|
|
|
|
if (Fl::is_scheme(new_scheme))
|
|
|
|
return;
|
|
|
|
|
|
|
|
Fl::scheme(new_scheme);
|
|
|
|
fluid_prefs.set("scheme_name", new_scheme);
|
2005-03-20 03:51:02 +03:00
|
|
|
|
2023-01-01 23:53:07 +03:00
|
|
|
// Backwards compatibility: store 1.3 scheme index (1-4).
|
|
|
|
// We assume that index 0-3 (base, plastic, gtk+, gleam) are in the
|
|
|
|
// same order as in 1.3.x (index 1-4), higher values are ignored
|
|
|
|
|
|
|
|
int scheme_index = scheme_choice->value();
|
|
|
|
if (scheme_index <= 3) // max. index for 1.3.x (Gleam)
|
|
|
|
fluid_prefs.set("scheme", scheme_index + 1); // compensate for different indexing
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
Read Fluid's scheme preferences and set the app's scheme.
|
|
|
|
|
|
|
|
Since FLTK 1.4.0 the scheme \b name is stored as a character string
|
|
|
|
with key "scheme_name" in the preference database.
|
|
|
|
|
|
|
|
In FLTK 1.3.x the scheme preference was stored as an integer index
|
|
|
|
with key "scheme" in the database. The known schemes were hardcoded in
|
|
|
|
Fluid's sources (here for reference):
|
|
|
|
|
|
|
|
| Index | 1.3 Scheme Name | Choice | 1.4 Scheme Name |
|
|
|
|
|-------|-----------------|-------|-----------------|
|
|
|
|
| 0 | Default (same as None) | n/a | n/a |
|
|
|
|
| 1 | None (same as Default) | 0 | base |
|
|
|
|
| 2 | Plastic | 1 | plastic |
|
|
|
|
| 3 | GTK+ | 2 | gtk+ |
|
|
|
|
| 4 | Gleam | 3 | gleam |
|
|
|
|
| n/a | n/a | 4 | oxy |
|
|
|
|
|
|
|
|
The new Fluid tries to keep backwards compatibility and reads both
|
|
|
|
keys (\p scheme and \p scheme_name). If the latter is defined, it is used.
|
|
|
|
If not the old \p scheme (index) is used - but we need to subtract one to
|
|
|
|
get the new Fl_Scheme_Choice index (column "Choice" above).
|
|
|
|
*/
|
|
|
|
void init_scheme() {
|
|
|
|
int scheme_index = 0; // scheme index for backwards compatibility (1.3.x)
|
2023-04-14 20:52:33 +03:00
|
|
|
char *scheme_name = 0; // scheme name since 1.4.0
|
2023-01-01 23:53:07 +03:00
|
|
|
fluid_prefs.get("scheme_name", scheme_name, "XXX"); // XXX means: not set => fallback 1.3.x
|
|
|
|
if (!strcmp(scheme_name, "XXX")) {
|
|
|
|
fluid_prefs.get("scheme", scheme_index, 0);
|
|
|
|
if (scheme_index > 0) {
|
|
|
|
scheme_index--;
|
|
|
|
scheme_choice->value(scheme_index); // set the choice value
|
|
|
|
}
|
|
|
|
if (scheme_index < 0)
|
|
|
|
scheme_index = 0;
|
|
|
|
else if (scheme_index > scheme_choice->size() - 1)
|
|
|
|
scheme_index = 0;
|
|
|
|
scheme_name = const_cast<char *>(scheme_choice->text(scheme_index));
|
|
|
|
fluid_prefs.set("scheme_name", scheme_name);
|
|
|
|
}
|
|
|
|
Fl::scheme(scheme_name);
|
2023-04-14 20:52:33 +03:00
|
|
|
free(scheme_name);
|
2005-03-20 03:51:02 +03:00
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Show or hide the widget bin.
|
|
|
|
The state is stored in the app preferences.
|
|
|
|
*/
|
2005-03-20 03:12:21 +03:00
|
|
|
void toggle_widgetbin_cb(Fl_Widget *, void *) {
|
|
|
|
if (!widgetbin_panel) {
|
|
|
|
make_widgetbin();
|
|
|
|
if (!position_window(widgetbin_panel,"widgetbin_pos", 1, 320, 30)) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (widgetbin_panel->visible()) {
|
|
|
|
widgetbin_panel->hide();
|
2010-02-26 16:03:21 +03:00
|
|
|
widgetbin_item->label("Show Widget &Bin...");
|
2005-03-20 03:12:21 +03:00
|
|
|
} else {
|
|
|
|
widgetbin_panel->show();
|
2010-02-26 16:03:21 +03:00
|
|
|
widgetbin_item->label("Hide Widget &Bin");
|
2005-03-20 03:12:21 +03:00
|
|
|
}
|
|
|
|
}
|
2002-04-30 22:11:49 +04:00
|
|
|
|
2005-11-03 23:43:19 +03:00
|
|
|
void toggle_sourceview_cb(Fl_Double_Window *, void *) {
|
2023-08-29 03:20:45 +03:00
|
|
|
sourceview_toggle_visibility();
|
2005-11-03 23:43:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void toggle_sourceview_b_cb(Fl_Button*, void *) {
|
2023-08-29 03:20:45 +03:00
|
|
|
sourceview_toggle_visibility();
|
2005-11-03 23:43:19 +03:00
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Build the main app window and create a few other dialogs.
|
|
|
|
*/
|
2005-03-20 03:12:21 +03:00
|
|
|
void make_main_window() {
|
2015-03-09 23:37:45 +03:00
|
|
|
if (!batch_mode) {
|
2023-07-12 00:13:46 +03:00
|
|
|
fluid_prefs.get("show_guides", show_guides, 1);
|
|
|
|
fluid_prefs.get("show_restricted", show_restricted, 1);
|
2009-09-23 23:24:34 +04:00
|
|
|
fluid_prefs.get("show_comments", show_comments, 1);
|
|
|
|
make_shell_window();
|
|
|
|
}
|
2002-04-30 22:11:49 +04:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
if (!main_window) {
|
|
|
|
Fl_Widget *o;
|
2021-12-05 02:18:41 +03:00
|
|
|
loadPixmaps();
|
1998-10-06 22:21:25 +04:00
|
|
|
main_window = new Fl_Double_Window(WINWIDTH,WINHEIGHT,"fluid");
|
|
|
|
main_window->box(FL_NO_BOX);
|
|
|
|
o = make_widget_browser(0,MENUHEIGHT,BROWSERWIDTH,BROWSERHEIGHT);
|
|
|
|
o->box(FL_FLAT_BOX);
|
2001-09-30 02:59:45 +04:00
|
|
|
o->tooltip("Double-click to view or change an item.");
|
1998-10-06 22:21:25 +04:00
|
|
|
main_window->resizable(o);
|
2005-03-18 00:57:17 +03:00
|
|
|
main_menubar = new Fl_Menu_Bar(0,0,BROWSERWIDTH,MENUHEIGHT);
|
|
|
|
main_menubar->menu(Main_Menu);
|
2010-02-26 16:03:21 +03:00
|
|
|
// quick access to all dynamic menu items
|
|
|
|
save_item = (Fl_Menu_Item*)main_menubar->find_item(save_cb);
|
2023-08-28 17:29:08 +03:00
|
|
|
history_item = (Fl_Menu_Item*)main_menubar->find_item(menu_file_open_history_cb);
|
2010-02-26 16:03:21 +03:00
|
|
|
widgetbin_item = (Fl_Menu_Item*)main_menubar->find_item(toggle_widgetbin_cb);
|
|
|
|
sourceview_item = (Fl_Menu_Item*)main_menubar->find_item((Fl_Callback*)toggle_sourceview_cb);
|
2021-12-08 22:52:33 +03:00
|
|
|
overlay_item = (Fl_Menu_Item*)main_menubar->find_item((Fl_Callback*)toggle_overlays);
|
2023-03-18 19:33:27 +03:00
|
|
|
guides_item = (Fl_Menu_Item*)main_menubar->find_item((Fl_Callback*)toggle_guides);
|
2023-07-12 00:13:46 +03:00
|
|
|
restricted_item = (Fl_Menu_Item*)main_menubar->find_item((Fl_Callback*)toggle_restricted);
|
2005-03-18 00:57:17 +03:00
|
|
|
main_menubar->global();
|
1998-10-06 22:21:25 +04:00
|
|
|
fill_in_New_Menu();
|
|
|
|
main_window->end();
|
|
|
|
}
|
2010-02-26 16:03:21 +03:00
|
|
|
|
2015-03-09 23:37:45 +03:00
|
|
|
if (!batch_mode) {
|
2010-02-26 16:03:21 +03:00
|
|
|
load_history();
|
2023-09-26 17:01:03 +03:00
|
|
|
g_shell_config = new Fd_Shell_Command_List;
|
|
|
|
// TODO: load example commands if this is the very first time we use this
|
|
|
|
// g_shell_config->restore_defaults();
|
2010-02-28 01:38:25 +03:00
|
|
|
make_settings_window();
|
2010-02-26 16:03:21 +03:00
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Load file history from preferences.
|
|
|
|
|
|
|
|
This loads the absolute filepaths of the last 10 used design files.
|
|
|
|
It also computes and stores the relative filepaths for display in
|
|
|
|
the main menu.
|
|
|
|
*/
|
2002-04-30 22:11:49 +04:00
|
|
|
void load_history() {
|
2020-07-01 19:03:10 +03:00
|
|
|
int i; // Looping var
|
|
|
|
int max_files;
|
2002-04-30 22:11:49 +04:00
|
|
|
|
2005-03-24 20:45:50 +03:00
|
|
|
|
|
|
|
fluid_prefs.get("recent_files", max_files, 5);
|
|
|
|
if (max_files > 10) max_files = 10;
|
|
|
|
|
|
|
|
for (i = 0; i < max_files; i ++) {
|
2002-05-01 02:25:18 +04:00
|
|
|
fluid_prefs.get( Fl_Preferences::Name("file%d", i), absolute_history[i], "", sizeof(absolute_history[i]));
|
2002-04-30 22:11:49 +04:00
|
|
|
if (absolute_history[i][0]) {
|
|
|
|
// Make a relative version of the filename for the menu...
|
|
|
|
fl_filename_relative(relative_history[i], sizeof(relative_history[i]),
|
|
|
|
absolute_history[i]);
|
|
|
|
|
2010-02-26 16:03:21 +03:00
|
|
|
if (i == 9) history_item[i].flags = FL_MENU_DIVIDER;
|
|
|
|
else history_item[i].flags = 0;
|
2005-03-24 20:45:50 +03:00
|
|
|
} else break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; i < 10; i ++) {
|
2010-02-26 16:03:21 +03:00
|
|
|
if (i) history_item[i-1].flags |= FL_MENU_DIVIDER;
|
|
|
|
history_item[i].hide();
|
2002-04-30 22:11:49 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Update file history from preferences.
|
|
|
|
|
|
|
|
Add this new filepath to the history and update the main menu.
|
|
|
|
Writes the new file history to the app preferences.
|
|
|
|
|
|
|
|
\param[in] flname path or filename of .fl file, will be converted into an
|
|
|
|
absolute file path based on the current working directory.
|
|
|
|
*/
|
2002-08-10 02:57:00 +04:00
|
|
|
void update_history(const char *flname) {
|
2020-07-01 19:03:10 +03:00
|
|
|
int i; // Looping var
|
|
|
|
char absolute[FL_PATH_MAX];
|
|
|
|
int max_files;
|
2005-03-24 20:45:50 +03:00
|
|
|
|
|
|
|
|
|
|
|
fluid_prefs.get("recent_files", max_files, 5);
|
|
|
|
if (max_files > 10) max_files = 10;
|
2002-04-30 22:11:49 +04:00
|
|
|
|
2002-08-10 02:57:00 +04:00
|
|
|
fl_filename_absolute(absolute, sizeof(absolute), flname);
|
2002-04-30 22:11:49 +04:00
|
|
|
|
2005-03-24 20:45:50 +03:00
|
|
|
for (i = 0; i < max_files; i ++)
|
2018-02-09 17:39:42 +03:00
|
|
|
#if defined(_WIN32) || defined(__APPLE__)
|
2002-04-30 22:11:49 +04:00
|
|
|
if (!strcasecmp(absolute, absolute_history[i])) break;
|
|
|
|
#else
|
2002-05-02 01:41:59 +04:00
|
|
|
if (!strcmp(absolute, absolute_history[i])) break;
|
2018-02-09 17:39:42 +03:00
|
|
|
#endif // _WIN32 || __APPLE__
|
2002-04-30 22:11:49 +04:00
|
|
|
|
|
|
|
if (i == 0) return;
|
|
|
|
|
2005-03-24 20:45:50 +03:00
|
|
|
if (i >= max_files) i = max_files - 1;
|
2002-04-30 22:11:49 +04:00
|
|
|
|
2002-08-10 02:57:00 +04:00
|
|
|
// Move the other flnames down in the list...
|
2002-04-30 22:11:49 +04:00
|
|
|
memmove(absolute_history + 1, absolute_history,
|
|
|
|
i * sizeof(absolute_history[0]));
|
|
|
|
memmove(relative_history + 1, relative_history,
|
|
|
|
i * sizeof(relative_history[0]));
|
|
|
|
|
|
|
|
// Put the new file at the top...
|
2002-05-16 16:47:44 +04:00
|
|
|
strlcpy(absolute_history[0], absolute, sizeof(absolute_history[0]));
|
2002-04-30 22:11:49 +04:00
|
|
|
|
|
|
|
fl_filename_relative(relative_history[0], sizeof(relative_history[0]),
|
|
|
|
absolute_history[0]);
|
|
|
|
|
|
|
|
// Update the menu items as needed...
|
2005-03-24 20:45:50 +03:00
|
|
|
for (i = 0; i < max_files; i ++) {
|
2002-05-01 02:25:18 +04:00
|
|
|
fluid_prefs.set( Fl_Preferences::Name("file%d", i), absolute_history[i]);
|
2005-03-25 05:39:25 +03:00
|
|
|
if (absolute_history[i][0]) {
|
2010-02-26 16:03:21 +03:00
|
|
|
if (i == 9) history_item[i].flags = FL_MENU_DIVIDER;
|
|
|
|
else history_item[i].flags = 0;
|
2005-03-25 05:39:25 +03:00
|
|
|
} else break;
|
2005-03-24 20:45:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (; i < 10; i ++) {
|
|
|
|
fluid_prefs.set( Fl_Preferences::Name("file%d", i), "");
|
2010-02-26 16:03:21 +03:00
|
|
|
if (i) history_item[i-1].flags |= FL_MENU_DIVIDER;
|
|
|
|
history_item[i].hide();
|
2002-04-30 22:11:49 +04:00
|
|
|
}
|
2011-08-18 17:43:39 +04:00
|
|
|
fluid_prefs.flush();
|
2002-04-30 22:11:49 +04:00
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Set the filename of the current .fl design.
|
|
|
|
\param[in] c the new absolute filename and path
|
|
|
|
*/
|
|
|
|
void set_filename(const char *c) {
|
|
|
|
if (filename) free((void *)filename);
|
|
|
|
filename = c ? fl_strdup(c) : NULL;
|
2008-09-02 16:03:30 +04:00
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
if (filename && !batch_mode)
|
|
|
|
update_history(filename);
|
2008-09-02 16:03:30 +04:00
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
set_modflag(modflag);
|
2008-09-02 16:03:30 +04:00
|
|
|
}
|
|
|
|
|
2023-09-26 17:01:03 +03:00
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Set the "modified" flag and update the title of the main window.
|
2008-09-02 16:03:30 +04:00
|
|
|
|
2022-11-10 01:12:55 +03:00
|
|
|
The first argument sets the modification state of the current design against
|
2021-12-10 03:22:15 +03:00
|
|
|
the corresponding .fl design file. Any change to the widget tree will mark
|
|
|
|
the design 'modified'. Saving the design will mark it clean.
|
|
|
|
|
|
|
|
The second argument is optional and set the modification state of the current
|
|
|
|
design against the source code and header file. Any change to the tree,
|
|
|
|
including saving the tree, will mark the code 'outdated'. Generating source
|
|
|
|
code and header files will clear this flag until the next modification.
|
|
|
|
|
|
|
|
\param[in] mf 0 to clear the modflag, 1 to mark the design "modified", -1 to
|
|
|
|
ignore this parameter
|
|
|
|
\param[in] mfc default -1 to let \c mf control \c modflag_c, 0 to mark the
|
2023-07-11 15:27:02 +03:00
|
|
|
code files current, 1 to mark it out of date. -2 to ignore changes to mf.
|
2021-12-10 03:22:15 +03:00
|
|
|
*/
|
|
|
|
void set_modflag(int mf, int mfc) {
|
|
|
|
const char *code_ext = NULL;
|
2023-08-28 17:29:08 +03:00
|
|
|
char new_title[FL_PATH_MAX];
|
2021-12-10 03:22:15 +03:00
|
|
|
|
|
|
|
// Update the modflag_c to the worst possible condition. We could be a bit
|
|
|
|
// more graceful and compare modification times of the files, but C++ has
|
|
|
|
// no API for that until C++17.
|
|
|
|
if (mf!=-1) {
|
|
|
|
modflag = mf;
|
|
|
|
if (mfc==-1 && mf==1)
|
|
|
|
mfc = mf;
|
|
|
|
}
|
2023-07-11 15:27:02 +03:00
|
|
|
if (mfc>=0) {
|
2021-12-10 03:22:15 +03:00
|
|
|
modflag_c = mfc;
|
|
|
|
}
|
2002-05-01 14:36:08 +04:00
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
if (main_window) {
|
2023-08-28 17:29:08 +03:00
|
|
|
Fl_String basename;
|
2021-12-08 17:52:15 +03:00
|
|
|
if (!filename) basename = "Untitled.fl";
|
2023-08-28 17:29:08 +03:00
|
|
|
else basename = fl_filename_name(Fl_String(filename));
|
2023-02-23 17:42:05 +03:00
|
|
|
code_ext = fl_filename_ext(g_project.code_file_name.c_str());
|
2021-12-10 03:22:15 +03:00
|
|
|
char mod_star = modflag ? '*' : ' ';
|
|
|
|
char mod_c_star = modflag_c ? '*' : ' ';
|
2023-08-28 17:29:08 +03:00
|
|
|
snprintf(new_title, sizeof(new_title), "%s%c %s%c",
|
|
|
|
basename.c_str(), mod_star, code_ext, mod_c_star);
|
|
|
|
const char *old_title = main_window->label();
|
|
|
|
// only update the title if it actually changed
|
|
|
|
if (!old_title || strcmp(old_title, new_title))
|
|
|
|
main_window->copy_label(new_title);
|
2002-05-01 14:36:08 +04:00
|
|
|
}
|
2021-12-08 17:52:15 +03:00
|
|
|
// if the UI was modified in any way, update the Source View panel
|
|
|
|
if (sourceview_panel && sourceview_panel->visible() && sv_autorefresh->value())
|
2023-08-29 03:20:45 +03:00
|
|
|
sourceview_defer_update();
|
2005-11-03 23:43:19 +03:00
|
|
|
}
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
// ---- Main program entry point
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Handle command line arguments.
|
|
|
|
\param[in] argc number of arguments in the list
|
|
|
|
\param[in] argv pointer to an array of arguments
|
|
|
|
\param[inout] i current argument index
|
|
|
|
\return number of arguments used; if 0, the argument is not supported
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
static int arg(int argc, char** argv, int& i) {
|
2022-11-29 02:04:47 +03:00
|
|
|
if (argv[i][0] != '-')
|
2022-11-15 19:48:06 +03:00
|
|
|
return 0;
|
2023-08-28 17:29:08 +03:00
|
|
|
if (argv[i][1] == 'd' && !argv[i][2]) {
|
|
|
|
G_debug=1;
|
|
|
|
i++; return 1;
|
|
|
|
}
|
|
|
|
if (argv[i][1] == 'u' && !argv[i][2]) {
|
|
|
|
update_file++;
|
|
|
|
batch_mode++;
|
|
|
|
i++; return 1;
|
|
|
|
}
|
|
|
|
if (argv[i][1] == 'c' && !argv[i][2]) {
|
|
|
|
compile_file++;
|
|
|
|
batch_mode++;
|
|
|
|
i++; return 1;
|
|
|
|
}
|
|
|
|
if (argv[i][1] == 'c' && argv[i][2] == 's' && !argv[i][3]) {
|
|
|
|
compile_file++;
|
|
|
|
compile_strings++;
|
|
|
|
batch_mode++;
|
|
|
|
i++; return 1;
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
if (argv[i][1] == 'o' && !argv[i][2] && i+1 < argc) {
|
2022-11-29 02:04:47 +03:00
|
|
|
g_code_filename_arg = argv[i+1];
|
2022-11-15 19:48:06 +03:00
|
|
|
batch_mode++;
|
2023-08-28 17:29:08 +03:00
|
|
|
i += 2; return 2;
|
1999-03-04 21:10:01 +03:00
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
if (argv[i][1] == 'h' && !argv[i][2]) {
|
2022-11-29 02:04:47 +03:00
|
|
|
if ( (i+1 < argc) && (argv[i+1][0] != '-') ) {
|
|
|
|
g_header_filename_arg = argv[i+1];
|
2022-11-15 19:48:06 +03:00
|
|
|
batch_mode++;
|
|
|
|
i += 2;
|
|
|
|
return 2;
|
|
|
|
} else {
|
|
|
|
// a lone "-h" without a filename will output the help string
|
|
|
|
return 0;
|
|
|
|
}
|
1999-03-04 21:10:01 +03:00
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-09 17:39:42 +03:00
|
|
|
#if ! (defined(_WIN32) && !defined (__CYGWIN__))
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2005-03-20 07:00:48 +03:00
|
|
|
int quit_flag = 0;
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <signal.h>
|
|
|
|
#ifdef _sigargs
|
|
|
|
#define SIGARG _sigargs
|
|
|
|
#else
|
|
|
|
#ifdef __sigargs
|
|
|
|
#define SIGARG __sigargs
|
|
|
|
#else
|
|
|
|
#define SIGARG int // you may need to fix this for older systems
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2000-08-20 08:35:17 +04:00
|
|
|
extern "C" {
|
1998-10-06 22:21:25 +04:00
|
|
|
static void sigint(SIGARG) {
|
|
|
|
signal(SIGINT,sigint);
|
2005-03-20 07:00:48 +03:00
|
|
|
quit_flag = 1;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2000-08-20 08:35:17 +04:00
|
|
|
}
|
2021-12-08 17:52:15 +03:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
#endif
|
|
|
|
|
2021-12-08 17:52:15 +03:00
|
|
|
/**
|
|
|
|
Start Fluid.
|
|
|
|
|
|
|
|
Fluid can run in interactive mode with a full user interface to design new
|
|
|
|
user interfaces and write the C++ files to manage them,
|
|
|
|
|
|
|
|
Fluid can run form the command line in batch mode to convert .fl design files
|
2023-08-26 16:17:28 +03:00
|
|
|
into C++ source and header files. In batch mode, no display is needed,
|
2021-12-08 17:52:15 +03:00
|
|
|
particularly no X11 connection will be attempted on Linux/Unix.
|
|
|
|
|
|
|
|
\param[in] argc number of arguments in the list
|
|
|
|
\param[in] argv pointer to an array of arguments
|
|
|
|
\return in batch mode, an error code will be returned via \c exit() . This
|
|
|
|
function return 1, if there was an error in the parameters list.
|
|
|
|
\todo On MSWindows, Fluid can under certain conditions open a dialog box, even
|
|
|
|
in batch mode. Is that intentional? Does it circumvent issues with Windows'
|
|
|
|
stderr and stdout?
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int main(int argc,char **argv) {
|
|
|
|
int i = 1;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2023-08-26 16:17:28 +03:00
|
|
|
setlocale(LC_ALL, ""); // enable multi-language errors in file chooser
|
2020-09-16 13:14:22 +03:00
|
|
|
setlocale(LC_NUMERIC, "C"); // make sure numeric values are written correctly
|
2023-09-05 16:11:09 +03:00
|
|
|
g_launch_path = end_with_slash(fl_getcwd()); // store the current path at launch
|
2020-09-16 13:14:22 +03:00
|
|
|
|
2022-11-15 19:48:06 +03:00
|
|
|
if ( (Fl::args(argc,argv,i,arg) == 0) // unsupported argument found
|
|
|
|
|| (batch_mode && (i != argc-1)) // .fl filename missing
|
|
|
|
|| (!batch_mode && (i < argc-1)) ) { // more than one filename found
|
2020-07-01 19:03:10 +03:00
|
|
|
static const char *msg =
|
2011-01-07 00:36:04 +03:00
|
|
|
"usage: %s <switches> name.fl\n"
|
2015-03-09 23:37:45 +03:00
|
|
|
" -u : update .fl file and exit (may be combined with '-c' or '-cs')\n"
|
2011-01-07 00:36:04 +03:00
|
|
|
" -c : write .cxx and .h and exit\n"
|
|
|
|
" -cs : write .cxx and .h and strings and exit\n"
|
|
|
|
" -o <name> : .cxx output filename, or extension if <name> starts with '.'\n"
|
2020-06-19 18:59:48 +03:00
|
|
|
" -h <name> : .h output filename, or extension if <name> starts with '.'\n"
|
|
|
|
" -d : enable internal debugging\n";
|
2022-11-23 12:59:43 +03:00
|
|
|
const char *app_name = NULL;
|
|
|
|
if ( (argc > 0) && argv[0] && argv[0][0] )
|
|
|
|
app_name = fl_filename_name(argv[0]);
|
|
|
|
if ( !app_name || !app_name[0])
|
|
|
|
app_name = "fluid";
|
2011-01-07 00:36:04 +03:00
|
|
|
#ifdef _MSC_VER
|
2022-11-23 12:59:43 +03:00
|
|
|
fl_message(msg, app_name);
|
2011-01-07 00:36:04 +03:00
|
|
|
#else
|
2022-11-23 12:59:43 +03:00
|
|
|
fprintf(stderr, msg, app_name);
|
2011-01-07 00:36:04 +03:00
|
|
|
#endif
|
1998-10-06 22:21:25 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2020-07-01 19:03:10 +03:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
const char *c = argv[i];
|
2002-08-17 00:10:21 +04:00
|
|
|
|
|
|
|
fl_register_images();
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
make_main_window();
|
2002-09-02 14:41:51 +04:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
if (c) set_filename(c);
|
2015-03-09 23:37:45 +03:00
|
|
|
if (!batch_mode) {
|
2010-12-01 21:31:23 +03:00
|
|
|
#ifdef __APPLE__
|
|
|
|
fl_open_callback(apple_open_cb);
|
|
|
|
#endif // __APPLE__
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl::visual((Fl_Mode)(FL_DOUBLE|FL_INDEX));
|
2001-09-30 02:59:45 +04:00
|
|
|
Fl_File_Icon::load_system_icons();
|
1998-10-06 22:21:25 +04:00
|
|
|
main_window->callback(exit_cb);
|
2002-11-03 03:01:21 +03:00
|
|
|
position_window(main_window,"main_window_pos", 1, 10, 30, WINWIDTH, WINHEIGHT );
|
1998-10-06 22:21:25 +04:00
|
|
|
main_window->show(argc,argv);
|
2002-11-03 03:01:21 +03:00
|
|
|
toggle_widgetbin_cb(0,0);
|
2005-11-03 23:43:19 +03:00
|
|
|
toggle_sourceview_cb(0,0);
|
2023-09-26 17:01:03 +03:00
|
|
|
if (g_shell_config)
|
|
|
|
g_shell_config->read(fluid_prefs, FD_STORE_USER);
|
2023-03-18 19:33:27 +03:00
|
|
|
g_layout_list.read(fluid_prefs, FD_STORE_USER);
|
2002-04-30 22:11:49 +04:00
|
|
|
if (!c && openlast_button->value() && absolute_history[0][0]) {
|
|
|
|
// Open previous file when no file specified...
|
2023-08-28 17:29:08 +03:00
|
|
|
open_project_file(absolute_history[0]);
|
2002-04-30 22:11:49 +04:00
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_suspend();
|
1998-10-06 22:21:25 +04:00
|
|
|
if (c && !read_file(c,0)) {
|
2015-03-09 23:37:45 +03:00
|
|
|
if (batch_mode) {
|
1998-10-06 22:21:25 +04:00
|
|
|
fprintf(stderr,"%s : %s\n", c, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
1998-11-05 19:04:53 +03:00
|
|
|
fl_message("Can't read %s: %s", c, strerror(errno));
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_resume();
|
2015-03-09 23:37:45 +03:00
|
|
|
|
2023-08-28 17:29:08 +03:00
|
|
|
// command line args override code and header filenames from the project file
|
2023-09-05 16:11:09 +03:00
|
|
|
// in batch mode only
|
|
|
|
if (batch_mode) {
|
|
|
|
if (!g_code_filename_arg.empty()) {
|
|
|
|
g_project.code_file_set = 1;
|
|
|
|
g_project.code_file_name = g_code_filename_arg;
|
|
|
|
}
|
|
|
|
if (!g_header_filename_arg.empty()) {
|
|
|
|
g_project.header_file_set = 1;
|
|
|
|
g_project.header_file_name = g_header_filename_arg;
|
|
|
|
}
|
2022-11-29 02:04:47 +03:00
|
|
|
}
|
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
if (update_file) { // fluid -u
|
2015-03-09 23:37:45 +03:00
|
|
|
write_file(c,0);
|
|
|
|
if (!compile_file)
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
if (compile_file) { // fluid -c[s]
|
2015-03-09 23:37:45 +03:00
|
|
|
if (compile_strings)
|
|
|
|
write_strings_cb(0,0);
|
2002-05-01 23:17:24 +04:00
|
|
|
write_cb(0,0);
|
|
|
|
exit(0);
|
|
|
|
}
|
2023-09-05 16:11:09 +03:00
|
|
|
|
2023-09-26 01:29:14 +03:00
|
|
|
// don't lock up if inconsistent command line arguments were given
|
2023-09-05 16:11:09 +03:00
|
|
|
if (batch_mode)
|
|
|
|
exit(0);
|
|
|
|
|
2005-03-19 11:38:21 +03:00
|
|
|
set_modflag(0);
|
2005-03-20 07:00:48 +03:00
|
|
|
undo_clear();
|
2018-02-09 17:39:42 +03:00
|
|
|
#ifndef _WIN32
|
1998-10-06 22:21:25 +04:00
|
|
|
signal(SIGINT,sigint);
|
|
|
|
#endif
|
2002-05-01 23:17:24 +04:00
|
|
|
|
2016-07-19 00:12:25 +03:00
|
|
|
// Set (but do not start) timer callback for external editor updates
|
|
|
|
ExternalCodeEditor::set_update_timer_callback(external_editor_timer);
|
|
|
|
|
2018-02-09 17:39:42 +03:00
|
|
|
#ifdef _WIN32
|
2005-03-20 07:00:48 +03:00
|
|
|
Fl::run();
|
|
|
|
#else
|
|
|
|
while (!quit_flag) Fl::wait();
|
|
|
|
if (quit_flag) exit_cb(0,0);
|
2018-02-09 17:39:42 +03:00
|
|
|
#endif // _WIN32
|
2005-03-20 07:00:48 +03:00
|
|
|
|
|
|
|
undo_clear();
|
|
|
|
return (0);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
2021-12-08 17:52:15 +03:00
|
|
|
|
|
|
|
/// \}
|
|
|
|
|