diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2008-12-12 14:02:27 +0100 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2008-12-12 14:02:27 +0100 |
commit | ddaedab835fa7ea3457f21a772d636921defdc46 (patch) | |
tree | 8f96b5a3a6700704e0a64bdcdedee1d2caf68517 /ide | |
parent | 2cd136cf7a0210e3cfde7a6f8ba32c9f09560047 (diff) | |
download | Nim-ddaedab835fa7ea3457f21a772d636921defdc46.tar.gz |
version 0.7.2
Diffstat (limited to 'ide')
-rw-r--r-- | ide/config.nim | 93 | ||||
-rw-r--r-- | ide/main.nim | 21 | ||||
-rw-r--r-- | ide/nimide.glade | 416 | ||||
-rw-r--r-- | ide/nimide.nim | 118 |
4 files changed, 413 insertions, 235 deletions
diff --git a/ide/config.nim b/ide/config.nim new file mode 100644 index 000000000..448a67bda --- /dev/null +++ b/ide/config.nim @@ -0,0 +1,93 @@ +# Does the config parsing for us + +import + parsecfg, strtabs, strutils + +type + TTokenClass* = enum + gtBackground, + gtNone, + gtWhitespace, + gtDecNumber, + gtBinNumber, + gtHexNumber, + gtOctNumber, + gtFloatNumber, + gtIdentifier, + gtKeyword, + gtStringLit, + gtLongStringLit, + gtCharLit, + gtEscapeSequence, + gtOperator, + gtPunctation, + gtComment, + gtLongComment, + gtRegularExpression, + gtTagStart, + gtTagEnd, + gtKey, + gtValue, + gtRawData, + gtAssembler, + gtPreprocessor, + gtDirective, + gtCommand, + gtRule, + gtHyperlink, + gtLabel, + gtReference, + gtOther, + gtCursor + + TColor* = colKeywords, colIdentifiers, colComments + TConfiguration* = object of TObject ## the configuration object + colors*: array [TTokenClass] of TColor ## the colors to use + filelist*: seq[string] ## the filelist + +const + colWhite = 0x00ffffff # rgb + colBlack = 0x00000000 + colYellow = + +proc readConfig(filename: string): TConfiguration = + # fill with reasonable defaults: + result.filelist = [] + result.colors[gtBackground] = colWhite + gtNone: + gtWhitespace, + gtDecNumber, + gtBinNumber, + gtHexNumber, + gtOctNumber, + gtFloatNumber, + gtIdentifier, + gtKeyword, + gtStringLit, + gtLongStringLit, + gtCharLit, + gtEscapeSequence, + gtOperator, + gtPunctation, + gtComment, + gtLongComment, + gtRegularExpression, + gtTagStart, + gtTagEnd, + gtKey, + gtValue, + gtRawData, + gtAssembler, + gtPreprocessor, + gtDirective, + gtCommand, + gtRule, + gtHyperlink, + gtLabel, + gtReference, + gtOther + gtCursor + var + p: TCfgParser + if open(p, filename): + diff --git a/ide/main.nim b/ide/main.nim index 22ab88d67..a7e9bb642 100644 --- a/ide/main.nim +++ b/ide/main.nim @@ -1,13 +1,13 @@ # The beginning of an IDE for Nimrod # (c) 2008 Andreas Rumpf -import glib2, gtk2, libglade2, dialogs, parseopt +import os, glib2, gtk2, libglade2, dialogs, parseopt proc on_window_destroy(obj: PGtkObject, data: pointer) {.cdecl.} = gtk_main_quit() const - GuiTemplate = "/media/hda4/nimrod/ide/nimide.glade" + GuiTemplate = "/media/hda1/Eigenes/nimrod/ide/nimide.glade" type TTab = object of TObject @@ -35,19 +35,19 @@ proc on_about_menu_item_activate(menuItem: PGtkMenuItem, proc load_file(e: var TMyTextEditor, filename: string) = var - err: ptr GError + err: pointer status: cstring text: cstring result: bool buffer: PGtkTextBuffer - gtk_statusbar_push(e.statusbar, e.statusbar_context_id, "Loading...") - while gtk_events_pending(): gtk_main_iteration() + discard gtk_statusbar_push(e.statusbar, e.statusbar_context_id, "Loading...") + while gtk_events_pending() != 0: discard gtk_main_iteration() # get the file contents result = g_file_get_contents(filename, addr(text), nil, addr(err)) if not result: - error_message("Cannot load file") - g_error_free(err) + error(e.window, "Cannot load file") + #g_error_free(err) # disable the text view while loading the buffer with the text gtk_widget_set_sensitive(e.text_view, false) @@ -103,7 +103,8 @@ proc check_for_save(e: var TMyTextEditor): bool = GtkWidget *dialog; const gchar *msg = "Do you want to save the changes you have made?"; dialog = gtk_message_dialog_new (nil, - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_DIALOG_MODAL or + GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, msg); @@ -146,15 +147,13 @@ proc main() = var editor: TMyTextEditor - gtk_nimrod_init() initApp(editor) gtk_widget_show(editor.window) gtk_main() +gtk_nimrod_init() main() - - proc on_window_delete_event(widget: PGtkWidget, event: PGdkEvent, e: TMyTextEditor): bool {.cdecl.} = if check_for_save(editor): diff --git a/ide/nimide.glade b/ide/nimide.glade index 0bd5f11f1..ce24683b2 100644 --- a/ide/nimide.glade +++ b/ide/nimide.glade @@ -1,224 +1,192 @@ -<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*--> -<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd"> - -<glade-interface> - -<widget class="GtkWindow" id="window"> - <property name="extension_events">GDK_EXTENSION_EVENTS_ALL</property> - <property name="title" translatable="yes"></property> - <property name="type">GTK_WINDOW_TOPLEVEL</property> - <property name="window_position">GTK_WIN_POS_NONE</property> - <property name="modal">False</property> - <property name="resizable">True</property> - <property name="destroy_with_parent">False</property> - <property name="decorated">True</property> - <property name="skip_taskbar_hint">False</property> - <property name="skip_pager_hint">False</property> - <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property> - <property name="gravity">GDK_GRAVITY_NORTH_WEST</property> - <property name="focus_on_map">True</property> - <property name="urgency_hint">False</property> - <signal name="destroy" handler="on_window_destroy" object="destroy"/> - - <child> - <widget class="GtkVBox" id="mainvbox"> - <property name="width_request">600</property> - <property name="height_request">400</property> - <property name="visible">True</property> - <property name="homogeneous">False</property> - <property name="spacing">0</property> - - <child> - <widget class="GtkMenuBar" id="menubar"> - <property name="visible">True</property> - <property name="pack_direction">GTK_PACK_DIRECTION_LTR</property> - <property name="child_pack_direction">GTK_PACK_DIRECTION_LTR</property> - - <child> - <widget class="GtkMenuItem" id="menuitem1"> - <property name="visible">True</property> - <property name="label" translatable="yes">_Datei</property> - <property name="use_underline">True</property> - - <child> - <widget class="GtkMenu" id="menu1"> - <property name="visible">True</property> - - <child> - <widget class="GtkImageMenuItem" id="new_menu_item"> - <property name="visible">True</property> - <property name="label">gtk-new</property> - <property name="use_stock">True</property> - </widget> - </child> - - <child> - <widget class="GtkImageMenuItem" id="open_menu_item"> - <property name="visible">True</property> - <property name="label">gtk-open</property> - <property name="use_stock">True</property> - </widget> - </child> - - <child> - <widget class="GtkImageMenuItem" id="save_menu_item"> - <property name="visible">True</property> - <property name="label">gtk-save</property> - <property name="use_stock">True</property> - </widget> - </child> - - <child> - <widget class="GtkImageMenuItem" id="save_as_menu_item"> - <property name="visible">True</property> - <property name="label">gtk-save-as</property> - <property name="use_stock">True</property> - </widget> - </child> - - <child> - <widget class="GtkSeparatorMenuItem" id="separatormenuitem1"> - <property name="visible">True</property> - </widget> - </child> - - <child> - <widget class="GtkImageMenuItem" id="quit_menu_item"> - <property name="visible">True</property> - <property name="label">gtk-quit</property> - <property name="use_stock">True</property> - </widget> - </child> - </widget> - </child> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="menuitem2"> - <property name="visible">True</property> - <property name="label" translatable="yes">_Bearbeiten</property> - <property name="use_underline">True</property> - - <child> - <widget class="GtkMenu" id="menu2"> - <property name="visible">True</property> - - <child> - <widget class="GtkImageMenuItem" id="cut_menu_item"> - <property name="visible">True</property> - <property name="label">gtk-cut</property> - <property name="use_stock">True</property> - </widget> - </child> - - <child> - <widget class="GtkImageMenuItem" id="copy_menu_item"> - <property name="visible">True</property> - <property name="label">gtk-copy</property> - <property name="use_stock">True</property> - </widget> - </child> - - <child> - <widget class="GtkImageMenuItem" id="paste_menu_item"> - <property name="visible">True</property> - <property name="label">gtk-paste</property> - <property name="use_stock">True</property> - </widget> - </child> - - <child> - <widget class="GtkImageMenuItem" id="delete_menu_item"> - <property name="visible">True</property> - <property name="label">gtk-delete</property> - <property name="use_stock">True</property> - </widget> - </child> - </widget> - </child> - </widget> - </child> - - <child> - <widget class="GtkMenuItem" id="menuitem4"> - <property name="visible">True</property> - <property name="label" translatable="yes">_Hilfe</property> - <property name="use_underline">True</property> - - <child> - <widget class="GtkMenu" id="menu3"> - <property name="visible">True</property> - - <child> - <widget class="GtkImageMenuItem" id="about_menu_item"> - <property name="visible">True</property> - <property name="label">gtk-about</property> - <property name="use_stock">True</property> - </widget> - </child> - </widget> - </child> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkScrolledWindow" id="scrolledwindow"> - <property name="border_width">1</property> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property> - <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> - <property name="shadow_type">GTK_SHADOW_ETCHED_IN</property> - <property name="window_placement">GTK_CORNER_TOP_LEFT</property> - - <child> - <widget class="GtkTextView" id="textview"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="editable">True</property> - <property name="overwrite">False</property> - <property name="accepts_tab">True</property> - <property name="justification">GTK_JUSTIFY_LEFT</property> - <property name="wrap_mode">GTK_WRAP_NONE</property> - <property name="cursor_visible">True</property> - <property name="pixels_above_lines">0</property> - <property name="pixels_below_lines">0</property> - <property name="pixels_inside_wrap">0</property> - <property name="left_margin">2</property> - <property name="right_margin">2</property> - <property name="indent">0</property> - <property name="text" translatable="yes"></property> - </widget> - </child> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">True</property> - <property name="fill">True</property> - </packing> - </child> - - <child> - <widget class="GtkStatusbar" id="statusbar"> - <property name="visible">True</property> - <property name="has_resize_grip">True</property> - </widget> - <packing> - <property name="padding">0</property> - <property name="expand">False</property> - <property name="fill">True</property> - </packing> - </child> - </widget> - </child> -</widget> - -</glade-interface> +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd"> +<!--*- mode: xml -*--> +<glade-interface> + <widget class="GtkWindow" id="window"> + <property name="extension_events">GDK_EXTENSION_EVENTS_ALL</property> + <signal name="destroy" handler="on_window_destroy" object="destroy"/> + <child> + <widget class="GtkVBox" id="mainvbox"> + <property name="width_request">600</property> + <property name="height_request">400</property> + <property name="visible">True</property> + <child> + <widget class="GtkMenuBar" id="menubar"> + <property name="visible">True</property> + <child> + <widget class="GtkMenuItem" id="menuitem1"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Datei</property> + <property name="use_underline">True</property> + <child> + <widget class="GtkMenu" id="menu1"> + <property name="visible">True</property> + <child> + <widget class="GtkImageMenuItem" id="new_menu_item"> + <property name="visible">True</property> + <property name="label">gtk-new</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + <child> + <widget class="GtkImageMenuItem" id="open_menu_item"> + <property name="visible">True</property> + <property name="label">gtk-open</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + <child> + <widget class="GtkImageMenuItem" id="save_menu_item"> + <property name="visible">True</property> + <property name="label">gtk-save</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + <child> + <widget class="GtkImageMenuItem" id="save_as_menu_item"> + <property name="visible">True</property> + <property name="label">gtk-save-as</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + <child> + <widget class="GtkSeparatorMenuItem" id="separatormenuitem1"> + <property name="visible">True</property> + </widget> + </child> + <child> + <widget class="GtkImageMenuItem" id="quit_menu_item"> + <property name="visible">True</property> + <property name="label">gtk-quit</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + </widget> + </child> + </widget> + </child> + <child> + <widget class="GtkMenuItem" id="menuitem2"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Bearbeiten</property> + <property name="use_underline">True</property> + <child> + <widget class="GtkMenu" id="menu2"> + <property name="visible">True</property> + <child> + <widget class="GtkImageMenuItem" id="cut_menu_item"> + <property name="visible">True</property> + <property name="label">gtk-cut</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + <child> + <widget class="GtkImageMenuItem" id="copy_menu_item"> + <property name="visible">True</property> + <property name="label">gtk-copy</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + <child> + <widget class="GtkImageMenuItem" id="paste_menu_item"> + <property name="visible">True</property> + <property name="label">gtk-paste</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + <child> + <widget class="GtkImageMenuItem" id="delete_menu_item"> + <property name="visible">True</property> + <property name="label">gtk-delete</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + </widget> + </child> + </widget> + </child> + <child> + <widget class="GtkMenuItem" id="menuitem4"> + <property name="visible">True</property> + <property name="label" translatable="yes">_Hilfe</property> + <property name="use_underline">True</property> + <child> + <widget class="GtkMenu" id="menu3"> + <property name="visible">True</property> + <child> + <widget class="GtkImageMenuItem" id="about_menu_item"> + <property name="visible">True</property> + <property name="label">gtk-about</property> + <property name="use_underline">True</property> + <property name="use_stock">True</property> + </widget> + </child> + </widget> + </child> + </widget> + </child> + </widget> + <packing> + <property name="expand">False</property> + </packing> + </child> + <child> + <widget class="GtkNotebook" id="notebook"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="tab_hborder">10</property> + <property name="tab_vborder">0</property> + <child> + <placeholder/> + </child> + <child> + <placeholder/> + <packing> + <property name="type">tab</property> + </packing> + </child> + <child> + <placeholder/> + </child> + <child> + <placeholder/> + <packing> + <property name="type">tab</property> + </packing> + </child> + <child> + <placeholder/> + </child> + <child> + <placeholder/> + <packing> + <property name="type">tab</property> + </packing> + </child> + </widget> + <packing> + <property name="position">1</property> + </packing> + </child> + <child> + <widget class="GtkStatusbar" id="statusbar"> + <property name="visible">True</property> + </widget> + <packing> + <property name="expand">False</property> + <property name="position">2</property> + </packing> + </child> + </widget> + </child> + </widget> +</glade-interface> diff --git a/ide/nimide.nim b/ide/nimide.nim new file mode 100644 index 000000000..c5abc3bbf --- /dev/null +++ b/ide/nimide.nim @@ -0,0 +1,118 @@ +# The beginning of an IDE for Nimrod +# (c) 2008 Andreas Rumpf + +import os, glib2, gdk2, gtk2, libglade2, pango, dialogs, parseopt + +const + GuiTemplate = "nimide.glade" + dummyConst = "" + +type + TTab {.pure, final.} = object + textview: PGtkTextView + filename: string + untitled: bool + hbox: PGtkHBox + e: PEditor + PTab = ptr TTab + + TEditor = object of TObject + window: PGtkWindow + statusbar: PGtkStatusBar + menu: PGtkMenuBar + notebook: PGtkNotebook + tabname: int # used for generating tab names + PEditor = ptr TEditor + +proc on_window_destroy(obj: PGtkObject, event: PGdkEvent, + data: pointer): gboolean {.cdecl.} = + gtk_main_quit() + +proc on_about_menu_item_activate(menuItem: PGtkMenuItem, e: PEditor) {.cdecl.} = + gtk_show_about_dialog(e.window, + "comments", "A fast and leight-weight IDE for Nimrod", + "copyright", "Copyright \xc2\xa9 2008 Andreas Rumpf", + "version", "0.1", + "website", "http://nimrod.ethexor.com", + "program-name", "Nimrod IDE", + nil) + +proc getTabIndex(e: PEditor, tab: PTab): int = + var i = 0 + while true: + var w = gtk_notebook_get_nth_page(e.notebook, i) + if w == nil: return -1 + var v = gtk_notebook_get_tab_label(e.notebook, w) + if tab.hbox == v: return i + inc(i) + +proc OnCloseTab(button: PGtkButton, tab: PTab) {.cdecl.} = + var idx = getTabIndex(tab.e, tab) + if idx >= 0: gtk_notebook_remove_page(tab.e.notebook, idx) + +proc createTab(e: PEditor, filename: string, untitled: bool) = + var t = cast[PTab](alloc0(sizeof(TTab))) + t.textview = gtk_text_view_new_with_buffer(gtk_text_buffer_new(nil)) + var font_desc = pango_font_description_from_string("monospace 10") + gtk_widget_modify_font(t.textview, font_desc) + pango_font_description_free(font_desc) + t.filename = filename + t.untitled = untitled + gtk_widget_show(t.textview) + var scroll = gtk_scrolled_window_new(nil, nil) + gtk_container_add(scroll, t.textview) + gtk_widget_show(scroll) + + t.e = e + t.hbox = gtk_hbox_new(false, 0) + var image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU) + var button = gtk_button_new() + var lab = gtk_label_new(filename) + gtk_button_set_image(button, image) + gtk_button_set_relief(button, GTK_RELIEF_NONE) + gtk_box_pack_start(t.hbox, lab, false, false, 2) + gtk_box_pack_end(t.hbox, button, false, false, 0) + + discard g_signal_connect(button, "clicked", G_Callback(onCloseTab), t) + gtk_widget_show(button) + gtk_widget_show(lab) + + var idx = gtk_notebook_append_page(e.notebook, scroll, t.hbox) + gtk_notebook_set_current_page(e.notebook, idx) + +proc on_new_menu_item_activate(menuItem: PGtkMenuItem, e: PEditor) {.cdecl.} = + inc(e.tabname) + createTab(e, "untitled-" & $e.tabname, true) + +proc main(e: PEditor) = + var builder = glade_xml_new(getApplicationDir() / GuiTemplate, nil, nil) + if builder == nil: quit("cannot open: " & GuiTemplate) + # get the components: + e.window = GTK_WINDOW(glade_xml_get_widget(builder, "window")) + e.statusbar = GTK_STATUSBAR(glade_xml_get_widget(builder, "statusbar")) + e.notebook = GTK_NOTEBOOK(glade_xml_get_widget(builder, "notebook")) + setHomogeneous(e.notebook^, 1) + + # connect the signal handlers: + glade_xml_signal_connect(builder, "on_window_destroy", + GCallback(on_window_destroy)) + var about = GTK_MENU_ITEM(glade_xml_get_widget(builder, "about_menu_item")) + discard g_signal_connect(about, "activate", + G_CALLBACK(on_about_menu_item_activate), e) + + var newItem = GTK_MENU_ITEM(glade_xml_get_widget(builder, "new_menu_item")) + discard g_signal_connect(newItem, "activate", + G_CALLBACK(on_new_menu_item_activate), e) + + var quitItem = GTK_MENU_ITEM(glade_xml_get_widget(builder, "quit_menu_item")) + discard g_signal_connect(quitItem, "activate", + G_CALLBACK(on_window_destroy), e) + + gtk_window_set_default_icon_name(GTK_STOCK_EDIT) + gtk_widget_show(e.window) + gtk_main() + + +gtk_nimrod_init() +var e = cast[PEditor](alloc0(sizeof(TEditor))) +main(e) |