Commit 2d093440 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Search and replace with g is not applied to the whole model

%s,from,to,g -> g is global across all scenes
parent 9c2e5a6e
...@@ -83,6 +83,10 @@ class Connection(QGraphicsPathItem, object): ...@@ -83,6 +83,10 @@ class Connection(QGraphicsPathItem, object):
return (QPointF(endp.x() - 5, endp.y() - 5), return (QPointF(endp.x() - 5, endp.y() - 5),
QPointF(endp.x() + 5, endp.y() - 5)) QPointF(endp.x() + 5, endp.y() - 5))
def select(self):
''' Select a connection - for future use? '''
return
def angle_arrow(self, path, origin='head'): def angle_arrow(self, path, origin='head'):
''' Compute the two points of the arrow head with the right angle ''' ''' Compute the two points of the arrow head with the right angle '''
if origin == 'tail': if origin == 'tail':
......
...@@ -829,7 +829,7 @@ class SDL_Scene(QtGui.QGraphicsScene, object): ...@@ -829,7 +829,7 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
# invalid pattern # invalid pattern
raise StopIteration raise StopIteration
if res: if res:
yield item.parentItem() yield item
def search(self, pattern, replace_with=None): def search(self, pattern, replace_with=None):
...@@ -847,16 +847,18 @@ class SDL_Scene(QtGui.QGraphicsScene, object): ...@@ -847,16 +847,18 @@ class SDL_Scene(QtGui.QGraphicsScene, object):
for item in self.search_item: for item in self.search_item:
new_string = re.sub(pattern, new_string = re.sub(pattern,
replace_with, replace_with,
unicode(item.text), unicode(item),
flags=re.IGNORECASE) flags=re.IGNORECASE)
undo_cmd = undoCommands.ReplaceText( undo_cmd = undoCommands.ReplaceText(
item.text, unicode(item.text), new_string) item, unicode(item), new_string)
self.undo_stack.push(undo_cmd) self.undo_stack.push(undo_cmd)
item.select() item.try_resize()
item.parentItem().select()
self.refresh() self.refresh()
else: else:
try: try:
item = self.search_item.next() item = self.search_item.next()
item = item.parentItem()
item.select() item.select()
self.highlight(item) self.highlight(item)
item.ensureVisible() item.ensureVisible()
...@@ -2170,13 +2172,21 @@ class OG_MainWindow(QtGui.QMainWindow, object): ...@@ -2170,13 +2172,21 @@ class OG_MainWindow(QtGui.QMainWindow, object):
''' '''
command = self.vi_bar.text() command = self.vi_bar.text()
# Match vi-like search and replace pattern (e.g. :%s,a,b,g) # Match vi-like search and replace pattern (e.g. :%s,a,b,g)
search = re.compile(r':%s(.)(.*)\1(.*)\1(.)') search = re.compile(r':%s(.)(.*)\1(.*)\1(.)?')
try: try:
_, pattern, new, _ = search.match(command).groups() _, pattern, new, loc = search.match(command).groups()
LOG.debug('Replacing {this} with {that}' LOG.debug('Replacing {this} with {that}'
.format(this=pattern, that=new)) .format(this=pattern, that=new))
if loc != 'g':
# apply only to the current scene
self.view.scene().search(pattern, replace_with=new) self.view.scene().search(pattern, replace_with=new)
except AttributeError: else:
# apply globally to the whole model
scene = self.view.top_scene()
for each in chain([scene], scene.all_nested_scenes):
each.search(pattern, replace_with=new)
except AttributeError as err:
print 'attribute error', str(err)
if command.startswith('/') and len(command) > 1: if command.startswith('/') and len(command) > 1:
LOG.debug('Searching for ' + command[1:]) LOG.debug('Searching for ' + command[1:])
self.view.scene().search(command[1:]) self.view.scene().search(command[1:])
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment