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 --- documentation/editor.html | 276 +++++++++++++++++++++++----------------------- 1 file changed, 136 insertions(+), 140 deletions(-) (limited to 'documentation/editor.html') 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: -- cgit v1.2.3