예제 #1
0
    def _show_diff(self, s):
        doc = document.Document()
        doc.append(s)
        mode = viewdiffmode.ViewDiffMode()
        doc.setmode(mode)

        kaa.app.show_dialog(doc)
예제 #2
0
    def _build_statusbar(self):
        self.statusbar = editor.TextEditorWindow(parent=self.frame)

        doc = document.Document()
        mode = statusbarmode.StatusBarMode()
        doc.setmode(mode)
        self.statusbar.show_doc(doc)
예제 #3
0
파일: msgboxmode.py 프로젝트: smorin/kaa
    def build_msgbox(cls, caption, options, callback, keys=None, border=False):
        doc = document.Document()
        mode = cls()
        mode.callback = callback
        mode.keys = keys
        mode.border = border
        doc.setmode(mode)

        with dialogmode.FormBuilder(doc) as f:

            # caption
            if caption:
                f.append_text('caption', caption)
                f.append_text('default', ' ')

            mode.shortcuts = {}
            for n, option in enumerate(options):
                m = re.search(r'&([^&])', option)
                shortcut = m.group(1)
                mode.shortcuts[shortcut.lower()] = option

                f.append_text('button',
                              option,
                              on_shortcut=lambda wnd, key=shortcut: mode.
                              on_shortcut(wnd, key),
                              shortcut_style='button.shortcut')

                if n < len(options) - 1:
                    f.append_text('separator', cls.SEPARATOR)

            f.append_text('default', ' ')
            f.append_text('underline', ' ')

        return doc
예제 #4
0
    def build(cls, target):
        doc = document.Document()
        mode = cls()
        doc.setmode(mode)
        mode.target = target

        with dialogmode.FormBuilder(doc) as f:
            f.append_text('caption', 'Select word:')
            f.append_text('default', ' ')
            f.append_text('default', '', mark_pair='query')
            f.append_text('default', ' ')

            f.append_text('right-button', '[&Replace]',
                          shortcut_style='right-button.shortcut',
                          on_shortcut=mode.selected)

            f.append_text('right-button', '[&Add word]',
                          shortcut_style='right-button.shortcut',
                          on_shortcut=mode.register)

            f.append_text('right-button', '[&Skip]',
                          shortcut_style='right-button.shortcut',
                          on_shortcut=mode.skip)

            f.append_text('right-button', '[&Quit]',
                          shortcut_style='right-button.shortcut',
                          on_shortcut=mode.quit)

        return doc
예제 #5
0
def show_console():
    cons = document.Document()
    mode = PythonConsoleMode()
    cons.setmode(mode)
    cons.set_title('<Python console>')

    kaa.app.show_doc(cons)
    kaa.app.messagebar.set_message('')
예제 #6
0
def show_fileinfo(target):
    doc = document.Document()
    mode = FileInfoMode(target)
    doc.setmode(mode)

    mode.build_doc()
    kaa.app.show_dialog(doc)
    kaa.app.messagebar.set_message('Hit underlined character to update.')
예제 #7
0
def show_git_log(d):
    repo = repo
    doc = document.Document()
    mode = GitStatusMode()
    doc.setmode(mode)

    mode.show_status(repo)
    kaa.app.show_doc(doc)
예제 #8
0
def show_git_log(d):
    repo = gitrepo.open_repo(d)
    doc = document.Document()
    mode = GitLogMode()
    doc.setmode(mode)

    mode.show_log(repo)
    kaa.app.show_doc(doc)
예제 #9
0
def show_diff(diff):
    doc = document.Document()
    doc.insert(0, diff)

    mode = ViewDiffMode()
    doc.setmode(mode)

    kaa.app.show_dialog(doc)
예제 #10
0
파일: editorcommand.py 프로젝트: smorin/kaa
    def showreplace(self, wnd):
        from kaa.ui.searchdlg import searchdlgmode

        doc = document.Document()
        mode = searchdlgmode.ReplaceDlgMode(target=wnd)
        doc.setmode(mode)
        mode.build_document()

        kaa.app.show_inputline(doc)
예제 #11
0
    def showgrep(self, wnd):
        from kaa.ui.grep import grepdlgmode

        doc = document.Document()
        mode = grepdlgmode.GrepDlgMode(wnd)
        doc.setmode(mode)
        mode.build_document()

        kaa.app.show_dialog(doc)
예제 #12
0
def show_git_status(d):
    repo = gitrepo.open_repo(d)

    doc = document.Document()
    mode = GitStatusMode()
    doc.setmode(mode)

    mode.show_status(repo)
    kaa.app.show_doc(doc)
