How can I tell which project I'm using in Sublime Text? - sublimetext

I often have multiple copies of the same Git repository on my machine. I usually have multiple Sublime Text windows open, each with the opened project for one of the Git repo copies.
Is there any setting that will show the project file's path on the status or title bar, or some other way of easily distinguishing otherwise similar projects from each other? As it is, I have no easy way of distinguishing which Sublime Text window is using which project file.

The title bar of Sublime will show you the file name portion of the project currently associated with a window by default; it's the text to the right of the name of the currently selected file inside round brackets. For example, here I have the OverrideAudit project currently open:
There's no way (currently) to display other information in the caption bar, but using some plugin code you can display text in the status bar instead.
[Edit] There is an open feature request on the issue tracker to add the ability to configure the title bar which you may want to weigh in on. [/Edit]
Here is an example of a plugin that replicates putting the project name from the window caption into the status bar. If desired you could modify the code in show_project that isolates only the project name to e.g. include the path if desired.
To use this, you can select Tools > Developer > New Plugin... from the menu and replace the default stub with this code, modifying as needed.
This code is also available on GitHub.
import sublime
import sublime_plugin
import os
# Related Reading:
# https://forum.sublimetext.com/t/displaying-project-name-on-the-rite-side-of-the-status-bar/24721
# This just displays the filename portion of the current project file in the
# status bar, which is the same text that appears by default in the window
# caption.
def plugin_loaded ():
"""
Ensure that all views in all windows show the associated project at startup.
"""
# Show project in all views of all windows
for window in sublime.windows ():
for view in window.views ():
show_project (view)
def show_project(view):
"""
If a project file is in use, add the name of it to the start of the status
bar.
"""
if view.window() is None:
return
project_file = view.window ().project_file_name ()
if project_file is not None:
project_name = os.path.splitext (os.path.basename (project_file))[0]
view.set_status ("00ProjectName", "[" + project_name + "]")
class ProjectInStatusbar(sublime_plugin.EventListener):
"""
Display the name of the current project in the status bar.
"""
def on_new(self, view):
show_project (view)
def on_load(self, view):
show_project (view)
def on_clone(self, view):
show_project (view)

Related

How to get content from field

