| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- MODULE spelling ;
- (*
- m2-GTK4 example - a GtkSourceView 5 editor with libspelling
- spell-checking attached to its buffer:
- GtkApplicationWindow > GtkScrolledWindow > GtkSourceView
- buffer <- SpellingTextBufferAdapter <- SpellingChecker
- Build: make examples
- Run: ./build/examples/spelling
- *)
- FROM Gio IMPORT g_application_run;
- FROM GtkApplication IMPORT gtk_application_new;
- FROM GtkWindow IMPORT gtk_application_window_new, gtk_window_set_title,
- gtk_window_set_default_size, gtk_window_set_child, gtk_window_present;
- FROM GtkScrolledWindow IMPORT gtk_scrolled_window_new,
- gtk_scrolled_window_set_child;
- FROM GtkWidget IMPORT gtk_widget_set_vexpand;
- FROM GtkTextBuffer IMPORT gtk_text_buffer_set_text;
- FROM GtkUtils IMPORT Connect;
- FROM GtkSourceFunctions IMPORT gtk_source_init;
- FROM GtkSourceBuffer IMPORT gtk_source_buffer_new;
- FROM GtkSourceView IMPORT gtk_source_view_new_with_buffer,
- gtk_source_view_set_show_line_numbers;
- FROM SpellingFunctions IMPORT spelling_init;
- FROM SpellingChecker IMPORT spelling_checker_get_default;
- FROM SpellingTextBufferAdapter IMPORT spelling_text_buffer_adapter_new;
- FROM SYSTEM IMPORT ADDRESS, ADR;
- FROM libc IMPORT printf;
- CONST
- AppId = "org.example.m2gtk4.Spelling";
- Sample =
- "Spell checking is attatched to this bufer and underlines misspeled words.\n" +
- "Right-click (or press the menu key) on a underlined word to see the\n" +
- "corrections offered by the default libspelling provider.\n";
- PROCEDURE OnActivate (application: ADDRESS; data: ADDRESS);
- VAR
- window, sw, view, buffer, checker, adapter: ADDRESS;
- BEGIN
- buffer := gtk_source_buffer_new(NIL);
- gtk_text_buffer_set_text(buffer, Sample, -1);
- checker := spelling_checker_get_default();
- IF checker # NIL THEN
- adapter := spelling_text_buffer_adapter_new(buffer, checker)
- END;
- view := gtk_source_view_new_with_buffer(buffer);
- gtk_source_view_set_show_line_numbers(view, 1);
- sw := gtk_scrolled_window_new();
- gtk_scrolled_window_set_child(sw, view);
- gtk_widget_set_vexpand(sw, 1);
- window := gtk_application_window_new(application);
- gtk_window_set_title(window, "m2-GTK4 - libspelling");
- gtk_window_set_default_size(window, 600, 400);
- gtk_window_set_child(window, sw);
- gtk_window_present(window)
- END OnActivate;
- VAR
- app: ADDRESS;
- BEGIN
- gtk_source_init();
- spelling_init();
- app := gtk_application_new(AppId, 0);
- IF app = NIL THEN
- printf("gtk_application_new failed\n");
- HALT(1)
- END;
- Connect(app, "activate", ADR(OnActivate), NIL);
- g_application_run(app, 0, NIL)
- END spelling.
|