Permalink
Browse files

- Added a way to Select which Graphical Diff Application to use

- Started the Diff Application in another threat to free Sublime Text 2
- Fixed typo
  • Loading branch information...
ericmartel committed Mar 22, 2012
1 parent 4f989e0 commit 05ee145e618adad0ef4efa1ede333ba979fc14e1
Showing with 140 additions and 41 deletions.
  1. +13 −3 Context.sublime-menu
  2. +4 −0 Default.sublime-commands
  3. +12 −2 Main.sublime-menu
  4. +80 −32 Perforce.py
  5. +1 −3 Perforce.sublime-settings
  6. +20 −0 graphicaldiffapplications.json
  7. +2 −1 messages.json
  8. +8 −0 messages/1.0.13.txt
View
@@ -34,9 +34,19 @@
"caption": "Diff"
},
{
- "command": "perforce_graphical_diff_with_depot",
- "caption": "Graphical Diff with Depot"
- },
+ "caption": "Graphical Diff Against Depot",
+ "children":
+ [
+ {
+ "command": "perforce_graphical_diff_with_depot",
+ "caption": "Diff"
+ },
+ {
+ "command": "perforce_select_graphical_diff_application",
+ "caption": "Select Diff Application"
+ }
+ ]
+ },
{
"command": "perforce_list_checked_out_files",
"caption": "List Checked Out Files"
View
@@ -27,6 +27,10 @@
"caption": "Perforce: Graphical Diff with Depot",
"command": "perforce_graphical_diff_with_depot"
},
+ {
+ "caption": "Perforce: Select Graphical Diff Application",
+ "command": "perforce_select_graphical_diff_application"
+ },
{
"caption": "Perforce: List Checkedout Files",
"command": "perforce_list_checked_out_files"
View
@@ -36,8 +36,18 @@
"caption": "Diff"
},
{
- "command": "perforce_graphical_diff_with_depot",
- "caption": "Graphical Diff with Depot"
+ "caption": "Graphical Diff Against Depot",
+ "children":
+ [
+ {
+ "command": "perforce_graphical_diff_with_depot",
+ "caption": "Diff"
+ },
+ {
+ "command": "perforce_select_graphical_diff_application",
+ "caption": "Select Diff Application"
+ }
+ ]
},
{
"command": "perforce_list_checked_out_files",
View
@@ -17,6 +17,7 @@
# Eric Martel - source bash_profile when calling p4 on Mac OSX
# Eric Martel - first implementation of submit
# Eric Martel - Better handling of P4CONFIG files
+# Andrew Butt & Eric Martel - threading of the diff task and selector for the graphical diff application
import sublime
import sublime_plugin
@@ -26,6 +27,7 @@
import subprocess
import tempfile
import threading
+import json
# Plugin Settings are located in 'perforce.sublime-settings' make a copy in the User folder to keep changes
@@ -38,6 +40,9 @@ def on_activated(self, view):
global global_folder
global_folder, filename = os.path.split(view.file_name())
+# Executed at startup to store the path of the plugin... necessary to open files relative to the plugin
+perforceplugin_dir = os.getcwdu()
+
# Utility functions
def ConstructCommand(in_command):
command = ''
@@ -442,42 +447,55 @@ def run(self, edit):
WarnUser("View does not contain a file")
# Graphical Diff With Depot section
-def GraphicalDiffWithDepot(self, in_folder, in_filename):
- perforce_settings = sublime.load_settings('Perforce.sublime-settings')
-
- success, content = PerforceCommandOnFile("print", in_folder, in_filename)
- if(not success):
- return 0, content
-
- # Create a temporary file to hold the depot version
- depotFileName = "depot"+in_filename
- tmp_file = open(os.path.join(tempfile.gettempdir(), depotFileName), 'w')
-
- # Remove the first two lines of content
- linebyline = content.splitlines();
- content=perforce_settings.get('perforce_end_line_separator').join(linebyline[1:]);
+class GraphicalDiffThread(threading.Thread):
+ def __init__(self, in_folder, in_filename, in_endlineseparator, in_command):
+ self.folder = in_folder
+ self.filename = in_filename
+ self.endlineseparator = in_endlineseparator
+ self.command = in_command
+ threading.Thread.__init__(self)
- try:
- tmp_file.write(content)
- finally:
- tmp_file.close()
+ def run(self):
+ success, content = PerforceCommandOnFile("print", self.folder, self.filename)
+ if(not success):
+ return 0, content
+
+ # Create a temporary file to hold the depot version
+ depotFileName = "depot"+self.filename
+ tmp_file = open(os.path.join(tempfile.gettempdir(), depotFileName), 'w')
+
+ # Remove the first two lines of content
+ linebyline = content.splitlines();
+ content=self.endlineseparator.join(linebyline[1:]);
+
+ try:
+ tmp_file.write(content)
+ finally:
+ tmp_file.close()
+
+ # Launch P4Diff with both files and the same arguments P4Win passes it
+ diffCommand = self.command
+ diffCommand = diffCommand.replace('%depotfile_path', tmp_file.name)
+ diffCommand = diffCommand.replace('%depotfile_name', depotFileName)
+ diffCommand = diffCommand.replace('%file_path', os.path.join(self.folder, self.filename))
+ diffCommand = diffCommand.replace('%file_name', self.filename)
+
+ command = ConstructCommand(diffCommand)
+
+ p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=global_folder, shell=True)
+ result, err = p.communicate()
- # Launch P4Diff with both files and the same arguments P4Win passes it
- diffCommand = perforce_settings.get('perforce_graphical_diff_command')
- diffCommand = diffCommand.replace('%depofile_path', tmp_file.name)
- diffCommand = diffCommand.replace('%depofile_name', depotFileName)
- diffCommand = diffCommand.replace('%file_path', os.path.join(in_folder, in_filename))
- diffCommand = diffCommand.replace('%file_name', in_filename)
+ # Clean up
+ os.unlink(tmp_file.name);
- command = ConstructCommand(diffCommand)
-
- p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=global_folder, shell=True)
- result, err = p.communicate()
-
- # Clean up
- os.unlink(tmp_file.name);
+def GraphicalDiffWithDepot(self, in_folder, in_filename):
+ perforce_settings = sublime.load_settings('Perforce.sublime-settings')
+ diffcommand = perforce_settings.get('perforce_selectedgraphicaldiffapp_command')
+ if not diffcommand:
+ diffcommand = perforce_settings.get('perforce_default_graphical_diff_command')
+ GraphicalDiffThread(in_folder, in_filename, perforce_settings.get('perforce_end_line_separator'), diffcommand).start()
- return -1, "Executing command " + command
+ return 1, "Launching thread for Graphical Diff"
class PerforceGraphicalDiffWithDepotCommand(sublime_plugin.TextCommand):
def run(self, edit):
@@ -494,6 +512,36 @@ def run(self, edit):
else:
WarnUser("View does not contain a file")
+class PerforceSelectGraphicalDiffApplicationCommand(sublime_plugin.WindowCommand):
+ def run(self):
+ diffapps = []
+ if os.path.exists(perforceplugin_dir + os.sep + 'graphicaldiffapplications.json'):
+ f = open(perforceplugin_dir + os.sep + 'graphicaldiffapplications.json')
+ applications = json.load(f)
+ f.close()
+
+ for entry in applications.get('applications'):
+ formattedentry = []
+ formattedentry.append(entry.get('name'))
+ formattedentry.append(entry.get('exename'))
+ diffapps.append(formattedentry)
+
+ self.window.show_quick_panel(diffapps, self.on_done)
+ def on_done(self, picked):
+ if picked == -1:
+ return
+
+ f = open(perforceplugin_dir + os.sep + 'graphicaldiffapplications.json')
+ applications = json.load(f)
+ entry = applications.get('applications')[picked]
+ f.close()
+
+ sublime.status_message(__name__ + ': Please make sure that ' + entry['exename'] + " is reachable - you might need to restart Sublime Text 2.")
+
+ settings = sublime.load_settings('Perforce.sublime-settings')
+ settings.set('perforce_selectedgraphicaldiffapp', entry['name'])
+ settings.set('perforce_selectedgraphicaldiffapp_command', entry['diffcommand'])
+ sublime.save_settings('Perforce.sublime-settings')
# List Checked Out Files section
class ListCheckedOutFilesThread(threading.Thread):
@@ -6,7 +6,5 @@
"perforce_warnings_enabled": true, // will output messages when warnings happen
"perforce_end_line_separator": "\n", // used to reconstruct the depot file after breaking it up to remove the first line
"perforce_log_warnings_to_status": true, // used to redirect logs to the status bar instead. The standard output is too big for the line (can be multi-line with the raw output of p4)
-
- // use %depofile_path / %file_path as place holder for the full qulified path and %depofile_name / %file_name for the file name only
- "perforce_graphical_diff_command": "p4diff \"%depofile_path\" \"%file_path\" -l \"%file_name in depot\" -e -1 4"
+ "perforce_default_graphical_diff_command": "p4diff \"%depotfile_path\" \"%file_path\" -l \"%file_name in depot\" -e -1 4" // used only if Select Graphical Diff Application is not called
}
@@ -0,0 +1,20 @@
+{
+ "schema_version": "1.2",
+ "applications": [
+ {
+ "name": "P4 Diff",
+ "exename": "p4diff",
+ "diffcommand": "p4diff \"%depotfile_path\" \"%file_path\" -l \"%file_name in depot\" -e -1 4"
+ },
+ {
+ "name": "P4 Merge",
+ "exename": "p4merge",
+ "diffcommand": "p4merge \"%depotfile_path\" \"%file_path\""
+ },
+ {
+ "name": "Araxis P4 Diff",
+ "exename": "AraxisP4Diff",
+ "diffcommand": "AraxisP4Diff \"%depotfile_path\" \"%file_path\""
+ }
+ ]
+}
View
@@ -9,5 +9,6 @@
"1.0.9": "messages/1.0.9.txt",
"1.0.10": "messages/1.0.10.txt",
"1.0.11": "messages/1.0.11.txt",
- "1.0.12": "messages/1.0.12.txt"
+ "1.0.12": "messages/1.0.12.txt",
+ "1.0.13": "messages/1.0.13.txt"
}
View
@@ -0,0 +1,8 @@
+Perforce integration 1.0.13 Changelog:
+
+Add
+- Added a way to Select which Graphical Diff Application to use
+
+Change
+- Started the Diff Application in another threat to free Sublime Text 2
+- Fixed typo

0 comments on commit 05ee145

Please sign in to comment.