1. rablador
  2. QuickRef

Commits

rablador  committed 2a43a00

Added splash item functionality. Some clean-up. Added information about QuickRef for Sublime Text 3.

  • Participants
  • Parent commits 14c2102
  • Branches develop

Comments (0)

Files changed (3)

File ChangeLog.txt

View file
 
 New features
 ------------
-Favourites now being moved to the to of the list without "sort_alphabetically" set to "true".
+Favourites now being moved to the to of the list without "sort_alphabetically" set to "true".
+
+Ver 2.1
+=======
+
+Rablador presents: QuickRef for Sublime Text 3!
+Note: The two versions of QuickRef are not interchangeable. You need the correct build for the version of Sublime Text that you are using.
+ST2: https://bitbucket.org/rablador/quickref
+ST3: https://bitbucket.org/rablador/quickref-st3
+
+New features (QuicRef for ST3)
+------------------------------
+All the features from QuickRef for Sublime Text 2 :).
+
+New features (QuicRef for ST2/ST3)
+----------------------------------
+Show update "splash" item in command list when QuickRef is updated.

File QuickRef.py

View file
       # Define a global error message.
       self.error_message = 'Yay, you\'re special!\n\nYou\'ve just found a bug. Due to the risk of getting spam e-mails I only take bug reports through Bitbucket\'s messaging system. Look, I know it\'s a hassle, but if you send me the error message below I WILL fix this!\n\nYou may have to restart Sublime Text 2 in order to continue using QuickRef.\n\n-----\n'
 
+      # Get OS platform.
+      platform = sublime.platform()
+      platform = platform[0].upper() + platform[1:].lower()
+
+      # Set main folder paths.
+      self.default_path = sublime.packages_path() + '/QuickRef'
+      self.user_path = sublime.packages_path() + '/User'
+
       # Load and parse default settings file.
-      default_settings_path = sublime.packages_path() + '/QuickRef/QuickRef.sublime-settings'
+      default_settings_path = self.default_path + '/QuickRef.sublime-settings'
       default_settings = self.parse_json(default_settings_path)
       default_settings = default_settings.get('settings')
 
+      # Make sure that a User dir in in the packages folder.
+      if not os.path.isdir(self.user_path):
+        os.mkdir(self.user_path)
+
       # Copy default settings file to user settings if no user settings file is present.
-      user_settings_path = sublime.packages_path() + '/User/QuickRef.sublime-settings'
+      user_settings_path = self.user_path + '/QuickRef.sublime-settings'
       if not os.path.exists(user_settings_path):
         shutil.copyfile(default_settings_path, user_settings_path)
 
       # Load and parse user settings file.
-      user_settings_object = sublime.load_settings('QuickRef.sublime-settings')
-      user_settings = user_settings_object.get('settings')
-
-      # Get OS platform.
-      platform = sublime.platform()
-      platform = platform[0].upper() + platform[1:].lower()
+      self.user_settings_object = sublime.load_settings('QuickRef.sublime-settings')
+      self.user_settings = self.user_settings_object.get('settings')
 
       try:
         self.command_list = []
         self.fav_command_list = []
         self.fav_run_commands = []
 
+        # Set user settings.
         self.regular_run_mode = kwargs['regular_run_mode'] if 'regular_run_mode' in kwargs else False
-        self.hardcore_mode = user_settings['hardcore_mode'] if 'hardcore_mode' in user_settings else default_settings['hardcore_mode']
-        self.beautify_captions = user_settings['beautify_captions'] if 'beautify_captions' in user_settings else default_settings['beautify_captions']
-        self.remove_duplicates = user_settings['remove_duplicates'] if 'remove_duplicates' in user_settings else default_settings['remove_duplicates']
-        self.remove_duplicate_contexts = user_settings['remove_duplicate_contexts'] if 'remove_duplicate_contexts' in user_settings else default_settings['remove_duplicate_contexts']
-        self.show_favourites = user_settings['show_favourites'] if 'show_favourites' in user_settings else default_settings['show_favourites']
-        self.show_command_contexts = user_settings['show_command_contexts'] if 'show_command_contexts' in user_settings else default_settings['show_command_contexts']
+        self.hardcore_mode = self.user_settings['hardcore_mode'] if 'hardcore_mode' in self.user_settings else default_settings['hardcore_mode']
+        self.beautify_captions = self.user_settings['beautify_captions'] if 'beautify_captions' in self.user_settings else default_settings['beautify_captions']
+        self.remove_duplicates = self.user_settings['remove_duplicates'] if 'remove_duplicates' in self.user_settings else default_settings['remove_duplicates']
+        self.remove_duplicate_contexts = self.user_settings['remove_duplicate_contexts'] if 'remove_duplicate_contexts' in self.user_settings else default_settings['remove_duplicate_contexts']
+        self.show_favourites = self.user_settings['show_favourites'] if 'show_favourites' in self.user_settings else default_settings['show_favourites']
+        self.show_command_contexts = self.user_settings['show_command_contexts'] if 'show_command_contexts' in self.user_settings else default_settings['show_command_contexts']
        
