3

When I click in a code area and then press control-a, I expect to see only the code in the code panel selected. Instead, everything on the page is selected. If I wanted to select everything on the page, then I would not have clicked in the code area.

Update: this is not an issue with short pieces of code, but for longer pieces, it sure is hard to copy just the code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Collections.Specialized;

using System.Runtime.InteropServices;
using System.EnterpriseServices;

using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Server;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.SOESupport;


//TODO: sign the project (project properties > signing tab > sign the assembly)
//      this is strongly suggested if the dll will be registered using regasm.exe <your>.dll /codebase


namespace RestSOE1
{
    [ComVisible(true)]
    [Guid("2d1eaa1c-c07c-47f1-b97e-b0730bbbf619")]
    [ClassInterface(ClassInterfaceType.None)]
    public class RestSOE1 : ServicedComponent, IServerObjectExtension, IObjectConstruct, IRESTRequestHandler
    {
        private string soe_name;

        private IPropertySet configProps;
        private IServerObjectHelper serverObjectHelper;
        private ServerLogger logger;
        private IRESTRequestHandler reqHandler;

        public RestSOE1()
        {
            soe_name = this.GetType().Name;
            logger = new ServerLogger();
            reqHandler = new SoeRestImpl(soe_name, CreateRestSchema()) as IRESTRequestHandler;
        }

        #region IServerObjectExtension Members

        public void Init(IServerObjectHelper pSOH)
        {
            serverObjectHelper = pSOH;
        }

        public void Shutdown()
        {
        }

        #endregion

        #region IObjectConstruct Members

        public void Construct(IPropertySet props)
        {
            configProps = props;
        }

        #endregion

        #region IRESTRequestHandler Members

        public string GetSchema()
        {
            return reqHandler.GetSchema();
        }

        public byte[] HandleRESTRequest(string Capabilities, string resourceName, string operationName, string operationInput, string outputFormat, string requestProperties, out string responseProperties)
        {
            return reqHandler.HandleRESTRequest(Capabilities, resourceName, operationName, operationInput, outputFormat, requestProperties, out responseProperties);
        }

        #endregion

        private RestResource CreateRestSchema()
        {
            RestResource rootRes = new RestResource(soe_name, false, RootResHandler);

            RestOperation sampleOper = new RestOperation("sampleOperation",
                                                      new string[] { "parm1", "parm2" },
                                                      new string[] { "json" },
                                                      SampleOperHandler);

            rootRes.operations.Add(sampleOper);

            return rootRes;
        }

        private byte[] RootResHandler(NameValueCollection boundVariables, string outputFormat, string requestProperties, out string responseProperties)
        {
            responseProperties = null;

            JsonObject result = new JsonObject();
            result.AddString("hello", "world");

            return Encoding.UTF8.GetBytes(result.ToJson());
        }

        private byte[] SampleOperHandler(NameValueCollection boundVariables,
                                                  JsonObject operationInput,
                                                      string outputFormat,
                                                      string requestProperties,
                                                  out string responseProperties)
        {
            responseProperties = null;

            string parm1Value;
            bool found = operationInput.TryGetString("parm1", out parm1Value);
            if (!found || string.IsNullOrEmpty(parm1Value))
                throw new ArgumentNullException("parm1");

            string parm2Value;
            found = operationInput.TryGetString("parm2", out parm2Value);
            if (!found || string.IsNullOrEmpty(parm2Value))
                throw new ArgumentNullException("parm2");

            JsonObject result = new JsonObject();
            result.AddString("parm1", parm1Value);
            result.AddString("parm2", parm2Value);

            return Encoding.UTF8.GetBytes(result.ToJson());
        }


    }
}
  • Select, then Ctrl-C is all that worked for me. – user681 May 27 '11 at 21:30
  • Sorry, I should have made it more clear that this is an issue when there's a lot of code, see revision. I thought there is an html tag that allows ctrl-a to select only what's in the div. – Kirk Kuykendall May 27 '11 at 21:55
  • could you provide other sites which do this correctly? I'm guessing it requires trapping things in Javascript and probably the implementation can be copied from elsewhere. – scw May 27 '11 at 22:12
  • Actually, maybe this should be a feature request, just a button that appears next to long code listings that allows user to copy to clipboard. I see now that ctrl-a is only expected to stay within a text area when the text is editable. (Like now as I type this comment). – Kirk Kuykendall May 27 '11 at 22:26
  • Sounds like the request for a code library link would be appropriate ( meta.gis.stackexchange.com/questions/462/… ) – user681 May 27 '11 at 23:30
4

When I click in a code area and then press control-a, I expect to see only the code in the code panel selected. Instead, everything on the page is selected. If I wanted to select everything on the page, then I would not have clicked in the code area.

That isn't how HTML selection works, though -- this might be an unreasonable expectation.

Also bear in mind we discourage posting giant blocks of code -- just post the relevant parts, the stuff necessary for the question or answer, and link to the complete code in pastebin or somewhere else off-site.

3

At https://tex.meta.stackexchange.com/questions/821/easy-way-to-copy-code-block/891#891, Martin Scharrer has written a Greasemonkey script that inserts a select all button under every chunk of code. When you click on it, the code chunk is selected, and you can copy it by pressing Ctrl + c. In its current form, the script only works on tex.stackexchange.com, but by inserting the line // @include http://*.stackexchange.com/* near the beginning, it can be made to work on all stackexchange sites.

1

For Firefox users, a simple solution for code within scrollable windows, such as your example, is to click in front of the first character of the code window and hold down Shift + Page Down until it reaches the bottom of the window. Voila, all the code is selected and you can then copy-paste as usual.

Note: You may have to use Shift + Down Arrow to get the last line. At least that was my experience with Firefox.

Note 2: This does not seem to work with Chrome or IE (tested on Windows 7).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .