예제 #1
0
파일: vcview.py 프로젝트: zbyna/meld
    def on_button_delete_clicked(self, obj):
        files = self._get_selected_files()
        for name in files:
            try:
                gfile = Gio.File.new_for_path(name)
                gfile.trash(None)
            except GLib.GError as e:
                misc.error_dialog(_("Error removing %s") % name, str(e))

        workdir = os.path.dirname(os.path.commonprefix(files))
        self.refresh_partial(workdir)
예제 #2
0
파일: vcview.py 프로젝트: thics/meld
    def on_button_delete_clicked(self, obj):
        files = self._get_selected_files()
        for name in files:
            try:
                gfile = Gio.File.new_for_path(name)
                gfile.trash(None)
            except GLib.GError as e:
                misc.error_dialog(_("Error removing %s") % name, str(e))

        workdir = os.path.dirname(os.path.commonprefix(files))
        self.refresh_partial(workdir)
예제 #3
0
 def file_saved_cb(self, saver, result, *args):
     gfile = saver.get_location()
     try:
         saver.save_finish(result)
     except GLib.Error as err:
         filename = GLib.markup_escape_text(gfile.get_parse_name())
         error_dialog(
             primary=_("Could not save file %s.") % filename,
             secondary=_("Couldn’t save file due to:\n%s") %
             (GLib.markup_escape_text(str(err))),
         )
예제 #4
0
파일: patchdialog.py 프로젝트: GNOME/meld
 def file_saved_cb(self, saver, result, *args):
     gfile = saver.get_location()
     try:
         saver.save_finish(result)
     except GLib.Error as err:
         filename = GLib.markup_escape_text(gfile.get_parse_name())
         error_dialog(
             primary=_("Could not save file %s.") % filename,
             secondary=_("Couldn’t save file due to:\n%s") % (
                 GLib.markup_escape_text(str(err))),
         )
예제 #5
0
파일: findbar.py 프로젝트: mrpdaemon/meld
 def _find_text(self, start_offset=1, backwards=False, wrap=True):
     match_case = self.match_case.get_active()
     whole_word = self.whole_word.get_active()
     regex = self.regex.get_active()
     assert self.textview
     buf = self.textview.get_buffer()
     insert = buf.get_iter_at_mark(buf.get_insert())
     tofind_utf8 = self.find_entry.get_text()
     tofind = tofind_utf8.decode("utf-8")
     start, end = buf.get_bounds()
     text = buf.get_text(start, end, False).decode("utf-8")
     if not regex:
         tofind = re.escape(tofind)
     if whole_word:
         tofind = r'\b' + tofind + r'\b'
     try:
         flags = re.M if match_case else re.M | re.I
         pattern = re.compile(tofind, flags)
     except re.error as e:
         misc.error_dialog(_("Regular expression error"), str(e))
     else:
         self.wrap_box.set_visible(False)
         if not backwards:
             match = pattern.search(text,
                                    insert.get_offset() + start_offset)
             if match is None and wrap:
                 self.wrap_box.set_visible(True)
                 match = pattern.search(text, 0)
         else:
             match = None
             for m in pattern.finditer(text, 0, insert.get_offset()):
                 match = m
             if match is None and wrap:
                 self.wrap_box.set_visible(True)
                 for m in pattern.finditer(text, insert.get_offset()):
                     match = m
         if match:
             it = buf.get_iter_at_offset(match.start())
             buf.place_cursor(it)
             it.forward_chars(match.end() - match.start())
             buf.move_mark(buf.get_selection_bound(), it)
             self.textview.scroll_to_mark(buf.get_insert(), 0.25, True, 0.5,
                                          0.5)
             return True
         else:
             buf.place_cursor(buf.get_iter_at_mark(buf.get_insert()))
             # FIXME: Even though docs suggest this should work, it does
             # not. It just sets the selection colour on the text, without
             # affecting the entry colour at all.
             color = Gdk.RGBA()
             color.parse("#ffdddd")
             self.find_entry.override_background_color(
                 Gtk.StateType.NORMAL, color)
             self.wrap_box.set_visible(False)
