From a6ffe9abc01d4747dae35555cc21db421cdfdf95 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Thu, 18 Oct 2001 19:21:45 +0000 Subject: Fix the editor demo and associated documentation. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1638 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- CHANGES | 3 + documentation/editor.html | 276 +++++++++++++++++++++++----------------------- test/editor.cxx | 10 +- 3 files changed, 144 insertions(+), 145 deletions(-) diff --git a/CHANGES b/CHANGES index 8d348e268..c068f375e 100644 --- a/CHANGES +++ b/CHANGES @@ -35,6 +35,9 @@ CHANGES IN FLTK 1.1.0b4 caused problems with the FLUID main window (flashing tooltip windows and serious problems with KDE 2.2) + - The editor demo had the save and discard button + actions reversed. + CHANGES IN FLTK 1.1.0b3 diff --git a/documentation/editor.html b/documentation/editor.html index 737afce62..236bc8162 100644 --- a/documentation/editor.html +++ b/documentation/editor.html @@ -1,6 +1,6 @@

4 - Designing a Simple Text Editor

- This chapter takes you through the design of a simple FLTK-based text +This chapter takes you through the design of a simple FLTK-based text editor.

Determining the Goals of the Text Editor

Since this will be the first big project you'll be doing with FLTK, @@ -15,68 +15,74 @@ lets define what we want our text editor to do:
  • Keep track of when the file has been changed.
  • Designing the Main Window

    - Now that we've outlined the goals for our editor, we can begin with +Now that we've outlined the goals for our editor, we can begin with the design of our GUI. Obviously the first thing that we need is a window:

    Variables

    - Our text editor will need some global variables to keep track of +Our text editor will need some global variables to keep track of things: - The window variable is our top-level window described -previously. We'll cover the other variables as we build the -application. +The textbuf variable is the text editor buffer for our +window described previously. We'll cover the other variables as +we build the application.

    Menubars and Menus

    - The first goal requires us to use a menubar and menus that define each +The first goal requires us to use a menubar and menus that define each function the editor needs to perform. The Fl_Menu_Item structure is used to define the menus and items in a menubar: Once we have the menus defined we can create the Fl_Menu_Bar - widget and assign the menus to it with: +widget and assign the menus to it with: - We'll define the callback functions later. +We'll define the callback functions later.

    Editing the Text

    - To keep things simple our text editor will use the -Fl_Multiline_Input widget to edit the text: +To keep things simple our text editor will use the +Fl_Text_Editor +widget to edit the text: - So that we can keep track of changes to the file, we also want to add -a "changed" callback: +So that we can keep track of changes to the file, we also want to add +a "modify" callback: - Finally, we want to use a mono-spaced font like FL_COURIER: +Finally, we want to use a mono-spaced font like FL_COURIER:

    The Replace Dialog

    - We can use the FLTK convenience functions for many of the editor's +We can use the FLTK convenience functions for many of the editor's dialogs, however the replace dialog needs its own custom window. To keep things simple we will have a "find" string, a "replace" string, and "replace all", "replace next", and "cancel" buttons. The strings @@ -134,7 +142,7 @@ Fl_Button *replace_cancel = new Fl_Button(230, 70, 60, 25, "Cancel");

    Callbacks

    - Now that we've defined the GUI components of our editor, we need to +Now that we've defined the GUI components of our editor, we need to define our callback functions.

    changed_cb()

    This function will be called whenever the user changes any text in the @@ -298,91 +306,102 @@ void quit_cb(void) { The replace callback just shows the replace dialog:

    replace2_cb()

    - This callback will replace the next occurence of the replacement +This callback will replace the next occurence of the replacement string. If nothing has been entered for the replacement string, then the replace dialog is displayed instead:

    replall_cb()

    - This callback will replace all occurences of the search string in the +This callback will replace all occurences of the search string in the file:

    replcan_cb()

    - This callback just hides the replace dialog: +This callback just hides the replace dialog:

    save_cb()

    - This callback saves the current file. If the current filename is +This callback saves the current file. If the current filename is blank it calls the "save as" callback: @@ -448,63 +469,38 @@ int check_save(void) { This function loads the specified file into the input widget: - When loading the file we use the -input->replace() method to "replace" the text at the end -of the buffer. The pos variable keeps track of the end of the -buffer. +When loading the file we use the +loadfile() +method to "replace" the text in the buffer.

    save_file()

    - This function saves the current buffer to the specified file: +This function saves the current buffer to the specified file: diff --git a/test/editor.cxx b/test/editor.cxx index 8ee30b17d..13faad636 100644 --- a/test/editor.cxx +++ b/test/editor.cxx @@ -1,5 +1,5 @@ // -// "$Id: editor.cxx,v 1.2.2.3.2.2 2001/09/30 17:37:06 easysw Exp $" +// "$Id: editor.cxx,v 1.2.2.3.2.3 2001/10/18 19:21:45 easysw Exp $" // // A simple text editor program for the Fast Light Tool Kit (FLTK). // @@ -109,12 +109,12 @@ int check_save(void) { "Would you like to save it now?", "Cancel", "Save", "Discard"); - if (r == 2) { + if (r == 1) { save_cb(); // Save the file... return !changed; - }; + } - return (r == 1) ? 1 : 0; + return (r == 2) ? 1 : 0; } int loading = 0; @@ -424,5 +424,5 @@ int main(int argc, char **argv) { } // -// End of "$Id: editor.cxx,v 1.2.2.3.2.2 2001/09/30 17:37:06 easysw Exp $". +// End of "$Id: editor.cxx,v 1.2.2.3.2.3 2001/10/18 19:21:45 easysw Exp $". // -- cgit v1.2.3