コード例 #1
0
def test_TextView_doCommandBySelector_():
    from editxt.textcommand import TextCommandController
    m = Mocker()
    tv = TextView.alloc().init()
    tc = m.replace(mod, "app").text_commander >> m.mock(TextCommandController)
    selector = m.mock()
    tc.do_textview_command_by_selector(tv, selector) >> True # omit super call
    with m:
        tv.doCommandBySelector_(selector)
コード例 #2
0
def test_TextView_performTextCommand_():
    from editxt.textcommand import TextCommandController
    m = Mocker()
    tv = TextView.alloc().init()
    tc = m.replace(mod, "app").text_commander >> m.mock(TextCommandController)
    sender = m.mock()
    tc.do_textview_command(tv, sender)
    with m:
        tv.performTextCommand_(sender)
コード例 #3
0
def test_TextView_performFindPanelAction_():
    from editxt.command.find import FindController
    m = Mocker()
    tv = TextView.alloc().init()
    fc = m.replace(mod, "FindController")
    sender = m.mock()
    (fc.shared_controller() >> m.mock(FindController)).perform_action(sender)
    with m:
        tv.performFindPanelAction_(sender)
コード例 #4
0
ファイル: document.py プロジェクト: khairy/editxt
    def set_main_view_of_window(self, view, window):
        frame = view.bounds()
        if self.scroll_view is None:
            lm = ak.NSLayoutManager.alloc().init()
            self.document.text_storage.addLayoutManager_(lm)
            tc = ak.NSTextContainer.alloc().initWithContainerSize_(frame.size)
            tc.setLineFragmentPadding_(10) # left margin
            lm.addTextContainer_(tc)

            self.scroll_view = sv = StatusbarScrollView.alloc().initWithFrame_(frame)
            sv.setHasHorizontalScroller_(True)
            sv.setHasVerticalScroller_(True)
            sv.setAutoresizingMask_(ak.NSViewWidthSizable | ak.NSViewHeightSizable)

            self.text_view = tv = TextView.alloc().initWithFrame_textContainer_(frame, tc)
            tv.setAllowsUndo_(True)
            tv.setVerticallyResizable_(True)
            tv.setMaxSize_(fn.NSMakeSize(LARGE_NUMBER_FOR_TEXT, LARGE_NUMBER_FOR_TEXT))
            # setTextContainerInset() with height > 0 causes a strange bug with
            # the movement of the line number ruler (it moves down when
            # scrolling down near the top of the document)
            tv.setTextContainerInset_(fn.NSMakeSize(0, 0)) # width/height
            tv.setDrawsBackground_(False)
            tv.setSmartInsertDeleteEnabled_(False)
            tv.setRichText_(False)
            tv.setUsesFontPanel_(False)
            tv.setUsesFindPanel_(True)
            tv.doc_view = self
            tv.setDelegate_(self)
#           #NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(
#           #    self, "processEdit:", NSTextStorageDidProcessEditingNotification, store)
            attrs = self.document.default_text_attributes()
            tv.setTypingAttributes_(attrs)
            font = attrs[ak.NSFontAttributeName]
            tv.setFont_(font)
            tv.setDefaultParagraphStyle_(attrs[ak.NSParagraphStyleAttributeName])

            sv.setDocumentView_(tv)
#           sv.setHorizontalLineScroll_(font.advancementForGlyph_(ord(u" ")).width)
#           sv.setVerticalLineScroll_(tv.layoutManager().defaultLineHeightForFont_(font))

            # setup line number ruler
            StatusbarScrollView.setRulerViewClass_(LineNumberView)
            sv.setHasVerticalRuler_(True)
            #sv.verticalRulerView().invalidateRuleThickness()
            sv.setRulersVisible_(True)

            self.soft_wrap = app.config["soft_wrap"]
            self.reset_edit_state()
        else:
            # reset frame in case the window was resized
            self.scroll_view.setFrame_(frame)
        view.addSubview_(self.scroll_view)
        window.makeFirstResponder_(self.text_view)
        self.document.update_syntaxer()
        self.scroll_view.verticalRulerView().invalidateRuleThickness()
        self.document.check_for_external_changes(window)
