site  contact  subhomenews

NicEdit text editor

June 18, 2009 — BarryK
Forum member nikobordx (Nicolas) has created a lovely little text editor, written in Genie. It uses gtksourceview to provide syntax highlighting, and it is so nice I have decided to replace Leafpad in the Woof builds.

I have created a package 'nicedit-1.0-pup4.pet' (which will be uploaded to ibiblio soon). The executable is just 43KB (leafpad is 73KB) and I have included the source code at /usr/local/NicEdit/nicedit.gs -- compile instructions are in the file. The source is just 24KB.

Here is a snapshot:


And here is the source:
/*Nicolas's Editor, NicEdit, version 1.0, 2009 GPL licence*/

/* Build with valac --pkg gtk+-2.0 --pkg gtksourceview-2.0 --pkg pango nicedit.gs */
/*BK some minor mods, 16 June 2009*/
/*BK tab indent: make sure your text editor is not set to convert tabs to spaces!*/

uses
Gtk
Pango

init
Gtk.init (ref args)
var test = new NicEdit ()
test.open_file(args[1])
test.show_all ()
Gtk.main ()

class NicEdit : Window
toolbar : Toolbar
text_view : SourceView
status_bar : Statusbar
status_bar2 : Statusbar
status_hbox : HBox
scrool : ScrolledWindow
document_modified : bool = false
separator_menu_item : SeparatorMenuItem
image_menu_item : ImageMenuItem
image_menu_item2 : ImageMenuItem
image_menu_item3 : ImageMenuItem
check_menu_item : CheckMenuItem
check_menu_item2 : CheckMenuItem
check_menu_item3 : CheckMenuItem
check_menu_item4 : CheckMenuItem
check_menu_item5 : CheckMenuItem
image_menu_item4 : ImageMenuItem
image_menu_item5 : ImageMenuItem
goto_window : Dialog
save : Dialog
search_dialog : Dialog
menu_item : MenuItem
messagedialog : MessageDialog
gototext : Entry
buf : SourceBuffer
thefile : string = ""
info : Dialog
search_entry : Entry
match_case : CheckButton
find_backwards : CheckButton
find_button : Widget
tmp_file : string = "/tmp/mytempfile.txt"
search_flags : SourceSearchFlags
newfont : FontSelectionDialog
newcolor : ColorSelectionDialog
font_desc : FontDescription

init
title = "NicEdit"
default_height = 560
default_width = 780 /*BK960*/
window_position = WindowPosition.CENTER
delete_event += exit_program

