Beispiel #1
0
def on_search_changed(sender, view, widget):
    search = widget.entry.get_text()
    idle(delete_all_marks, view)

    if search and ( len(search) != 1 or ( not search.isdigit() and not search.isalpha()
            and not search.isspace() ) ):
        idle(add_mark_task, view, search, is_icase(view), is_regex(view), False)
Beispiel #2
0
    def load_file(self, filename, line=None):
        self.buffer.uri = os.path.abspath(filename)
        self.buffer.encoding = 'utf-8'
        self.buffer.saveable = True

        if os.path.exists(self.uri):
            self.view.window.freeze_updates()
            self.on_modified_changed_handler.block()
            self.buffer.begin_not_undoable_action()

            text = open(filename).read()

            try:
                utext = text.decode('utf-8')
            except UnicodeDecodeError, e:
                try:
                    import chardet
                    result = chardet.detect(text)
                    if result['encoding']:
                        utext = text.decode(result['encoding'])
                        self.buffer.encoding = result['encoding']
                        idle(self.message,
                            'Automatically selected ' + self.buffer.encoding + 'encoding', 'info', 5000)
                    else:
                        self.buffer.saveable = False
                        utext = 'Is this a text file?'
                except ImportError:
                    self.buffer.saveable = False
                    utext = str(e)
                except UnicodeDecodeError, ee:
                    self.buffer.saveable = False
                    utext = str(ee)
Beispiel #3
0
 def on_search_entry_changed(self, *args):
     search = self.search_entry.get_text().strip()
     self.current_search = object()
     if search:
         idle(self.fill_filelist, search, self.current_search)
     else:
         idle(self.fill_with_dirs)
Beispiel #4
0
    def on_textview_key_press_event(self, sender, event):
        if event.keyval != gtk.keysyms.Return:
            return False

        cursor = self.editor.cursor
        line_start = cursor.copy()
        line_start.set_line(line_start.get_line())

        text = line_start.get_text(cursor).strip()
        if text and text[-1] == ':':
            end = line_start.copy()
            end.forward_word_end()
            end.backward_word_start()
            ws = line_start.get_text(end)

            if self.editor.view.get_insert_spaces_instead_of_tabs():
                tab = u' ' * self.editor.view.get_tab_width()
            else:
                tab = u'\t'

            self.editor.buffer.begin_user_action()
            self.editor.buffer.insert(cursor, u'\n' + ws + tab)
            self.editor.buffer.end_user_action()

            idle(self.editor.view.scroll_mark_onscreen, self.editor.buffer.get_insert())

            return True

        return False
Beispiel #5
0
 def on_editors_view_cursor_changed(self, *args):
     pwindow = self.pwindow()
     if pwindow and pwindow.manager.conf["EDITOR_LIST_SWITCH_ON_SELECT"] and not self.block_cursor:
         path, _ = self.editors_view.get_cursor()
         uri, editor = self.model[path][3]
         if editor and editor():
             idle(editor().focus)
Beispiel #6
0
    def __init__(self, conf, buf=None):
        self.last_cursor_move = None

        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)

        self.buffer = buf or gtksourceview2.Buffer()

        self.view = gtksourceview2.View()
        self.view.set_buffer(self.buffer)
        sw.add(self.view)
        self.view.editor_ref = weakref.ref(self)

        self.ins_mark = self.sb_mark = None
        self.view.connect('focus-in-event', self.on_focus_in)
        self.view.connect('focus-out-event', self.on_focus_out)

        self.widget = gtk.VBox(False, 0)
        self.widget.pack_start(sw)

        self.widget.show_all()

        connect_all(self, buffer=self.buffer, view=self.view)

        if conf['DISABLE_LEFT_CLICK']:
            weak_connect(self.view, 'button-press-event', self, 'on_button_press_event')

        self.conf = conf

        if buf:
            idle(self.update_view_preferences)
            idle(self.update_title)
Beispiel #7
0
 def activate(self, *args):
     (model, iter) = self.dialogs_view.get_selection().get_selected()
     if iter:
         name = model.get_value(iter, 0)
         prefs.registered_dialogs[name][1](self.editor())
         idle(self.hide)
     else:
         self.editor().message('You need select item')
Beispiel #8
0
def on_entry_activate(sender, editor, widget):
    idle(hide, editor, widget)
    try:
        line = int(sender.get_text())
        editor.add_spot()
        idle(editor.goto_line, line)
    except ValueError:
        pass
Beispiel #9
0
    def show(self, editor):
        self.tree = None
        self.editor = weakref.ref(editor)
        self.search_entry.grab_focus()

        self.window.set_transient_for(editor.window)
        self.window.present()

        idle(self.fill)
