让Notepad++拥有快速保存的功能

下载notepad++的代码,用Visual Studio 2005打开notepadplus.sln.
修改notepad_plus.cpp中的fileSave()方法,并重新编译。
修改后的代码如下,很初级的修改,还只适合自己使用。

bool Notepad_plus::fileSave()
{
    if (_pEditView->isCurrentDocDirty())
    {
        const char *fn = _pEditView->getCurrentTitle();
        if (Buffer::isUntitled(fn))
        {
            //return fileSaveAs();
            string fn_quickfile = "E://LouGnib4Office//PortableWork//20070705-myFiles//QuickSave//";
            const int temBufLen = 32;
            char tmpbuf[temBufLen];
            time_t ltime = time(0);
            struct tm *today;

            today = localtime(&ltime);
            strftime(tmpbuf, temBufLen, "%Y%m%d%H%M%S", today);

            fn_quickfile += tmpbuf;
            fn_quickfile += ".txt";

            const char *pfn = fn_quickfile.c_str();

            doSave(pfn, _pEditView->getCurrentBuffer().getUnicodeMode());
            _pEditView->setCurrentTitle(pfn);
            _pEditView->setCurrentDocReadOnly(false);
            _pDocTab->updateCurrentTabItem(PathFindFileName(pfn));
            setTitleWith(pfn);
            setLangStatus(_pEditView->getCurrentDocType());
            checkLangsMenu(-1);
            return true;
        }
        else
        {
            const NppGUI & nppgui = (NppParameters::getInstance())->getNppGUI();
            BackupFeature backup = nppgui._backup;
            if (backup == bak_simple)
            {
                //copy fn to fn.backup
                string fn_bak(fn);
                if ((nppgui._useDir) && (nppgui._backupDir[0] != '/0'))
                {
                    char path[MAX_PATH];
                    char *name;

                    strcpy(path, fn);
                    name = ::PathFindFileName(path);
                    fn_bak = nppgui._backupDir;
                    fn_bak += "//";
                    fn_bak += name;
                }
                else
                {
                    fn_bak = fn;
                }
                fn_bak += ".bak";
                ::CopyFile(fn, fn_bak.c_str(), FALSE);
            }
            else if (backup == bak_verbose)
            {
                char path[MAX_PATH];
                char *name;
                string fn_dateTime_bak;
               
                strcpy(path, fn);

                name = ::PathFindFileName(path);
                ::PathRemoveFileSpec(path);
               
                if ((nppgui._useDir) && (nppgui._backupDir[0] != '/0'))
                {//printStr(nppgui._backupDir);
                    fn_dateTime_bak = nppgui._backupDir;
                    fn_dateTime_bak += "//";
                }
                else
                {
                    const char *bakDir = "nppBackup";
                    fn_dateTime_bak = path;
                    fn_dateTime_bak += "//";
                    fn_dateTime_bak += bakDir;
                    fn_dateTime_bak += "//";

                    if (!::PathFileExists(fn_dateTime_bak.c_str()))
                    {
                        ::CreateDirectory(bakDir, NULL);
                    }
                }

                fn_dateTime_bak += name;

                const int temBufLen = 32;
                char tmpbuf[temBufLen];
                time_t ltime = time(0);
                struct tm *today;

                today = localtime(&ltime);
                strftime(tmpbuf, temBufLen, "%Y-%m-%d_%H%M%S", today);

                fn_dateTime_bak += ".";
                fn_dateTime_bak += tmpbuf;
                fn_dateTime_bak += ".bak";

                ::CopyFile(fn, fn_dateTime_bak.c_str(), FALSE);
            }
            return doSave(fn, _pEditView->getCurrentBuffer().getUnicodeMode());
        }
    }
    return false;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值