/* Menus */
var bar = new MenuBar()
var menu1 = new Menu()
image_menu_item = new ImageMenuItem.from_stock(STOCK_NEW, null)
image_menu_item.activate += new_text
menu1.append(image_menu_item)
image_menu_item = new ImageMenuItem.from_stock(STOCK_OPEN, null)
image_menu_item.activate += on_open_clicked
menu1.append(image_menu_item)
separator_menu_item = new SeparatorMenuItem()
menu1.append(separator_menu_item)
image_menu_item = new ImageMenuItem.from_stock(STOCK_SAVE, null)
image_menu_item.activate += save_clicked
menu1.append(image_menu_item)
image_menu_item = new ImageMenuItem.from_stock(STOCK_SAVE_AS, null)
image_menu_item.activate += on_save_as_clicked
menu1.append(image_menu_item)
separator_menu_item = new SeparatorMenuItem()
menu1.append(separator_menu_item)
image_menu_item = new ImageMenuItem.from_stock(STOCK_PRINT, null)
image_menu_item.activate += print_file
menu1.append(image_menu_item)
separator_menu_item = new SeparatorMenuItem()
menu1.append(separator_menu_item)
image_menu_item = new ImageMenuItem.from_stock(STOCK_QUIT, null)
image_menu_item.activate += exit_clicked
menu1.append(image_menu_item)
var launcher = new MenuItem.with_mnemonic("_File")
launcher.set_submenu(menu1)
bar.append(launcher)
/* *************** */
var menu2 = new Menu()
image_menu_item2 = new ImageMenuItem.from_stock(STOCK_UNDO, null)
image_menu_item2.activate += undo_clicked
menu2.append(image_menu_item2)
image_menu_item2 = new ImageMenuItem.from_stock(STOCK_REDO, null)
image_menu_item2.activate += redo_clicked
menu2.append(image_menu_item2)
separator_menu_item = new SeparatorMenuItem()
menu2.append(separator_menu_item)
image_menu_item2 = new ImageMenuItem.from_stock(STOCK_CUT, null)
image_menu_item2.activate += cut_clipboard
menu2.append(image_menu_item2)
image_menu_item2 = new ImageMenuItem.from_stock(STOCK_COPY, null)
image_menu_item2.activate += copy_clipboard
menu2.append(image_menu_item2)
image_menu_item2 = new ImageMenuItem.from_stock(STOCK_PASTE, null)
image_menu_item2.activate += paste_clipboard
menu2.append(image_menu_item2)
separator_menu_item = new SeparatorMenuItem()
menu2.append(separator_menu_item)
image_menu_item2 = new ImageMenuItem.from_stock(STOCK_SELECT_ALL, null)
image_menu_item2.activate += select_all
menu2.append(image_menu_item2)
var launcher2 = new MenuItem.with_mnemonic("E_dit")
launcher2.set_submenu(menu2)
bar.append(launcher2)
/* *************** */
var menu3 = new Menu()
check_menu_item = new CheckMenuItem.with_label("Show Toolbar")
menu3.append(check_menu_item)
check_menu_item.set_active(true)
check_menu_item.toggled += on_check
separator_menu_item = new SeparatorMenuItem()
menu3.append(separator_menu_item)
check_menu_item2 = new CheckMenuItem.with_label("Insert spaces instead of tabs")
menu3.append(check_menu_item2)
check_menu_item2.toggled += on_check2
separator_menu_item = new SeparatorMenuItem()
menu3.append(separator_menu_item)
check_menu_item3 = new CheckMenuItem.with_label("Highlight current line")
menu3.append(check_menu_item3)
check_menu_item3.toggled += on_check3
separator_menu_item = new SeparatorMenuItem()
menu3.append(separator_menu_item)
check_menu_item4 = new CheckMenuItem.with_label("Show line number")
menu3.append(check_menu_item4)
check_menu_item4.toggled += on_check4
separator_menu_item = new SeparatorMenuItem()
menu3.append(separator_menu_item)
check_menu_item5 = new CheckMenuItem.with_label("Highlight syntax")
menu3.append(check_menu_item5)
check_menu_item5.set_active(true)
check_menu_item5.toggled += on_check5
var launcher3 = new MenuItem.with_mnemonic("_View")
launcher3.set_submenu(menu3)
bar.append(launcher3)
/* *************** */
var menu4 = new Menu()
image_menu_item4 = new ImageMenuItem.from_stock(STOCK_FIND, null)
image_menu_item4.activate += searchdialog
menu4.append(image_menu_item4)
separator_menu_item = new SeparatorMenuItem()
menu4.append(separator_menu_item)
image_menu_item4 = new ImageMenuItem.from_stock(STOCK_JUMP_TO, null)
image_menu_item4.activate += go_to_line_window
menu4.append(image_menu_item4)
var launcher4 = new MenuItem.with_mnemonic("_Search")
launcher4.set_submenu(menu4)
bar.append(launcher4)
/* *************** */
var menu5 = new Menu()
menu_item = new MenuItem.with_label("Change Background Color")
menu_item.activate += change_background_color
menu5.append(menu_item)
menu_item = new MenuItem.with_label("Change Text Color")
menu_item.activate += change_text_color
menu5.append(menu_item)
menu_item = new MenuItem.with_label("Change Font")
menu_item.activate += change_font
menu5.append(menu_item)
separator_menu_item = new SeparatorMenuItem()
menu5.append(separator_menu_item)
menu5.append(menu_item = new MenuItem.with_label("Document Stats"))
menu_item.activate += info_clicked
var launcher5 = new MenuItem.with_label("Tools")
launcher5.set_submenu(menu5)
bar.append(launcher5)
/* *************** */
var menu6 = new Menu()
image_menu_item5 = new ImageMenuItem.from_stock(STOCK_ABOUT, null)
image_menu_item5.activate += about_clicked
menu6.append(image_menu_item5)
var launcher6 = new MenuItem.with_label("About") /*BK("?")*/
launcher6.set_submenu(menu6)
bar.append(launcher6)