Beispiel #10
0
 def open_file(self, *args):
     fname, name, root, top = self.get_selected_file()
     if fname:
         if os.path.isdir(fname):
             idle(self.fill_with_dirs, root, os.path.join(top, name), True)
         else:
             self.hide()
             refresh_gui()
             self.pwindow().open_or_activate(fname)
Beispiel #11
0
def activate_func(view, path, entry, is_final):
    if is_final:
        pos = get_pos(entry)
        root, key = get_key(entry)
        if root[-1] != '/':
            root += '/'

        entry.set_text(root + view.get_model()[path][0])
        entry.set_position(-1)
        idle(entry.emit, 'changed')
Beispiel #12
0
    def job():
        try:
            plugin = handlers[editor]
        except KeyError:
            return

        try:
            problems = plugin.env.lint(plugin.project_path, editor.utext, editor.uri)
        except Exception, e:
            idle(editor.message, str(e), 'error')
            return
Beispiel #13
0
def on_buffer_changed(buffer):
    if buffer in stop_managers:
        cursor = get_iter_at_cursor(buffer)
        sm = stop_managers[buffer]
        if sm.cursor_in_snippet_range(cursor):
            if sm.snippet_collapsed():
                del stop_managers[buffer]
            else:
                idle(sm.replace_inserts)
        else:
            del stop_managers[buffer]
Beispiel #14
0
def add_job(editor):
    from threading import Thread
    from uxie.utils import idle

    def job():
        try:
            problems = get_problem_list(editor.uri, editor.project_root, editor.snaked_conf["PYLINT_CMD"])
        except Exception, e:
            idle(editor.message, str(e), 5000)
            return

        idle(mark_problems, editor, "pylint", problems)
Beispiel #15
0
    def edit_context(self, ctx):
        user_snippet_filename = join_to_settings_dir('snaked', 'snippets', ctx + '.snippets')
        if ctx in self.existing_snippets and \
                self.existing_snippets[ctx] != user_snippet_filename:

            import shutil
            make_missing_dirs(user_snippet_filename)
            shutil.copy(self.existing_snippets[ctx], user_snippet_filename)

        idle(self.hide)
        e = self.editor().open_file(user_snippet_filename)
        e.connect('file-saved', on_snippet_saved, ctx)
Beispiel #16
0
    def close_editor(self, *args):
        model, pathes = self.editors_view.get_selection().get_selected_rows()
        for p in pathes:
            u, e = model[p][3]
            if e and e():
                e().close()

        refresh_gui()
        if self.editor_list:
            idle(self.fill)
        else:
            self.hide()
Beispiel #17
0
    def browse_top(self):
        if not self.filelist_tree.is_focus():
            return False

        if self.search_entry.get_text():
            self.pwindow().emessage('You are not in browse mode', 'warn')
            return

        fname, name, root, top = self.get_selected_file()
        if fname:
            if not top:
                self.pwindow().emessage('No way!', 'warn')
            else:
                place = os.path.basename(top)
                idle(self.fill_with_dirs, root, os.path.dirname(top), place)
Beispiel #18
0
def get_matcher(view, search, ignore_case, regex, show_feedback=True):
    flags = re.UNICODE
    if ignore_case:
        flags |= re.IGNORECASE

    if regex:
        try:
            return re.compile(unicode(search), flags)
        except Exception, e:
            if show_feedback:
                view.get_toplevel().message('Bad regex: ' + str(e), 'error', 3000, parent=view)
                if view in active_search_widgets:
                    idle(active_search_widgets[view].entry.grab_focus)

            return None
Beispiel #19
0
    def update_editor_settings(self):
        manager = self.pwindow().manager
        editor = self.pwindow().get_editor_context()
        buf = editor.buffer if editor else None

        if editor:
            manager.set_buffer_prefs(buf, buf.uri, buf.lang)
            editor.update_view_preferences()

        for b in manager.buffers:
            if b is not buf:
                idle(manager.set_buffer_prefs, b, b.uri, b.lang)

        for e in manager.get_editors():
            if e is not editor:
                idle(e.update_view_preferences)
Beispiel #20
0
    def free_open(self):
        dialog = gtk.FileChooserDialog("Open file...",
            None,
            gtk.FILE_CHOOSER_ACTION_OPEN,
            (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
            gtk.STOCK_OPEN, gtk.RESPONSE_OK))

        dialog.set_default_response(gtk.RESPONSE_OK)
        dialog.set_current_folder(self.roots[0])

        response = dialog.run()
        if response == gtk.RESPONSE_OK:
            idle(self.pwindow().open_or_activate, dialog.get_filename())
            idle(self.hide)

        dialog.destroy()
