{"thread":{"id":"34506","subject":"[PATCH] gitk: Add a \"Save file as\" menu item","startedAt":"2013-07-21T12:38:45Z","lastAt":"2013-07-28T15:30:05Z","messageCount":5,"participants":["Andreas Amann","Peter Krefting"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"223874","messageId":"87ppuculyi.fsf@msstf091.ucc.ie","threadId":"34506","inReplyTo":null,"subject":"[PATCH] gitk: Add a \"Save file as\" menu item","fromName":"Andreas Amann","fromEmail":"a.amann@ucc.ie","sentAt":"2013-07-21T12:38:45Z","receivedAt":"2013-07-21T12:38:45Z","isPatch":true,"sender":{"key":"a.amann@ucc.ie","avatar":null},"body":"Previously, there was no easy way to save a particular file from the\ncurrently selected revision.\n\nThis patch adds a menu item \"Save file as\" to the file list popup\nmenu, which opens a file selection dialog to determine the name under\nwhich a file should be saved.  The default filename is of the form\n\"[shortid] basename\".  If the current revision is the index, the\ndefault pattern is of the form \"[index] basename\".  This works for\nboth, the \"Patch\" and \"Tree\" view.  The menu item is disabled for the\n\"local uncommitted changes\" fake revision.\n\nSigned-off-by: Andreas Amann <andreas.amann@web.de>\n---\n gitk | 30 ++++++++++++++++++++++++++++++\n 1 file changed, 30 insertions(+)\n\ndiff --git a/gitk b/gitk\nindex 5cd00d8..dbedaf6 100755\n--- a/gitk\n+++ b/gitk\n@@ -2595,6 +2595,7 @@ proc makewindow {} {\n \t{mc \"Highlight this too\" command {flist_hl 0}}\n \t{mc \"Highlight this only\" command {flist_hl 1}}\n \t{mc \"External diff\" command {external_diff}}\n+\t{mc \"Save file as\" command {save_file_as}}\n \t{mc \"Blame parent commit\" command {external_blame 1}}\n     }\n     $flist_menu configure -tearoff 0\n@@ -3378,6 +3379,7 @@ proc sel_flist {w x y} {\n proc pop_flist_menu {w X Y x y} {\n     global ctext cflist cmitmode flist_menu flist_menu_file\n     global treediffs diffids\n+    global nullid\n \n     stopfinding\n     set l [lindex [split [$w index \"@$x,$y\"] \".\"] 0]\n@@ -3395,6 +3397,12 @@ proc pop_flist_menu {w X Y x y} {\n     }\n     # Disable \"External diff\" item in tree mode\n     $flist_menu entryconf 2 -state $xdiffstate\n+    set savefilestate \"normal\"\n+    if {[lindex $diffids 0] eq $nullid} {\n+\tset savefilestate \"disabled\"\n+    }\n+    # Disable \"Save file as\" item for worktree\n+    $flist_menu entryconf 3 -state $savefilestate\n     tk_popup $flist_menu $X $Y\n }\n \n@@ -3496,6 +3504,28 @@ proc external_diff_get_one_file {diffid filename diffdir} {\n \t       \"revision $diffid\"]\n }\n \n+proc save_file_as {} {\n+    global nullid nullid2\n+    global flist_menu_file\n+    global diffids\n+\n+    set diffid [lindex $diffids 0]\n+    if {$diffid == $nullid} {\n+\treturn\n+    } elseif {$diffid == $nullid2} {\n+\tset diffidtext \"\\[index\\]\"\n+\tset diffid \"\"\n+    } else {\n+\tset diffidtext \"\\[[shortids $diffid]\\]\"\n+    }\n+    set difffile \"$diffidtext [file tail $flist_menu_file]\"\n+    set difffile [tk_getSaveFile -initialfile $difffile -title \"Save file as\" -parent .]\n+    if {$difffile eq {}} {\n+\treturn\n+    }\n+    save_file_from_commit $diffid:$flist_menu_file $difffile \"revision $diffid\"\n+}\n+\n proc external_diff {} {\n     global nullid nullid2\n     global flist_menu_file\n-- \n1.8.3.1\n"},{"id":"223885","messageId":"alpine.DEB.2.00.1307211910250.9615@ds9.cixit.se","threadId":"34506","inReplyTo":"87ppuculyi.fsf@msstf091.ucc.ie","subject":"Re: [PATCH] gitk: Add a \"Save file as\" menu item","fromName":"Peter Krefting","fromEmail":"peter@softwolves.pp.se","sentAt":"2013-07-21T18:13:08Z","receivedAt":"2013-07-21T18:13:08Z","isPatch":true,"sender":{"key":"peter@softwolves.pp.se","avatar":"https://avatars.githubusercontent.com/u/990764?v=4"},"body":"Andreas Amann:\n\n> +    set difffile \"$diffidtext [file tail $flist_menu_file]\"\n> +    set difffile [tk_getSaveFile -initialfile $difffile -title \"Save file as\" -parent .]\n> +    if {$difffile eq {}} {\n> +\treturn\n> +    }\n> +    save_file_from_commit $diffid:$flist_menu_file $difffile \"revision $diffid\"\n\nI might be misunderstanding the code (this is not one of my preferred \nprogramming languages), but it looks like this is missing the gettext \nmarkers necessary to get these strings localized.\n\n-- \n\\\\// Peter - http://www.softwolves.pp.se/\n"},{"id":"223886","messageId":"87zjtfhepo.fsf@msstf091.ucc.ie","threadId":"34506","inReplyTo":"alpine.DEB.2.00.1307211910250.9615@ds9.cixit.se","subject":"Re: [PATCH] gitk: Add a \"Save file as\" menu item","fromName":"Andreas Amann","fromEmail":"a.amann@ucc.ie","sentAt":"2013-07-21T19:53:39Z","receivedAt":"2013-07-21T19:53:39Z","isPatch":true,"sender":{"key":"a.amann@ucc.ie","avatar":null},"body":"Peter Krefting <peter@softwolves.pp.se> writes:\n> Andreas Amann:\n>\n>> +    set difffile \"$diffidtext [file tail $flist_menu_file]\"\n>> +    set difffile [tk_getSaveFile -initialfile $difffile -title \"Save file as\" -parent .]\n>> +    if {$difffile eq {}} {\n>> +\treturn\n>> +    }\n>> +    save_file_from_commit $diffid:$flist_menu_file $difffile \"revision $diffid\"\n>\n> I might be misunderstanding the code (this is not one of my preferred \n> programming languages), but it looks like this is missing the gettext \n> markers necessary to get these strings localized.\n\nthanks for pointing this out.  Will resend an updated patch.\n"},{"id":"223888","messageId":"87wqojhemb.fsf@msstf091.ucc.ie","threadId":"34506","inReplyTo":"alpine.DEB.2.00.1307211910250.9615@ds9.cixit.se","subject":"[PATCH v2] gitk: Add a \"Save file as\" menu item","fromName":"Andreas Amann","fromEmail":"a.amann@ucc.ie","sentAt":"2013-07-21T19:55:40Z","receivedAt":"2013-07-21T19:55:40Z","isPatch":true,"sender":{"key":"a.amann@ucc.ie","avatar":null},"body":"Previously, there was no easy way to save a particular file from the\ncurrently selected revision.\n\nThis patch adds a menu item \"Save file as\" to the file list popup\nmenu, which opens a file selection dialog to determine the name under\nwhich a file should be saved.  The default filename is of the form\n\"[shortid] basename\".  If the current revision is the index, the\ndefault pattern is of the form \"[index] basename\".  This works for\nboth, the \"Patch\" and \"Tree\" view.  The menu item is disabled for the\n\"local uncommitted changes\" fake revision.\n\nSigned-off-by: Andreas Amann <andreas.amann@web.de>\n---\n gitk | 32 ++++++++++++++++++++++++++++++++\n 1 file changed, 32 insertions(+)\n\ndiff --git a/gitk b/gitk\nindex 5cd00d8..b5a70b5 100755\n--- a/gitk\n+++ b/gitk\n@@ -2595,6 +2595,7 @@ proc makewindow {} {\n \t{mc \"Highlight this too\" command {flist_hl 0}}\n \t{mc \"Highlight this only\" command {flist_hl 1}}\n \t{mc \"External diff\" command {external_diff}}\n+\t{mc \"Save file as\" command {save_file_as}}\n \t{mc \"Blame parent commit\" command {external_blame 1}}\n     }\n     $flist_menu configure -tearoff 0\n@@ -3378,6 +3379,7 @@ proc sel_flist {w x y} {\n proc pop_flist_menu {w X Y x y} {\n     global ctext cflist cmitmode flist_menu flist_menu_file\n     global treediffs diffids\n+    global nullid\n \n     stopfinding\n     set l [lindex [split [$w index \"@$x,$y\"] \".\"] 0]\n@@ -3395,6 +3397,12 @@ proc pop_flist_menu {w X Y x y} {\n     }\n     # Disable \"External diff\" item in tree mode\n     $flist_menu entryconf 2 -state $xdiffstate\n+    set savefilestate \"normal\"\n+    if {[lindex $diffids 0] eq $nullid} {\n+\tset savefilestate \"disabled\"\n+    }\n+    # Disable \"Save file as\" item \"local uncommited changes\" revision\n+    $flist_menu entryconf 3 -state $savefilestate\n     tk_popup $flist_menu $X $Y\n }\n \n@@ -3496,6 +3504,30 @@ proc external_diff_get_one_file {diffid filename diffdir} {\n \t       \"revision $diffid\"]\n }\n \n+proc save_file_as {} {\n+    global nullid nullid2\n+    global flist_menu_file\n+    global diffids\n+\n+    set diffid [lindex $diffids 0]\n+    if {$diffid == $nullid} {\n+\treturn\n+    } elseif {$diffid == $nullid2} {\n+\tset diffidtext [mc \"index\"]\n+\tset diffid \"\"\n+\tset whattext $diffidtext\n+    } else {\n+\tset diffidtext [shortids $diffid]\n+\tset whattext \"[mc \"revision\"] $diffidtext\"\n+    }\n+    set difffile \"\\[$diffidtext\\] [file tail $flist_menu_file]\"\n+    set difffile [tk_getSaveFile -initialfile $difffile -title [mc \"Save file as\"] -parent .]\n+    if {$difffile eq {}} {\n+\treturn\n+    }\n+    save_file_from_commit $diffid:$flist_menu_file $difffile $whattext\n+}\n+\n proc external_diff {} {\n     global nullid nullid2\n     global flist_menu_file\n-- \n1.8.3.3\n"},{"id":"224203","messageId":"87li4qem82.fsf@msstf091.ucc.ie","threadId":"34506","inReplyTo":"87wqojhemb.fsf@msstf091.ucc.ie","subject":"[PATCH v3] gitk: Add a \"Save file as\" menu item","fromName":"Andreas Amann","fromEmail":"a.amann@ucc.ie","sentAt":"2013-07-28T15:30:05Z","receivedAt":"2013-07-28T15:30:05Z","isPatch":true,"sender":{"key":"a.amann@ucc.ie","avatar":null},"body":"Previously, there was no easy way to save a particular file from the\ncurrently selected revision.\n\nThis patch adds a menu item \"Save file as\" to the file list popup\nmenu, which opens a file selection dialog to determine the name under\nwhich a file should be saved.  The default filename is of the form\n\"[shortid] basename\".  If the current revision is the index, the\ndefault pattern is of the form \"[index] basename\".  This works for\nboth, the \"Patch\" and \"Tree\" view.  The menu item is disabled for the\n\"local uncommitted changes\" fake revision.\n\nSigned-off-by: Andreas Amann <andreas.amann@web.de>\n---\n gitk | 36 ++++++++++++++++++++++++++++++++++++\n 1 file changed, 36 insertions(+)\n\nThe previous version V2 of the patch did not work, when gitk was started\nin a subdirectory of the repo and a file was saved from tree view.  This\nis now fixed. \n\ndiff --git a/gitk b/gitk\nindex 5cd00d8..6b66f18 100755\n--- a/gitk\n+++ b/gitk\n@@ -2595,6 +2595,7 @@ proc makewindow {} {\n \t{mc \"Highlight this too\" command {flist_hl 0}}\n \t{mc \"Highlight this only\" command {flist_hl 1}}\n \t{mc \"External diff\" command {external_diff}}\n+\t{mc \"Save file as\" command {save_file_as}}\n \t{mc \"Blame parent commit\" command {external_blame 1}}\n     }\n     $flist_menu configure -tearoff 0\n@@ -3378,6 +3379,7 @@ proc sel_flist {w x y} {\n proc pop_flist_menu {w X Y x y} {\n     global ctext cflist cmitmode flist_menu flist_menu_file\n     global treediffs diffids\n+    global nullid\n \n     stopfinding\n     set l [lindex [split [$w index \"@$x,$y\"] \".\"] 0]\n@@ -3395,6 +3397,12 @@ proc pop_flist_menu {w X Y x y} {\n     }\n     # Disable \"External diff\" item in tree mode\n     $flist_menu entryconf 2 -state $xdiffstate\n+    set savefilestate \"normal\"\n+    if {[lindex $diffids 0] eq $nullid} {\n+\tset savefilestate \"disabled\"\n+    }\n+    # Disable \"Save file as\" item \"local uncommited changes\" revision\n+    $flist_menu entryconf 3 -state $savefilestate\n     tk_popup $flist_menu $X $Y\n }\n \n@@ -3496,6 +3504,34 @@ proc external_diff_get_one_file {diffid filename diffdir} {\n \t       \"revision $diffid\"]\n }\n \n+proc save_file_as {} {\n+    global nullid nullid2\n+    global flist_menu_file cmitmode\n+    global diffids\n+\n+    set diffid [lindex $diffids 0]\n+    if {$diffid == $nullid} {\n+\treturn\n+    } elseif {$diffid == $nullid2} {\n+\tset diffidtext [mc \"index\"]\n+\tset diffid \"\"\n+\tset whattext $diffidtext\n+    } else {\n+\tset diffidtext [shortids $diffid]\n+\tset whattext \"[mc \"revision\"] $diffidtext\"\n+    }\n+    set diffid $diffid:\n+    if {$cmitmode eq \"tree\"} {\n+\tset diffid $diffid./\n+    }\n+    set difffile \"\\[$diffidtext\\] [file tail $flist_menu_file]\"\n+    set difffile [tk_getSaveFile -initialfile $difffile -title [mc \"Save file as\"] -parent .]\n+    if {$difffile eq {}} {\n+\treturn\n+    }\n+    save_file_from_commit $diffid$flist_menu_file $difffile $whattext\n+}\n+\n proc external_diff {} {\n     global nullid nullid2\n     global flist_menu_file\n-- \n1.8.3.3\n\n\nAndreas Amann <a.amann@ucc.ie> writes:\n> Previously, there was no easy way to save a particular file from the\n> currently selected revision.\n>\n> This patch adds a menu item \"Save file as\" to the file list popup\n> menu, which opens a file selection dialog to determine the name under\n> which a file should be saved.  The default filename is of the form\n> \"[shortid] basename\".  If the current revision is the index, the\n> default pattern is of the form \"[index] basename\".  This works for\n> both, the \"Patch\" and \"Tree\" view.  The menu item is disabled for the\n> \"local uncommitted changes\" fake revision.\n>\n> Signed-off-by: Andreas Amann <andreas.amann@web.de>\n> ---\n>  gitk | 32 ++++++++++++++++++++++++++++++++\n>  1 file changed, 32 insertions(+)\n>\n> diff --git a/gitk b/gitk\n> index 5cd00d8..b5a70b5 100755\n> --- a/gitk\n> +++ b/gitk\n> @@ -2595,6 +2595,7 @@ proc makewindow {} {\n>  \t{mc \"Highlight this too\" command {flist_hl 0}}\n>  \t{mc \"Highlight this only\" command {flist_hl 1}}\n>  \t{mc \"External diff\" command {external_diff}}\n> +\t{mc \"Save file as\" command {save_file_as}}\n>  \t{mc \"Blame parent commit\" command {external_blame 1}}\n>      }\n>      $flist_menu configure -tearoff 0\n> @@ -3378,6 +3379,7 @@ proc sel_flist {w x y} {\n>  proc pop_flist_menu {w X Y x y} {\n>      global ctext cflist cmitmode flist_menu flist_menu_file\n>      global treediffs diffids\n> +    global nullid\n>  \n>      stopfinding\n>      set l [lindex [split [$w index \"@$x,$y\"] \".\"] 0]\n> @@ -3395,6 +3397,12 @@ proc pop_flist_menu {w X Y x y} {\n>      }\n>      # Disable \"External diff\" item in tree mode\n>      $flist_menu entryconf 2 -state $xdiffstate\n> +    set savefilestate \"normal\"\n> +    if {[lindex $diffids 0] eq $nullid} {\n> +\tset savefilestate \"disabled\"\n> +    }\n> +    # Disable \"Save file as\" item \"local uncommited changes\" revision\n> +    $flist_menu entryconf 3 -state $savefilestate\n>      tk_popup $flist_menu $X $Y\n>  }\n>  \n> @@ -3496,6 +3504,30 @@ proc external_diff_get_one_file {diffid filename diffdir} {\n>  \t       \"revision $diffid\"]\n>  }\n>  \n> +proc save_file_as {} {\n> +    global nullid nullid2\n> +    global flist_menu_file\n> +    global diffids\n> +\n> +    set diffid [lindex $diffids 0]\n> +    if {$diffid == $nullid} {\n> +\treturn\n> +    } elseif {$diffid == $nullid2} {\n> +\tset diffidtext [mc \"index\"]\n> +\tset diffid \"\"\n> +\tset whattext $diffidtext\n> +    } else {\n> +\tset diffidtext [shortids $diffid]\n> +\tset whattext \"[mc \"revision\"] $diffidtext\"\n> +    }\n> +    set difffile \"\\[$diffidtext\\] [file tail $flist_menu_file]\"\n> +    set difffile [tk_getSaveFile -initialfile $difffile -title [mc \"Save file as\"] -parent .]\n> +    if {$difffile eq {}} {\n> +\treturn\n> +    }\n> +    save_file_from_commit $diffid:$flist_menu_file $difffile $whattext\n> +}\n> +\n>  proc external_diff {} {\n>      global nullid nullid2\n>      global flist_menu_file\n> -- \n> 1.8.3.3\n"}]}