I'm totally new to Base. I have different forms but in one named F_STRUCT of them I'm trying to make a macro which will allow the user to autofill another field when he select a zipcode.
so the database looks like this.
ID_ZIP ZIP CITY
1 97425 Les Avirons
2 82289 Toto
In my forms, I have a select which allows to select the ZIP code. It's label and name is ZipCode.
So I don't really know where to find the API reference for all the methods and chill methods, I followed examples from internet.
I tried this
Sub getZip
Dim Doc As Object
Dim DrawPage As Object
Dim Form As Object
Doc = StarDesktop.CurrentComponent
DrawPage = Doc.DrawPage
Form = DrawPage.Forms.GetByIndex(0)
Toto = Form.GetByName("ZipCode")
Print "hey"
End Sub
But it returns an error on the Toto = Form.GetByName("ZipCode") line.
The code works, so the problem must be how you created the form or control. Follow these instructions to set up a correct example:
Create Form in Design View
Use the List Box tool (is that what you mean by "select"?) and create a control.
Cancel out of the wizard if it pops up.
Right-click on the control and select Control Properties (not Name, which would modify the shape name instead of the control's name).
Set the Name to "ZipCode" (without quotes).
Save and close the form.
Open the form. In the window of that form (the CurrentComponent) go to Tools -> Macros -> Run Macro.
A list of documentation links for Base is at https://ask.libreoffice.org/en/question/80972/to-learn-libreoffice-base-are-there-introductions-or-tutorials/?answer=80973#post-id-80973.

Cannot create new live template in RubyMine7.1.4

I'm using rubymine 7.1.4 and I found that I could not create new live template. I tried to create the live template with the following steps
1. Go to Preferences -> Editors -> Live template
2. I select the "user" group and click the "+" icon in the top-right corner, then select "1. Live template"
3. I fill in the "Abbreviation" field with mmfd and "Description field with "method_missing for decorators", then the "Template text" field with
def method_missing?(method_name, *args, &block)
#tweet.send(method_name, *args, &block)
end
def respond_to_missing?(method_name, include_private=false)
#tweet.respond_to?(method_name, include_private=false) || super
end
I click the "Define" and select Ruby as the context. Then I click the OK button.
Then I went to a ruby file editor and type the abbreviation "mmfd", and nothing happened.
I reopen the "live template" preference page and the template I created was gone.
I also tried select the code in the editor and then perform "Save as live template", fill in the abbreviation, and this way does not work neither.

Pythonic way of applying changes on closing a dialog window

I couldn't find any useful resources for this subject. I hope I can find some guidance here.
I made a dialog window class using Glade, Gtk (3.10) and Python 3. It has about 30 options that can be changed. In the init function I set up the whole dialog window and set the options to the current value. I also define a bool-variable that stores if any of the widgets was changed:
self.settings_changed = False
So for each widget I set up a function that catches the "change-signal" and does the following:
def on_checkbutton_line_width_changed(self, widget):
#Set setting_changed to True so that the dialog knows something changed
self.settings_changed = True
#Store the changed value in a temporary variable
self.temp_checkbutton_value = widget.get_active()
Now when I click "Cancel" on the dialog I just don't apply any of the temporary values. But when I click "Apply" I want all changed variables to be applied. But here is my problem: Of those 30 changed variables only a few exist and all the others would lead to a lot of AttributeErrors, because the temporary variable doesn't exist.
I tried avoiding the errors by using a lot of try-except functions:
try:
self.dataclass.set_checkbutton(self.temp_checkbutton_value)
except:
pass
Is there a easier (and shorter) way to solve this? I imagine that there should be a way to build a queue of changes that are executed after each other after clicking on "Apply", but my potato-like python skills have so far not helped me in solving this.
Here's an example that might help:
class MyWidget:
def __init__(self):
self.changes = []
def cancel_changes(self):
self.changes.clear()
def change_name(self, new_name):
self.changes.append(('change_name', new_name))
def change_color(self, new_color):
self.changes.append(('change_color', new_color))
def apply_changes(self):
for change in self.changes:
print("{} - {}".format(change[0], change[1])
alternatively you could do something like:
self.changes.append(lambda: self.dataclass.set_checkoutbutton(value))
and then apply changes would be:
for change in self.changes:
change()

How could I use per-folder color schemes? (Sublime Text 3)

Here is my problem: when writing javascript for both server and client-side, I regularly share methods and/or have close file names. I would love to be able to keep the context in mind, just by the background color of the opened files. I thus look for a way to tell sublime text to use one color scheme for files in the server folder and an other for those in the client folder: any clue on how I could do that?
I'm not sure it's even possible as it would imply a per-folder config file I guess, but that's my bottle in the sea...
thanks!
The easiest way to do this is with projects. Set up a project for your client-side folder, and another for your server-side folder. Then, go to Project -> Edit Project and you'll see something like this:
{
"folders":
[
{
"follow_symlinks": true,
"path": "/home/mattdmo/Projects/js/MySweetApp/server-side"
}
]
}
There are two other top-level arrays you can add: "settings" and "build_systems". The settings section can include anything that goes in Preferences -> Settings-User, including "color_scheme":
{
"folders":
[
{
"follow_symlinks": true,
"path": "/home/mattdmo/Projects/js/MySweetApp/server-side"
}
],
"settings":
{
"color_scheme": "Packages/Neon Color Scheme/Neon.tmTheme"
}
}
Just edit both .sublime-project files you made earlier to add a settings section and different color_scheme choices within, and you'll be all set.
EDIT
While pondering this again, I came up with a different solution using a plugin. Create a new Python file with the following contents:
import sublime
import sublime_plugin
class ClientServerColorSchemeCommand(sublime_plugin.TextCommand):
def run(self, edit):
if "/server/" in self.view.file_name():
self.view.settings().set("color_scheme",
"Packages/User/server.tmTheme")
elif "/client/" in self.view.file_name():
self.view.settings().set("color_scheme",
"Packages/User/client.tmTheme")
class ClientServerEventListener(sublime_plugin.EventListener):
def on_load_async(self, view):
view.run_command("client_server_color_scheme")
Make sure you adjust the "color_scheme" settings to the color schemes you want to use for client and server files, and feel free to tweak "/server/" and/or "/client/" in the if/elif statements if you want to make them more specific. If you're on Windows, change the forward slashes / to double back-slashes \\. Save the file as Packages/User/client_server_color_scheme.py where Packages is the folder opened when selecting the Preferences -> Browse Packages... menu option.
Once saved, the event listener will start up immediately, and any file you open that contains the specified path will have the color scheme set to whatever you indicate. All other files from other paths will use your default color scheme.
Please note that this plugin will only work in ST3. To make it work in ST2, change def on_load_async to def on_load.
I modified MattDMo's solution and it works with the latest Sublime Text 3 (build 3143):
import sublime, sublime_plugin
class ColorSchemeByPathCommand(sublime_plugin.TextCommand):
def run(self, edit):
settings = self.view.settings()
if "/test/" in self.view.file_name():
settings.set('color_scheme', "Packages/User/SublimeLinter/Orange01 (SL).tmTheme")
else:
settings.set('color_scheme', "Packages/User/SublimeLinter/Blue01 (SL).tmTheme")
class ColorSchemeByPathEventListener(sublime_plugin.EventListener):
def on_load_async(self, view):
view.run_command("color_scheme_by_path")

How to have only one tab open in wxribbon bar in wxpython?

I am building a GUI and I am using wxribbon for wxpython. I want to have only one tab(ribbon page) in when user starts my app, from where user can dynamically add more pages or can add panels and buttons to a page. I am able to achieve all the dynamic parts of ribbon. The only problem I have is that I am unable to start with only one ribbon page. When I define only one page, I don't see the ribbon bar(tab bar), what I see is only the page. Now, when I define two page in the beginning, then I see the bar. Can someone tell me what I code have to change in wxribbon so that I am able to have a tab bar visible with only one page in it. Any help would be great. Thanks!. The sample code I am using to add a page is as follows :
import wxRibbon as RB
self._ribbon = RB.RibbonBar(self, id = wx.ID_ANY)
page_1 = RB.RibbonPage(self._ribbon, WORKPIECE, "Workpiece", Bitmap("eye.xpm"))
page_2 = RB.RibbonPage(self._ribbon, wx.ID_ANY, "New Tab", Bitmap("empty.xpm"))
You need the flag RIBBON_BAR_ALWAYS_SHOW_TABS
try this:
self._ribbon = RB.RibbonBar(self, wx.ID_ANY, agwStyle = RB.RIBBON_BAR_DEFAULT_STYLE | RB.RIBBON_BAR_ALWAYS_SHOW_TABS)

Resources