Esempio n. 1
0
  def __init__(self, parent, plugin, doc):

    self.plugin = plugin
    dataDir = plugin.get_data_dir()
    
    self.doc = doc

    self.builder = gtk.Builder()
    self.builder.add_from_file(os.path.join(dataDir, "browsedialog.glade"))

    dic = {
      "on_hpaned_files_size_allocate" : self.on_hpaned_files_size_allocate,
      "on_combobox1_changed" : self.on_combobox1_changed,
      "on_browse_clicked" : self.on_browse_clicked,
      "on_window_main_response" : self.on_window_main_response
    }

    self["dialog"].set_transient_for(parent)

    self.builder.connect_signals(dic)

    self.doc1 = gedit.Document()
    self.doc2 = gedit.Document()

    copy(doc, self.doc1)
    copy(doc, self.doc2)

    self.doc1.goto_line(0)
    self.doc2.goto_line(0)

    self.view1 = gedit.View(self.doc1)
    self.view2 = gedit.View(self.doc2)

    self["h_scrolledwindow1"].add(self.view1)
    self["h_scrolledwindow2"].add(self.view2)

    self.doc1.readonly = True
    self.doc2.readonly = True

    self["dialog"].set_default_response(gtk.RESPONSE_OK)
    self["dialog"].add_button(gtk.STOCK_OK, gtk.RESPONSE_OK)
    self["dialog"].add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)

    self.load_encs()
    self["combobox1"].set_active(0)
    self["combobox1"].grab_focus()

    cell = gtk.CellRendererText()
    self["combobox1"].pack_start(cell, True)
    self["combobox1"].add_attribute(cell, 'text', 1)
Esempio n. 2
0
    def load_other_file(self, source):
        current_tab = self.window.get_active_tab()

        self.same_document[current_tab] = False

        self.split_views[current_tab].remove(self.split_views[current_tab].get_children()[1])

        new_document = gedit.Document()#.gedit_document_new()
        new_document.load("file://" + source.replace(" ", "%20"), self.encoding, 1, True)
        new_view = gedit.View(new_document)#.gedit_view_new(new_document)

        new_document.connect("mark-set", self.update_line_column_data)

        #new_document.save(0)

        self.alt_views[current_tab] = new_document

        sw = gtk.ScrolledWindow()
        sw.add(new_view)

        self.split_views[current_tab].add2(sw)

        self.label_other_document.set_label(os.path.basename(source).replace("%20", " "))

        self.window.get_active_tab().show_all()
Esempio n. 3
0
    def do_get_info_widget(self, proposal):
        if not self.info_widget:
            view = gedit.View(gedit.Document())
            manager = get_language_manager()

            lang = manager.get_language('snippets')
            view.get_buffer().set_language(lang)

            sw = gtk.ScrolledWindow()
            sw.add(view)

            self.info_view = view
            self.info_widget = sw

        return self.info_widget
Esempio n. 4
0
    def split_view(self, whatever, direction="vertical"):

        # Get the tab / document
        current_tab = self.window.get_active_tab()
        current_document = self.window.get_active_document()

        old_other_view = None
        if (current_tab in self.split_views):
            old_other_view = self.split_views[current_tab].get_child2()

        # Create a new HPaned or VPaned object for the splitview.
        if (direction == "vertical"):
            self.split_views[current_tab] = gtk.HPaned()

        else:
            self.split_views[current_tab] = gtk.VPaned()

        old_view = None

        if (not (current_tab in self.same_document)):
            self.same_document[current_tab] = True

        # Here we just kind of loop through the child object of the tab
        # and get rid of all of the existing GUI objects.
        for each in current_tab.get_children():

            # The child of the child has the View object for the active document.
            for any in each.get_children():

                old_view = any
                each.remove(any)

            # Create a scrolled window for the left / top side.
            sw1 = gtk.ScrolledWindow()
            sw1.add(old_view)

            # Set up a new View object
            new_view = None

            # If we are viewing a separate file, then just get that document
            if (current_tab in self.alt_views):
                new_view = gedit.View(self.alt_views[current_tab])#.get_children()[0]

            # Otherwise, just share the same document as the active View.
            # This makes sure changes to either side reflect in the other side.
            else:
                new_view = gedit.View(current_document)

            # Second scrolled window.
            sw2 = gtk.ScrolledWindow()
            sw2.add(new_view)

            # Add the two scrolled windows to our Paned object.
            self.split_views[current_tab].add1(sw1)
            self.split_views[current_tab].add2(sw2)

            # The next few lines of code just create some buttons.
            hbox = gtk.HBox()

            self.btn_cancel = gtk.Button("End Splitview")
            self.btn_cancel.connect("clicked", self.end_split_view)

            self.btn_flip = gtk.Button("Vertical Splitview")
            self.btn_flip.connect("clicked", self.flip_split_view)

            self.btn_view_other_file = gtk.Button("View other file...")
            self.btn_view_other_file.connect("clicked", self.view_other_file)

            self.btn_save_alt_file = gtk.Button("Save Alt Document")
            self.btn_save_alt_file.connect("clicked", self.save_other_file)

            self.label_other_document = gtk.Label(os.path.basename(current_document.get_uri()))
            self.label_other_document.set_alignment(1.0, self.label_other_document.get_alignment()[1])

            hbox.pack_start(self.btn_cancel, False, False)
            hbox.pack_start(self.btn_flip, False, False)
            hbox.pack_start(self.btn_view_other_file, False, False)
            hbox.pack_start(self.btn_save_alt_file, False, False)
            hbox.pack_start(self.label_other_document)

            vbox = gtk.VBox()

            vbox.pack_start(hbox, False, False)
            vbox.pack_start(self.split_views[current_tab])

            each.add_with_viewport(vbox)

            # The trick of this whole thing is that you have to wait a second for the
            # Paned object to figure out how much room it can take up.  So, we're just
            # going to set a timer that'll check every 500 milliseconds until it
            # decides it can trust the width that the Paned object returns.
            gobject.timeout_add(500, self.debug)

        current_tab.show_all()

        # If we're just using the same document twice, then we don't need to worry
        # about "saving" the "other" document.
        if (self.same_document[current_tab] == True):
            self.btn_save_alt_file.hide()