예제 #6
0
 def _find_text(self, start_offset=1, backwards=False, wrap=True):
     match_case = self.match_case.get_active()
     whole_word = self.whole_word.get_active()
     regex = self.regex.get_active()
     assert self.textview
     buf = self.textview.get_buffer()
     insert = buf.get_iter_at_mark(buf.get_insert())
     tofind_utf8 = self.find_entry.get_text()
     tofind = tofind_utf8.decode("utf-8")
     start, end = buf.get_bounds()
     text = buf.get_text(start, end, False).decode("utf-8")
     if not regex:
         tofind = re.escape(tofind)
     if whole_word:
         tofind = r'\b' + tofind + r'\b'
     try:
         flags = re.M if match_case else re.M | re.I
         pattern = re.compile(tofind, flags)
     except re.error as e:
         misc.error_dialog(_("Regular expression error"), str(e))
     else:
         self.wrap_box.set_visible(False)
         if not backwards:
             match = pattern.search(text,
                                    insert.get_offset() + start_offset)
             if match is None and wrap:
                 self.wrap_box.set_visible(True)
                 match = pattern.search(text, 0)
         else:
             match = None
             for m in pattern.finditer(text, 0, insert.get_offset()):
                 match = m
             if match is None and wrap:
                 self.wrap_box.set_visible(True)
                 for m in pattern.finditer(text, insert.get_offset()):
                     match = m
         if match:
             it = buf.get_iter_at_offset(match.start())
             buf.place_cursor(it)
             it.forward_chars(match.end() - match.start())
             buf.move_mark(buf.get_selection_bound(), it)
             self.textview.scroll_to_mark(
                 buf.get_insert(), 0.25, True, 0.5, 0.5)
             return True
         else:
             buf.place_cursor(buf.get_iter_at_mark(buf.get_insert()))
             # FIXME: Even though docs suggest this should work, it does
             # not. It just sets the selection colour on the text, without
             # affecting the entry colour at all.
             color = Gdk.RGBA()
             color.parse("#ffdddd")
             self.find_entry.override_background_color(
                 Gtk.StateType.NORMAL, color)
             self.wrap_box.set_visible(False)
예제 #7
0
    def on_button_delete_clicked(self, obj):
        files = self._get_selected_files()
        for name in files:
            gfile = Gio.File.new_for_path(name)

            try:
                trash_or_confirm(gfile)
            except Exception as e:
                error_dialog(
                    _("Error deleting {}").format(
                        GLib.markup_escape_text(gfile.get_parse_name()), ),
                    str(e),
                )

        workdir = os.path.dirname(os.path.commonprefix(files))
        self.refresh_partial(workdir)
예제 #8
0
파일: vcview.py 프로젝트: GNOME/meld
    def action_delete(self, *args):
        files = self._get_selected_files()
        for name in files:
            gfile = Gio.File.new_for_path(name)

            try:
                trash_or_confirm(gfile)
            except Exception as e:
                error_dialog(
                    _("Error deleting {}").format(
                        GLib.markup_escape_text(gfile.get_parse_name()),
                    ),
                    str(e),
                )

        workdir = os.path.dirname(os.path.commonprefix(files))
        self.refresh_partial(workdir)
예제 #9
0
파일: vcview.py 프로젝트: thics/meld
    def _command_iter(self, command, files, refresh, working_dir):
        """An iterable that runs a VC command on a set of files

        This method is intended to be used as a scheduled task, with
        standard out and error output displayed in this view's
        consolestream.
        """

        def shelljoin(command):
            def quote(s):
                return '"%s"' % s if len(s.split()) > 1 else s
            return " ".join(quote(tok) for tok in command)

        files = [os.path.relpath(f, working_dir) for f in files]
        msg = shelljoin(command + files) + " (in %s)\n" % working_dir
        self.consolestream.command(msg)
        readiter = misc.read_pipe_iter(
            command + files, workdir=working_dir,
            errorstream=self.consolestream)
        try:
            result = next(readiter)
            while not result:
                yield 1
                result = next(readiter)
        except IOError as err:
            misc.error_dialog(
                "Error running command",
                "While running '%s'\nError: %s" % (msg, err))
            result = (1, "")

        returncode, output = result
        self.consolestream.output(output + "\n")

        if returncode:
            self.console_vbox.show()

        if refresh:
            refresh = functools.partial(self.refresh_partial, working_dir)
            GLib.idle_add(refresh)
예제 #10
0
파일: vcview.py 프로젝트: skluchan/meld
    def _command_iter(self, command, files, refresh, working_dir):
        """An iterable that runs a VC command on a set of files

        This method is intended to be used as a scheduled task, with
        standard out and error output displayed in this view's
        consolestream.
        """

        def shelljoin(command):
            def quote(s):
                return '"%s"' % s if len(s.split()) > 1 else s
            return " ".join(quote(tok) for tok in command)

        files = [os.path.relpath(f, working_dir) for f in files]
        msg = shelljoin(command + files) + " (in %s)\n" % working_dir
        self.consolestream.command(msg)
        readiter = read_pipe_iter(
            command + files, workdir=working_dir,
            errorstream=self.consolestream)
        try:
            result = next(readiter)
            while not result:
                yield 1
                result = next(readiter)
        except IOError as err:
            error_dialog(
                "Error running command",
                "While running '%s'\nError: %s" % (msg, err))
            result = (1, "")

        returncode, output = result
        self.consolestream.output(output + "\n")

        if returncode:
            self.console_vbox.show()

        if refresh:
            refresh = functools.partial(self.refresh_partial, working_dir)
            GLib.idle_add(refresh)