simple_notepad_8.e 18 KB

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