/* Toolbar */
toolbar = new Toolbar ()
var separator = new SeparatorToolItem ()
var separator2 = new SeparatorToolItem ()
var separator3 = new SeparatorToolItem ()
var separator4 = new SeparatorToolItem ()
var new_button = new ToolButton.from_stock (STOCK_NEW)
var open_button = new ToolButton.from_stock (STOCK_OPEN)
var save_button = new ToolButton.from_stock (STOCK_SAVE)
var print_button = new ToolButton.from_stock (STOCK_PRINT)
var undo_button = new ToolButton.from_stock (STOCK_UNDO)
var redo_button = new ToolButton.from_stock (STOCK_REDO)
var cut_button = new ToolButton.from_stock (STOCK_CUT)
var copy_button = new ToolButton.from_stock (STOCK_COPY)
var paste_button = new ToolButton.from_stock (STOCK_PASTE)
var find_button = new ToolButton.from_stock (STOCK_FIND)
toolbar.add (new_button)
toolbar.add (open_button)
toolbar.add (save_button)
toolbar.add (separator)
toolbar.add (print_button)
toolbar.add (separator2)
toolbar.add (undo_button)
toolbar.add (redo_button)
toolbar.add (separator3)
toolbar.add (cut_button)
toolbar.add (copy_button)
toolbar.add (paste_button)
toolbar.add (separator4)
toolbar.add (find_button)
new_button.clicked += new_text
open_button.clicked += on_open_clicked
save_button.clicked += save_clicked
print_button.clicked += print_file
undo_button.clicked += undo_clicked
redo_button.clicked += redo_clicked
cut_button.clicked += cut_clipboard
copy_button.clicked += copy_clipboard
paste_button.clicked += paste_clipboard
find_button.clicked += searchdialog

/* Textview */
var manager = new SourceLanguageManager()
buf = new SourceBuffer(null)
buf.language = manager.get_language ("vala")
buf.set_highlight_syntax (true)
text_view = new SourceView.with_buffer(buf)
text_view.set_insert_spaces_instead_of_tabs(false)
text_view.buffer.changed += text_changed
buf.set_highlight_syntax (true)

/* Scrolled Window */
var scroll = new ScrolledWindow (null, null)
scroll.set_policy (PolicyType.AUTOMATIC, PolicyType.AUTOMATIC)
scroll.add (text_view)

/* Status Bar */
status_bar = new Statusbar ()
status_bar.set_has_resize_grip (false)
status_bar.pop(0)
status_bar.push(0, "New unregistered file")
status_bar2 = new Statusbar ()
status_bar2.set_has_resize_grip (false)
status_bar2.pop(0)

/* HBox */
status_hbox = new HBox (false, 0)
status_hbox.pack_start (status_bar, true, true, 0)
status_hbox.pack_start (status_bar2, true, true, 0)

/* VBox */
var vbox = new VBox (false, 0)
vbox.pack_start (bar, false, true, 0)
vbox.pack_start (toolbar, false, true, 0)
vbox.pack_start (scroll, true, true, 0)
vbox.pack_start (status_hbox, false, true, 0)
add (vbox)