예제 #13
0
    def build(cls, target):
        doc = document.Document()
        mode = cls()
        doc.setmode(mode)
        mode.target = target

        with dialogmode.FormBuilder(doc) as f:
            f.append_text('caption', 'Select word:')
            f.append_text('default', ' ')
            f.append_text('default', '', mark_pair='query')

        return doc
예제 #14
0
    def build(cls, target):
        doc = document.Document()
        mode = cls()
        doc.setmode(mode)

        mode.org_wnd = target
        mode.target = target.splitter.parent

        with dialogmode.FormBuilder(doc) as f:
            f.append_text('caption',
                          'Hit cursor left/right key to resize window.')
        return doc
예제 #15
0
파일: filterlist.py 프로젝트: smorin/kaa
    def build(cls, caption, callback):
        doc = document.Document()
        mode = cls()
        doc.setmode(mode)

        mode.callback = callback

        with dialogmode.FormBuilder(doc) as f:
            f.append_text('caption', caption)
            f.append_text('default', ' ')
            f.append_text('default', '', mark_pair='query')

        return doc
예제 #16
0
def show_callstack(port, stack):
    doc = document.Document()
    doc.set_title('Python call stack')
    mode = PythonDebuggerPanel()
    mode.port = port

    doc.setmode(mode)
    mode.build(stack)

    dlg = kaa.app.show_inputline(doc)
    ret = dlg.get_label('editor')

    stacklist = document.Document()
    stacklistmode = PythonStackList()
    stacklist.setmode(stacklistmode)
    stacklistmode.build(stack)

    wnd = dlg.add_doc('dlg_stacklist', 0, stacklist)
    stacklistmode.update_sel(wnd, 0)

    mode.show_curline(ret)

    return ret
예제 #17
0
파일: inputlinemode.py 프로젝트: smorin/kaa
    def build(cls, caption, callback, filter=None, history=(), value=''):
        doc = document.Document()
        mode = cls()
        doc.setmode(mode)
        mode.caption = caption
        mode.callback = callback
        mode.filter = filter
        mode.history = history

        with dialogmode.FormBuilder(doc) as f:
            # caption
            f.append_text('caption', caption)
            f.append_text('default', ' ')
            f.append_text('default', value, mark_pair='inputtext')

        return doc
예제 #18
0
파일: statusmode.py 프로젝트: smorin/kaa
def show_git_status(d):
    cur = Path(d).absolute()
    while not cur.joinpath('.git').is_dir():
        p = cur.parent
        if p == cur:
            raise RuntimeError('Not a git repogitory')
        cur = p

    repo_dir = str(cur)
    repo = Repo(repo_dir)

    doc = document.Document()
    mode = GitStatusMode()
    doc.setmode(mode)

    mode.show_status(repo)
    kaa.app.show_doc(doc)
예제 #19
0
    def build(cls, filename, callback):
        doc = document.Document()
        mode = cls()
        doc.setmode(mode)

        mode.callback = callback

        with dialogmode.FormBuilder(doc) as f:
            f.append_text('caption', 'Directory name:')
            f.append_text('default', ' ')
            f.append_text('default', filename, mark_pair='filename')
            f.append_text('default', ' ')

            f.append_text(
                'right-button',
                '[&Select this dir]',
                shortcut_style='right-button.shortcut',
                on_shortcut=lambda wnd: wnd.document.mode.on_select_dir(wnd))

        return doc
예제 #20
0
def show(commandline, s):
    doc = document.Document()
    doc.set_title(' '.join(commandline.split()))
    mode = MakeoutputMode()
    doc.setmode(mode)

    doc.insert(0, s)

    mode = doc.mode
    style_filename = mode.get_styleid('filenameindex-filename')
    style_lineno = mode.get_styleid('filenameindex-lineno')

    for m in mode.RE_FILENAME.finditer(doc):
        f, t = m.span('FILENAME')
        doc.setstyles(f, t, style_filename, update=False)

        f, t = m.span('LINENO')
        doc.setstyles(f, t, style_lineno, update=False)

    kaa.app.show_doc(doc)
예제 #21
0
def view_doc_diff(curdoc, callback=None):
    orig = kaa.app.storage.openfile(curdoc.fileinfo.fullpathname,
                                    curdoc.fileinfo.encoding,
                                    curdoc.fileinfo.newline,
                                    nohist=True)

    org_lines = list(orig.iterlines(0))
    orig.close()

    cur_lines = list(curdoc.iterlines(0))
    diff = ''.join(
        difflib.unified_diff(org_lines, cur_lines,
                             curdoc.fileinfo.fullpathname, '(buffer)'))

    doc = document.Document()
    doc.insert(0, diff)

    mode = ViewDiffMode()
    mode.callback = callback
    doc.setmode(mode)

    kaa.app.show_dialog(doc)
