simple_notepad_8.e 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. class SIMPLE_NOTEPAD_8
  2. insert
  3. IUP_INTERFACE
  4. create {ANY}
  5. make
  6. feature {ANY}
  7. ml: IUP_MULTILINE
  8. cfg: IUP_CONFIG
  9. str_find (str, str_to_find, casesensitive: STRING; pos: INTEGER): INTEGER
  10. do
  11. if str.count.is_equal(0) or str_to_find.count.is_equal(0) then
  12. Result := -1
  13. elseif casesensitive.is_equal("OFF") then
  14. str.to_lower
  15. str_to_find.to_lower
  16. end
  17. Result := str.substring_index(str_to_find, pos)
  18. end
  19. read_file (file_name: STRING): STRING
  20. local
  21. tfr: TEXT_FILE_READ
  22. str: STRING
  23. ms: IUP_MESSAGE
  24. do
  25. create str.make_empty
  26. create tfr.connect_to(file_name)
  27. if tfr.is_connected then
  28. from
  29. tfr.read_line
  30. until
  31. tfr.end_of_input
  32. loop
  33. str.append(tfr.last_string)
  34. str.append_character('%N')
  35. tfr.read_line
  36. end
  37. str.append(tfr.last_string)
  38. tfr.disconnect
  39. else
  40. str.append("Fail when reading from file: ")
  41. str.append(file_name)
  42. create ms.message("Error", str)
  43. end
  44. Result := str
  45. end
  46. write_file (file_name, text: STRING): INTEGER
  47. local
  48. tfw: TEXT_FILE_WRITE
  49. ms: IUP_MESSAGE
  50. str: STRING
  51. do
  52. create tfw.connect_to(file_name)
  53. if tfw.is_connected then
  54. tfw.put_string(text)
  55. tfw.disconnect
  56. Result := 1
  57. else
  58. str.make_empty
  59. str.append("Fail when writing to file: ")
  60. str.append(file_name)
  61. create ms.message("Error", str)
  62. Result := 0
  63. end
  64. end
  65. --********************************** Callbacks *****************************************
  66. edit_menu_open_cb (m: IUP_MENU): STRING
  67. local
  68. cb: IUP_CLIPBOARD
  69. item_p, item_c, item_cp, item_del: IUP_MENU_ITEM
  70. do
  71. cb := get_clipboard
  72. item_p ::= m.get_dialog_child("ITEM_PASTE")
  73. item_c ::= m.get_dialog_child("ITEM_CUT")
  74. item_cp ::= m.get_dialog_child("ITEM_COPY")
  75. item_del ::= m.get_dialog_child("ITEM_DELETE")
  76. if cb.is_text_available then
  77. item_p.set_active(True)
  78. else
  79. item_p.set_active(False)
  80. end
  81. if ml.get_selected_text.is_empty then
  82. item_c.set_active(False)
  83. item_cp.set_active(False)
  84. item_del.set_active(False)
  85. else
  86. item_c.set_active(True)
  87. item_cp.set_active(True)
  88. item_del.set_active(True)
  89. end
  90. Result := "IUP_DEFAULT"
  91. end
  92. item_recent_cb (c: IUP_CONFIG): STRING
  93. local
  94. text: STRING
  95. do
  96. text := read_file(c.get_title)
  97. ml.set_value(text)
  98. Result := "IUP_DEFAULT"
  99. end
  100. config_recent_cb (c: IUP_CONFIG): STRING
  101. local
  102. file, text: STRING
  103. do
  104. file := c.get_title
  105. text := read_file(file)
  106. ml.set_value(text)
  107. Result := "IUP_DEFAULT"
  108. end
  109. multitext_caret_cb (m: IUP_TEXT; lin, col, pos: INTEGER): STRING
  110. local
  111. lbl_statusbar: IUP_LABEL
  112. str: STRING
  113. do
  114. if lbl_statusbar ?:= m.get_dialog_child("STATUSBAR") then
  115. lbl_statusbar ::= m.get_dialog_child("STATUSBAR")
  116. str := "Line "
  117. str.append(lin.to_string)
  118. str.append(", Col ")
  119. str.append(col.to_string)
  120. lbl_statusbar.set_title(str)
  121. end
  122. Result := "IUP_DEFAULT"
  123. end
  124. item_open_action_cb (widget: IUP_WIDGET): STRING
  125. local
  126. status: INTEGER
  127. rv, name, text: STRING
  128. fd: IUP_FILE_DIALOG
  129. do
  130. create fd.file_dialog
  131. fd.set_dialog_type("OPEN")
  132. fd.set_ext_filter("Text files|*.txt|All Files|*.*|")
  133. fd.set_title("Select a text file")
  134. rv := fd.popup_predefined_xy("IUP_CENTER", "IUP_CENTER")
  135. if rv.is_equal("IUP_NOERROR") then
  136. status := fd.get_status
  137. if status.is_equal(0) then
  138. name := fd.get_value
  139. text := read_file(name)
  140. cfg.update_recent_file_menu(name)
  141. ml.set_value(text)
  142. end
  143. end
  144. fd.destroy
  145. Result := "IUP_DEFAULT"
  146. end
  147. item_saveas_action_cb (widget: IUP_WIDGET): STRING
  148. local
  149. status, r: INTEGER
  150. rv, name, text: STRING
  151. fd: IUP_FILE_DIALOG
  152. do
  153. create fd.file_dialog
  154. fd.set_dialog_type("SAVE")
  155. fd.set_ext_filter("Text files|*.txt|All Files|*.*|")
  156. fd.set_title("Select a text file")
  157. rv := fd.popup_predefined_xy("IUP_CENTER", "IUP_CENTER")
  158. if rv.is_equal("IUP_NOERROR") then
  159. status := fd.get_status
  160. if not status.is_equal(-1) then
  161. name := fd.get_value
  162. text := ml.get_value
  163. r := write_file(name, text)
  164. if r.is_equal(1) then
  165. cfg.update_recent_file_menu(name)
  166. end
  167. end
  168. end
  169. fd.destroy
  170. Result := "IUP_DEFAULT"
  171. end
  172. item_font_action_cb (widget: IUP_MENU_ITEM): STRING
  173. local
  174. status: INTEGER
  175. rv, ft, selected: STRING
  176. fd: IUP_FONT_DIALOG
  177. do
  178. create fd.font_dialog
  179. ft := ml.get_font
  180. fd.set_value(ft)
  181. rv := fd.popup_predefined_xy("IUP_CENTER", "IUP_CENTER")
  182. if rv.is_equal("IUP_NOERROR") then
  183. status := fd.get_status
  184. if status.is_equal(1) then
  185. selected := fd.get_value
  186. ml.set_font(selected)
  187. cfg.set_variable_string("MainWindow", "Font", selected)
  188. end
  189. end
  190. fd.destroy
  191. Result := "IUP_DEFAULT"
  192. end
  193. item_about_action_cb (widget: IUP_MENU_ITEM): STRING
  194. local
  195. ms: IUP_MESSAGE
  196. do
  197. create ms.message("About"," Simple Notepad%N%NAutors:%N Gustavo Lyrio%N Antonio Scuri")
  198. Result := "IUP_DEFAULT"
  199. end
  200. item_exit_action_cb (widget: IUP_MENU_ITEM): STRING
  201. local
  202. i: INTEGER
  203. d: IUP_DIALOG
  204. do
  205. d := widget.get_dialog
  206. cfg.save_dialog (d, "MainWindow")
  207. i := cfg.save
  208. cfg.destroy
  209. Result := "IUP_CLOSE"
  210. end
  211. close_dialog_cb (d: IUP_DIALOG): STRING
  212. local
  213. i: INTEGER
  214. do
  215. cfg.save_dialog (d, "MainWindow")
  216. i := cfg.save
  217. cfg.destroy
  218. Result := "IUP_CLOSE"
  219. end
  220. goto_ok_action_cb(widget: IUP_BUTTON): STRING
  221. local
  222. line_count, line: INTEGER
  223. txt: IUP_TEXT
  224. ms: IUP_MESSAGE
  225. do
  226. if txt ?:= widget.get_dialog_child("LINE_TEXT") then
  227. txt ::= widget.get_dialog_child("LINE_TEXT")
  228. line_count := widget.get_attribute_integer("TEXT_LINECOUNT")
  229. line := txt.get_value.to_integer
  230. if line < 1 and line >= line_count then
  231. create ms.message("Error", "Invalid line number.")
  232. Result := "IUP_DEFAULT"
  233. end
  234. widget.get_dialog.set_attribute_integer("STATUS", 1)
  235. Result := "IUP_CLOSE"
  236. end
  237. end
  238. goto_cancel_action_cb(widget: IUP_BUTTON): STRING
  239. do
  240. widget.get_dialog.set_attribute_integer("STATUS", 0)
  241. Result := "IUP_CLOSE"
  242. end
  243. item_goto_action_cb (widget: IUP_WIDGET): STRING
  244. local
  245. dlg, d: IUP_DIALOG
  246. vbox: IUP_VBOX
  247. hbox: IUP_HBOX
  248. bt_ok, bt_cancel: IUP_BUTTON
  249. f: IUP_FILL
  250. lbl: IUP_LABEL
  251. txt: IUP_TEXT
  252. str, s: STRING
  253. line_count, line, pos: INTEGER
  254. item: IUP_MENU_ITEM
  255. do
  256. line_count := ml.get_line_count
  257. str := "Line Number [1-"
  258. str.append_string(ml.get_line_count.to_string)
  259. str.append_string("]:")
  260. create lbl.label(str)
  261. create txt.text
  262. txt.set_mask("IUP_MASK_UINT") -- unsigned integer numbers only
  263. txt.set_name("LINE_TEXT")
  264. txt.set_visible_columns(20)
  265. create bt_ok.button("OK")
  266. bt_ok.set_attribute_integer("TEXT_LINECOUNT", line_count)
  267. bt_ok.set_padding(10, 2)
  268. bt_ok.set_cb_action(agent goto_ok_action_cb(?))
  269. create bt_cancel.button("Cancel")
  270. bt_cancel.set_padding(10, 2)
  271. bt_cancel.set_cb_action(agent goto_cancel_action_cb(?))
  272. create f.fill
  273. create hbox.hbox({ARRAY[IUP_WIDGET] 1, << f, bt_ok, bt_cancel >>})
  274. hbox.set_normalize_size("HORIZONTAL")
  275. create vbox.vbox({ARRAY[IUP_WIDGET] 1, << lbl, txt, hbox >>})
  276. vbox.set_margin(10, 10)
  277. vbox.set_gap(5)
  278. create dlg.dialog(vbox)
  279. dlg.set_title("Go To Line")
  280. dlg.set_modal_dialog_frame(True)
  281. dlg.set_default_enter_widget(bt_ok)
  282. dlg.set_default_escape_widget(bt_cancel)
  283. if {IUP_MENU_ITEM} ?:= widget then
  284. item ::= widget
  285. dlg.set_parent_dialog_widget(item.get_dialog)
  286. elseif {IUP_DIALOG} ?:= widget then
  287. d ::= widget
  288. dlg.set_parent_dialog_widget(d)
  289. end
  290. s := dlg.popup_predefined_xy ("IUP_CENTERPARENT", "IUP_CENTERPARENT")
  291. if s.is_equal("IUP_NOERROR") and dlg.get_attribute_integer("STATUS").is_equal(1) then
  292. line := txt.get_value.to_integer
  293. pos := ml.text_convert_lin_col_to_pos(line, 0)
  294. ml.set_multiline_caret_pos(pos)
  295. ml.scroll_to_pos(pos)
  296. end
  297. dlg.destroy
  298. Result := "IUP_DEFAULT"
  299. end
  300. find_next_action_cb (widget: IUP_BUTTON): STRING
  301. local
  302. str, str_to_find, casesensitive: STRING
  303. find_pos, pos, end_pos: INTEGER
  304. txt: IUP_TEXT
  305. find_case: IUP_TOGGLE
  306. tup: TUPLE[INTEGER, INTEGER]
  307. pw: IUP_WIDGET
  308. ms: IUP_MESSAGE
  309. do
  310. str := ml.get_value
  311. find_pos := ml.get_attribute_integer("FIND_POS")
  312. if find_pos = 0 then
  313. find_pos := 1
  314. end
  315. if txt ?:= widget.get_dialog_child("FIND_TEXT") then
  316. txt ::= widget.get_dialog_child("FIND_TEXT")
  317. str_to_find := txt.get_value
  318. if find_case ?:= widget.get_dialog_child("FIND_CASE") then
  319. find_case ::= widget.get_dialog_child("FIND_CASE")
  320. casesensitive := find_case.get_value
  321. -- Rest 1 since the string start at 1, but multiline position
  322. -- start at 0.
  323. pos := str_find(str, str_to_find, casesensitive, find_pos) - 1
  324. if pos < 0 and find_pos > 0 then
  325. -- try again from the start
  326. pos := str_find(str, str_to_find, casesensitive, 1) - 1
  327. end
  328. if pos > 0 then
  329. end_pos := pos + str_to_find.count
  330. ml.set_attribute_integer("FIND_POS", end_pos)
  331. pw := ml.set_focus
  332. ml.set_multiline_selection_pos(pos, end_pos)
  333. tup := ml.text_convert_pos_to_lin_col(pos)
  334. -- position at col=0, just scroll lines
  335. pos := ml.text_convert_lin_col_to_pos(tup.item_1, 0)
  336. ml.scroll_to_pos(pos)
  337. else
  338. create ms.message("Warning", "Text not found.")
  339. end
  340. end
  341. end
  342. Result := "IUP_DEFAULT"
  343. end
  344. find_close_action_cb (widget: IUP_BUTTON): STRING
  345. do
  346. widget.get_dialog.hide
  347. Result := "IUP_DEFAULT"
  348. end
  349. item_find_action_cb (widget: IUP_WIDGET): STRING
  350. local
  351. dlg, main_dlg: IUP_DIALOG
  352. lbl: IUP_LABEL
  353. txt: IUP_TEXT
  354. btn, bt_next, bt_close: IUP_BUTTON
  355. find_case: IUP_TOGGLE
  356. f: IUP_FILL
  357. hbox: IUP_HBOX
  358. vbox: IUP_VBOX
  359. s: STRING
  360. item: IUP_MENU_ITEM
  361. do
  362. if btn ?:= widget then
  363. btn ::= widget
  364. main_dlg := btn.get_dialog
  365. elseif item ?:= widget then
  366. item ::= widget
  367. main_dlg := item.get_dialog
  368. elseif main_dlg ?:= widget then
  369. main_dlg ::= widget
  370. end
  371. if dlg ?:= main_dlg.get_attribute_widget("FIND_DIALOG") then
  372. dlg ::= main_dlg.get_attribute_widget("FIND_DIALOG")
  373. end
  374. if dlg = Void then
  375. create lbl.label("Find What:")
  376. create txt.text
  377. txt.set_name("FIND_TEXT")
  378. txt.set_visible_columns(20)
  379. create find_case.toggle("Case Sensitive")
  380. find_case.set_name("FIND_CASE")
  381. create bt_next.button("Find Next")
  382. bt_next.set_padding(10, 2)
  383. bt_next.set_cb_action(agent find_next_action_cb(?))
  384. create bt_close.button("Close")
  385. bt_close.set_padding(10, 2)
  386. bt_close.set_cb_action(agent find_close_action_cb(?))
  387. create f.fill
  388. create hbox.hbox({ARRAY[IUP_WIDGET] 1, << f, bt_next, bt_close >>})
  389. hbox.set_normalize_size("HORIZONTAL")
  390. create vbox.vbox({ARRAY[IUP_WIDGET] 1, << lbl, txt, find_case, hbox >>})
  391. vbox.set_margin(10, 10)
  392. vbox.set_gap(10)
  393. create dlg.dialog(vbox)
  394. dlg.set_title("Find")
  395. dlg.set_modal_dialog_frame(True)
  396. dlg.set_default_enter_widget(bt_next)
  397. dlg.set_default_escape_widget(bt_close)
  398. dlg.set_parent_dialog_widget(main_dlg)
  399. -- Save the dialog to reuse it
  400. main_dlg.set_attribute_widget("FIND_DIALOG", dlg)
  401. end
  402. -- center parent first time, next time reuse the last position
  403. s := dlg.show_predefined_xy("IUP_CURRENT", "IUP_CURRENT")
  404. Result := "IUP_DEFAULT"
  405. end
  406. item_copy_action_cb(item: IUP_MENU_ITEM): STRING
  407. local
  408. cp: IUP_CLIPBOARD
  409. do
  410. cp := get_clipboard
  411. cp.add_text(ml.get_selected_text)
  412. Result := "IUP_DEFAULT"
  413. end
  414. item_paste_action_cb(item: IUP_MENU_ITEM): STRING
  415. local
  416. cp: IUP_CLIPBOARD
  417. do
  418. cp := get_clipboard
  419. ml.insert(cp.get_text)
  420. Result := "IUP_DEFAULT"
  421. end
  422. item_cut_action_cb(item: IUP_MENU_ITEM): STRING
  423. local
  424. cp: IUP_CLIPBOARD
  425. do
  426. cp := get_clipboard
  427. cp.add_text(ml.get_selected_text)
  428. ml.set_selected_text("")
  429. Result := "IUP_DEFAULT"
  430. end
  431. item_delete_action_cb(item: IUP_MENU_ITEM): STRING
  432. do
  433. ml.set_selected_text("")
  434. Result := "IUP_DEFAULT"
  435. end
  436. item_select_all_action_cb(item: IUP_MENU_ITEM): STRING
  437. do
  438. ml.select_all
  439. Result := "IUP_DEFAULT"
  440. end
  441. key_pressed (dlg: IUP_DIALOG; k: INTEGER): STRING
  442. do
  443. if k.is_equal(iup_open.x_key_ctrl('O')) then
  444. Result := item_open_action_cb(dlg)
  445. elseif k.is_equal(iup_open.x_key_ctrl('S')) then
  446. Result := item_saveas_action_cb(dlg)
  447. elseif k.is_equal(iup_open.x_key_ctrl('F')) then
  448. Result := item_find_action_cb(dlg)
  449. elseif k.is_equal(iup_open.x_key_ctrl('G')) then
  450. Result := item_goto_action_cb(dlg)
  451. else
  452. Result := "IUP_DEFAULT"
  453. end
  454. end
  455. --********************************** Make *****************************************
  456. make
  457. local
  458. i: STRING
  459. x: INTEGER
  460. gui: IUP
  461. v: IUP_VBOX
  462. w: IUP_DIALOG
  463. item_exit, item_open, item_saveas, item_font, item_about: IUP_MENU_ITEM
  464. item_find, item_goto, item_copy, item_paste, item_cut, item_delete, item_select_all: IUP_MENU_ITEM
  465. sep1, sep2, sep3: IUP_MENU_SEPARATOR
  466. file_menu, edit_menu, format_menu, help_menu, menu, recent_menu: IUP_MENU
  467. sub_menu_file, sub_menu_edit, sub_menu_format, sub_menu_help, sub_menu_recent: IUP_SUBMENU
  468. btn_open, btn_save, btn_find: IUP_BUTTON
  469. lbl_statusbar, toolbar_sep: IUP_LABEL
  470. toolbar_hb: IUP_HBOX
  471. do
  472. gui := iup_open
  473. gui.load_images
  474. create cfg.config
  475. cfg.set_app_name("simple_notepad")
  476. x := cfg.load
  477. create ml.multiline
  478. ml.set_expand("YES")
  479. ml.set_cb_caret(agent multitext_caret_cb(?,?,?,?))
  480. i := cfg.get_variable_string("MainWindow", "Font")
  481. if not i.is_empty then
  482. ml.set_font(i)
  483. end
  484. create item_open.item("&Open... %TCtrl+O")
  485. item_open.set_hide_mark(True)
  486. item_open.set_cb_action(agent item_open_action_cb(?))
  487. create btn_open.button("")
  488. btn_open.set_image("IUP_FileOpen")
  489. btn_open.set_flat(True)
  490. btn_open.set_can_focus(False)
  491. btn_open.set_tip("Open (Ctrl+O)")
  492. btn_open.set_cb_action(agent item_open_action_cb(?))
  493. create item_saveas.item("Save &As...%TCtrl+S")
  494. item_saveas.set_hide_mark(True)
  495. item_saveas.set_cb_action(agent item_saveas_action_cb(?))
  496. create btn_save.button("")
  497. btn_save.set_image("IUP_FileSave")
  498. btn_save.set_flat(True)
  499. btn_save.set_can_focus(False)
  500. btn_save.set_tip("Save (Ctrl+S)")
  501. btn_save.set_cb_action(agent item_saveas_action_cb(?))
  502. create item_exit.item("E&xit")
  503. item_exit.set_hide_mark(True)
  504. item_exit.set_cb_action(agent item_exit_action_cb(?))
  505. create item_find.item("&Find...%TCtrl+F")
  506. item_find.set_hide_mark(True)
  507. item_find.set_cb_action(agent item_find_action_cb(?))
  508. create btn_find.button("")
  509. btn_find.set_image("IUP_EditFind")
  510. btn_find.set_flat(True)
  511. btn_find.set_can_focus(False)
  512. btn_find.set_tip("Find (Ctrl+F)")
  513. btn_find.set_cb_action(agent item_find_action_cb(?))
  514. create item_goto.item("&Go To...%TCtrl+G")
  515. item_goto.set_hide_mark(True)
  516. item_goto.set_cb_action(agent item_goto_action_cb(?))
  517. create item_font.item("&Font...%TCtrl+F")
  518. item_font.set_hide_mark(True)
  519. item_font.set_cb_action(agent item_font_action_cb(?))
  520. create item_about.item("&About...")
  521. item_about.set_hide_mark(True)
  522. item_about.set_cb_action(agent item_about_action_cb(?))
  523. create item_copy.item("Copy%TCtrl+C")
  524. item_copy.set_name("ITEM_COPY")
  525. item_copy.set_hide_mark(True)
  526. item_copy.set_cb_action(agent item_copy_action_cb(?))
  527. create item_paste.item("Paste%TCtrl+V")
  528. item_paste.set_name("ITEM_PASTE")
  529. item_paste.set_hide_mark(True)
  530. item_paste.set_cb_action(agent item_paste_action_cb(?))
  531. create item_cut.item("Cut%TCtrl+X")
  532. item_cut.set_name("ITEM_CUT")
  533. item_cut.set_hide_mark(True)
  534. item_cut.set_cb_action(agent item_cut_action_cb(?))
  535. create item_delete.item("Delete%TDel")
  536. item_delete.set_name("ITEM_DELETE")
  537. item_delete.set_hide_mark(True)
  538. item_delete.set_cb_action(agent item_delete_action_cb(?))
  539. create item_select_all.item("Select All%TCtrl+A")
  540. item_select_all.set_hide_mark(True)
  541. item_select_all.set_cb_action(agent item_select_all_action_cb(?))
  542. create sep1.separator
  543. create sep2.separator
  544. create sep3.separator
  545. create toolbar_sep.label_empty
  546. toolbar_sep.set_vertical_separator
  547. create recent_menu.menu_empty
  548. create sub_menu_recent.submenu("Recent &Files", recent_menu)
  549. create file_menu.menu({ARRAY[IUP_MENU_ELEMENT] 1, << item_open, item_saveas, sep1, sub_menu_recent, item_exit >>})
  550. create edit_menu.menu({ARRAY[IUP_MENU_ELEMENT] 1, << item_cut, item_copy, item_paste, item_delete, sep2, item_find, item_goto, sep3, item_select_all >>})
  551. create format_menu.menu({ARRAY[IUP_MENU_ELEMENT] 1, << item_font >>})
  552. create help_menu.menu({ARRAY[IUP_MENU_ELEMENT] 1, << item_about >>})
  553. edit_menu.set_cb_open(agent edit_menu_open_cb(?))
  554. create sub_menu_file.submenu("&File", file_menu)
  555. create sub_menu_edit.submenu("&Edit", edit_menu)
  556. create sub_menu_format.submenu("F&ormat", format_menu)
  557. create sub_menu_help.submenu("&Help", help_menu)
  558. create menu.menu({ARRAY[IUP_MENU_ELEMENT] 1, << sub_menu_file, sub_menu_edit, sub_menu_format, sub_menu_help >>})
  559. create toolbar_hb.hbox({ARRAY[IUP_WIDGET] 1, << btn_open, btn_save, toolbar_sep, btn_find >>})
  560. toolbar_hb.set_margin(5, 5)
  561. toolbar_hb.set_gap(2)
  562. create lbl_statusbar.label("Lin 1, Col 1")
  563. lbl_statusbar.set_name("STATUSBAR")
  564. lbl_statusbar.set_expand("HORIZONTAL")
  565. lbl_statusbar.set_padding(10, 5)
  566. create v.vbox({ARRAY[IUP_WIDGET] 1, << toolbar_hb, ml, lbl_statusbar >>})
  567. create w.dialog(v)
  568. w.set_menu_widget(menu)
  569. w.set_cb_k_any(agent key_pressed(?, ?))
  570. w.set_title("Simple Notepad")
  571. w.set_predefined_size("HALF", "HALF")
  572. -- parent for some pre-defined dialogs in callbak functions
  573. gui.set_global_parent_dialog_widget(w)
  574. w.set_user_size(0, 0)
  575. w.set_cb_close(agent close_dialog_cb(?))
  576. cfg.set_recent_file_menu(recent_menu, agent config_recent_cb(?), 10)
  577. cfg.show_dialog(w, "MainWindow")
  578. gui.main_loop
  579. gui.close
  580. end
  581. end