I have 4 view in my sublime now. And I want to insert some text to one view. I am trying like this. but no luck.
getAllViews = self.window.views()
jobView = getAllViews[1]
jobEdit = jobView.begin_edit()
jobView.insert(jobEdit, 0, 'Hello')
jobView.end_edit(jobEdit)
Is there any better Idea to do this ?
Updating my question
I am editing my current view layout to 4 pane layout and I want to put some diff data to my newly created layouts. I have this code now .
import sublime
import sublime_plugin
import os, subprocess
class SpliterCommand(sublime_plugin.TextCommand):
def on_done(self, Regex):
self.window.set_layout({
"cols": [0, 0.5, 1],
"rows": [0.0, 0.33, 0.66, 1.0],
"cells": [ [0, 0, 1, 3], [1, 0, 2, 1], [1, 1, 2, 2], [1, 2, 2, 3]]
})
def run(self, edit):
self.editview = edit
self.window = sublime.active_window()
self.window.show_input_panel('User Input', "Hello",self.on_done,None,None)
getAllViews = self.window.layouts()
This will split ui in 4 layout. But not able to set data to the new layouts.
The problem is that when you create a new group the group is empty (doesn't contains views), so you can't insert text if there is no view. You need to create a new view in every empty group to insert characters in them. I've updated your on_done method so that a view is created in every empty group and some text is inserted in the new view. This is explained inside code comments.
def on_done(self, Regex):
self.window.set_layout({
"cols": [0, 0.5, 1],
"rows": [0.0, 0.33, 0.66, 1.0],
"cells": [ [0, 0, 1, 3], [1, 0, 2, 1], [1, 1, 2, 2], [1, 2, 2, 3]]
})
# For each of the new groups call putHello (self.window.num_groups() = 4)
for numGroup in range(self.window.num_groups()):
# If the group is empty (has no views) then we create a new file (view) and insert the text hello
if len(self.window.views_in_group(numGroup)) == 0:
self.window.focus_group(numGroup) # Focus in group
createdView = self.window.new_file() # New view in group
createdView.run_command("insert",{"characters": "Hello"}) # Insert in created view
Before:
After:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With