def on_check ()
checked : bool = check_menu_item.get_active()
if checked is true
toolbar.show()
else
toolbar.hide()

def on_check2 ()
checked : bool = check_menu_item2.get_active()
if checked is true
text_view.set_insert_spaces_instead_of_tabs(true)
else
text_view.set_insert_spaces_instead_of_tabs(false)

def on_check3 ()
checked : bool = check_menu_item3.get_active()
if checked is true
text_view.set_highlight_current_line(true)
else
text_view.set_highlight_current_line(false)

def on_check4 ()
checked : bool = check_menu_item4.get_active()
if checked is true
text_view.set_show_line_numbers(true)
else
text_view.set_show_line_numbers(false)

def on_check5 ()
checked : bool = check_menu_item5.get_active()
if checked is true
buf.set_highlight_syntax (true)
else
buf.set_highlight_syntax (false)

def text_changed ()
document_modified = true
status_bar2.push(0, "Unregistered")

def new_text ()
if document_modified is true
messagedialog = new MessageDialog (this, Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL, Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, ("The file is unregistered, do you want to save it ?"))
messagedialog.add_button (STOCK_CANCEL, ResponseType.CANCEL)
var response = messagedialog.run()
if response is ResponseType.YES
messagedialog.destroy()
save_clicked ()
clear_text()
else if response is ResponseType.NO
clear_text()
messagedialog.destroy()
else if response is ResponseType.CANCEL
messagedialog.destroy()
else
clear_text()

def clear_text()
text_view.buffer.set_text ("", 0)
status_bar.push(0, "New unregistered file")
status_bar2.push(0, "")
document_modified = false
thefile = ""

def select_all ()
text_view.select_all (true)

def undo_clicked ()
text_view.undo()

def redo_clicked ()
text_view.redo()

def cut_clipboard ()
text_view.cut_clipboard()

def copy_clipboard ()
text_view.copy_clipboard()

def paste_clipboard ()
text_view.paste_clipboard()

def current_line () : int
iter : TextIter
text_view.buffer.get_iter_at_mark (out iter, text_view.buffer.get_insert ())
return iter.get_line()

def line_count () : int
return text_view.buffer.get_line_count ()

def info_clicked ()
info = new Dialog ()
info.title = "Text Info :"
info.default_height = 300
info.default_width = 300
info.window_position = WindowPosition.CENTER
info.set_modal(true)
info.set_skip_taskbar_hint(true)
info.set_resizable(false)
info.has_separator = false
info.border_width = 5
var label = new Label("File : " + thefile)
var label1 = new Label("Current line : " + current_line ().to_string())
var label2 = new Label("Number of line : " + line_count ().to_string())
var button = new Button.with_mnemonic("Close")
button.clicked += def (s)
info.hide()
info.vbox.pack_start (label, false, true, 0)
info.vbox.pack_start (label1, false, true, 0)
info.vbox.pack_start (label2, false, true, 0)
info.vbox.pack_start (button, false, true, 0)
info.show_all()
info.run()

def searchdialog()
search_dialog = new Dialog()
search_dialog.title = "Find"
search_dialog.set_default_size (300, 50)
search_dialog.position = WindowPosition.CENTER
search_dialog.has_separator = false
search_dialog.border_width = 5
search_dialog.set_deletable(false)
search_dialog.set_resizable(false)
search_dialog.set_skip_taskbar_hint(true)
search_entry = new Entry ()
var search_label = new Label.with_mnemonic ("_Search for:")
search_label.mnemonic_widget = this.search_entry
this.match_case = new CheckButton.with_mnemonic ("_Match case")
this.find_backwards = new CheckButton.with_mnemonic ("Find _backwards")
var hbox = new HBox (false, 20)
hbox.pack_start (search_label, false, true, 0)
hbox.pack_start (this.search_entry, true, true, 0)
search_dialog.vbox.pack_start (hbox, false, true, 0)
search_dialog.vbox.pack_start (this.match_case, false, true, 0)
search_dialog.vbox.pack_start (this.find_backwards, false, true, 0)
search_dialog.vbox.spacing = 10
search_dialog.add_button (STOCK_HELP, ResponseType.HELP)
search_dialog.add_button (STOCK_CLOSE, ResponseType.CLOSE)
search_dialog.add_button (STOCK_FIND, ResponseType.APPLY)
search_dialog.response += on_response
search_dialog.show_all ()
search_dialog.run()

