def GetLangTemplateDict(self, lastlangstr=False): if lastlangstr: langId = synglob.GetIdFromDescription(self.lastlangstr) else: csel = self.langchoice.GetStringSelection() langId = synglob.GetIdFromDescription(csel) return self.plugin.templates[langId]
def testGetIdFromDescription(self): """Get getting a language id from its description string""" id_ = synglob.GetIdFromDescription(u"Python") self.assertEquals(id_, synglob.ID_LANG_PYTHON) id_ = synglob.GetIdFromDescription(u"python") self.assertEquals(id_, synglob.ID_LANG_PYTHON) id_ = synglob.GetIdFromDescription(u"C") self.assertEquals(id_, synglob.ID_LANG_C) id_ = synglob.GetIdFromDescription(u"SomeFakeLang") self.assertEquals(id_, synglob.ID_LANG_TXT)
def OnLangChange(self, evt): self.ApplyTemplateInfo(lastlangstr=True) self.listbox.SetItems(self.GetTemplateNames()) self.plugin._log("[codetemplater][info]setting %s to %s" % \ (self.lastlangstr,self.langchoice.GetStringSelection())) self.UpdateTemplateinfoUI(None) self.plugin.currentlang = synglob.GetIdFromDescription( self.langchoice.GetStringSelection()) self.lastlangstr = self.langchoice.GetStringSelection()
def PopulateLexerMenu(langmenu): """Create a menu with all the lexer options @return: wx.Menu """ mconfig = profiler.Profile_Get('LEXERMENU', default=list()) mconfig.sort() for label in mconfig: lid = synglob.GetIdFromDescription(label) langmenu.Append(lid, label, _("Switch Lexer to %s") % label, wx.ITEM_CHECK)
def load_templates(): """ returns a dictionary mapping template names to template objects for the requested lexer type """ from collections import defaultdict wx.GetApp().GetLog()('[codetemplater][info]getting %s' % PROFILE_KEY_TEMPLATES) temps = Profile_Get(PROFILE_KEY_TEMPLATES) templd = defaultdict(lambda: dict()) try: if temps is None: dct = load_default_templates() #default templates have text name keys instead of IDs like the plugin wants for k, v in dct.iteritems(): templd[synglob.GetIdFromDescription(k)] = v else: #saved templates store the dict instead of objects, # and use language names instead of IDs logfunct = wx.GetApp().GetLog() for langname, ld in temps.iteritems(): newld = {} for tempname, d in ld.iteritems(): logfunct('[codetemplater][info]dkeys %s' % d.keys()) logfunct('[codetemplater][info]dname %s' % d['name']) logfunct('[codetemplater][info]templ %s' % d['templ']) logfunct('[codetemplater][info]description %s' % d['description']) logfunct('[codetemplater][info]indent %s' % d['indent']) newld[tempname] = CodeTemplate(d['name'], d['templ'], d['description'], d['indent']) templd[synglob.GetIdFromDescription(langname)] = newld return templd except: Profile_Del(PROFILE_KEY_TEMPLATES) raise
def CreateLexerMenu(self): """Create the Lexer menu""" settingsmenu = self._menus['settings'] item = settingsmenu.FindItemById(ed_glob.ID_LEXER) if item: settingsmenu.Remove(ed_glob.ID_LEXER) mconfig = profiler.Profile_Get('LEXERMENU', default=list()) mconfig.sort() # Create the menu langmenu = wx.Menu() langmenu.Append(ed_glob.ID_LEXER_CUSTOM, _("Customize..."), _("Customize the items shown in this menu.")) langmenu.AppendSeparator() for label in mconfig: lid = synglob.GetIdFromDescription(label) langmenu.Append(lid, label, _("Switch Lexer to %s") % label, wx.ITEM_CHECK) settingsmenu.AppendMenu(ed_glob.ID_LEXER, _("Lexers"), langmenu, _("Manually Set a Lexer/Syntax"))
def GetHandlerByName(name): """Get an output handler by name""" lang_id = synglob.GetIdFromDescription(name) return GetHandlerById(lang_id)
def __init__(self, parent, plugin, initiallang=None, *args, **kwargs): super(TemplateEditorPanel, self).__init__(parent, *args, **kwargs) # Attributes self.plugin = plugin self.removing = False self.lastind = None self.lastname = '' # Layout left side of panel to display and alter list of templates basesizer = wx.BoxSizer(wx.HORIZONTAL) listsizer = wx.BoxSizer(wx.VERTICAL) staticbox = wx.StaticBox(self, label=_("Code Templates")) boxsz = wx.StaticBoxSizer(staticbox, wx.VERTICAL) langchoices = get_language_list() if isinstance(initiallang, basestring): id = synglob.GetIdFromDescription(initiallang) else: id = initiallang initiallang = synglob.GetDescriptionFromId(initiallang) if initiallang is None or initiallang not in langchoices: initiallang = langchoices[0] self.lastlangstr = initiallang self.langchoice = wx.Choice(self, wx.ID_ANY, choices=langchoices) self.langchoice.SetSelection(self.langchoice.FindString(initiallang)) self.Bind(wx.EVT_CHOICE, self.OnLangChange, self.langchoice) listsizer.Add(self.langchoice, 0, wx.ALIGN_CENTRE | wx.ALL, 5) self.listbox = wx.ListBox(self, wx.ID_ANY, size=(150, 300), choices=self.GetTemplateNames(), style=wx.LB_SINGLE) self.Bind(wx.EVT_LISTBOX, self.OnListChange, self.listbox) listsizer.Add(self.listbox, 1, wx.ALIGN_CENTRE | wx.ALL, 5) buttonsizer = wx.BoxSizer(wx.HORIZONTAL) addbutton = wx.Button(self, wx.ID_ADD) addbutton.SetToolTipString(_("Add a New Template")) self.Bind(wx.EVT_BUTTON, self.OnAdd, addbutton) buttonsizer.Add(addbutton, 1, wx.ALIGN_CENTRE | wx.ALL, 5) self.rembutton = wx.Button(self, wx.ID_DELETE) self.rembutton.SetToolTipString(_("Remove the selected Template")) self.Bind(wx.EVT_BUTTON, self.OnRemove, self.rembutton) self.rembutton.Enable(False) buttonsizer.Add(self.rembutton, 1, wx.ALIGN_CENTRE | wx.ALL, 5) listsizer.Add(buttonsizer, 0, wx.ALIGN_CENTRE | wx.ALL, 2) boxsz.Add(listsizer, 1, wx.EXPAND) basesizer.Add(boxsz, 0, wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 5) # Layout right side of panel to display the selected template templateinfo = wx.BoxSizer(wx.VERTICAL) namesizer = wx.BoxSizer(wx.HORIZONTAL) helplabel = wx.StaticText(self, wx.ID_ANY, _("Name:")) namesizer.Add(helplabel, 0, wx.ALIGN_CENTRE | wx.ALL, 2) self.nametxt = wx.TextCtrl(self, wx.ID_ANY) namesizer.Add(self.nametxt, 1, wx.GROW | wx.ALIGN_CENTRE | wx.ALL, 2) templateinfo.Add(namesizer, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2) self.nametxt.Enable(False) helpsizer = wx.BoxSizer(wx.HORIZONTAL) helplabel = wx.StaticText(self, wx.ID_ANY, _("Help Text:")) helpsizer.Add(helplabel, 0, wx.ALIGN_CENTRE | wx.ALL, 2) self.helptxt = wx.TextCtrl(self, wx.ID_ANY) helpsizer.Add(self.helptxt, 1, wx.GROW | wx.ALIGN_CENTRE | wx.ALL, 2) templateinfo.Add(helpsizer, 0, wx.GROW | wx.ALIGN_CENTER_VERTICAL | wx.ALL, 2) self.helptxt.Enable(False) indsizer = wx.BoxSizer(wx.HORIZONTAL) self.indentcb = wx.CheckBox(self, label=_("Obey Indentation?")) tooltip = _( "Check to have all lines of the template be indented to match the indentation at which the template is inserted" ) self.indentcb.SetToolTipString(tooltip) indsizer.Add(self.indentcb, 0, wx.ALIGN_CENTRE | wx.ALL, 2) templateinfo.Add(indsizer, 0, wx.ALIGN_CENTER | wx.ALL, 2) self.indentcb.Enable(False) templabel = wx.StaticText( self, wx.ID_ANY, _("Template Codes:\n") + '"${same}": ' + _('Replace with selected text.\n"') + '${upper}":' + _('Replace with selected, first character upper case.\n') + '"${lower}":' + _('Replace with selected, first character lower case.\n') + '"$$":' + _('An "$" character.') + u'\n' + '"#CUR":' + _('Move cursor to this location after inserting template.') + '\n' + _('tabs will be replaced by the appropriate indent.')) templateinfo.Add(templabel, 0, wx.ALIGN_CENTER | wx.ALL, 2) self.temptxt = wx.TextCtrl(self, wx.ID_ANY, size=(300, 200), style=wx.TE_MULTILINE) templateinfo.Add(self.temptxt, 1, wx.EXPAND | wx.ALL, 2) self.temptxt.Enable(False) basesizer.Add(templateinfo, 1, wx.EXPAND | wx.ALIGN_CENTER | wx.ALL, 5) self.SetSizer(basesizer)