Commit | Line | Data |
---|---|---|
69695f33 MW |
1 | /* Copyright (c) 2006 by Arkkra Enterprises */ |
2 | /* All rights reserved */ | |
3 | ||
4 | #ifndef _FILE_H_ | |
5 | #define _FILE_H_ | |
6 | ||
7 | #include <FL/Fl.H> | |
8 | #include <FL/Fl_Widget.H> | |
9 | #include <FL/Fl_Double_Window.H> | |
10 | #include <FL/Fl_Box.H> | |
11 | #include <FL/Fl_Input.H> | |
12 | #include <FL/Fl_Text_Editor.H> | |
13 | #include <FL/Fl_File_Browser.H> | |
14 | #include <FL/Fl_Button.H> | |
15 | #include <FL/Fl_Return_Button.H> | |
16 | #include <FL/Fl_Choice.H> | |
17 | #include <FL/filename.H> | |
18 | ||
19 | class Main; | |
20 | ||
21 | ||
22 | // Class used to ask user if they want to save changes. | |
23 | // The FLTK fl_choice doesn't do quite what we want, so we make our own... | |
24 | ||
25 | class Save_confirm_dialog : Fl_Double_Window { | |
26 | public: | |
27 | enum Answer { Cancel, No, Yes }; | |
28 | ||
29 | // This brings up the dialog | |
30 | static Answer confirm_save(const char * text, bool hide_the_No = false); | |
31 | ||
32 | private: | |
33 | Save_confirm_dialog(const char * text); | |
34 | ~Save_confirm_dialog(void); | |
35 | ||
36 | // Widgets | |
37 | Fl_Box * icon_p; | |
38 | Fl_Box * message_p; | |
39 | Fl_Return_Button * yes_p; | |
40 | Fl_Button * no_p; | |
41 | Fl_Button * cancel_p; | |
42 | }; | |
43 | ||
44 | ||
45 | ||
46 | // Class for the items off of "File" on the main menu bar | |
47 | ||
48 | class File { | |
49 | ||
50 | friend class Run; | |
51 | ||
52 | public: | |
53 | File(); | |
54 | ~File(); | |
55 | ||
56 | // Callbacks | |
57 | static void modify_cb(int, int, int, int, const char *, void * data); | |
58 | static void New_cb(Fl_Widget *, void * data); | |
59 | static void NewFromTemplate_cb(Fl_Widget *, void * data); | |
60 | static void Open_cb(Fl_Widget *, void * data); | |
61 | static void Save_cb(Fl_Widget *, void * data); | |
62 | static void SaveAs_cb(Fl_Widget *, void * data); | |
63 | static void Exit_cb(Fl_Widget *, void * data); | |
64 | ||
65 | // Load a file into the text editor | |
66 | void load_file(const char * name); | |
67 | ||
68 | // Give access to the text editor buffer | |
69 | Fl_Text_Buffer * get_buffer() { return editor_p->buffer(); } | |
70 | ||
71 | // Gives real filename, or "Untitled.mup" if there is none | |
72 | const char * effective_filename(); | |
73 | ||
74 | // This class needs access to Main class and its text editor. | |
75 | // Creator should call these to point to the proper instances | |
76 | void set_editor(Fl_Text_Editor * ed_p); | |
77 | void set_parent(Main * main_p); | |
78 | ||
79 | // These show the dialog and return the file name the user enters. | |
80 | const char * open_ask_user(void); | |
81 | const char * save_as_ask_user(void); | |
82 | ||
83 | // Ask user if they want to save the currently unsaved changes. | |
84 | Save_confirm_dialog::Answer save_changes_check(const char * extra_text = "", | |
85 | bool hide_the_No = false); | |
86 | ||
87 | #ifndef OS_LIKE_WIN32 | |
88 | // Make icon for Mup files. | |
89 | static void add_mup_icon(void); | |
90 | #endif | |
91 | ||
92 | ||
93 | private: | |
94 | // Callbacks | |
95 | void New(void); | |
96 | void Open(void); | |
97 | void NewFromTemplate(void); | |
98 | void Save(bool honor_auto_display = true); | |
99 | void SaveAs(bool honor_auto_display = true); | |
100 | void Exit(void); | |
101 | ||
102 | // Write out the current file | |
103 | void save_file(bool honor_auto_display); | |
104 | ||
105 | // Put current file name in window label | |
106 | void set_window_label(void); | |
107 | ||
108 | // Reset things for starting to edit a different file | |
109 | void begin_new_file(void); | |
110 | ||
111 | // The name of file being edited | |
112 | char * filename; | |
113 | ||
114 | // If buffer has changed since last being saved | |
115 | bool unsaved_changes; | |
116 | ||
117 | // Pointers to other class instances we need | |
118 | Fl_Text_Editor * editor_p; | |
119 | Main * parent_window_p; | |
120 | }; | |
121 | ||
122 | #endif |