コード例 #5
0
 def test(c):
     m = Mocker()
     tv = TextView.alloc().initWithFrame_(fn.NSMakeRect(0, 0, 100, 100)) # x, y, w, h
     tc = m.method(tv.textContainer)() >> (m.mock(ak.NSTextContainer) if c.setup else None)
     lm = m.method(tv.layoutManager)() >> (m.mock(ak.NSLayoutManager) if c.setup else None)
     sv = m.method(tv.enclosingScrollView)() >> (m.mock(ak.NSScrollView) if c.setup else None)
     height = 100
     if c.setup:
         lm.usedRectForTextContainer_(tc) >> fn.NSMakeRect(0, 0, 100, c.content_height)
         sv.contentSize() >> fn.NSMakeSize(100, 100) # w, h
         if c.content_height + 75 > 100:
             height = c.content_height + 75
     with m:
         tv.setFrameSize_(fn.NSMakeSize(100, height))
         eq_(tv.frameSize(), fn.NSMakeSize(100, c.final_height))
コード例 #6
0
 def test(c):
     m = Mocker()
     fc = m.replace(mod, "FindController")
     tv = TextView.alloc().init()
     item = m.mock(ak.NSMenuItem)
     expectation = (item.action() << c.action)
     if c.action == "performFindPanelAction:":
         tag = item.tag() >> 42
         (fc.shared_controller() >> m.mock(FindController)). \
             validate_action(tag) >> True
     elif c.action == "performTextCommand:":
         expectation.count(2)
         tc = m.replace(mod, "app").text_commander >> m.mock(TextCommandController)
         tc.is_textview_command_enabled(tv, item) >> True
     else:
         raise NotImplementedError # left untested because I don't know how to mock a super call
     with m:
         assert tv.validateUserInterfaceItem_(item)
コード例 #7
0
ファイル: document.py プロジェクト: khairy/editxt
    def set_main_view_of_window(self, view, window):
        frame = view.bounds()
        if self.scroll_view is None:
            lm = ak.NSLayoutManager.alloc().init()
            self.document.text_storage.addLayoutManager_(lm)
            tc = ak.NSTextContainer.alloc().initWithContainerSize_(frame.size)
            tc.setLineFragmentPadding_(10)  # left margin
            lm.addTextContainer_(tc)

            self.scroll_view = sv = StatusbarScrollView.alloc().initWithFrame_(
                frame)
            sv.setHasHorizontalScroller_(True)
            sv.setHasVerticalScroller_(True)
            sv.setAutoresizingMask_(ak.NSViewWidthSizable
                                    | ak.NSViewHeightSizable)

            self.text_view = tv = TextView.alloc(
            ).initWithFrame_textContainer_(frame, tc)
            tv.setAllowsUndo_(True)
            tv.setVerticallyResizable_(True)
            tv.setMaxSize_(
                fn.NSMakeSize(LARGE_NUMBER_FOR_TEXT, LARGE_NUMBER_FOR_TEXT))
            # setTextContainerInset() with height > 0 causes a strange bug with
            # the movement of the line number ruler (it moves down when
            # scrolling down near the top of the document)
            tv.setTextContainerInset_(fn.NSMakeSize(0, 0))  # width/height
            tv.setDrawsBackground_(False)
            tv.setSmartInsertDeleteEnabled_(False)
            tv.setRichText_(False)
            tv.setUsesFontPanel_(False)
            tv.setUsesFindPanel_(True)
            tv.doc_view = self
            tv.setDelegate_(self)
            #           #NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(
            #           #    self, "processEdit:", NSTextStorageDidProcessEditingNotification, store)
            attrs = self.document.default_text_attributes()
            tv.setTypingAttributes_(attrs)
            font = attrs[ak.NSFontAttributeName]
            tv.setFont_(font)
            tv.setDefaultParagraphStyle_(
                attrs[ak.NSParagraphStyleAttributeName])

            sv.setDocumentView_(tv)
            #           sv.setHorizontalLineScroll_(font.advancementForGlyph_(ord(u" ")).width)
            #           sv.setVerticalLineScroll_(tv.layoutManager().defaultLineHeightForFont_(font))

            # setup line number ruler
            StatusbarScrollView.setRulerViewClass_(LineNumberView)
            sv.setHasVerticalRuler_(True)
            #sv.verticalRulerView().invalidateRuleThickness()
            sv.setRulersVisible_(True)

            self.soft_wrap = app.config["soft_wrap"]
            self.reset_edit_state()
        else:
            # reset frame in case the window was resized
            self.scroll_view.setFrame_(frame)
        view.addSubview_(self.scroll_view)
        window.makeFirstResponder_(self.text_view)
        self.document.update_syntaxer()
        self.scroll_view.verticalRulerView().invalidateRuleThickness()
        self.document.check_for_external_changes(window)