def on_response(response_id : int)
if response_id is ResponseType.CLOSE
search_dialog.hide()
if response_id is ResponseType.APPLY
findtext()
if response_id is ResponseType.HELP
messagedialog = new MessageDialog (this, Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.CLOSE, ("Type word and click 'Find'"))
messagedialog.run()
messagedialog.destroy()

def findtext ()
match_start : TextIter
match_end : TextIter
start_iter : TextIter
end_iter : TextIter
iter : TextIter
found : bool = false

text_view.buffer.get_start_iter (out start_iter)
text_view.buffer.get_end_iter (out end_iter)
text_view.buffer.get_selection_bounds (null, out iter)

if match_case.get_active() is true
search_flags |= SourceSearchFlags.CASE_INSENSITIVE | SourceSearchFlags.TEXT_ONLY
if find_backwards.get_active() is true
found = source_iter_backward_search (iter , search_entry.get_text(), search_flags, out match_start, out match_end, null)
text_view.buffer.place_cursor (iter)
text_view.scroll_to_mark (text_view.buffer.get_insert (), 0.25, false, 0.0, 0.0)
else
found = source_iter_forward_search (iter , search_entry.get_text(), search_flags, out match_start, out match_end, null)
text_view.buffer.place_cursor (iter)
text_view.scroll_to_mark (text_view.buffer.get_insert (), 0.25, false, 0.0, 0.0)


if found is true
text_view.buffer.select_range(match_start , match_end)

def go_to_line_window ()
goto_window = new Dialog()
goto_window.title = "Go to line :"
goto_window.set_default_size (300, 50)
goto_window.position = WindowPosition.CENTER
goto_window.has_separator = false
goto_window.border_width = 5
goto_window.set_deletable(false)
goto_window.set_resizable(false)
goto_window.set_skip_taskbar_hint(true)
gototext = new Entry()
var okbutton = new Button.with_label ("Go!")
okbutton.clicked += def (s)
go_to_line(gototext.get_text().to_int())
goto_window.hide()
var hbox = new HBox (false, 0)
hbox.pack_start (gototext, true, true, 0)
hbox.pack_start (okbutton, false, true, 0)
goto_window.vbox.pack_start (hbox, false, true, 0)
goto_window.show_all()
goto_window.run()

def go_to_line (line_number : int)
iter : TextIter
text_view.buffer.get_iter_at_line (out iter, line_number)
iter.set_line (line_number - 1)
text_view.buffer.place_cursor (iter)
text_view.scroll_to_iter (iter, 0, false, 0, 0)

def change_background_color ()
newcolor = new ColorSelectionDialog ("Choose your prefered background color:")
var response = newcolor.run()
if response is ResponseType.OK
color : Gdk.Color
var colorsel = (ColorSelection) newcolor.colorsel
colorsel.get_current_color (out color)
text_view.modify_base (Gtk.StateType.NORMAL, color)
newcolor.destroy()
if response is ResponseType.CANCEL
newcolor.destroy()
if response is ResponseType.HELP
messagedialog = new MessageDialog (this, Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.CLOSE, ("Choose your color and click 'Ok'"))
messagedialog.run()
messagedialog.destroy()