예제 #22
0
    def build(cls, caption, items, sel, callback, onchange=None):
        doc = document.Document()
        mode = cls()
        doc.setmode(mode)

        mode.items = items
        mode.cursel = sel
        mode.callback = callback
        mode.onchange = onchange

        with dialogmode.FormBuilder(doc) as f:

            if caption:
                f.append_text('caption', caption.replace('&', '&&'))
                f.append_text('default', cls.CAPTIONSEP)

            for i, item in enumerate(items):
                f.append_text('default', item.replace('&', '&&'), mark_pair=i)
                f.append_text('default', cls.ITEMSEP)

            mode._update_style(None)
        return doc
예제 #23
0
파일: app.py 프로젝트: smorin/kaa
    def init(self, mainframe):
        self.init_commands()

        if self.config.palette:
            self.set_palette(self.config.palette)
        elif not self.colors:
            self.set_palette(self.DEFAULT_PALETTE)

        self.config.init_history()

        from kaa.ui.messagebar import messagebarmode
        self.messagebar = messagebarmode.MessageBarMode()

        doc = document.Document()
        doc.setmode(self.messagebar)
        mainframe.set_messagebar(doc)

        self.mainframe = mainframe
        self.focus = self.mainframe
        self.macro = macro.Macro()

        self.mainframe.on_console_resized()
        self.messagebar.set_message(self.DEFAULT_MENU_MESSAGE)
예제 #24
0
    def build(cls, filename, newline, encoding, callback):
        doc = document.Document()
        mode = cls()
        doc.setmode(mode)

        mode.newline = newline if newline else kaa.app.config.DEFAULT_NEWLINE
        mode.encoding = encoding if encoding else kaa.app.config.DEFAULT_ENCODING
        mode.callback = callback

        with dialogmode.FormBuilder(doc) as f:
            f.append_text('caption', 'Filename:')
            f.append_text('default', ' ')
            f.append_text('default', filename, mark_pair='filename')
            f.append_text('default', ' ')

            f.append_text(
                'right-button',
                '[&Encoding:{}]'.format(mode.encoding),
                mark_pair='enc',
                shortcut_style='right-button.shortcut',
                on_shortcut=lambda wnd: wnd.document.mode.select_encoding(wnd))

            f.append_text(
                'right-button',
                '[&Newline:{}]'.format(mode.newline),
                mark_pair='newline',
                shortcut_style='right-button.shortcut',
                on_shortcut=lambda wnd: wnd.document.mode.select_newline(wnd))

            f.append_text(
                'right-button',
                '[&Create dir]',
                shortcut_style='right-button.shortcut',
                on_shortcut=lambda wnd: wnd.document.mode.create_dir(wnd))

        return doc
예제 #25
0
파일: selectlist.py 프로젝트: smorin/kaa
    def build(cls):
        doc = document.Document()
        mode = cls()
        doc.setmode(mode)

        return doc
예제 #26
0
def grep(option, target):

# todo: reuse grep pane in same frame
#        buddy = wnd.splitter.get_buddy()
#        if not buddy:
#            buddy = wnd.splitter.split(vert=False, doc=doc)
#            self._locate_doc(buddy.wnd, doc, lineno)
#        else:
#            if buddy.wnd and buddy.wnd.document is doc:
#                self._locate_doc(buddy.wnd, doc, lineno)
#                return
#

    if not target:
        doc = document.Document()
        mode = GrepMode()
        doc.setmode(mode)
    else:
        doc = target.document
        doc.delete(0, doc.endpos())
        mode = doc.mode

    doc.set_title('<grep>')
    mode.grepoption = option.clone()
    mode.encoding = mode.grepoption.encoding
    mode.newlilne = mode.grepoption.newline

    dir = os.path.abspath(os.path.expanduser(option.directory))
    if not os.path.isdir(dir):
        s = 'Cannot find directory `{}`.'.format(dir)
        doc.append(s)
    else:
        try:
            # Restore to cooked mode to accept ^C.
            curses.def_prog_mode()
            curses.endwin()

            try:
                print('Hit ^C to cancel grep.')
                nfiles, nhits = _search(dir, option, doc)
            finally:
                curses.reset_prog_mode()
                kaa.app.mainframe.refresh()

        except KeyboardInterrupt:
            kaa.app.messagebar.set_message('Grep canceled')
            return

        if not nfiles:
            s = 'Cannot find file `{}`.'.format(option.filenames)
            doc.append(s)
        elif not nhits:
            s = 'Cannot find `{}`.'.format(option.text)
            doc.append(s)
        else:
            s = 'Found {} times in {} files'.format(nhits, nfiles)

    kaa.app.messagebar.set_message(s)

    if not target:
        kaa.app.show_doc(doc)
    else:
        target.activate()