-        sort_alphabetically = user_settings['sort_alphabetically'] if 'sort_alphabetically' in user_settings else default_settings['sort_alphabetically']
-        key_filter = user_settings['key_filter'] if 'key_filter' in user_settings else default_settings['key_filter']
-        show_default_key_bindings = user_settings['show_default_key_bindings'] if 'show_default_key_bindings' in user_settings else default_settings['show_default_key_bindings']
-        show_user_key_bindings = user_settings['show_user_key_bindings'] if 'show_user_key_bindings' in user_settings else default_settings['show_user_key_bindings']
-        show_user_commands = user_settings['show_user_commands'] if 'show_user_commands' in user_settings else default_settings['show_user_commands']
-        key_filter = user_settings['key_filter'] if 'key_filter' in user_settings else default_settings['key_filter']
+        sort_alphabetically = self.user_settings['sort_alphabetically'] if 'sort_alphabetically' in self.user_settings else default_settings['sort_alphabetically']
+        key_filter = self.user_settings['key_filter'] if 'key_filter' in self.user_settings else default_settings['key_filter']
+        show_default_key_bindings = self.user_settings['show_default_key_bindings'] if 'show_default_key_bindings' in self.user_settings else default_settings['show_default_key_bindings']
+        show_user_key_bindings = self.user_settings['show_user_key_bindings'] if 'show_user_key_bindings' in self.user_settings else default_settings['show_user_key_bindings']
+        show_user_commands = self.user_settings['show_user_commands'] if 'show_user_commands' in self.user_settings else default_settings['show_user_commands']
+        key_filter = self.user_settings['key_filter'] if 'key_filter' in self.user_settings else default_settings['key_filter']
 
         # Get favourites from file.
         if self.show_favourites:
-          favourites_path = sublime.packages_path() + '/User/QuickRef-favs.sublime-settings'
+          favourites_path = self.user_path + '/QuickRef-favs.sublime-settings'
           if os.path.exists(favourites_path):
             with open(favourites_path) as content:
               for command in content:
 
         if show_user_commands:
           # Parse commands from user settings file.
-          user_commands = user_settings_object.get('commands')
+          user_commands = self.user_settings_object.get('commands')
     
           for command in user_commands:
             # Put keys on one line, separate with commas.
 
         if show_user_key_bindings:
           # Load and parse commands from user keymap file.
-          user_key_bindings_path = sublime.packages_path() + '/User/Default (' + platform + ').sublime-keymap'
+          user_key_bindings_path = self.user_path + '/Default (' + platform + ').sublime-keymap'
           user_key_bindings = self.parse_json(user_key_bindings_path)
 
           for command in user_key_bindings:
         # Concatenate favourites and other commands to one list.
         self.command_list = self.fav_command_list + self.command_list
         self.run_commands = self.fav_run_commands + self.run_commands
+        
+        if os.path.exists(self.default_path + '/show_update_splash'):
+          self.command_list = [['- QuickRef has been updated!', '- Select to remove this item and see what\'s new.']] + self.command_list
+          self.run_commands = [['Show update']] + self.run_commands
 
         # Display caption and keyboard shortcuts in quick panel.
         sublime.active_window().show_quick_panel(self.command_list, self.on_select)
   def on_select(self, idx):
     # If command list has items and one was selected (index equals zero or more).
     if self.command_list and idx > -1:
+      # Show latest updates in new window.
+      if 'Show update' == self.run_commands[idx][0]:
+        # Undefine command list in order to "reset" the plugin (see run()).
+        self.command_list = None
+        # Open file with latest changes from change log.
+        sublime.active_window().open_file(self.default_path + '/InThisVersion.txt', sublime.TRANSIENT)
+        # Remove splash control file to indicate that no splash should be shown.
+        os.remove(self.default_path + '/show_update_splash')
+
       # Add favourites to file.
-      if not self.regular_run_mode:
+      elif not self.regular_run_mode:
         try:
           # Open a (new) favourites file.
-          favourites = open(sublime.packages_path() + '/User/QuickRef-favs.sublime-settings', 'w')
+          favourites = open(self.user_path + '/QuickRef-favs.sublime-settings', 'w')
           # Concatenate the complete command.
           command = self.run_commands[idx][1] + ',' + self.command_list[idx][1]          
           # Add command if not in favourites list.
       '(^)?[^\S\n]*/(?:\*(.*?)\*/[^\S\n]*|/[^\n]*)($)?',
       re.DOTALL | re.MULTILINE
     )
-    
+
     # First remove comments and then use the json module package.
     # Comments must look like: // ...  or  /* ... */
     try:
       with open(filename) as f:
         content = ''.join(f.readlines())
 
+        # Remove illegal commas (,) from last item in JSON arrays.
+        content = re.sub(r',\n\s+]', '\n]', content)
+
         # Looking for comments.
         match = comment_re.search(content)
         while match:

File ReadMe.md

View file
 
 All OS:s supported!
 
+Works for both Sublime Text 2 & 3!
+Note: The two versions of QuickRef are not interchangeable. You need the correct build for the version of Sublime Text that you are using.
+
 ## Installation
 ---------------
 
-#### Package Control
+#### Package Control (ST2 only for now)
 Easiest and quickest way to install is through Package Control: http://wbond.net/sublime_packages/package_control
 
-#### Git
-Clone the repository into your Sublime Text 2 "Packages" directory:
+#### Git (ST2 & ST3)
+Clone the repository into your Sublime Text 2/3 "Packages" directory.
+ST2: https://bitbucket.org/rablador/quickref
+ST3: https://bitbucket.org/rablador/quickref-st3
 
-#### Download
-Download the latest source from this repository and copy the QuickRef folder to your Sublime Text 2 "Packages" directory.
+#### Download (ST2 & ST3)
+Download the latest source from this repository and copy the QuickRef folder to your Sublime Text 2/3 "Packages" directory.
+ST2: https://bitbucket.org/rablador/quickref
+ST3: https://bitbucket.org/rablador/quickref-st3
 
 ## Usage
 --------
 ## About
 --------
 
-QuickRef is created by Rablador. The code is free. As in do whatever you like with it.
+QuickRef is created and maintained by Rablador. The code is free. As in do whatever you like with it.