Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Many improvements for the suggest feature.

  • Loading branch information...
commit ebad44f0991205466161e5839c3cdcea98c23071 1 parent 3e8853b
@dom96 dom96 authored
View
9 aporia.ini
@@ -2,8 +2,8 @@
Name: "Aporia"
Version: "$version"
; Windows and i386 must be first!
-OS: "windows;linux"
-CPU: "i386"
+OS: "windows;linux;macosx"
+CPU: "i386;amd64"
Authors: "Dominik Picheta"
Description: """Aporia is an IDE for the Nimrod programming language. Aporia
uses GTK as the default toolkit, and the gtksourceview for the text editor
@@ -12,6 +12,9 @@ component."""
App: GUI
License: "copying.txt"
+[lib]
+Files: "$nimrod/lib/nimbase.h"
+
[Other]
Files: "gpl.html"
@@ -19,7 +22,7 @@ Files: "gpl.html"
Files: "aporia.exe"
Files: "gtk"
Files: "share"
-BinPath: r"gtk\bin"
+#BinPath: r"gtk\bin"
InnoSetup: "Yes"
[UnixBin]
View
16 aporia.nim
@@ -267,6 +267,11 @@ proc SourceViewKeyPress(sourceView: PWidget, event: PEventKey,
var selectedPath = TreeModel.getPath(addr(selectedIter))
var index = selectedPath.getIndices()[]
var name = win.suggest.items[index].nmName
+ # Remove the part that was already typed
+ if win.suggest.currentFilter != "":
+ assert(normalize(name).startsWith(win.suggest.currentFilter))
+ name = name[win.suggest.currentFilter.len() .. -1]
+
# We have the name of the item. Now insert it into the TextBuffer.
var currentTab = win.SourceViewTabs.getCurrentPage()
win.Tabs[currentTab].buffer.insertAtCursor(name, len(name))
@@ -311,13 +316,14 @@ proc SourceViewKeyRelease(sourceView: PWidget, event: PEventKey,
# Don't need to know the char behind, because if it is a dot, then
# the suggest dialog is hidden by ...KeyPress
- # Repopulate suggest
- doSuggest(win)
+ win.filterSuggest()
else:
- echod("Key released: ", key)
- if win.settings.suggestFeature and win.suggest.shown:
- doSuggest(win)
+ if key.toLower() != "down" and key.toLower() != "up":
+ echod("Key released: ", key)
+
+ if win.settings.suggestFeature and win.suggest.shown:
+ win.filterSuggest()
# Other(Helper) functions
View
0  aporia.cfg → nimrod.cfg
File renamed without changes
View
61 suggest.nim
@@ -23,14 +23,17 @@ when not defined(os.findExe):
if ExistsFile(x): return x
result = ""
-proc addSuggestItem*(win: MainWin, name: string, markup: String,
+proc addSuggestItem*(win: var MainWin, name: string, markup: String,
color: String = "#000000") =
var iter: TTreeIter
var listStore = cast[PListStore](win.suggest.TreeView.getModel())
listStore.append(addr(iter))
listStore.set(addr(iter), 0, name, 1, markup, 2, color, -1)
-proc moveSuggest*(win: MainWin, start: PTextIter, tab: Tab) =
+proc addSuggestItem(win: var MainWin, item: TSuggestItem) =
+ win.addSuggestItem(item.nmName, "<b>$1</b>" % [item.nmName])
+
+proc moveSuggest*(win: var MainWin, start: PTextIter, tab: Tab) =
# Calculate the location of the suggest dialog.
var iterLoc: TRectangle
@@ -82,8 +85,9 @@ proc execNimSuggest(file, addToPath: string, line: int, column: int):
if dots.len() == 2:
item.nmName = item.name[dots[0].len()+1.. -1]
else:
- echo("[Suggest] Skipping ", item.name)
- continue
+ echo("[Suggest] Unknown module name for ", item.name)
+ #continue
+ item.nmName = item.name
result.add(item)
@@ -95,7 +99,9 @@ proc populateSuggest*(win: var MainWin, start: PTextIter, tab: Tab): bool =
for t in items(win.Tabs):
if t.filename != "":
var f: TFile
- if f.open(getTempDir() / splitFile(t.filename).name & ".nim", fmWrite):
+ var fileSplit = splitFile(t.filename)
+ echo("Saving ", getTempDir() / fileSplit.name & fileSplit.ext)
+ if f.open(getTempDir() / fileSplit.name & fileSplit.ext, fmWrite):
# Save everything.
# - Get the text from the TextView.
var startIter: TTextIter
@@ -105,7 +111,7 @@ proc populateSuggest*(win: var MainWin, start: PTextIter, tab: Tab): bool =
t.buffer.getEndIter(addr(endIter))
var text = t.buffer.getText(addr(startIter), addr(endIter), False)
-
+
# - Save it.
f.write(text)
else:
@@ -113,10 +119,18 @@ proc populateSuggest*(win: var MainWin, start: PTextIter, tab: Tab): bool =
return False
f.close()
- var file = getTempDir() / splitFile(tab.filename).name & ".nim"
+ var currentTabSplit = splitFile(tab.filename)
+
+ # Copy over nimrod.cfg if it exists to /tmp
+ if existsFile(currentTabSplit.dir / "nimrod".addFileExt("cfg")):
+ copyFile(currentTabSplit.dir / "nimrod".addFileExt("cfg"),
+ getTempDir() / "nimrod".addFileExt("cfg"))
+
+ var file = getTempDir() / currentTabSplit.name & ".nim"
win.suggest.items = execNimSuggest(file, splitFile(tab.filename).dir,
start.getLine(),
start.getLineOffset())
+ win.suggest.allitems = win.suggest.items
if win.suggest.items.len == 0:
echo("[Warning] No items found for suggest")
@@ -126,7 +140,9 @@ proc populateSuggest*(win: var MainWin, start: PTextIter, tab: Tab): bool =
#removeFile(file)
for i in items(win.suggest.items):
- win.addSuggestItem(i.nmName, "<b>$1</b>" % [i.nmName])
+ win.addSuggestItem(i)
+
+ win.suggest.currentFilter = ""
return True
@@ -135,6 +151,35 @@ proc clear*(suggest: var TSuggestDialog) =
# TODO: Why do I have to cast it? Why can't I just do PListStore(TreeModel)?
cast[PListStore](TreeModel).clear()
suggest.items = @[]
+ suggest.allItems = @[]
+
+proc filterSuggest*(win: var MainWin) =
+ ## Filters the current suggest items after whatever is behind the cursor.
+ # Get text before the cursor, up to a dot.
+ var current = win.SourceViewTabs.getCurrentPage()
+ var tab = win.Tabs[current]
+ var cursor: TTextIter
+ # Get the iter at the cursor position.
+ tab.buffer.getIterAtMark(addr(cursor), tab.buffer.getInsert())
+ # Search backwards for a dot.
+ var startMatch: TTextIter
+ var endMatch: TTextIter
+ var matched = (addr(cursor)).backwardSearch(".", TEXT_SEARCH_TEXT_ONLY,
+ addr(startMatch), addr(endMatch), nil)
+ assert(matched)
+ var text = (addr(endMatch)).getText(addr(cursor))
+ echo("[Suggest] Filtering ", text)
+ win.suggest.currentFilter = normalize($text)
+ # Filter the items.
+ var allItems = win.suggest.allItems
+ win.suggest.clear()
+ var newItems: seq[TSuggestItem] = @[]
+ for i in items(allItems):
+ if normalize(i.nmName).startsWith(normalize($text)):
+ newItems.add(i)
+ win.addSuggestItem(i)
+ win.suggest.items = newItems
+ win.suggest.allItems = allItems
proc show*(suggest: var TSuggestDialog) =
if not suggest.shown:
View
4 types.nim
@@ -67,8 +67,10 @@ type
TSuggestDialog* = object
dialog*: gtk2.PWindow
treeView*: PTreeView
- items*: seq[TSuggestItem]
+ items*: seq[TSuggestItem] ## Visible items (In the treeview)
+ allItems*: seq[TSuggestItem] ## All items found in current context.
shown*: bool
+ currentFilter*: string
TExecMode* = enum
ExecNone, ExecNimrod, ExecRun, ExecCustom
Please sign in to comment.
Something went wrong with that request. Please try again.