def change_text_color ()
newcolor = new ColorSelectionDialog ("Choose your prefered text color:")
var response = newcolor.run()
if response is ResponseType.OK
color : Gdk.Color
var colorsel = (ColorSelection) newcolor.colorsel
colorsel.get_current_color (out color)
text_view.modify_text (Gtk.StateType.NORMAL, color)
newcolor.destroy()
if response is ResponseType.CANCEL
newcolor.destroy()
if response is ResponseType.HELP
messagedialog = new MessageDialog (this, Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.CLOSE, ("Choose your color and click 'Ok'"))
messagedialog.run()
messagedialog.destroy()

def change_font ()
newfont = new FontSelectionDialog("Select font:")
var response = newfont.run()
if response is ResponseType.OK
font_desc = FontDescription.from_string(newfont.get_font_name())
text_view.modify_font(font_desc)
newfont.destroy()
if response is ResponseType.CANCEL
newfont.destroy()

def exit_clicked ()
exit_program()

def exit_program () : bool
delete_tmp_file()
if document_modified is true
messagedialog = new MessageDialog (this, Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL, Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, ("The file is unregistered, do you want to save it ?"))
messagedialog.add_button (STOCK_CANCEL, ResponseType.CANCEL)
var response = messagedialog.run()
if response is ResponseType.YES
messagedialog.destroy()
save_clicked ()
Gtk.main_quit()
else if response is ResponseType.NO
messagedialog.destroy()
Gtk.main_quit()
else if response is ResponseType.CANCEL
messagedialog.destroy()
return true
else
Gtk.main_quit()
return false

def delete_tmp_file()
try
var destination = File.new_for_path (tmp_file)
destination.delete(null)
except ex : GLib.Error
print("")

def print_file()
delete_tmp_file()
end, start : TextIter
text_view.buffer.get_bounds (out start, out end)
try
var file = File.new_for_path(tmp_file)
var thefile_stream = file.create (FileCreateFlags.NONE, null)
var data_stream = new DataOutputStream (thefile_stream)
data_stream.put_string (text_view.buffer.get_text(start, end, false), null)
try
Process.spawn_command_line_async("/usr/bin/lpr " + tmp_file)
except ex : GLib.Error
messagedialog = new MessageDialog (this, Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, ("Oop's, i'm unable to find 'lpr' for printing !!"))
messagedialog.run()
messagedialog.destroy()
except e : GLib.Error
messagedialog = new MessageDialog (this, Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, ("Unable to print !"))
messagedialog.run()
messagedialog.destroy()

def save_clicked ()
if thefile is ""
on_save_as_clicked ()
else
save_file()

def on_save_as_clicked ()
var file_chooser = new FileChooserDialog ("Save File", this, FileChooserAction.SAVE, STOCK_CANCEL, ResponseType.CANCEL, STOCK_SAVE, ResponseType.ACCEPT, null)
if (file_chooser.run () == ResponseType.ACCEPT)
save_new_file (file_chooser.get_filename ())
file_chooser.destroy ()

def save_new_file (filename : string)
end, start : TextIter
text_view.buffer.get_bounds (out start, out end)
try
var file = File.new_for_path(filename)
var thefile_stream = file.create (FileCreateFlags.NONE, null)
var data_stream = new DataOutputStream (thefile_stream)
data_stream.put_string (text_view.buffer.get_text(start, end, false), null)
thefile = filename
open_file(filename)
except e : GLib.Error
messagedialog = new MessageDialog (this, Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, ("Unable to save file !"))
messagedialog.run()
messagedialog.destroy()

def save_file()
filename : string = thefile
end, start : TextIter
text_view.buffer.get_bounds (out start, out end)
try
var file = File.new_for_path(thefile)
var renamed = file.set_display_name ("samplefile.bak", null)
var thefile_stream = file.create (FileCreateFlags.NONE, null)
var data_stream = new DataOutputStream (thefile_stream)
data_stream.put_string (text_view.buffer.get_text(start, end, false), null)
renamed.delete(null)
thefile = filename
open_file(filename)
except e : GLib.Error
messagedialog = new MessageDialog (this, Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, ("Unable to save file !"))
messagedialog.run()
messagedialog.destroy()

