def test_command(self): s = self.editor.segment ranges = [(100,120)] dest_indexes = ranges_to_indexes(ranges) source_indexes = ranges_to_indexes([(20, 60)]) common = min(len(dest_indexes), len(source_indexes)) j = self.editor.get_selected_index_metadata(source_indexes) style, where_comments, comments = self.editor.restore_selected_index_metadata(j) cmd = PasteCommand(s, ranges, -1, s[source_indexes], source_indexes, style, where_comments, comments) cmd.perform(self.editor) j2 = self.editor.get_selected_index_metadata(dest_indexes) style2, where_comments2, comments2 = json.loads(j2) assert np.all(style[0:common] - style2[0:common] == 0)
def do_change(self, editor, undo): indexes = ranges_to_indexes(self.ranges) undo.flags.index_range = indexes[0], indexes[-1] old_data = self.segment[indexes].copy() self.segment[indexes] = self.get_baseline_data(old_data, editor, indexes) return old_data
def test_metadata(self): s = self.editor.segment indexes = np.asarray([4,5,8,9,10,11,12,13,28,29,30,31,32,40,41,50,51,52]) j = self.editor.get_selected_index_metadata(indexes) style, where_comments, comments = self.editor.restore_selected_index_metadata(j) print style s1 = s.get_style_at_indexes(indexes) assert np.all((s1 - style) == 0) print "comments from source", where_comments, comments dest = 100 last = dest + len(style) dest_indexes = ranges_to_indexes([(dest, last)]) print "dest indexes", dest, last, dest_indexes assert len(dest_indexes) == len(style) s.style[dest_indexes] = style assert np.all(s.style[dest_indexes] - style == 0) print "dest comment indexes", dest_indexes[where_comments] s.set_comments_at_indexes(dest_indexes[where_comments], comments) j2 = self.editor.get_selected_index_metadata(dest_indexes) style2, where_comments2, comments2 = self.editor.restore_selected_index_metadata(j2) print "comments from dest", where_comments2, comments2 for w, w2 in zip(where_comments, where_comments2): assert w == w2 assert comments == comments2
def undo_change(self, editor, old_data): if old_data is not None: indexes = ranges_to_indexes(self.ranges) for addr, label in old_data.iteritems(): if label is None: self.segment.memory_map.pop(addr, "") else: self.segment.memory_map[addr] = label
def perform(self, editor): indexes = ranges_to_indexes(self.ranges) self.undo_info = undo = UndoInfo() undo.flags.byte_values_changed = True undo.flags.index_range = indexes[0], indexes[-1] old_data = self.segment[indexes].copy() self.segment[indexes] = self.get_baseline_data(old_data, editor, indexes) undo.data = (old_data, ) return undo
def do_change(self, editor, undo): print self.ranges indexes = ranges_to_indexes(self.ranges) origin = self.segment.start_addr old = {} for i in indexes: addr = i + origin old[addr] = self.segment.memory_map.get(addr, None) self.segment.memory_map.pop(addr, "") return old
def __init__(self, segment, ranges, text): ChangeMetadataCommand.__init__(self, segment) # Only use the first byte of each range self.ranges = self.convert_ranges(ranges) log.debug("%s operating on ranges: %s" % (self.pretty_name, str(ranges))) self.text = text indexes = ranges_to_indexes(self.ranges) self.index_range = indexes[0], indexes[-1] if len(ranges) == 1: self.pretty_name = "%s @ %04x" % (self.pretty_name, self.segment.start_addr + indexes[0])
def perform(self, editor): indexes = ranges_to_indexes(self.ranges) if np.alen(indexes) == 0: if self.indexes is not None: indexes = self.indexes.copy() - self.indexes[0] + self.cursor else: indexes = np.arange(self.cursor, self.cursor + np.alen(self.data)) max_index = len(self.segment) indexes = indexes[indexes < max_index] data = self.get_data(self.segment.data[indexes]) indexes = indexes[0:np.alen(data)] self.undo_info = undo = UndoInfo() undo.flags.byte_values_changed = True undo.flags.index_range = indexes[0], indexes[-1] undo.flags.select_range = True old_data = self.segment[indexes].copy() self.segment[indexes] = data undo.data = (old_data, indexes) return undo
def get_selected_ranges_and_indexes(self): opt = self.get_optimized_selected_ranges() return opt, ranges_to_indexes(opt)
def undo(self, editor): old_data, = self.undo_info.data indexes = ranges_to_indexes(self.ranges) self.segment[indexes] = old_data return self.undo_info
def get_selected_ranges_and_indexes(self, caret_handler): opt = self.get_selected_ranges(caret_handler) return opt, ranges_to_indexes(opt)