• Login
sketchucation logo sketchucation
  • Login
ℹ️ GoFundMe | Our friend Gus Robatto needs some help in a challenging time Learn More

Setting file types in the savepanel

Scheduled Pinned Locked Moved Developers' Forum
21 Posts 8 Posters 1.8k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    tvcasualty
    last edited by 14 Sept 2013, 07:24

    Sorry to drudge up old news, but this is an embarrassingly old issue, be nice to have a filter option in the API by now.
    Here was my solution because I didn't like the fact that it could possibly overwrite a file accidentally using TIGs approach (untitled != untitled.txt for example). Anyhow it can be a burden to hit save twice, but I'd rather do that 100x then accidentally save over something important.

    Where:

    
    EXT = "txt"
    default_dir = "c;\\temp\\"
    default_file = "untitled"
    
    

    The following while loop:

    
    name_valid = false 
    while name_valid == false 
     path_to_save_to = UI.savepanel("Save Code File", default_dir, default_file)
     #path_to_save_to = path_to_save_to.tr("\\","/") # This maybe required.
     fileext = File.extname(path_to_save_to) # filename with prefix stripped
     filebase = File.basename(path_to_save_to, ".#{EXT}")
     #puts fileext.inspect
     if fileext == "" || fileext == nil
      default_file = filebase + ".#{EXT}"
      UI.messagebox "Oops! Including the file extension '#{EXT}'\nThis is an embarrassing workaround...\nPlease hit save again."
      #puts default_file.inspect
     else
      filename = filebase + ".#{EXT}"
      path_to_save_to = File.dirname(path_to_save_to) + "\\" + filename
      name_valid = true
     end
    end
    
    
    1 Reply Last reply Reply Quote 0
    • 1
    • 2
    • 2 / 2
    2 / 2
    • First post
      21/21
      Last post
    Buy SketchPlus
    Buy SUbD
    Buy WrapR
    Buy eBook
    Buy Modelur
    Buy Vertex Tools
    Buy SketchCuisine
    Buy FormFonts

    Advertisement