def on_open_clicked ()
if document_modified is true
messagedialog = new MessageDialog (this, Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL, Gtk.MessageType.QUESTION, Gtk.ButtonsType.YES_NO, ("The file is unregistered, do you want to save it ?"))
var response = messagedialog.run()
if response is ResponseType.YES
save_clicked ()
messagedialog.destroy()
else if response is ResponseType.NO
open_file_now()
messagedialog.destroy()
else
open_file_now()

def open_file_now ()
var file_chooser = new FileChooserDialog ("Open File", this, FileChooserAction.OPEN, STOCK_CANCEL, ResponseType.CANCEL, STOCK_OPEN, ResponseType.ACCEPT, null)
if (file_chooser.run () == ResponseType.ACCEPT)
open_file (file_chooser.get_filename ())
file_chooser.destroy ()

def open_file (filename : string)
try
text : string
length : ulong
FileUtils.get_contents (filename, out text, out length)
test1 : int = length.to_string().to_int()
text_view.buffer.set_text (text, test1)
go_to_line(1)
status_bar.push(0, "You are editing: " + filename)
document_modified = false
thefile = filename
status_bar2.push(0, "")
except e : GLib.Error
messagedialog = new MessageDialog (this, Gtk.DialogFlags.DESTROY_WITH_PARENT | Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, ("Unable to open file !"))
messagedialog.run()
messagedialog.destroy()

def about_clicked ()
var about = new AboutDialog ()
about.set_version("1.0")
about.set_program_name("NicEdit")
about.set_comments("Edit your text file with syntax highlighting")
about.set_copyright("Nicolas alias nikobordx, 2009, GPL licence") /*BK*/
about.run()
about.hide()


I have made some small mods. One thing I would like is for the default font to be monospace 13point -- there is a menu entry for font setting, but it is not remembered. If the basic settings could be saved, to say ~/.niceditrc and read at startup, that would be great. I am frustrated at not being "up to speed" with Genie/GTK coding, as Nicolas and Mark are -- I'm going to take time off Puppy development soon and focus on that!. It is probably quite simple to save a little .niceditrc settings file.

Note that I changed Nicolas's source to tab indents -- that's just my personal preference. He originally used indentation of 4 spaces. The thing to be careful about with tabs is that your text editor is not setup to convert them to spaces -- note also, Medit 0.9.4 has a bug, tabs must be set to 8 spaces only. I am using Medit these days due to the syntax highlighting support for Genie, and probably future Woof builds will have Medit instead of Geany.

There is also another bug in NicEdit, it seems to be stuck on Vala syntax highlighting. That is the default in the source code. Gtksourceview does have a mechanism for determining the file type and there seems to be line in the source for setting the language but it is staying stuck on "vala", failing that the 'file' utility can be used. I am confident that Nicolas will fix these bugs, which is why I'm replacing Leafpad with NicEdit.

Comments

Another NicEdit
Username: someone
Just to make you aware of another "nicedit": http://nicedit.com/

Syntax Highlighting bug
Username: Dougal
"I'd say this line might have something to do with it: buf.language = manager.get_language ("vala") It uses vala as default, so if no filetype is detected it probably stays on it.

Syntax Highlighting bug
Username: Nicolas
"Hi, I have changed the source for syntax highlighting. Now you can choose the language, and if you do not, NicEdit auto-detect it trought file extension ! Stay tuned, Nicolas.

nicedit
Username: ttuuxxx
"I think its a great looking little editor :) Also some other ideas might be add image handling, then it could be pdf creator, or a basic wysiwyg html editor, for quick mark-ups for things like how-to or help docs. But really it does look real nice:) great job Nic, who knows maybe in the future it might replace Gnumeric, wouldn't that be cool Pspreadsheet, lol ttuuxxx

Re: another NicEdit
Username: BarryK
"Oops, ok, maybe I'll rename it to "NicoEdit".


Tags: woof