• 登入
sketchucation logo sketchucation
  • 登入
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Setting file types in the savepanel

已排程 已置頂 已鎖定 已移動 Developers' Forum
21 貼文 8 Posters 1.8k 瀏覽
正在載入更多貼文
  • 從舊到新
  • 從新到舊
  • 最多點贊
回覆
  • 在新貼文中回覆
登入後回覆
此主題已被刪除。只有擁有主題管理權限的使用者可以查看。
  • T 離線
    talig
    最後由 編輯 2009年4月23日 下午9:30

    Hi again everyone,
    I've got a simple one this time 😄
    I want to set the "save as type" value in the savepanel. To, let's say, *.csv. It's true that I can make the file be whatever I want it to be, but I'm thinking usability here.
    So - does anyone have a clue?
    Thanks,

    • Tali

    p.s. Thanks to you guys I'm drawing near to wrapping up this project I'm working on. 👍

    Avatar: all rights reserved to Bryan Eppihimer

    1 條回覆 最後回覆 回覆 引用 0
    • T 離線
      TIG Moderator
      最後由 編輯 2009年4月24日 上午11:51

      You can't specify a file-type but you can give the default file-name + .file-type-suffic

      filepath=UI.savepanel("DialogTitle","DirectoryPath","DefaultFileName.csv")
      

      that way at least the user starts off with a proper file name that they can mangle later...
      You can trap erroneous filepath names later. Let's say that the user inputs "MyFile" without the .csv suffix: use the variable 'filepath' to test it.

      filepath=filepath.tr("\\","/")#in case any PC ruby weirdness...
      filebase=File.basename(filepath,".csv")#name with suffix stripped
      filename=File.basename(filepath)#name with suffx attached
      if filebase != filename #it's NOT a .csv file
        UI.messagebox("Filename must end with '.csv' - it will be added...")# option error report
        filename=filebase+".csv"
        filepath=File.dirname(filepath)+filename
      end#if
      

      Now you can use 'filepath' to save the file etc...
      Alternatively you could pop up the error message and then immediately re-open the 'savepanel' - perhaps using the 'corrected name' as the new file's default-name - in case the user is likely to totally mistype...
      .

      TIG

      1 條回覆 最後回覆 回覆 引用 0
      • T 離線
        talig
        最後由 編輯 2009年4月24日 下午6:07

        Thanks TIG,
        I know I can set the default file name.
        But I find it puzzling that the list of file types exists but it's empty and can't be filled. This isn't the case when you're trying to save a model - so it must be possible somehow, and if not - I guess it's the most trivial wishlist item... 😞
        I'll wait to see if someone knows how to do this.

        Avatar: all rights reserved to Bryan Eppihimer

        1 條回覆 最後回覆 回覆 引用 0
        • W 離線
          WorCoder
          最後由 編輯 2010年10月20日 下午3:23

          Just getting this thread out of retirement...

          Is there any new solution to this?
          I would love to see this one fixed. (Meaning a possible mask application or anything for the filetype selector in the savepanel.)

          Regards 😎

          1 條回覆 最後回覆 回覆 引用 0
          • H 離線
            honoluludesktop
            最後由 編輯 2010年10月20日 下午7:49

            Jim, Thanks. I knew about the .ext bug making _.ext, but didn't know about using it with ""|nil. So, there is no way to force the savepanel to open with .ext in a predetermined folder?

            1 條回覆 最後回覆 回覆 引用 0
            • T 離線
              thomthom
              最後由 編輯 2010年10月20日 下午7:52

              Why (""|nil) instead if just nil ?

              Thomas Thomassen — SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 條回覆 最後回覆 回覆 引用 0
              • J 離線
                Jim
                最後由 編輯 2010年10月20日 下午7:53

                Apologies - that was just meant as a notation for either "" or nil.

                Hi

                1 條回覆 最後回覆 回覆 引用 0
                • T 離線
                  thomthom
                  最後由 編輯 2010年10月20日 下午7:55

                  Ah, gotcha!

                  Thomas Thomassen — SketchUp Monkey & Coding addict
                  List of my plugins and link to the CookieWare fund

                  1 條回覆 最後回覆 回覆 引用 0
                  • J 離線
                    Jim
                    最後由 編輯 2010年10月20日 下午8:04

                    @honoluludesktop said:

                    So, there is no way to force the savepanel to open with *.ext in a predetermined folder?

                    Not that I know.

                    Hi

                    1 條回覆 最後回覆 回覆 引用 0
                    • J 離線
                      Jim
                      最後由 編輯 2010年10月21日 上午12:04

                      Still can't add filetypes to the "Save as type" dropdown, as far as I know.

                      But you can provide a extension mask as follows:

                      UI.savepanel "Title", nil, "*.rb" (can use empty String or nil for middle param)

                      Note, if you try to provide a directory name (the 2nd parameter,) the file mask gets messed up - it's a bug (IMO.) The file mask asterisk will get translated into an underscore: " _.rb"

                      And this might only work on Windows, I don't know.

                      Also, to work around the bug it may be possible to use Dir.chdir() to set the default directory before calling savepanel. (Update: Looks like this doesn't work. Windows must store the MRU location somewhere.)

                      Hi

                      1 條回覆 最後回覆 回覆 引用 0
                      • T 離線
                        thomthom
                        最後由 編輯 2010年10月21日 上午8:56

                        It's been reported before - but it doesn't hurt reminding them...
                        http://forums.sketchucation.com/viewtopic.php?f=11&t=29023

                        Thomas Thomassen — SketchUp Monkey & Coding addict
                        List of my plugins and link to the CookieWare fund

                        1 條回覆 最後回覆 回覆 引用 0
                        • W 離線
                          WorCoder
                          最後由 編輯 2010年10月21日 上午9:01

                          Thanks for the effort, guys.
                          Sadly this doesn't really help.

                          Seems to me as more inconvenient to have to move to the desired folder every time.

                          What bugs me the most is, that one can't click save and then immediately start typing the filename, in the way that the whole line (including ".xxx")is highlighted.

                          Since there might be some not really intelligent people handling this, I would love a way for them to immediately start typing, but still have the right extension visible as well.
                          Do I have to file a bug-report to get this in or is there nothing one can do to try and get functionality of the filetype selector!?

                          1 條回覆 最後回覆 回覆 引用 0
                          • T 離線
                            TIG Moderator
                            最後由 編輯 2010年10月21日 上午9:25

                            If the users are so stupid why even give them the chance of saving the file in a weird folder or giving it a stupid name ?
                            Why not always locate and name the file 'with the model'.
                            First use a trap (puts "Save SKP!";return nil if model.path=="" in case your SKP is not saved.
                            You get the folder from folder=File.dirname(model.path)
                            You could then 'set' the file-name based on the model, so file=model.title+".xxx" or whatever file type suffix you want.
                            You could use the Scene name in the name too...
                            scene=model.pages.selected_page.name.gsub(/[^A-Za-z0-9_-]/,"_")
                            [The gsub is to avoid making a file name with 'illegal' characters like /:"etc]
                            Then file=model.title+"_"+scene+".xxx"
                            OR you could use a file name based on the 'date/time' which will always be different...
                            time=sprintf("%.1d\n",(Time.now.to_f*100))
                            Then file=model.title+"_"+time+".xxx"
                            Set the path=File.join(folder,file).tr("\\","/")
                            [The tr is only to tidy up if you are to display it later - e.g. in a confirming dialog - as you might get a mix of / and \ on a PC]
                            Now use the path to export, or save as a data file etc...
                            Alternatively you could let the user set the file name with a simple inputbox
                            results=inputbox(["File Name: "],[model.title],"Type in XXX File Name [WITHOUT a '.xxx' suffix]") return nil if not results file=(File.basename(results[0]).gsub(/[^A-Za-z0-9_-]/,"_"))+".xxx"
                            which traps 'stupid' input or file suffix...

                            TIG

                            1 條回覆 最後回覆 回覆 引用 0
                            • W 離線
                              WorCoder
                              最後由 編輯 2010年10月21日 上午10:33

                              Thanks for those tips! I really appreciate this.

                              I see your point. Since there are pro and dumb users, the features I would love to include are:

                              • selecting your own name for the file
                              • selecting your wished folder to store into
                              • keep "uneducated" users from messing up the filetype
                              • keep a clean interface for ease of use and esthetic reasons

                              And somehow I'm also on the point that talig mentioned

                              @talig said:

                              ...I find it puzzling that the list of file types exists but it's empty and can't be filled.

                              Mainly because I think this is just a basic functionality and I don't see the point in this option not being provided.
                              ☀

                              1 條回覆 最後回覆 回覆 引用 0
                              • W 離線
                                WorCoder
                                最後由 編輯 2010年10月21日 上午10:51

                                P.S.: I did send in a report, so maybe there might be a fix in the future...

                                1 條回覆 最後回覆 回覆 引用 0
                                • T 離線
                                  thomthom
                                  最後由 編輯 2010年10月21日 上午11:02

                                  @worcoder said:

                                  • keep "uneducated" users from messing up the filetype

                                  Can't you just correct the filename you are returned? If there is not file extension, automatically append it before saving? Since Windows since XP hide the file extension on known files many users are completely unaware of file extensions anyway.

                                  Thomas Thomassen — SketchUp Monkey & Coding addict
                                  List of my plugins and link to the CookieWare fund

                                  1 條回覆 最後回覆 回覆 引用 0
                                  • W 離線
                                    WorCoder
                                    最後由 編輯 2010年11月16日 下午3:09

                                    @thomthom said:

                                    many users are completely unaware of file extensions anyway.

                                    Sorry for the late reply, was on holiday...
                                    Sure I can correct the file extension, but I'd still love to have the nice looking "clean" solution with a working file type selector. 😉

                                    We'll see what the future brings.

                                    1 條回覆 最後回覆 回覆 引用 0
                                    • Dan RathbunD 離線
                                      Dan Rathbun
                                      最後由 編輯 2010年11月17日 上午3:33

                                      @thomthom said:

                                      Since Windows since XP hide the file extension on known files many users are completely unaware of file extensions anyway.

                                      Not a given.

                                      On all our machines (or any machine I work on,) I turn file extension display back ON.

                                      I'm not here much anymore.

                                      1 條回覆 最後回覆 回覆 引用 0
                                      • T 離線
                                        thomthom
                                        最後由 編輯 2010年11月17日 上午7:16

                                        @dan rathbun said:

                                        @thomthom said:

                                        Since Windows since XP hide the file extension on known files many users are completely unaware of file extensions anyway.

                                        Not a given.

                                        On all our machines (or any machine I work on,) I turn file extension display back ON.

                                        Yes - but by default XP hides it.

                                        Thomas Thomassen — SketchUp Monkey & Coding addict
                                        List of my plugins and link to the CookieWare fund

                                        1 條回覆 最後回覆 回覆 引用 0
                                        • Dan RathbunD 離線
                                          Dan Rathbun
                                          最後由 編輯 2010年11月17日 上午8:45

                                          @thomthom said:

                                          Yes - but by default XP hides it.

                                          Which is one of the dumbest things Microsoft does.

                                          I'm not here much anymore.

                                          1 條回覆 最後回覆 回覆 引用 0
                                          • 1
                                          • 2
                                          • 1 / 2
                                          • 第一個貼文
                                            最後的貼文
                                          Buy SketchPlus
                                          Buy SUbD
                                          Buy WrapR
                                          Buy eBook
                                          Buy Modelur
                                          Buy Vertex Tools
                                          Buy SketchCuisine
                                          Buy FormFonts

                                          Advertisement