123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- class SIMPLE_NOTEPAD_3
- insert
- IUP_INTERFACE
- create {ANY}
- make
- feature {ANY}
- -- attribute to be used inside the menu callbacks.
- ml: IUP_MULTILINE
- read_file (file_name: STRING): STRING
- local
- tfr: TEXT_FILE_READ
- str: STRING
- ms: IUP_MESSAGE
- do
- create str.make_empty
- create tfr.connect_to(file_name)
- if tfr.is_connected then
- from
- tfr.read_line
- until
- tfr.end_of_input
- loop
- str.append(tfr.last_string)
- str.append_character('%N')
- tfr.read_line
- end
-
- str.append(tfr.last_string)
- tfr.disconnect
- else
- str.append("Fail when reading from file: ")
- str.append(file_name)
- create ms.message("Error", str)
- end
-
- Result := str
- end
- write_file (file_name, text: STRING)
- local
- tfw: TEXT_FILE_WRITE
- ms: IUP_MESSAGE
- str: STRING
- do
- create tfw.connect_to(file_name)
- if tfw.is_connected then
- tfw.put_string(text)
- tfw.disconnect
- else
- str.make_empty
- str.append("Fail when writing to file: ")
- str.append(file_name)
- create ms.message("Error", str)
- end
- end
- open_cb (widget: IUP_MENU_ITEM): STRING
- local
- status: INTEGER
- rv, name, text: STRING
- fd: IUP_FILE_DIALOG
- do
- create fd.file_dialog
- fd.set_dialog_type("OPEN")
- fd.set_ext_filter("Text files|*.txt|All Files|*.*|")
- fd.set_title("Select a text file")
- rv := fd.popup_predefined_xy("IUP_CENTER", "IUP_CENTER")
- if rv.is_equal("IUP_NOERROR") then
- status := fd.get_status
- if status.is_equal(0) then
- name := fd.get_value
- text := read_file(name)
- ml.set_value(text)
- end
- end
- fd.destroy
- Result := "IUP_DEFAULT"
- end
- saveas_cb (widget: IUP_MENU_ITEM): STRING
- local
- status: INTEGER
- rv, name, text: STRING
- fd: IUP_FILE_DIALOG
- do
- create fd.file_dialog
- fd.set_dialog_type("SAVE")
- fd.set_ext_filter("Text files|*.txt|All Files|*.*|")
- fd.set_title("Select a text file")
- rv := fd.popup_predefined_xy("IUP_CENTER", "IUP_CENTER")
- if rv.is_equal("IUP_NOERROR") then
- status := fd.get_status
- if not status.is_equal(-1) then
- name := fd.get_value
- text := ml.get_value
- write_file(name, text)
- end
- end
- fd.destroy
- Result := "IUP_DEFAULT"
- end
- font_cb (widget: IUP_MENU_ITEM): STRING
- local
- status: INTEGER
- rv, ft, selected: STRING
- fd: IUP_FONT_DIALOG
- do
- create fd.font_dialog
- ft := ml.get_font
- fd.set_value(ft)
- rv := fd.popup_predefined_xy("IUP_CENTER", "IUP_CENTER")
- if rv.is_equal("IUP_NOERROR") then
- status := fd.get_status
- if status.is_equal(1) then
- selected := fd.get_value
- ml.set_font(selected)
- end
- end
- fd.destroy
- Result := "IUP_DEFAULT"
- end
- about_cb (widget: IUP_MENU_ITEM): STRING
- local
- ms: IUP_MESSAGE
- do
- create ms.message("About"," Simple Notepad%N%NAutors:%N Gustavo Lyrio%N Antonio Scuri%N German Arias")
- Result := "IUP_DEFAULT"
- end
- exit_cb (widget: IUP_MENU_ITEM): STRING
- do
- Result := "IUP_CLOSE"
- end
- make
- local
- i: STRING
- gui: IUP
- v: IUP_VBOX
- w: IUP_DIALOG
- item_exit, item_open, item_saveas, item_font, item_about: IUP_MENU_ITEM
- sep: IUP_MENU_SEPARATOR
- file_menu, format_menu, help_menu, menu: IUP_MENU
- sub_menu_file, sub_menu_format, sub_menu_help: IUP_SUBMENU
- do
- gui := iup_open
-
- create ml.multiline
- ml.set_expand("YES")
-
- create v.vbox({ARRAY[IUP_WIDGET] 1, << ml >>})
- create item_open.item("Open...")
- item_open.set_hide_mark(True)
- item_open.set_cb_action(agent open_cb(?))
- create item_saveas.item("Save As...")
- item_saveas.set_hide_mark(True)
- item_saveas.set_cb_action(agent saveas_cb(?))
- create item_exit.item("Exit")
- item_exit.set_hide_mark(True)
- item_exit.set_cb_action(agent exit_cb(?))
- create item_font.item("Font...")
- item_font.set_hide_mark(True)
- item_font.set_cb_action(agent font_cb(?))
- create item_about.item("About...")
- item_about.set_hide_mark(True)
- item_about.set_cb_action(agent about_cb(?))
- create sep.separator
- create file_menu.menu({ARRAY[IUP_MENU_ELEMENT] 1, << item_open, item_saveas, sep, item_exit >>})
- create format_menu.menu({ARRAY[IUP_MENU_ELEMENT] 1, << item_font >>})
- create help_menu.menu({ARRAY[IUP_MENU_ELEMENT] 1, << item_about >>})
- create sub_menu_file.submenu("File", file_menu)
- create sub_menu_format.submenu("Format", format_menu)
- create sub_menu_help.submenu("Help", help_menu)
-
- create menu.menu({ARRAY[IUP_MENU_ELEMENT] 1, << sub_menu_file, sub_menu_format, sub_menu_help >>})
-
- create w.dialog(v)
- w.set_menu_widget(menu)
- w.set_title("Simple Notepad")
- w.set_predefined_size("QUARTER", "QUARTER")
-
- i := w.show_predefined_xy("IUP_CENTER", "IUP_CENTER")
- w.set_user_size(0, 0)
-
- gui.main_loop
- gui.close
- end
- end
|