Beispiel #21
0
def add_lint_job(editor):
    from threading import Thread
    from uxie.utils import idle

    def job():
        try:
            plugin = handlers[editor]
        except KeyError:
            return

        try:
            problems = plugin.env.lint(plugin.project_path, editor.utext, editor.uri)
        except Exception, e:
            idle(editor.message, str(e), 'error')
            return

        idle(mark_exact_problems, editor, 'supp-lint', problems)
Beispiel #22
0
def run():
    import sys, os

    try:
        uri = sys.argv[1]
    except IndexError:
        uri = os.getcwd()


    import gtk
    from .app import App
    from uxie.utils import idle

    application = App()
    idle(application.open, uri)

    gtk.main()
Beispiel #23
0
    def toggle_hidden(self):
        if self.search_entry.get_text():
            self.pwindow().emessage('You are not in browse mode', 'warn')
            return

        conf = self.pwindow().manager.conf
        conf['QUICK_OPEN_SHOW_HIDDEN'] = not conf['QUICK_OPEN_SHOW_HIDDEN']

        self.pwindow().emessage('Show hidden files' if conf['QUICK_OPEN_SHOW_HIDDEN']
            else 'Do not show hidden files', 'info')

        fname, name, root, top = self.get_selected_file()
        if fname:
            idle(self.fill_with_dirs, root, top, name)
        else:
            if len(self.filelist):
                name, top = self.filelist[0]
                idle(self.fill_with_dirs, root, top)
Beispiel #24
0
    def on_page_removed(self, note, child, idx):
        switch_to = None
        for e in self.editors:
            if e.widget is child:
                spot = self.manager.spot_manager.get_last(None, e)
                if spot:
                    switch_to = note.page_num(spot.editor().widget)

                break

        if switch_to is None and idx > 0:
            switch_to = idx - 1

        if switch_to is not None:
            note.set_current_page(switch_to)
            refresh_gui()

        e = self.get_editor_context()
        if e:
            idle(e.view.grab_focus)
Beispiel #25
0
 def activate_editor(self, path):
     uri, editor = self.model[path][3]
     if editor and editor():
         ce = self.current_editor
         if ce:
             ce.add_spot()
         idle(editor().focus)
         idle(self.hide)
     elif uri:
         ce = self.current_editor
         if ce:
             ce.add_spot()
         idle(self.pwindow().open_or_activate, uri)
         idle(self.hide)
Beispiel #26
0
def mark_occurences(view, search, ignore_case, regex, show_feedback=True):
    global mark_task_is_in_queue
    mark_task_is_in_queue = False
    matcher = get_matcher(view, search, ignore_case, regex, show_feedback)
    if not matcher:
        return False

    count = 0
    buf = view.get_buffer()
    utext = buf.get_text(*buf.get_bounds()).decode('utf-8')
    for m in matcher.finditer(utext):
        buf.apply_tag(get_tag(view),
            *map(buf.get_iter_at_offset, m.span()))

        count += 1

    if count == 1:
        if show_feedback:
            idle(view.get_toplevel().message, 'One occurrence is marked', 'done', parent=view)
    elif count > 1:
        if show_feedback:
            idle(view.get_toplevel().message, '%d occurrences are marked' % count, 'done', parent=view)
    else:
        if show_feedback:
            idle(view.get_toplevel().message, 'Text not found', 'warn', parent=view)
        return False

    return True
Beispiel #27
0
    def rename(self):
        if len(self.model.selection) == 1:
            dialog = InputDialog('Rename', self.widget.get_toplevel())

            fi = self.model[self.model.selection.keys()[0]][2]
            fname = fi.get_edit_name().decode('utf-8')

            dialog.entry.set_text(fname)

            fname_without_extension, sep, _ = fname.rpartition('.')
            if sep and fname_without_extension:
                idle(dialog.entry.select_region, 0, len(fname_without_extension))

            if dialog.run() == gtk.RESPONSE_ACCEPT:
                newname = dialog.entry.get_text()
                gfile = self.current_folder.get_child(fi.get_name())
                try:
                    gfile.set_display_name(newname)
                except Exception, e:
                    self.feedback.show(str(e), 'error')
                else:
                    self.feedback.show('Renamed', 'done')

            dialog.destroy()
Beispiel #28
0
 def on_search_entry_changed(self, *args):
     search = self.search_entry.get_text().strip().lower()
     idle(self.fill_dialogs, search)
Beispiel #29
0
 def on_delete_event(self, *args):
     idle(self.hide)
     return True
Beispiel #30
0
def on_key_press(sender, event, editor, widget):
    if event.keyval == gtk.keysyms.Escape:
        idle(hide, editor, widget)
        return True

    return False